]> git.earman.xyz Git - sensor-watch.git/commitdiff
Made the faces I care about not need to continuously re-find the timezone
authorDavid Volovskiy <devolov@gmail.com>
Fri, 2 Aug 2024 11:37:30 +0000 (07:37 -0400)
committerDavid Volovskiy <devolov@gmail.com>
Fri, 2 Aug 2024 11:37:30 +0000 (07:37 -0400)
movement/watch_faces/clock/world_clock2_face.c
movement/watch_faces/clock/world_clock2_face.h
movement/watch_faces/clock/world_clock_face.c
movement/watch_faces/clock/world_clock_face.h
movement/watch_faces/complication/moon_phase_face.c
movement/watch_faces/complication/sunrise_sunset_face.c
movement/watch_faces/complication/sunrise_sunset_face.h

index 6ff806bf9ed8920dd505903735653f2c7c943798..cf37a4092c50b5d20b6f2f2ef6d539832383028b 100644 (file)
@@ -154,6 +154,7 @@ void world_clock2_face_activate(movement_settings_t *settings, void *context)
             movement_request_tick_frequency(4);
             break;
     }
+    state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
     refresh_face = true;
 }
 
@@ -165,7 +166,6 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
     uint32_t timestamp;
     uint32_t previous_date_time;
     watch_date_time date_time;
-    int16_t tz;
 
     switch (event.event_type) {
        case EVENT_ACTIVATE:
@@ -184,9 +184,8 @@ static bool mode_display(movement_event_t event, movement_settings_t *settings,
 
             /* Determine current time at time zone and store date/time */
            date_time = watch_rtc_get_date_time();
-        tz = get_timezone_offset(settings->bit.time_zone, date_time);
-           timestamp = watch_utility_date_time_to_unix_time(date_time, tz * 60);
-           date_time = watch_utility_date_time_from_unix_time(timestamp, tz * 60);
+           timestamp = watch_utility_date_time_to_unix_time(date_time, state->tz * 60);
+           date_time = watch_utility_date_time_from_unix_time(timestamp, state->tz * 60);
            previous_date_time = state->previous_date_time;
            state->previous_date_time = date_time.reg;
 
@@ -286,7 +285,7 @@ static bool mode_settings(movement_event_t event, movement_settings_t *settings,
                 watch_clear_indicator(WATCH_INDICATOR_PM);
                 refresh_face = false;
             }
-           result = div(get_timezone_offset(state->current_zone, watch_rtc_get_date_time()), 60);
+           result = div(state->tz, 60);
            hours = result.quot;
            minutes = result.rem;
 
index 0baac2123b17c453f4c1150d24d37a82cb8abbc8..efc107e12684e7052d97abe02b63af3b978e89ef 100644 (file)
@@ -104,6 +104,7 @@ typedef struct {
     world_clock2_mode_t current_mode;
     uint8_t current_zone;
     uint32_t previous_date_time;
+    int16_t tz;
 } world_clock2_state_t;
 
 void world_clock2_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr);
index c34db921fdddf99f11b9a39973125c714f2fb64f..e7f393e8e8b6ee786e499a99a067a1196922c6ba 100644 (file)
@@ -54,13 +54,13 @@ void world_clock_face_activate(movement_settings_t *settings, void *context) {
 static bool world_clock_face_do_display_mode(movement_event_t event, movement_settings_t *settings, world_clock_state_t *state) {
     char buf[11];
     uint8_t pos;
-    int16_t tz;
 
     uint32_t timestamp;
     uint32_t previous_date_time;
     watch_date_time date_time;
     switch (event.event_type) {
         case EVENT_ACTIVATE:
+            state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
             if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H);
             watch_set_colon();
             state->previous_date_time = 0xFFFFFFFF;
@@ -68,9 +68,8 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
         case EVENT_TICK:
         case EVENT_LOW_ENERGY_UPDATE:
             date_time = watch_rtc_get_date_time();
-            tz = get_timezone_offset(settings->bit.time_zone, date_time);
-            timestamp = watch_utility_date_time_to_unix_time(date_time, tz * 60);
-            date_time = watch_utility_date_time_from_unix_time(timestamp, tz * 60);
+            timestamp = watch_utility_date_time_to_unix_time(date_time, state->tz * 60);
+            date_time = watch_utility_date_time_from_unix_time(timestamp, state->tz * 60);
             previous_date_time = state->previous_date_time;
             state->previous_date_time = date_time.reg;
 
@@ -127,8 +126,6 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
 }
 
 static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_settings_t *settings, world_clock_state_t *state) {
-    watch_date_time date_time;
-    int16_t tz;
     switch (event.event_type) {
         case EVENT_MODE_BUTTON_UP:
             if (state->backup_register) watch_store_backup_data(state->settings.reg, state->backup_register);
@@ -172,13 +169,11 @@ static bool _world_clock_face_do_settings_mode(movement_event_t event, movement_
     }
 
     char buf[13];
-    date_time = watch_rtc_get_date_time();
-    tz = get_timezone_offset(settings->bit.time_zone, date_time);
     sprintf(buf, "%c%c %3d%02d  ",
         movement_valid_position_0_chars[state->settings.bit.char_0],
         movement_valid_position_1_chars[state->settings.bit.char_1],
-        (int8_t) (tz / 60),
-        (int8_t) (tz % 60) * (tz < 0 ? -1 : 1));
+        (int8_t) (state->tz / 60),
+        (int8_t) (state->tz % 60) * (state->tz < 0 ? -1 : 1));
     watch_set_colon();
     watch_clear_indicator(WATCH_INDICATOR_PM);
 
index 92e91a6ff28bc63f71f0457ecc466c2045bf2bfa..e76d85ea2764f65c471681f359a669ea5b262e22 100644 (file)
@@ -62,6 +62,7 @@ typedef struct {
     uint8_t backup_register;
     uint8_t current_screen;
     uint32_t previous_date_time;
+    int16_t tz;
 } world_clock_state_t;
 
 void world_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
index 47ed6e6d0952b15354bfc8bd2fd99a936e833e5e..c5718434e221902235583cecf818c8e35e6d3e18 100644 (file)
@@ -139,6 +139,7 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
 
     switch (event.event_type) {
         case EVENT_ACTIVATE:
+        
             _update(settings, state, state->offset);
             break;
         case EVENT_TICK:
index a6ec764afbda9cab362c46f557616111c74930a3..ad03d883e5aa79bcb12f44f836eaefb50ac21432 100644 (file)
@@ -54,8 +54,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
     }
 
     watch_date_time date_time = watch_rtc_get_date_time(); // the current local date / time
-    int16_t tz = get_timezone_offset(settings->bit.time_zone, date_time);
-    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, tz * 60, 0); // the current date / time in UTC
+    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, state->tz * 60, 0); // the current date / time in UTC
     watch_date_time scratch_time; // scratchpad, contains different values at different times
     scratch_time.reg = utc_now.reg;
 
@@ -70,7 +69,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
     // sunriset returns the rise/set times as signed decimal hours in UTC.
     // this can mean hours below 0 or above 31, which won't fit into a watch_date_time struct.
     // to deal with this, we set aside the offset in hours, and add it back before converting it to a watch_date_time.
-    double hours_from_utc = ((double)tz) / 60.0;
+    double hours_from_utc = ((double)state->tz) / 60.0;
 
     // we loop twice because if it's after sunset today, we need to recalculate to display values for tomorrow.
     for(int i = 0; i < 2; i++) {
@@ -317,6 +316,7 @@ void sunrise_sunset_face_activate(movement_settings_t *settings, void *context)
     movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
     state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude);
     state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude);
+    state->tz = get_timezone_offset(settings->bit.time_zone, watch_rtc_get_date_time());
 }
 
 bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
index 16e65b73e207967cf15fd06777a04eece63235f1..71b8462a6cd0a455c34d7dd34f2f7e948139d770 100644 (file)
@@ -52,6 +52,7 @@ typedef struct {
     uint8_t rise_index;
     uint8_t active_digit;
     bool location_changed;
+    int16_t tz;
     watch_date_time rise_set_expires;
     sunrise_sunset_lat_lon_settings_t working_latitude;
     sunrise_sunset_lat_lon_settings_t working_longitude;