diff options
author | Jeremy O'Brien <neutral@fastmail.com> | 2022-11-02 12:22:34 -0400 |
---|---|---|
committer | Jeremy O'Brien <neutral@fastmail.com> | 2022-11-02 12:22:34 -0400 |
commit | 9d3602220ac8498d37c9914c50b2af8bdc80b78f (patch) | |
tree | 70054279ffe46988ea2c989dc41b7df9571cdd3f | |
parent | b7a461d280d06749aeb14af1e8c17cbf3616055b (diff) | |
download | Sensor-Watch-9d3602220ac8498d37c9914c50b2af8bdc80b78f.tar.gz Sensor-Watch-9d3602220ac8498d37c9914c50b2af8bdc80b78f.tar.bz2 Sensor-Watch-9d3602220ac8498d37c9914c50b2af8bdc80b78f.zip |
Add hours support to the countdown face
-rw-r--r-- | movement/watch_faces/complication/countdown_face.c | 29 | ||||
-rw-r--r-- | movement/watch_faces/complication/countdown_face.h | 7 |
2 files changed, 24 insertions, 12 deletions
diff --git a/movement/watch_faces/complication/countdown_face.c b/movement/watch_faces/complication/countdown_face.c index 194006b1..6969a55f 100644 --- a/movement/watch_faces/complication/countdown_face.c +++ b/movement/watch_faces/complication/countdown_face.c @@ -31,7 +31,7 @@ #include "watch_utility.h" -#define CD_SELECTIONS 2 +#define CD_SELECTIONS 3 #define DEFAULT_MINUTES 3 @@ -44,7 +44,7 @@ static void start(countdown_state_t *state, movement_settings_t *settings) { state->mode = cd_running; state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); - state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes, state->seconds); + state->target_ts = watch_utility_offset_timestamp(state->now_ts, state->hours, state->minutes, state->seconds); watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings)); movement_schedule_background_task(target_dt); watch_set_indicator(WATCH_INDICATOR_BELL); @@ -55,28 +55,33 @@ static void draw(countdown_state_t *state, uint8_t subsecond) { uint32_t delta; div_t result; - uint8_t min, sec; + uint8_t hour, min, sec; switch (state->mode) { case cd_running: delta = state->target_ts - state->now_ts; result = div(delta, 60); - min = result.quot; sec = result.rem; + result = div(result.quot, 60); + hour = result.quot; + min = result.rem; - sprintf(buf, "CD %2d%02d", min, sec); + sprintf(buf, "CD %2d%02d%02d", hour, min, sec); break; case cd_waiting: - sprintf(buf, "CD %2d%02d", state->minutes, state->seconds); + sprintf(buf, "CD %2d%02d%02d", state->hours, state->minutes, state->seconds); break; case cd_setting: - sprintf(buf, "CD %2d%02d", state->minutes, state->seconds); + sprintf(buf, "CD %2d%02d%02d", state->hours, state->minutes, state->seconds); if (subsecond % 2) { switch(state->selection) { case 0: - buf[6] = buf[7] = ' '; + buf[4] = buf[5] = ' '; break; case 1: + buf[6] = buf[7] = ' '; + break; + case 2: buf[8] = buf[9] = ' '; break; default: @@ -102,9 +107,12 @@ static void ring(countdown_state_t *state) { static void settings_increment(countdown_state_t *state) { switch(state->selection) { case 0: - state->minutes = (state->minutes + 1) % 100; + state->hours = (state->hours + 1) % 24; break; case 1: + state->minutes = (state->minutes + 1) % 60; + break; + case 2: state->seconds = (state->seconds + 1) % 60; break; default: @@ -179,7 +187,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, reset(state); break; case cd_waiting: - if (!(state->minutes == 0 && state->seconds == 0)) { + if (!(state->hours == 0 && state->minutes == 0 && state->seconds == 0)) { // Only start the timer if we have a valid time. start(state, settings); } @@ -195,6 +203,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, break; case EVENT_ALARM_LONG_PRESS: if (state->mode == cd_setting) { + state->hours = 0; state->minutes = 0; state->seconds = 0; draw(state, event.subsecond); diff --git a/movement/watch_faces/complication/countdown_face.h b/movement/watch_faces/complication/countdown_face.h index 657c6377..f6c845d6 100644 --- a/movement/watch_faces/complication/countdown_face.h +++ b/movement/watch_faces/complication/countdown_face.h @@ -32,8 +32,10 @@ /* A countdown/timer face -Max countdown is 99 minutes and 59 seconds since we have to prevent the watch -from going to deep sleep using movement_schedule_background_task +Max countdown is 23 hours, 59 minutes and 59 seconds. + +Note: we have to prevent the watch from going to deep sleep using +movement_schedule_background_task() while the timer is running. */ @@ -46,6 +48,7 @@ typedef enum { typedef struct { uint32_t target_ts; uint32_t now_ts; + uint8_t hours; uint8_t minutes; uint8_t seconds; uint8_t selection; |