Debounce shake to submit
This commit is contained in:
1 parent
d05443aa3d
commit
8820df1a85
1 file changed
+23
-3
+23
-3
@@ -65,6 +65,7 @@ static uint8_t s_current_triangle_num;
|
|||||||
static uint8_t s_solution_indices[3];
|
static uint8_t s_solution_indices[3];
|
||||||
static uint8_t s_selected_indices[3] = {9, 9, 9};
|
static uint8_t s_selected_indices[3] = {9, 9, 9};
|
||||||
static uint8_t s_secs_since_last_input;
|
static uint8_t s_secs_since_last_input;
|
||||||
|
static uint8_t s_shake_cooldown;
|
||||||
static uint8_t s_countdown_int = 0;
|
static uint8_t s_countdown_int = 0;
|
||||||
static char s_countdown_buf[4];
|
static char s_countdown_buf[4];
|
||||||
static char s_progress_buf[9];
|
static char s_progress_buf[9];
|
||||||
@@ -77,6 +78,7 @@ static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar
|
|||||||
static const GColor s_primary_color = GColorJaegerGreen;
|
static const GColor s_primary_color = GColorJaegerGreen;
|
||||||
//// alarm
|
//// alarm
|
||||||
#define MAX_SECS_WITHOUT_INPUT 10
|
#define MAX_SECS_WITHOUT_INPUT 10
|
||||||
|
#define SHAKE_COOLDOWN_SECS 2
|
||||||
static const uint8_t s_drop_height = 22;
|
static const uint8_t s_drop_height = 22;
|
||||||
static const GRect s_drop_function_grect = GRect(PBL_IF_ROUND_ELSE(55, 45), s_bottom_bar_grect.origin.y + ((s_bottom_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(s_drop_height - 1, s_drop_height / 2)), 50, s_drop_height);
|
static const GRect s_drop_function_grect = GRect(PBL_IF_ROUND_ELSE(55, 45), s_bottom_bar_grect.origin.y + ((s_bottom_bar_grect.size.h / 2) - PBL_IF_ROUND_ELSE(s_drop_height - 1, s_drop_height / 2)), 50, s_drop_height);
|
||||||
static const GRect s_drop_over_grect = GRect(s_drop_function_grect.origin.x + 78, s_drop_function_grect.origin.y - 13, s_drop_function_grect.size.w + 1, s_drop_function_grect.size.h);
|
static const GRect s_drop_over_grect = GRect(s_drop_function_grect.origin.x + 78, s_drop_function_grect.origin.y - 13, s_drop_function_grect.size.w + 1, s_drop_function_grect.size.h);
|
||||||
@@ -446,10 +448,23 @@ static void update_for_new_triangle() {
|
|||||||
text_layer_set_text(s_progress_txt_layer, s_progress_buf);
|
text_layer_set_text(s_progress_txt_layer, s_progress_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void increment_secs_since_last_input() {
|
||||||
|
if (s_secs_since_last_input < 10) {
|
||||||
|
s_secs_since_last_input++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void decrement_shake_cooldown() {
|
||||||
|
if (s_shake_cooldown != 0) {
|
||||||
|
s_shake_cooldown--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
|
static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed) {
|
||||||
s_countdown_int--;
|
s_countdown_int--;
|
||||||
|
decrement_shake_cooldown();
|
||||||
if (s_current_triangle_num == 1) {
|
if (s_current_triangle_num == 1) {
|
||||||
s_secs_since_last_input++;
|
increment_secs_since_last_input();
|
||||||
if (s_secs_since_last_input >= MAX_SECS_WITHOUT_INPUT) { // pause vibrations during user input; this fixes shake detection and saves battery
|
if (s_secs_since_last_input >= MAX_SECS_WITHOUT_INPUT) { // pause vibrations during user input; this fixes shake detection and saves battery
|
||||||
vibes_enqueue_custom_pattern(s_first_triangle_vibe_pattern);
|
vibes_enqueue_custom_pattern(s_first_triangle_vibe_pattern);
|
||||||
}
|
}
|
||||||
@@ -460,9 +475,8 @@ static void alarm_seconds_handler(struct tm *tick_time, TimeUnits units_changed)
|
|||||||
send_zap(settings.PavlokIntensity);
|
send_zap(settings.PavlokIntensity);
|
||||||
if (s_current_triangle_num > 1) {
|
if (s_current_triangle_num > 1) {
|
||||||
s_current_triangle_num--;
|
s_current_triangle_num--;
|
||||||
} else {
|
|
||||||
s_secs_since_last_input = 10;
|
|
||||||
}
|
}
|
||||||
|
s_secs_since_last_input = 10;
|
||||||
right_triangle_layer_regen(s_triangle_layer);
|
right_triangle_layer_regen(s_triangle_layer);
|
||||||
update_for_new_triangle();
|
update_for_new_triangle();
|
||||||
}
|
}
|
||||||
@@ -521,6 +535,10 @@ static void alarm_select_click_handler(void *recognizer, void *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
|
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
|
||||||
|
if (s_shake_cooldown != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check solution
|
// check solution
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
if (s_selected_indices[i] != s_solution_indices[i]) {
|
if (s_selected_indices[i] != s_solution_indices[i]) {
|
||||||
@@ -542,6 +560,8 @@ static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
|
|||||||
update_for_new_triangle();
|
update_for_new_triangle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_shake_cooldown = SHAKE_COOLDOWN_SECS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void alarm_click_config_provider(void *ctx) {
|
static void alarm_click_config_provider(void *ctx) {
|
||||||
|
|||||||
Reference in new issue
Block a user