From 0ef80b62da5ada255ca1968e7437cb66606bd78d Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Sat, 14 Jan 2023 14:21:04 -0500 Subject: add movement_default_loop_handler, test with default watch faces --- movement/movement.c | 20 ++++++++++++++++++++ movement/movement.h | 3 +++ movement/template/template.c | 16 +++++++++------- movement/watch_faces/clock/simple_clock_face.c | 8 +------- movement/watch_faces/clock/world_clock_face.c | 8 +------- movement/watch_faces/complication/moon_phase_face.c | 8 +------- movement/watch_faces/complication/stopwatch_face.c | 5 +---- .../watch_faces/complication/sunrise_sunset_face.c | 7 +------ movement/watch_faces/settings/preferences_face.c | 8 ++++++-- movement/watch_faces/settings/set_time_face.c | 2 +- 10 files changed, 44 insertions(+), 41 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 6c5f93a0..05da1800 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -218,6 +218,26 @@ void movement_illuminate_led(void) { } } +bool movement_default_loop_handler(movement_event_t event, movement_settings_t *settings) { + (void)settings; + + switch (event.event_type) { + case EVENT_MODE_BUTTON_UP: + movement_move_to_next_face(); + break; + case EVENT_LIGHT_BUTTON_DOWN: + movement_illuminate_led(); + break; + case EVENT_MODE_LONG_PRESS: + movement_move_to_face(0); + break; + default: + break; + } + + return true; +} + void movement_move_to_face(uint8_t watch_face_index) { movement_state.watch_face_changed = true; movement_state.next_watch_face = watch_face_index; diff --git a/movement/movement.h b/movement/movement.h index 7b5c4647..66bf6af4 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -285,6 +285,9 @@ typedef struct { void movement_move_to_face(uint8_t watch_face_index); void movement_move_to_next_face(void); + +bool movement_default_loop_handler(movement_event_t event, movement_settings_t *settings); + void movement_illuminate_led(void); void movement_request_tick_frequency(uint8_t freq); diff --git a/movement/template/template.c b/movement/template/template.c index 91611d08..ea1d05a0 100644 --- a/movement/template/template.c +++ b/movement/template/template.c @@ -53,13 +53,10 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t * case EVENT_TICK: // If needed, update your display here. break; - case EVENT_MODE_BUTTON_UP: - // You shouldn't need to change this case; Mode almost always moves to the next watch face. - movement_move_to_next_face(); - break; case EVENT_LIGHT_BUTTON_UP: - // If you have other uses for the Light button, you can opt not to illuminate the LED for this event. - movement_illuminate_led(); + // You can use the Light button for your own purposes. Note that by default, Movement will also + // illuminatethe LED in response to EVENT_LIGHT_BUTTON_DOWN; to suppress that behavior, add an + // empty case for EVENT_LIGHT_BUTTON_DOWN. break; case EVENT_ALARM_BUTTON_UP: // Just in case you have need for another button. @@ -76,7 +73,12 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t * // watch_start_tick_animation(500); break; default: - break; + // Movement's default loop handler will step in for any cases you don't handle above: + // * EVENT_LIGHT_BUTTON_DOWN lights the LED + // * EVENT_ALARM_BUTTON_UP moves to the next watch face in the list + // * EVENT_MODE_LONG_PRESS returns to the first watch face in the list + // You can override any of these behaviors by adding a case for these events to this switch statement. + return movement_default_loop_handler(event, settings); } // return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here, diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index 76055998..fbc2c4b3 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -128,12 +128,6 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting // handle alarm indicator if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state); break; - case EVENT_MODE_BUTTON_UP: - movement_move_to_next_face(); - return false; - case EVENT_LIGHT_BUTTON_DOWN: - movement_illuminate_led(); - break; case EVENT_ALARM_LONG_PRESS: state->signal_enabled = !state->signal_enabled; if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); @@ -145,7 +139,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting movement_play_signal(); break; default: - break; + return movement_default_loop_handler(event, settings); } return true; diff --git a/movement/watch_faces/clock/world_clock_face.c b/movement/watch_faces/clock/world_clock_face.c index 4004bab2..b12d9cdf 100644 --- a/movement/watch_faces/clock/world_clock_face.c +++ b/movement/watch_faces/clock/world_clock_face.c @@ -113,18 +113,12 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se } watch_display_string(buf, pos); break; - case EVENT_MODE_BUTTON_UP: - movement_move_to_next_face(); - return false; - case EVENT_LIGHT_BUTTON_DOWN: - movement_illuminate_led(); - break; case EVENT_ALARM_LONG_PRESS: movement_request_tick_frequency(4); state->current_screen = 1; break; default: - break; + return movement_default_loop_handler(event, settings); } return true; diff --git a/movement/watch_faces/complication/moon_phase_face.c b/movement/watch_faces/complication/moon_phase_face.c index eb919375..9aac374a 100644 --- a/movement/watch_faces/complication/moon_phase_face.c +++ b/movement/watch_faces/complication/moon_phase_face.c @@ -155,12 +155,6 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings, watch_display_string(" ", 8); if (!watch_tick_animation_is_running()) watch_start_tick_animation(1000); break; - case EVENT_MODE_BUTTON_UP: - movement_move_to_next_face(); - break; - case EVENT_LIGHT_BUTTON_DOWN: - movement_illuminate_led(); - break; case EVENT_ALARM_BUTTON_UP: // Pressing the alarm adds an offset of one day to the displayed value, // so you can see moon phases in the future. @@ -171,7 +165,7 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings, // QUESTION: Should timeout reset offset to 0? break; default: - break; + return movement_default_loop_handler(event, settings); } return true; diff --git a/movement/watch_faces/complication/stopwatch_face.c b/movement/watch_faces/complication/stopwatch_face.c index 2a69e9d5..03a74697 100644 --- a/movement/watch_faces/complication/stopwatch_face.c +++ b/movement/watch_faces/complication/stopwatch_face.c @@ -107,9 +107,6 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, _stopwatch_face_update_display(stopwatch_state, true); } break; - case EVENT_MODE_BUTTON_UP: - movement_move_to_next_face(); - break; case EVENT_LIGHT_BUTTON_DOWN: movement_illuminate_led(); if (!stopwatch_state->running) { @@ -161,7 +158,7 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, } break; default: - break; + return movement_default_loop_handler(event, settings); } return true; diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 7807de83..82de9c6e 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -339,9 +339,6 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti _sunrise_sunset_face_update_settings_display(event, state); } break; - case EVENT_MODE_BUTTON_UP: - movement_move_to_next_face(); - break; case EVENT_LIGHT_BUTTON_DOWN: if (state->page) { state->active_digit++; @@ -360,8 +357,6 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti _sunrise_sunset_face_update(settings, state); } break; - case EVENT_LIGHT_BUTTON_UP: - break; case EVENT_ALARM_BUTTON_UP: if (state->page) { _sunrise_sunset_face_advance_digit(state); @@ -393,7 +388,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti } break; default: - break; + return movement_default_loop_handler(event, settings); } return true; diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c index 790c9de5..d3e62f74 100644 --- a/movement/watch_faces/settings/preferences_face.c +++ b/movement/watch_faces/settings/preferences_face.c @@ -56,11 +56,15 @@ void preferences_face_activate(movement_settings_t *settings, void *context) { bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { uint8_t current_page = *((uint8_t *)context); switch (event.event_type) { + case EVENT_TICK: + case EVENT_ACTIVATE: + // Do nothing; handled below. + break; case EVENT_MODE_BUTTON_UP: watch_set_led_off(); movement_move_to_next_face(); return false; - case EVENT_LIGHT_BUTTON_UP: + case EVENT_LIGHT_BUTTON_DOWN: current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFEFENCES; *((uint8_t *)context) = current_page; break; @@ -93,7 +97,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings movement_move_to_face(0); break; default: - break; + return movement_default_loop_handler(event, settings); } watch_display_string((char *)preferences_face_titles[current_page], 0); diff --git a/movement/watch_faces/settings/set_time_face.c b/movement/watch_faces/settings/set_time_face.c index f6ac4935..bfaea9fc 100644 --- a/movement/watch_faces/settings/set_time_face.c +++ b/movement/watch_faces/settings/set_time_face.c @@ -128,7 +128,7 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v movement_move_to_face(0); break; default: - break; + return movement_default_loop_handler(event, settings); } char buf[11]; -- cgit v1.2.3