From 07d6a05e33edd7ddf3a97b7f9ec47bdec950983d Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Sun, 29 Sep 2024 09:30:12 -0400 Subject: [PATCH] refactor time zone index to function calls --- movement.c | 8 ++++++++ movement.h | 3 +++ movement/watch_faces/complication/habit_face.c | 4 ++-- .../watch_faces/settings/set_time_hackwatch_face.c | 11 ++++++----- watch-faces/settings/set_time_face.c | 8 ++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/movement.c b/movement.c index 6d7897eb..3bf006f2 100644 --- a/movement.c +++ b/movement.c @@ -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; } diff --git a/movement.h b/movement.h index 2ac312f9..8c7f19a6 100644 --- a/movement.h +++ b/movement.h @@ -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); diff --git a/movement/watch_faces/complication/habit_face.c b/movement/watch_faces/complication/habit_face.c index ffc1e94a..55e7ffce 100644 --- a/movement/watch_faces/complication/habit_face.c +++ b/movement/watch_faces/complication/habit_face.c @@ -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) { diff --git a/movement/watch_faces/settings/set_time_hackwatch_face.c b/movement/watch_faces/settings/set_time_hackwatch_face.c index 0b6c76e3..551233ae 100644 --- a/movement/watch_faces/settings/set_time_hackwatch_face.c +++ b/movement/watch_faces/settings/set_time_hackwatch_face.c @@ -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)) diff --git a/watch-faces/settings/set_time_face.c b/watch-faces/settings/set_time_face.c index ea627499..b8bdab10 100644 --- a/watch-faces/settings/set_time_face.c +++ b/watch-faces/settings/set_time_face.c @@ -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())); } }