From 2824a62908b9f7b6e24b25c5ba46e0f3287ae80f Mon Sep 17 00:00:00 2001 From: David Volovskiy Date: Sun, 4 Aug 2024 09:43:56 -0400 Subject: [PATCH] Bugfix on not registering the top of an hour --- movement/movement.c | 22 +++++++++++++++---- movement/movement.h | 2 +- movement/watch_faces/clock/clock_face.c | 7 +----- .../watch_faces/clock/simple_clock_face.c | 7 +----- watch-library/shared/watch/watch_utility.c | 6 ++--- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/movement/movement.c b/movement/movement.c index 256aa8a..aead621 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -430,8 +430,8 @@ uint8_t movement_claim_backup_register(void) { return movement_state.next_available_backup_register++; } -uint8_t check_and_act_on_daylight_savings(watch_date_time date_time) { - if (movement_state.settings.bit.dst_active) return date_time.unit.hour; +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(); @@ -439,15 +439,17 @@ uint8_t check_and_act_on_daylight_savings(watch_date_time date_time) { clear_dst_skip_rolling_back(); } else if (dst_result == DST_ENDING && !dst_skip_rolling_back) { - set_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 date_time.unit.hour; + return false; } int16_t get_timezone_offset(uint8_t timezone_idx, watch_date_time date_time) { @@ -476,6 +478,18 @@ void app_init(void) { movement_state.settings.bit.le_interval = MOVEMENT_DEFAULT_LOW_ENERGY_INTERVAL; movement_state.settings.bit.led_duration = MOVEMENT_DEFAULT_LED_DURATION; movement_state.settings.bit.dst_active = MOVEMENT_DEFAULT_DST_ACTIVE; + +#ifdef MAKEFILE_TIMEZONE + timezone_offsets = dst_occurring(watch_rtc_get_date_time()) ? movement_timezone_dst_offsets : movement_timezone_offsets; + for (int i = 0; i < NUM_TIME_ZONES; i++) { + if (timezone_offsets[i] == MAKEFILE_TIMEZONE) { + movement_state.settings.bit.time_zone = i; + break; + } + } +#else + movement_state.settings.bit.time_zone = 35; // Atlantic Time as default +#endif movement_state.light_ticks = -1; movement_state.alarm_ticks = -1; movement_state.next_available_backup_register = 4; diff --git a/movement/movement.h b/movement/movement.h index 6dd38ba..e75f4e8 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -313,7 +313,7 @@ void movement_play_alarm(void); void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note); uint8_t movement_claim_backup_register(void); -uint8_t check_and_act_on_daylight_savings(watch_date_time date_time); // Returns the currently set hour +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 af601ce..e29d587 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -284,12 +284,7 @@ bool clock_face_wants_background_task(movement_settings_t *settings, void *conte (void) settings; clock_state_t *state = (clock_state_t *) context; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t hour_dst = check_and_act_on_daylight_savings(date_time); - if(hour_dst != date_time.unit.hour) { - char buf[3 + 1]; - sprintf(buf, "%2d", hour_dst); - watch_display_string(buf, 4); - } + check_and_act_on_daylight_savings(date_time); if (!state->time_signal_enabled) return false; 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 20dfb54..118dc32 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -154,12 +154,7 @@ bool simple_clock_face_wants_background_task(movement_settings_t *settings, void (void) settings; simple_clock_state_t *state = (simple_clock_state_t *)context; watch_date_time date_time = watch_rtc_get_date_time(); - uint8_t hour_dst = check_and_act_on_daylight_savings(date_time); - if(hour_dst != date_time.unit.hour) { - char buf[3 + 1]; - sprintf(buf, "%2d", hour_dst); - watch_display_string(buf, 4); - } + check_and_act_on_daylight_savings(date_time); if (!state->signal_enabled) return false; return date_time.unit.minute == 0; diff --git a/watch-library/shared/watch/watch_utility.c b/watch-library/shared/watch/watch_utility.c index 5938b60..3dfb37b 100644 --- a/watch-library/shared/watch/watch_utility.c +++ b/watch-library/shared/watch/watch_utility.c @@ -106,10 +106,10 @@ uint8_t get_dst_status(watch_date_time date_time) { dst_end_time.unit.day = 15 - watch_utility_get_iso8601_weekday_number(dst_end_time.unit.year + WATCH_RTC_REFERENCE_YEAR, dst_end_time.unit.month, 1); unix_dst_end_time = watch_utility_date_time_to_unix_time(dst_end_time, 0); - if (date_time.unit.second > 45) // In emu, it's been seen that we may trigger at 59sec rather than exactly 0 each time - date_time.unit.minute = (date_time.unit.minute + 1) % 60; - date_time.unit.second = 0; unix_curr_time = watch_utility_date_time_to_unix_time(date_time, 0); + unix_curr_time -= date_time.unit.second; + if (date_time.unit.second > 45) // In emu, it's been seen that we may trigger at 59sec rather than exactly 0 each time + unix_curr_time += 60; if (unix_curr_time == unix_dst_start_time) return DST_STARTING; if (unix_curr_time == unix_dst_end_time) return DST_ENDING;