From 598e87618654c53a5a41e4a77b981b07c738283f Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sun, 4 Aug 2024 10:11:33 -0400 Subject: [PATCH] check_and_act_on_daylight_savings now only occurs in one spot --- movement/movement.c | 48 ++++++++++--------- movement/movement.h | 1 - movement/watch_faces/clock/clock_face.c | 4 +- .../clock/minute_repeater_decimal_face.c | 4 +- .../clock/repetition_minute_face.c | 4 +- .../clock/simple_clock_bin_led_face.c | 4 +- .../watch_faces/clock/simple_clock_face.c | 4 +- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index aead621..ebd831f 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -247,6 +247,31 @@ static inline void _movement_disable_fast_tick_if_possible(void) { } } +static bool _check_and_act_on_daylight_savings(void) { + if (!movement_state.settings.bit.dst_active) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + // No need for all of the unix time calculations for times not at the beginning or end of the hour + if (date_time.unit.minute > 1 && date_time.unit.minute < 59) return false; + uint8_t dst_result = get_dst_status(date_time); + bool dst_skip_rolling_back = get_dst_skip_rolling_back(); + + if (dst_skip_rolling_back && (dst_result == DST_ENDED)) { + clear_dst_skip_rolling_back(); + } + else if (dst_result == DST_ENDING && !dst_skip_rolling_back) { + date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24; + watch_rtc_set_date_time(date_time); + set_dst_skip_rolling_back(); + return true; + } + else if (dst_result == DST_STARTING) { + date_time.unit.hour = (date_time.unit.hour + 1) % 24; + watch_rtc_set_date_time(date_time); + return true; + } + return false; +} + static void _movement_handle_background_tasks(void) { for(uint8_t i = 0; i < MOVEMENT_NUM_FACES; i++) { // For each face, if the watch face wants a background task... @@ -256,6 +281,7 @@ static void _movement_handle_background_tasks(void) { watch_faces[i].loop(background_event, &movement_state.settings, watch_face_contexts[i]); } } + _check_and_act_on_daylight_savings(); movement_state.needs_background_tasks_handled = false; } @@ -430,28 +456,6 @@ uint8_t movement_claim_backup_register(void) { return movement_state.next_available_backup_register++; } -bool check_and_act_on_daylight_savings(watch_date_time date_time) { - if (!movement_state.settings.bit.dst_active) return false; - uint8_t dst_result = get_dst_status(date_time); - bool dst_skip_rolling_back = get_dst_skip_rolling_back(); - - if (dst_skip_rolling_back && (dst_result == DST_ENDED)) { - clear_dst_skip_rolling_back(); - } - else if (dst_result == DST_ENDING && !dst_skip_rolling_back) { - date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24; - watch_rtc_set_date_time(date_time); - set_dst_skip_rolling_back(); - return true; - } - else if (dst_result == DST_STARTING) { - date_time.unit.hour = (date_time.unit.hour + 1) % 24; - watch_rtc_set_date_time(date_time); - return true; - } - return false; -} - int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) { if (!movement_state.settings.bit.dst_active) return movement_timezone_offsets[timezone_idx]; if (dst_occurring(date_time)) diff --git a/movement/movement.h b/movement/movement.h index e75f4e8..d0595fb 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -313,7 +313,6 @@ void movement_play_alarm(void); void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note); uint8_t movement_claim_backup_register(void); -bool check_and_act_on_daylight_savings(watch_date_time date_time); // Returns if the time was changed due to DST int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time); #endif // MOVEMENT_H_ diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index e29d587..eab5cd8 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -283,9 +283,9 @@ void clock_face_resign(movement_settings_t *settings, void *context) { bool clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; clock_state_t *state = (clock_state_t *) context; - watch_date_time date_time = watch_rtc_get_date_time(); - check_and_act_on_daylight_savings(date_time); if (!state->time_signal_enabled) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/minute_repeater_decimal_face.c b/movement/watch_faces/clock/minute_repeater_decimal_face.c index ab0e6de..2cedc30 100644 --- a/movement/watch_faces/clock/minute_repeater_decimal_face.c +++ b/movement/watch_faces/clock/minute_repeater_decimal_face.c @@ -230,9 +230,9 @@ void minute_repeater_decimal_face_resign(movement_settings_t *settings, void *co bool minute_repeater_decimal_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; minute_repeater_decimal_state_t *state = (minute_repeater_decimal_state_t *)context; - watch_date_time date_time = watch_rtc_get_date_time(); - check_and_act_on_daylight_savings(date_time); if (!state->signal_enabled) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c index 1afc4ce..e9e5e31 100644 --- a/movement/watch_faces/clock/repetition_minute_face.c +++ b/movement/watch_faces/clock/repetition_minute_face.c @@ -213,9 +213,9 @@ void repetition_minute_face_resign(movement_settings_t *settings, void *context) bool repetition_minute_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; repetition_minute_state_t *state = (repetition_minute_state_t *)context; - watch_date_time date_time = watch_rtc_get_date_time(); - check_and_act_on_daylight_savings(date_time); if (!state->signal_enabled) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/simple_clock_bin_led_face.c b/movement/watch_faces/clock/simple_clock_bin_led_face.c index 1762cfa..cf39c18 100644 --- a/movement/watch_faces/clock/simple_clock_bin_led_face.c +++ b/movement/watch_faces/clock/simple_clock_bin_led_face.c @@ -214,9 +214,9 @@ void simple_clock_bin_led_face_resign(movement_settings_t *settings, void *conte bool simple_clock_bin_led_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; simple_clock_bin_led_state_t *state = (simple_clock_bin_led_state_t *)context; - watch_date_time date_time = watch_rtc_get_date_time(); - check_and_act_on_daylight_savings(date_time); if (!state->signal_enabled) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + return date_time.unit.minute == 0; } diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index 118dc32..fbc2c4b 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -153,9 +153,9 @@ void simple_clock_face_resign(movement_settings_t *settings, void *context) { bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; simple_clock_state_t *state = (simple_clock_state_t *)context; - watch_date_time date_time = watch_rtc_get_date_time(); - check_and_act_on_daylight_savings(date_time); if (!state->signal_enabled) return false; + watch_date_time date_time = watch_rtc_get_date_time(); + return date_time.unit.minute == 0; }