]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: implement time zone setting
authorJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:06:49 +0000 (10:06 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:36:01 +0000 (10:36 -0500)
movement/movement.c
movement/movement.h
movement/watch_faces/settings/set_time_face.c
watch-library/watch/watch_utility.c
watch-library/watch/watch_utility.h

index 797e75bf9f5873dcdce2d6ac2f15ff89c74caf0c..1a31175a677ba16886b632c540cd7a68a467ad94 100644 (file)
@@ -11,6 +11,50 @@ const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600,
 const int32_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800};
 movement_event_t event;
 
+const int16_t movement_timezone_offsets[] = {
+    -720,   //  0 : -12:00:00 (Baker Island Time)
+    -660,   //  1 : -11:00:00 (Niue Time)
+    -600,   //  2 : -10:00:00 (Hawaii-Aleutian Standard Time)
+    -570,   //  3 :  -9:30:00 (Marquesas Islands Time)
+    -540,   //  4 :  -9:00:00 (Alaska Standard Time)
+    -480,   //  5 :  -8:00:00 (Pacific Standard Time)
+    -420,   //  6 :  -7:00:00 (Mountain Standard Time)
+    -360,   //  7 :  -6:00:00 (Central Standard Time)
+    -300,   //  8 :  -5:00:00 (Eastern Standard Time)
+    -270,   //  9 :  -4:30:00 (Venezuelan Standard Time)
+    -240,   // 10 :  -4:00:00 (Atlantic Standard Time)
+    -210,   // 11 :  -3:30:00 (Newfoundland Standard Time)
+    -180,   // 12 :  -3:00:00 (Brasilia Time)
+    -150,   // 13 :  -2:30:00 (Newfoundland Daylight Time)
+    -120,   // 14 :  -2:00:00 (Fernando de Noronha Time)
+    -60,    // 15 :  -1:00:00 (Azores Standard Time)
+    0,      // 16 :   0:00:00 (UTC)
+    60,     // 17 :   1:00:00 (Central European Time)
+    120,    // 18 :   2:00:00 (South African Standard Time)
+    180,    // 19 :   3:00:00 (Arabia Standard Time)
+    210,    // 20 :   3:30:00 (Iran Standard Time)
+    240,    // 21 :   4:00:00 (Georgia Standard Time)
+    270,    // 22 :   4:30:00 (Afghanistan Time)
+    300,    // 23 :   5:00:00 (Pakistan Standard Time)
+    330,    // 24 :   5:30:00 (Indian Standard Time)
+    345,    // 25 :   5:45:00 (Nepal Time)
+    360,    // 26 :   6:00:00 (Kyrgyzstan time)
+    390,    // 27 :   6:30:00 (Myanmar Time)
+    420,    // 28 :   7:00:00 (Thailand Standard Time)
+    480,    // 29 :   8:00:00 (China Standard Time, Australian Western Standard Time)
+    525,    // 30 :   8:45:00 (Australian Central Western Standard Time)
+    540,    // 31 :   9:00:00 (Japan Standard Time, Korea Standard Time)
+    570,    // 32 :   9:30:00 (Australian Central Standard Time)
+    600,    // 33 :  10:00:00 (Australian Eastern Standard Time)
+    630,    // 34 :  10:30:00 (Lord Howe Standard Time)
+    660,    // 35 :  11:00:00 (Solomon Islands Time)
+    720,    // 36 :  12:00:00 (New Zealand Standard Time)
+    765,    // 37 :  12:45:00 (Chatham Standard Time)
+    780,    // 38 :  13:00:00 (Tonga Time)
+    825,    // 39 :  13:45:00 (Chatham Daylight Time)
+    840,    // 40 :  14:00:00 (Line Islands Time)
+};
+
 void cb_mode_btn_interrupt();
 void cb_light_btn_interrupt();
 void cb_alarm_btn_interrupt();
@@ -65,6 +109,7 @@ void app_init() {
     movement_state.settings.bit.button_should_sound = true;
     movement_state.settings.bit.le_interval = 1;
     movement_state.settings.bit.led_duration = 1;
+    movement_state.settings.bit.time_zone = 16; // default to GMT
     _movement_reset_inactivity_countdown();
 }
 
index 6953549a5132d829f7d95a5394093f2eb5fae7b8..4e791fca93fa3b59ab7cdae4d0ca296dacfb1303 100644 (file)
@@ -27,7 +27,7 @@ typedef union {
         uint8_t led_duration : 2;           // how many seconds to shine the LED for (x2), or 0 to disable it.
         uint8_t led_red_color : 4;          // for general purpose illumination, the red LED value (0-15)
         uint8_t led_green_color : 4;        // for general purpose illumination, the green LED value (0-15)
-        uint8_t time_zone : 6;              // TODO: an integer representing an index in the (to be implemented) time zone table.
+        uint8_t time_zone : 6;              // an integer representing an index in the time zone table.
 
         // while Movement itself doesn't implement a clock or display units, it may make sense to include some
         // global settings for watch faces to check. The 12/24 hour preference could inform a clock or a
@@ -97,6 +97,8 @@ typedef struct {
     uint8_t subsecond;
 } movement_event_t;
 
+extern const int16_t movement_timezone_offsets[];
+
 /** @brief Perform setup for your watch face.
   * @details It's tempting to say this is 'one-time' setup, but technically this function is called more than
   *          once. When the watch first boots, this function is called with a NULL context_ptr, indicating
index 6b82c68b05c902e2771594a8b2dc02d470078a86..fd4142793ed6232001a81e090c1998efd1fa8fd4 100644 (file)
@@ -2,8 +2,8 @@
 #include "set_time_face.h"
 #include "watch.h"
 
-#define SET_TIME_FACE_NUM_SETTINGS (6)
-const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "MN", "SE", "YR", "MO", "DA"};
+#define SET_TIME_FACE_NUM_SETTINGS (7)
+const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"};
 
 void set_time_face_setup(movement_settings_t *settings, void ** context_ptr) {
     (void) settings;
@@ -55,6 +55,10 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
                         date_time.unit.day = 1;
                     }
                     break;
+                case 6: // time zone
+                    settings->bit.time_zone++;
+                    if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
+                    break;
             }
             watch_rtc_set_date_time(date_time);
             break;
@@ -76,12 +80,22 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
             if (date_time.unit.hour > 12) watch_set_indicator(WATCH_INDICATOR_PM);
             else watch_clear_indicator(WATCH_INDICATOR_PM);
         }
-    } else {
+    } else if (current_page < 6) {
         watch_clear_colon();
         watch_clear_indicator(WATCH_INDICATOR_24H);
         watch_clear_indicator(WATCH_INDICATOR_PM);
         sprintf(buf, "%s  %2d%02d%02d", set_time_face_titles[current_page], date_time.unit.year + 20, date_time.unit.month, date_time.unit.day);
+    } else {
+        if (event.subsecond % 2) {
+            watch_clear_colon();
+            sprintf(buf, "%s        ", set_time_face_titles[current_page]);
+        } else {
+            watch_set_colon();
+            sprintf(buf, "%s %3d%02d  ", set_time_face_titles[current_page], (int8_t) (movement_timezone_offsets[settings->bit.time_zone] / 60), (int8_t) (movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
+        }
     }
+
+    // blink up the parameter we're setting
     if (event.subsecond % 2) {
         switch (current_page) {
             case 0:
index df80840497c46c51666bf8cd821a0700415deb3c..82ea5a6b57224a6723b87ca7a943b111ff129cbb 100644 (file)
@@ -51,6 +51,7 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_
         334  // December
     };
 
+    printf("input: %d/%d/%d %d:%02d:%02d offset by %ld\n", year, month, day, hour, minute, second, utc_offset);
 
     uint32_t year_adj = year + 4800;
     uint32_t febs = year_adj - (month <= 2 ? 1 : 0);  /* Februaries since base. */
@@ -59,9 +60,12 @@ uint32_t watch_utility_convert_to_unix_time(uint16_t year, uint8_t month, uint8_
     days -= 2472692;  /* Adjust to Unix epoch. */
 
     uint32_t timestamp = days * 86400;
-    timestamp += (hour + utc_offset) * 3600;
+    timestamp += hour * 3600;
     timestamp += minute * 60;
     timestamp += second;
+    printf("timestamp was %ld.\ntimezone is %ld.\n", timestamp, utc_offset);
+    timestamp -= utc_offset;
+    printf("timestamp now %ld.\n\n", timestamp);
 
     return timestamp;
 }
index a6035dc3a49addac82cb6ab94770d2ffa727cb43..5374fb1c44f0e5b98aaa0714bc477767e45037c1 100644 (file)
@@ -46,6 +46,7 @@ const char * watch_utility_get_weekday(watch_date_time date_time);
   * @param hour The hour of the date you wish to convert.
   * @param minute The minute of the date you wish to convert.
   * @param second The second of the date you wish to convert.
+  * @param utc_offset The number of seconds that date_time is offset from UTC, or 0 if the time is UTC.
   * @return A UNIX timestamp for the given date/time and UTC offset.
   * @note Implemented by Wesley Ellis (tahnok) and based on BSD-licensed code by Josh Haberman:
   *       https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html