From e2cba9f2f2ed43a9ec4f35749867190aa08de9f9 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:36:34 -0300 Subject: [PATCH] faces/clock: simplify alarm indication function Deduplicates state in the clock state and movement settings. Makes the code simpler. Also makes it use the correct indicator. For some reason it had been switched with the hourly chime indicator. WATCH_INDICATOR_BELL The small bell indicating that an alarm is set. WATCH_INDICATOR_SIGNAL The hourly signal indicator. Also useful for indicating that sensors are on. --- movement/watch_faces/clock/clock_face.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 24e33c9c..ec0afe86 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -34,7 +34,6 @@ typedef struct { uint8_t watch_face_index; bool signal_enabled; bool battery_low; - bool alarm_enabled; } clock_state_t; static void clock_indicate(WatchIndicatorSegment indicator, bool on) { @@ -45,10 +44,8 @@ static void clock_indicate(WatchIndicatorSegment indicator, bool on) { } } -static void _update_alarm_indicator(bool settings_alarm_enabled, clock_state_t *state) { - state->alarm_enabled = settings_alarm_enabled; - if (state->alarm_enabled) watch_set_indicator(WATCH_INDICATOR_SIGNAL); - else watch_clear_indicator(WATCH_INDICATOR_SIGNAL); +static void clock_indicate_alarm(movement_settings_t *settings) { + clock_indicate(WATCH_INDICATOR_BELL, settings->bit.alarm_enabled); } void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { @@ -64,7 +61,7 @@ void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v } void clock_face_activate(movement_settings_t *settings, void *context) { - clock_state_t *state = (clock_state_t *) context; + clock_state_t *clock = (clock_state_t *) context; if (watch_tick_animation_is_running()) watch_stop_tick_animation(); @@ -74,13 +71,12 @@ void clock_face_activate(movement_settings_t *settings, void *context) { if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); else watch_clear_indicator(WATCH_INDICATOR_BELL); - // show alarm indicator if there is an active alarm - _update_alarm_indicator(settings->bit.alarm_enabled, state); + clock_indicate_alarm(settings); watch_set_colon(); // this ensures that none of the timestamp fields will match, so we can re-render them all. - state->previous_date_time = 0xFFFFFFFF; + clock->previous_date_time = 0xFFFFFFFF; } bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { @@ -142,8 +138,10 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void } } watch_display_string(buf, pos); + // handle alarm indicator - if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state); + clock_indicate_alarm(settings); + break; case EVENT_ALARM_LONG_PRESS: state->signal_enabled = !state->signal_enabled;