From 5c3967aea28dff5a2731a28862c5cae3b995f875 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Thu, 25 Nov 2021 10:06:49 -0500 Subject: movement: implement time zone setting --- movement/movement.c | 45 +++++++++++++++++++++++++++ movement/movement.h | 4 ++- movement/watch_faces/settings/set_time_face.c | 20 ++++++++++-- 3 files changed, 65 insertions(+), 4 deletions(-) (limited to 'movement') diff --git a/movement/movement.c b/movement/movement.c index 797e75bf..1a31175a 100644 --- a/movement/movement.c +++ b/movement/movement.c @@ -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(); } diff --git a/movement/movement.h b/movement/movement.h index 6953549a..4e791fca 100644 --- a/movement/movement.h +++ b/movement/movement.h @@ -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 diff --git a/movement/watch_faces/settings/set_time_face.c b/movement/watch_faces/settings/set_time_face.c index 6b82c68b..fd414279 100644 --- a/movement/watch_faces/settings/set_time_face.c +++ b/movement/watch_faces/settings/set_time_face.c @@ -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: -- cgit v1.2.3