]> git.earman.xyz Git - sensor-watch.git/commitdiff
refactor time zone index to function calls
authorjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 13:30:12 +0000 (09:30 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Sun, 29 Sep 2024 14:18:11 +0000 (10:18 -0400)
movement.c
movement.h
movement/watch_faces/complication/habit_face.c
movement/watch_faces/settings/set_time_hackwatch_face.c
watch-faces/settings/set_time_face.c

index 6d7897eb2ee2866ac621baee9e914e9a765ae84e..3bf006f2906ebad71f0c89149fbbd1df3c0e3e5e 100644 (file)
@@ -329,6 +329,14 @@ int32_t movement_get_current_timezone_offset(void) {
     return movement_get_current_timezone_offset_for_zone(movement_state.settings.bit.time_zone);
 }
 
+int32_t movement_get_timezone_index(void) {
+    return movement_state.settings.bit.time_zone;
+}
+
+void movement_set_timezone_index(uint8_t value) {
+    movement_state.settings.bit.time_zone = value;
+}
+
 bool movement_button_should_sound(void) {
     return movement_state.settings.bit.button_should_sound;
 }
index 2ac312f943df5535d6556c3706e24a881d6fd6dc..8c7f19a63d9978679601359883193ab5bce5cdfa 100644 (file)
@@ -331,6 +331,9 @@ uint8_t movement_claim_backup_register(void);
 int32_t movement_get_current_timezone_offset_for_zone(uint8_t zone_index);
 int32_t movement_get_current_timezone_offset(void);
 
+int32_t movement_get_timezone_index(void);
+void movement_set_timezone_index(uint8_t value);
+
 bool movement_button_should_sound(void);
 void movement_set_button_should_sound(bool value);
 
index ffc1e94aee40ea54eee5f4d67f860c488c550631..55e7ffced5ef3c148d805013473872788bd7d77a 100644 (file)
@@ -58,7 +58,7 @@ void habit_face_setup(movement_settings_t *settings, uint8_t watch_face_index,
     habit_state_t *state = (habit_state_t *)*context_ptr;
     state->lookback = 0;
     state->last_update = watch_utility_offset_timestamp(
-        today_unix(settings->bit.time_zone), -24, 0, 0);
+        today_unix(movement_get_current_timezone_offset()), -24, 0, 0);
   }
 }
 
@@ -111,7 +111,7 @@ bool habit_face_loop(movement_event_t event, movement_settings_t *settings,
                      void *context) {
   habit_state_t *state = (habit_state_t *)context;
 
-  const uint32_t today_now_unix = today_unix(settings->bit.time_zone);
+  const uint32_t today_now_unix = today_unix(movement_get_current_timezone_offset());
   const bool can_do = (state->lookback & 1) == 0;
 
   switch (event.event_type) {
index 0b6c76e3d5ec1276ff4fafcea78a28cda8ebb078..551233aebaae68092c646b28e83ca0f6d9b2631b 100644 (file)
@@ -27,6 +27,7 @@
 #include "set_time_hackwatch_face.h"
 #include "watch.h"
 #include "watch_utility.h"
+#include "zones.h"
 
 char set_time_hackwatch_face_titles[][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"};
 #define set_time_hackwatch_face_NUM_SETTINGS (sizeof(set_time_hackwatch_face_titles) / sizeof(*set_time_hackwatch_face_titles))
@@ -125,10 +126,10 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
                         date_time_settings.unit.day++;
                     break;
                 case 6: // time zone
-                    if (settings->bit.time_zone > 0) {
-                        settings->bit.time_zone--;
+                    if (movement_get_timezone_index() > 0) {
+                        movement_set_timezone_index(movement_get_timezone_index() - 1);
                     } else {
-                        settings->bit.time_zone = 40;
+                        movement_set_timezone_index(NUM_ZONE_NAMES - 1);
                     }
                     break;
             }
@@ -167,8 +168,8 @@ bool set_time_hackwatch_face_loop(movement_event_t event, movement_settings_t *s
                     date_time_settings.unit.day = date_time_settings.unit.day + 1;
                     break;
                 case 6: // time zone
-                    settings->bit.time_zone++;
-                    if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
+                    movement_set_timezone_index(movement_get_timezone_index() + 1);
+                    if (movement_get_timezone_index() >= NUM_ZONE_NAMES) movement_set_timezone_index(0);
                     break;
             }
             if (date_time_settings.unit.day > days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR))
index ea6274997da2b08f18dabf4005478e0dcf7168b0..b8bdab10ae9e3cbc903c562938f5f36d2e3c8e2a 100644 (file)
@@ -58,8 +58,8 @@ static void _handle_alarm_button(movement_settings_t *settings, watch_date_time
             break;
         }
         case 6: // time zone
-            settings->bit.time_zone++;
-            if (settings->bit.time_zone >= NUM_ZONE_NAMES) settings->bit.time_zone = 0;
+            movement_set_timezone_index(movement_get_timezone_index() + 1);
+            if (movement_get_timezone_index() >= NUM_ZONE_NAMES) movement_set_timezone_index(0);
             break;
     }
     if (date_time.unit.day > days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR))
@@ -150,8 +150,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
         if (event.subsecond % 2) {
             memset(buf, ' ', sizeof(buf));
         } else {
-            watch_display_text(WATCH_POSITION_TOP_LEFT, (char *) (zone_names + 11 * settings->bit.time_zone));
-            sprintf(buf, "%s", (char *) (3 + zone_names + 11 * settings->bit.time_zone));
+            watch_display_text(WATCH_POSITION_TOP_LEFT, (char *) (zone_names + 11 * movement_get_timezone_index()));
+            sprintf(buf, "%s", (char *) (3 + zone_names + 11 * movement_get_timezone_index()));
         }
     }