From 4804b0bb386bde98195066669c2c32374c609dde Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Sat, 28 Sep 2024 17:43:10 -0400 Subject: [PATCH] migrate countdown to Second Movement --- Makefile | 1 + movement_config.h | 1 + movement_faces.h | 1 + watch-faces.mk | 1 + .../complication/countdown_face.c | 15 ++++++--------- .../complication/countdown_face.h | 0 6 files changed, 10 insertions(+), 9 deletions(-) rename {movement/watch_faces => watch-faces}/complication/countdown_face.c (97%) rename {movement/watch_faces => watch-faces}/complication/countdown_face.h (100%) diff --git a/Makefile b/Makefile index 3dbdf4b8..b399ee40 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ INCLUDES += \ -I./watch-library/shared/watch \ -I./watch-library/hardware/watch \ -I./watch-faces/clock \ + -I./watch-faces/complication \ -I./watch-faces/settings \ # Add your source files here. diff --git a/movement_config.h b/movement_config.h index 902e72a3..f5c7a2cf 100644 --- a/movement_config.h +++ b/movement_config.h @@ -30,6 +30,7 @@ const watch_face_t watch_faces[] = { simple_clock_face, world_clock_face, + countdown_face, preferences_face, set_time_face, }; diff --git a/movement_faces.h b/movement_faces.h index f4ca6917..61d2f37c 100644 --- a/movement_faces.h +++ b/movement_faces.h @@ -26,6 +26,7 @@ #include "simple_clock_face.h" #include "world_clock_face.h" +#include "countdown_face.h" #include "set_time_face.h" #include "preferences_face.h" // New includes go above this line. diff --git a/watch-faces.mk b/watch-faces.mk index c84a17e5..52407820 100644 --- a/watch-faces.mk +++ b/watch-faces.mk @@ -1,5 +1,6 @@ SRCS += \ ./watch-faces/clock/simple_clock_face.c \ ./watch-faces/clock/world_clock_face.c \ + ./watch-faces/complication/countdown_face.c \ ./watch-faces/settings/set_time_face.c \ ./watch-faces/settings/preferences_face.c \ diff --git a/movement/watch_faces/complication/countdown_face.c b/watch-faces/complication/countdown_face.c similarity index 97% rename from movement/watch_faces/complication/countdown_face.c rename to watch-faces/complication/countdown_face.c index f585ebc3..ac7b2d24 100644 --- a/movement/watch_faces/complication/countdown_face.c +++ b/watch-faces/complication/countdown_face.c @@ -45,10 +45,6 @@ static void abort_quick_ticks(countdown_state_t *state) { } } -static inline int32_t get_tz_offset(movement_settings_t *settings) { - return movement_timezone_offsets[settings->bit.time_zone] * 60; -} - static inline void store_countdown(countdown_state_t *state) { /* Store set countdown time */ state->set_hours = state->hours; @@ -70,13 +66,14 @@ static inline void button_beep(movement_settings_t *settings) { } static void schedule_countdown(countdown_state_t *state, movement_settings_t *settings) { + (void) settings; // Calculate the new state->now_ts but don't update it until we've updated the target - // avoid possible race where the old target is compared to the new time and immediately triggers - uint32_t new_now = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), get_tz_offset(settings)); + uint32_t new_now = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_get_current_timezone_offset()); state->target_ts = watch_utility_offset_timestamp(new_now, state->hours, state->minutes, state->seconds); state->now_ts = new_now; - watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings)); + watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, movement_get_current_timezone_offset()); movement_schedule_background_task_for_face(state->watch_face_index, target_dt); } @@ -136,7 +133,7 @@ static void draw(countdown_state_t *state, uint8_t subsecond) { } break; } - watch_display_string(buf, 0); + watch_display_text(WATCH_POSITION_FULL, buf); } static void pause(countdown_state_t *state) { @@ -203,7 +200,7 @@ void countdown_face_activate(movement_settings_t *settings, void *context) { countdown_state_t *state = (countdown_state_t *)context; if(state->mode == cd_running) { watch_date_time now = watch_rtc_get_date_time(); - state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); + state->now_ts = watch_utility_date_time_to_unix_time(now, movement_get_current_timezone_offset()); watch_set_indicator(WATCH_INDICATOR_SIGNAL); } watch_set_colon(); @@ -224,7 +221,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, break; case EVENT_TICK: if (quick_ticks_running) { - if (watch_get_pin_level(BTN_ALARM)) + if (HAL_GPIO_BTN_ALARM_read()) settings_increment(state); else abort_quick_ticks(state); diff --git a/movement/watch_faces/complication/countdown_face.h b/watch-faces/complication/countdown_face.h similarity index 100% rename from movement/watch_faces/complication/countdown_face.h rename to watch-faces/complication/countdown_face.h