diff options
author | Slim <slim@pirate.tn> | 2022-12-02 19:53:56 +0100 |
---|---|---|
committer | Slim <slim@pirate.tn> | 2022-12-02 19:53:56 +0100 |
commit | 9cb2d3278adcc96c3d86279936a5ef3a1b667c08 (patch) | |
tree | af1ba8cefa06a7d8594931daf34ced67f70debf9 /movement/watch_faces | |
parent | a69547805b54c0c986241386213948416ac0fa1d (diff) | |
parent | 26228552cf9759e4dfaaa16c0fc3ea78b141b246 (diff) | |
download | Sensor-Watch-9cb2d3278adcc96c3d86279936a5ef3a1b667c08.tar.gz Sensor-Watch-9cb2d3278adcc96c3d86279936a5ef3a1b667c08.tar.bz2 Sensor-Watch-9cb2d3278adcc96c3d86279936a5ef3a1b667c08.zip |
Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into main
Diffstat (limited to 'movement/watch_faces')
-rw-r--r-- | movement/watch_faces/complication/stopwatch_face.c | 48 | ||||
-rw-r--r-- | movement/watch_faces/complication/sunrise_sunset_face.c | 17 | ||||
-rw-r--r-- | movement/watch_faces/settings/set_time_face.c | 4 |
3 files changed, 59 insertions, 10 deletions
diff --git a/movement/watch_faces/complication/stopwatch_face.c b/movement/watch_faces/complication/stopwatch_face.c index e85bbd65..2a69e9d5 100644 --- a/movement/watch_faces/complication/stopwatch_face.c +++ b/movement/watch_faces/complication/stopwatch_face.c @@ -29,6 +29,12 @@ #include "watch.h" #include "watch_utility.h" +// distant future for background task: January 1, 2083 +// see stopwatch_face_activate for details +static const watch_date_time distant_future = { + .unit = {0, 0, 0, 1, 1, 63} +}; + void stopwatch_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -49,6 +55,7 @@ static void _stopwatch_face_update_display(stopwatch_state_t *stopwatch_state, b if (stopwatch_state->seconds_counted >= 3456000) { // display maxes out just shy of 40 days, thanks to the limit on the day digits (0-39) stopwatch_state->running = false; + movement_cancel_background_task(); watch_display_string("st39235959", 0); return; } @@ -72,12 +79,21 @@ static void _stopwatch_face_update_display(stopwatch_state_t *stopwatch_state, b void stopwatch_face_activate(movement_settings_t *settings, void *context) { (void) settings; - (void) context; if (watch_tick_animation_is_running()) watch_stop_tick_animation(); + + stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context; + if (stopwatch_state->running) { + // because the low power update happens on the minute mark, and the wearer could start + // the stopwatch anytime, the low power update could fire up to 59 seconds later than + // we need it to, causing the stopwatch to display stale data. + // So let's schedule a background task that will never fire. This will keep the watch + // from entering low energy mode while the stopwatch is on screen. This background task + // will remain scheduled until the stopwatch stops OR this watch face resigns. + movement_schedule_background_task(distant_future); + } } bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { - (void) settings; stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context; switch (event.event_type) { @@ -103,6 +119,9 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, } break; case EVENT_ALARM_BUTTON_DOWN: + if (settings->bit.button_should_sound) { + watch_buzzer_play_note(BUZZER_NOTE_C8, 50); + } stopwatch_state->running = !stopwatch_state->running; if (stopwatch_state->running) { // we're running now, so we need to set the start_time. @@ -118,15 +137,28 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, // and resume from the "virtual" start time that's that many seconds ago. stopwatch_state->start_time = watch_utility_date_time_from_unix_time(timestamp, 0); } + // schedule our keepalive task when running... + movement_schedule_background_task(distant_future); + } else { + // and cancel it when stopped. + movement_cancel_background_task(); } break; case EVENT_TIMEOUT: // explicitly ignore the timeout event so we stay on screen break; case EVENT_LOW_ENERGY_UPDATE: - if (!watch_tick_animation_is_running()) watch_start_tick_animation(500); - _stopwatch_face_update_display(stopwatch_state, false); - watch_set_indicator(WATCH_INDICATOR_BELL); + if (!watch_tick_animation_is_running()) watch_start_tick_animation(1000); + if (!stopwatch_state->running) { + // since the tick animation is running, displaying the stopped time could be misleading, + // as it could imply that the stopwatch is running. instead, show a blank display to + // indicate that we are in sleep mode. + watch_display_string("st ---- ", 0); + } else { + // this OTOH shouldn't happen anymore; if we're running, we shouldn't enter low energy mode + _stopwatch_face_update_display(stopwatch_state, false); + watch_set_indicator(WATCH_INDICATOR_BELL); + } break; default: break; @@ -138,4 +170,8 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void stopwatch_face_resign(movement_settings_t *settings, void *context) { (void) settings; (void) context; -}
\ No newline at end of file + + // regardless of whether we're running or stopped, cancel the task + // that was keeping us awake while on screen. + movement_cancel_background_task(); +} diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c index 8dea812e..7807de83 100644 --- a/movement/watch_faces/complication/sunrise_sunset_face.c +++ b/movement/watch_faces/complication/sunrise_sunset_face.c @@ -96,6 +96,11 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s if (seconds < 30) scratch_time.unit.minute = floor(minutes); else scratch_time.unit.minute = ceil(minutes); + if (scratch_time.unit.minute == 60) { + scratch_time.unit.minute = 0; + scratch_time.unit.hour = (scratch_time.unit.hour + 1) % 24; + } + if (date_time.reg < scratch_time.reg) _sunrise_sunset_set_expiration(state, scratch_time); if (date_time.reg < scratch_time.reg || show_next_match) { @@ -118,6 +123,11 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s if (seconds < 30) scratch_time.unit.minute = floor(minutes); else scratch_time.unit.minute = ceil(minutes); + if (scratch_time.unit.minute == 60) { + scratch_time.unit.minute = 0; + scratch_time.unit.hour = (scratch_time.unit.hour + 1) % 24; + } + if (date_time.reg < scratch_time.reg) _sunrise_sunset_set_expiration(state, scratch_time); if (date_time.reg < scratch_time.reg || show_next_match) { @@ -371,8 +381,11 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti } break; case EVENT_TIMEOUT: - if (state->page || state->rise_index) { - // on timeout, exit settings mode and return to the next sunrise or sunset + if (watch_get_backup_data(1) == 0) { + // if no location set, return home + movement_move_to_face(0); + } else if (state->page || state->rise_index) { + // otherwise on timeout, exit settings mode and return to the next sunrise or sunset state->page = 0; state->rise_index = 0; movement_request_tick_frequency(1); diff --git a/movement/watch_faces/settings/set_time_face.c b/movement/watch_faces/settings/set_time_face.c index af5421f1..1605f119 100644 --- a/movement/watch_faces/settings/set_time_face.c +++ b/movement/watch_faces/settings/set_time_face.c @@ -66,8 +66,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v date_time.unit.second = 0; break; case 3: // year - // only allow 2021-2030. fix this sometime next decade - date_time.unit.year = ((date_time.unit.year % 10) + 1); + // only allow 2021-2050. fix this if we make it that far. + date_time.unit.year = ((date_time.unit.year % 30) + 1); break; case 4: // month date_time.unit.month = (date_time.unit.month % 12) + 1; |