]> git.earman.xyz Git - sensor-watch.git/commitdiff
Bugfix on not registering the top of an hour
authorDavid Volovskiy <devolov@gmail.com>
Sun, 4 Aug 2024 13:43:56 +0000 (09:43 -0400)
committerDavid Volovskiy <devolov@gmail.com>
Sun, 4 Aug 2024 13:53:04 +0000 (09:53 -0400)
movement/movement.c
movement/movement.h
movement/watch_faces/clock/clock_face.c
movement/watch_faces/clock/simple_clock_face.c
watch-library/shared/watch/watch_utility.c

index 256aa8a84d33187a7d2545cdc8df054d93d48e03..aead62107701c8faf886a45880854799ea612775 100644 (file)
@@ -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;
index 6dd38ba7f32d87abb8ac181099ac1befce9d9585..e75f4e8dc0b35ef36c7c0db5bf93063436722190 100644 (file)
@@ -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_
index af601ce77167f2df87c3308df3d08af50ece2de0..e29d587cbf97b6ac1f71e8a7553f2d020d617c43 100644 (file)
@@ -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;
index 20dfb54479ccc4d1b07f1ea0d28440f77a02c42f..118dc32dccdfd82000d36b02e49f1d6775c2b3f7 100644 (file)
@@ -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;
index 5938b60636bd0ce6f449d14e935d85ca404adfcc..3dfb37ba58d2faa2b2e28232d8acfca5de984e1b 100644 (file)
@@ -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;