Replace select hold w/shake to submit

This commit is contained in:
RandyTheSilly committed 2026-10-30 22:01:02 -04:00
1 parent 74ef206883
commit d05443aa3d
1 file changed
+16 -4
+16 -4
View File
@@ -64,6 +64,7 @@ static bool s_skip_current_day = false;
static uint8_t s_current_triangle_num; 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_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];
@@ -75,6 +76,7 @@ static const GRect s_top_bar_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, s_edge_bar_h
static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height); static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height);
static const GColor s_primary_color = GColorJaegerGreen; static const GColor s_primary_color = GColorJaegerGreen;
//// alarm //// alarm
#define MAX_SECS_WITHOUT_INPUT 10
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);
@@ -447,7 +449,10 @@ static void update_for_new_triangle() {
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--;
if (s_current_triangle_num == 1) { if (s_current_triangle_num == 1) {
vibes_enqueue_custom_pattern(s_first_triangle_vibe_pattern); s_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
vibes_enqueue_custom_pattern(s_first_triangle_vibe_pattern);
}
} }
snprintf(s_countdown_buf, sizeof(s_countdown_buf), "%03u", s_countdown_int); snprintf(s_countdown_buf, sizeof(s_countdown_buf), "%03u", s_countdown_int);
text_layer_set_text(s_countdown_txt_layer, s_countdown_buf); text_layer_set_text(s_countdown_txt_layer, s_countdown_buf);
@@ -455,6 +460,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;
} }
right_triangle_layer_regen(s_triangle_layer); right_triangle_layer_regen(s_triangle_layer);
update_for_new_triangle(); update_for_new_triangle();
@@ -489,6 +496,7 @@ static void alarm_highlight_layer_update_proc(Layer *layer, GContext *ctx) {
} }
static void alarm_up_click_handler(void *recognizer, void *ctx) { static void alarm_up_click_handler(void *recognizer, void *ctx) {
s_secs_since_last_input = 0;
if (s_highlight_pos == 0) { if (s_highlight_pos == 0) {
s_highlight_pos = 2; s_highlight_pos = 2;
} else { } else {
@@ -498,6 +506,7 @@ static void alarm_up_click_handler(void *recognizer, void *ctx) {
} }
static void alarm_down_click_handler(void *recognizer, void *ctx) { static void alarm_down_click_handler(void *recognizer, void *ctx) {
s_secs_since_last_input = 0;
if (s_highlight_pos == 2) { if (s_highlight_pos == 2) {
s_highlight_pos = 0; s_highlight_pos = 0;
} else { } else {
@@ -507,10 +516,11 @@ static void alarm_down_click_handler(void *recognizer, void *ctx) {
} }
static void alarm_select_click_handler(void *recognizer, void *ctx) { static void alarm_select_click_handler(void *recognizer, void *ctx) {
s_secs_since_last_input = 0;
window_stack_push(s_drop_window, true); window_stack_push(s_drop_window, true);
} }
static void alarm_select_hold_handler(void *recognizer, void *ctx) { static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
// 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]) {
@@ -539,7 +549,6 @@ static void alarm_click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_UP, alarm_up_click_handler); window_single_click_subscribe(BUTTON_ID_UP, alarm_up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, alarm_down_click_handler); window_single_click_subscribe(BUTTON_ID_DOWN, alarm_down_click_handler);
window_single_click_subscribe(BUTTON_ID_SELECT, alarm_select_click_handler); window_single_click_subscribe(BUTTON_ID_SELECT, alarm_select_click_handler);
window_long_click_subscribe(BUTTON_ID_SELECT, 2500, alarm_select_hold_handler, NULL);
} }
static uint16_t menu_get_num_rows(MenuLayer *menu_layer, uint16_t section_index, void *context) { static uint16_t menu_get_num_rows(MenuLayer *menu_layer, uint16_t section_index, void *context) {
@@ -733,15 +742,19 @@ static void alarm_window_load() {
layer_add_child(window_layer, text_layer_get_layer(s_progress_txt_layer)); layer_add_child(window_layer, text_layer_get_layer(s_progress_txt_layer));
// configure UI around current triangle in s_triangle_layer // configure UI around current triangle in s_triangle_layer
s_current_triangle_num = 1;
s_secs_since_last_input = MAX_SECS_WITHOUT_INPUT;
update_for_new_triangle(); update_for_new_triangle();
// schedule recovery alarm and begin countdown :) // schedule recovery alarm and begin countdown :)
schedule_alarm(WAKE_RECOVERY_ALARM); schedule_alarm(WAKE_RECOVERY_ALARM);
accel_tap_service_subscribe(accel_tap_handler);
tick_timer_service_subscribe(SECOND_UNIT, alarm_seconds_handler); tick_timer_service_subscribe(SECOND_UNIT, alarm_seconds_handler);
} }
static void alarm_window_unload() { static void alarm_window_unload() {
tick_timer_service_unsubscribe(); tick_timer_service_unsubscribe();
accel_tap_service_unsubscribe();
text_layer_destroy(s_countdown_txt_layer); text_layer_destroy(s_countdown_txt_layer);
window_destroy(s_drop_window); window_destroy(s_drop_window);
text_layer_destroy(s_side_a_txt_layer); text_layer_destroy(s_side_a_txt_layer);
@@ -770,7 +783,6 @@ static void push_alarm_window() {
send_zap(settings.PavlokIntensity); send_zap(settings.PavlokIntensity);
} }
s_current_triangle_num = 1;
window_set_window_handlers( window_set_window_handlers(
s_window, s_window,
(WindowHandlers){.load = alarm_window_load, .unload = alarm_window_unload}); (WindowHandlers){.load = alarm_window_load, .unload = alarm_window_unload});