From b6120d7673d13fc69d29247fda92222b38cffb0d Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:19:12 -0300 Subject: [PATCH 01/19] movement/faces: add clock_face Copy the simple_clock_face into clock_face for refactoring, maintaining the original until the new face can be tested. The new clock_face will only gain features from now on. Just "clock face" also feels more canonical. --- movement/make/Makefile | 1 + movement/movement_faces.h | 1 + movement/watch_faces/clock/clock_face.c | 161 ++++++++++++++++++++++++ movement/watch_faces/clock/clock_face.h | 63 ++++++++++ 4 files changed, 226 insertions(+) create mode 100644 movement/watch_faces/clock/clock_face.c create mode 100644 movement/watch_faces/clock/clock_face.h diff --git a/movement/make/Makefile b/movement/make/Makefile index 42dfc644d..fffa4e996 100644 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -50,6 +50,7 @@ SRCS += \ ../movement.c \ ../filesystem.c \ ../watch_faces/clock/simple_clock_face.c \ + ../watch_faces/clock/clock_face.c \ ../watch_faces/clock/world_clock_face.c \ ../watch_faces/clock/beats_face.c \ ../watch_faces/clock/weeknumber_clock_face.c \ diff --git a/movement/movement_faces.h b/movement/movement_faces.h index 7feb0f408..35571109a 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -26,6 +26,7 @@ #define MOVEMENT_FACES_H_ #include "simple_clock_face.h" +#include "clock_face.h" #include "world_clock_face.h" #include "preferences_face.h" #include "set_time_face.h" diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c new file mode 100644 index 000000000..a18bc3a1d --- /dev/null +++ b/movement/watch_faces/clock/clock_face.c @@ -0,0 +1,161 @@ +/* + * MIT License + * + * Copyright (c) 2022 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "clock_face.h" +#include "watch.h" +#include "watch_utility.h" +#include "watch_private_display.h" + +static void _update_alarm_indicator(bool settings_alarm_enabled, clock_state_t *state) { + state->alarm_enabled = settings_alarm_enabled; + if (state->alarm_enabled) watch_set_indicator(WATCH_INDICATOR_SIGNAL); + else watch_clear_indicator(WATCH_INDICATOR_SIGNAL); +} + +void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { + (void) settings; + (void) watch_face_index; + + if (*context_ptr == NULL) { + *context_ptr = malloc(sizeof(clock_state_t)); + clock_state_t *state = (clock_state_t *) *context_ptr; + state->signal_enabled = false; + state->watch_face_index = watch_face_index; + } +} + +void clock_face_activate(movement_settings_t *settings, void *context) { + clock_state_t *state = (clock_state_t *) context; + + if (watch_tick_animation_is_running()) watch_stop_tick_animation(); + + if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H); + + // handle chime indicator + if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); + else watch_clear_indicator(WATCH_INDICATOR_BELL); + + // show alarm indicator if there is an active alarm + _update_alarm_indicator(settings->bit.alarm_enabled, state); + + watch_set_colon(); + + // this ensures that none of the timestamp fields will match, so we can re-render them all. + state->previous_date_time = 0xFFFFFFFF; +} + +bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + clock_state_t *state = (clock_state_t *) context; + char buf[11]; + uint8_t pos; + + watch_date_time date_time; + uint32_t previous_date_time; + switch (event.event_type) { + case EVENT_ACTIVATE: + case EVENT_TICK: + case EVENT_LOW_ENERGY_UPDATE: + date_time = watch_rtc_get_date_time(); + previous_date_time = state->previous_date_time; + state->previous_date_time = date_time.reg; + + // check the battery voltage once a day... + if (date_time.unit.day != state->last_battery_check) { + state->last_battery_check = date_time.unit.day; + watch_enable_adc(); + uint16_t voltage = watch_get_vcc_voltage(); + watch_disable_adc(); + // 2.2 volts will happen when the battery has maybe 5-10% remaining? + // we can refine this later. + state->battery_low = (voltage < 2200); + } + + // ...and set the LAP indicator if low. + if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP); + + if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + // everything before seconds is the same, don't waste cycles setting those segments. + watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8); + watch_display_character_lp_seconds('0' + date_time.unit.second % 10, 9); + break; + } else if ((date_time.reg >> 12) == (previous_date_time >> 12) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + // everything before minutes is the same. + pos = 6; + sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second); + } else { + // other stuff changed; let's do it all. + if (!settings->bit.clock_mode_24h) { + // if we are in 12 hour mode, do some cleanup. + if (date_time.unit.hour < 12) { + watch_clear_indicator(WATCH_INDICATOR_PM); + } else { + watch_set_indicator(WATCH_INDICATOR_PM); + } + date_time.unit.hour %= 12; + if (date_time.unit.hour == 0) date_time.unit.hour = 12; + } + pos = 0; + if (event.event_type == EVENT_LOW_ENERGY_UPDATE) { + if (!watch_tick_animation_is_running()) watch_start_tick_animation(500); + sprintf(buf, "%s%2d%2d%02d ", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute); + } else { + sprintf(buf, "%s%2d%2d%02d%02d", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second); + } + } + watch_display_string(buf, pos); + // handle alarm indicator + if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state); + break; + case EVENT_ALARM_LONG_PRESS: + state->signal_enabled = !state->signal_enabled; + if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); + else watch_clear_indicator(WATCH_INDICATOR_BELL); + break; + case EVENT_BACKGROUND_TASK: + // uncomment this line to snap back to the clock face when the hour signal sounds: + // movement_move_to_face(state->watch_face_index); + movement_play_signal(); + break; + default: + return movement_default_loop_handler(event, settings); + } + + return true; +} + +void clock_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} + +bool clock_face_wants_background_task(movement_settings_t *settings, void *context) { + (void) settings; + clock_state_t *state = (clock_state_t *) context; + if (!state->signal_enabled) return false; + + watch_date_time date_time = watch_rtc_get_date_time(); + + return date_time.unit.minute == 0; +} diff --git a/movement/watch_faces/clock/clock_face.h b/movement/watch_faces/clock/clock_face.h new file mode 100644 index 000000000..d2aa5ecb4 --- /dev/null +++ b/movement/watch_faces/clock/clock_face.h @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (c) 2022 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef CLOCK_FACE_H_ +#define CLOCK_FACE_H_ + +/* + * CLOCK FACE + * + * Displays the current local time, just like the original watch. + * This is the default display mode in most watch configurations. + * + * Long-press ALARM to toggle the hourly chime. + * + */ + +#include "movement.h" + +typedef struct { + uint32_t previous_date_time; + uint8_t last_battery_check; + uint8_t watch_face_index; + bool signal_enabled; + bool battery_low; + bool alarm_enabled; +} clock_state_t; + +void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void clock_face_activate(movement_settings_t *settings, void *context); +bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void clock_face_resign(movement_settings_t *settings, void *context); +bool clock_face_wants_background_task(movement_settings_t *settings, void *context); + +#define clock_face ((const watch_face_t) { \ + clock_face_setup, \ + clock_face_activate, \ + clock_face_loop, \ + clock_face_resign, \ + clock_face_wants_background_task, \ +}) + +#endif // CLOCK_FACE_H_ From 6230fd66398260c219984b83e88a3fff4c30588b Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:40:21 -0300 Subject: [PATCH 02/19] faces/clock: move structure definition Instances of the clock state structure are only passed to the clock face itself and only via the opaque context pointer. No other code uses it. Thus there is no need to expose it in a header file. So make it an implementation detail of the watch face by localizing it inside the translation unit. --- movement/watch_faces/clock/clock_face.c | 9 +++++++++ movement/watch_faces/clock/clock_face.h | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index a18bc3a1d..070968a78 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -28,6 +28,15 @@ #include "watch_utility.h" #include "watch_private_display.h" +typedef struct { + uint32_t previous_date_time; + uint8_t last_battery_check; + uint8_t watch_face_index; + bool signal_enabled; + bool battery_low; + bool alarm_enabled; +} clock_state_t; + static void _update_alarm_indicator(bool settings_alarm_enabled, clock_state_t *state) { state->alarm_enabled = settings_alarm_enabled; if (state->alarm_enabled) watch_set_indicator(WATCH_INDICATOR_SIGNAL); diff --git a/movement/watch_faces/clock/clock_face.h b/movement/watch_faces/clock/clock_face.h index d2aa5ecb4..f973f2707 100644 --- a/movement/watch_faces/clock/clock_face.h +++ b/movement/watch_faces/clock/clock_face.h @@ -37,15 +37,6 @@ #include "movement.h" -typedef struct { - uint32_t previous_date_time; - uint8_t last_battery_check; - uint8_t watch_face_index; - bool signal_enabled; - bool battery_low; - bool alarm_enabled; -} clock_state_t; - void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); void clock_face_activate(movement_settings_t *settings, void *context); bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context); From 90ea9acb131c4e842087559410c907a9a7c43a07 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:16:06 -0300 Subject: [PATCH 03/19] faces/clock: define general indication function Sets or clears the specified indicator based on some boolean value. --- movement/watch_faces/clock/clock_face.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 070968a78..24e33c9c5 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -37,6 +37,14 @@ typedef struct { bool alarm_enabled; } clock_state_t; +static void clock_indicate(WatchIndicatorSegment indicator, bool on) { + if (on) { + watch_set_indicator(indicator); + } else { + watch_clear_indicator(indicator); + } +} + static void _update_alarm_indicator(bool settings_alarm_enabled, clock_state_t *state) { state->alarm_enabled = settings_alarm_enabled; if (state->alarm_enabled) watch_set_indicator(WATCH_INDICATOR_SIGNAL); From 4580600b489540a4a75a969f1929280a138afe3a Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:36:34 -0300 Subject: [PATCH 04/19] faces/clock: simplify alarm indication function Deduplicates state in the clock state and movement settings. Makes the code simpler. Also makes it use the correct indicator. For some reason it had been switched with the hourly chime indicator. WATCH_INDICATOR_BELL The small bell indicating that an alarm is set. WATCH_INDICATOR_SIGNAL The hourly signal indicator. Also useful for indicating that sensors are on. --- movement/watch_faces/clock/clock_face.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 24e33c9c5..ec0afe866 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -34,7 +34,6 @@ typedef struct { uint8_t watch_face_index; bool signal_enabled; bool battery_low; - bool alarm_enabled; } clock_state_t; static void clock_indicate(WatchIndicatorSegment indicator, bool on) { @@ -45,10 +44,8 @@ static void clock_indicate(WatchIndicatorSegment indicator, bool on) { } } -static void _update_alarm_indicator(bool settings_alarm_enabled, clock_state_t *state) { - state->alarm_enabled = settings_alarm_enabled; - if (state->alarm_enabled) watch_set_indicator(WATCH_INDICATOR_SIGNAL); - else watch_clear_indicator(WATCH_INDICATOR_SIGNAL); +static void clock_indicate_alarm(movement_settings_t *settings) { + clock_indicate(WATCH_INDICATOR_BELL, settings->bit.alarm_enabled); } void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { @@ -64,7 +61,7 @@ void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v } void clock_face_activate(movement_settings_t *settings, void *context) { - clock_state_t *state = (clock_state_t *) context; + clock_state_t *clock = (clock_state_t *) context; if (watch_tick_animation_is_running()) watch_stop_tick_animation(); @@ -74,13 +71,12 @@ void clock_face_activate(movement_settings_t *settings, void *context) { if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); else watch_clear_indicator(WATCH_INDICATOR_BELL); - // show alarm indicator if there is an active alarm - _update_alarm_indicator(settings->bit.alarm_enabled, state); + clock_indicate_alarm(settings); watch_set_colon(); // this ensures that none of the timestamp fields will match, so we can re-render them all. - state->previous_date_time = 0xFFFFFFFF; + clock->previous_date_time = 0xFFFFFFFF; } bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { @@ -142,8 +138,10 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void } } watch_display_string(buf, pos); + // handle alarm indicator - if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state); + clock_indicate_alarm(settings); + break; case EVENT_ALARM_LONG_PRESS: state->signal_enabled = !state->signal_enabled; From e84c524c704f46cff7e303a9a08e472ba7b0c7ad Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:44:52 -0300 Subject: [PATCH 05/19] faces/clock: simplify signal indication function Simplifies the code and makes it use the correct indicator. For some reason it had been switched with the alarm indicator. WATCH_INDICATOR_BELL The small bell indicating that an alarm is set. WATCH_INDICATOR_SIGNAL The hourly signal indicator. Also useful for indicating that sensors are on. --- movement/watch_faces/clock/clock_face.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index ec0afe866..8fa154497 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -32,7 +32,7 @@ typedef struct { uint32_t previous_date_time; uint8_t last_battery_check; uint8_t watch_face_index; - bool signal_enabled; + bool time_signal_enabled; bool battery_low; } clock_state_t; @@ -48,6 +48,10 @@ static void clock_indicate_alarm(movement_settings_t *settings) { clock_indicate(WATCH_INDICATOR_BELL, settings->bit.alarm_enabled); } +static void clock_indicate_time_signal(clock_state_t *clock) { + clock_indicate(WATCH_INDICATOR_SIGNAL, clock->time_signal_enabled); +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -55,7 +59,7 @@ void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v if (*context_ptr == NULL) { *context_ptr = malloc(sizeof(clock_state_t)); clock_state_t *state = (clock_state_t *) *context_ptr; - state->signal_enabled = false; + state->time_signal_enabled = false; state->watch_face_index = watch_face_index; } } @@ -67,10 +71,7 @@ void clock_face_activate(movement_settings_t *settings, void *context) { if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H); - // handle chime indicator - if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); - else watch_clear_indicator(WATCH_INDICATOR_BELL); - + clock_indicate_time_signal(clock); clock_indicate_alarm(settings); watch_set_colon(); @@ -144,9 +145,8 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void break; case EVENT_ALARM_LONG_PRESS: - state->signal_enabled = !state->signal_enabled; - if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); - else watch_clear_indicator(WATCH_INDICATOR_BELL); + state->time_signal_enabled = !state->time_signal_enabled; + clock_indicate_time_signal(state); break; case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: @@ -168,7 +168,7 @@ void clock_face_resign(movement_settings_t *settings, void *context) { bool clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; clock_state_t *state = (clock_state_t *) context; - if (!state->signal_enabled) return false; + if (!state->time_signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); From 3c635ae0370276eebb311cbce77fc2c417251fee Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:52:51 -0300 Subject: [PATCH 06/19] faces/clock: simplify 24h indication function Simplifies the code by adding a dedicated function for this. --- movement/watch_faces/clock/clock_face.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 8fa154497..9eca88e97 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -52,6 +52,10 @@ static void clock_indicate_time_signal(clock_state_t *clock) { clock_indicate(WATCH_INDICATOR_SIGNAL, clock->time_signal_enabled); } +static void clock_indicate_24h(movement_settings_t *settings) { + clock_indicate(WATCH_INDICATOR_24H, settings->bit.clock_mode_24h); +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -69,10 +73,9 @@ void clock_face_activate(movement_settings_t *settings, void *context) { if (watch_tick_animation_is_running()) watch_stop_tick_animation(); - if (settings->bit.clock_mode_24h) watch_set_indicator(WATCH_INDICATOR_24H); - clock_indicate_time_signal(clock); clock_indicate_alarm(settings); + clock_indicate_24h(settings); watch_set_colon(); From d9fda5d6c4e2f31168879c6c13573fe6c26155a1 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 20:13:07 -0300 Subject: [PATCH 07/19] faces/clock: simplify PM indication function Simplifies the code by adding dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 9eca88e97..8ed0e6a89 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -56,6 +56,25 @@ static void clock_indicate_24h(movement_settings_t *settings) { clock_indicate(WATCH_INDICATOR_24H, settings->bit.clock_mode_24h); } +static bool clock_is_pm(watch_date_time date_time) { + return date_time.unit.hour >= 12; +} + +static void clock_indicate_pm(movement_settings_t *settings, watch_date_time date_time) { + if (settings->bit.clock_mode_24h) { return; } + clock_indicate(WATCH_INDICATOR_PM, clock_is_pm(date_time)); +} + +static watch_date_time clock_24h_to_12h(watch_date_time date_time) { + date_time.unit.hour %= 12; + + if (date_time.unit.hour == 0) { + date_time.unit.hour = 12; + } + + return date_time; +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -125,13 +144,8 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void // other stuff changed; let's do it all. if (!settings->bit.clock_mode_24h) { // if we are in 12 hour mode, do some cleanup. - if (date_time.unit.hour < 12) { - watch_clear_indicator(WATCH_INDICATOR_PM); - } else { - watch_set_indicator(WATCH_INDICATOR_PM); - } - date_time.unit.hour %= 12; - if (date_time.unit.hour == 0) date_time.unit.hour = 12; + clock_indicate_pm(settings, date_time); + date_time = clock_24h_to_12h(date_time); } pos = 0; if (event.event_type == EVENT_LOW_ENERGY_UPDATE) { From 5a944675ce7cc2bffe9862017311455094782021 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 22:31:12 -0300 Subject: [PATCH 08/19] faces/clock: refactor daily battery check Move the code in question to a dedicated function. Better organized. Add overridable preprocessor definition for the low battery threshold. --- movement/watch_faces/clock/clock_face.c | 32 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 8ed0e6a89..537104a44 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -28,6 +28,12 @@ #include "watch_utility.h" #include "watch_private_display.h" +// 2.2 volts will happen when the battery has maybe 5-10% remaining? +// we can refine this later. +#ifndef CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD +#define CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD 2200 +#endif + typedef struct { uint32_t previous_date_time; uint8_t last_battery_check; @@ -75,6 +81,19 @@ static watch_date_time clock_24h_to_12h(watch_date_time date_time) { return date_time; } +static void clock_check_battery_periodically(clock_state_t *clock, watch_date_time date_time) { + // check the battery voltage once a day + if (date_time.unit.day == clock->last_battery_check) { return; } + + clock->last_battery_check = date_time.unit.day; + + watch_enable_adc(); + uint16_t voltage = watch_get_vcc_voltage(); + watch_disable_adc(); + + clock->battery_low = voltage < CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD; +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -117,18 +136,9 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void previous_date_time = state->previous_date_time; state->previous_date_time = date_time.reg; - // check the battery voltage once a day... - if (date_time.unit.day != state->last_battery_check) { - state->last_battery_check = date_time.unit.day; - watch_enable_adc(); - uint16_t voltage = watch_get_vcc_voltage(); - watch_disable_adc(); - // 2.2 volts will happen when the battery has maybe 5-10% remaining? - // we can refine this later. - state->battery_low = (voltage < 2200); - } + clock_check_battery_periodically(state, date_time); - // ...and set the LAP indicator if low. + // Set the LAP indicator if battery power is low if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP); if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { From b5513a024758d4b6be79a5394061388c9ddc0ade Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 22:38:28 -0300 Subject: [PATCH 09/19] faces/clock: simplify LAP indication function Simplifies the code by adding a dedicated function for this. Also documents the meaning of the LAP indicator: Low Available Power. --- movement/watch_faces/clock/clock_face.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 537104a44..08007a89a 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -94,6 +94,11 @@ static void clock_check_battery_periodically(clock_state_t *clock, watch_date_ti clock->battery_low = voltage < CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD; } +static void clock_indicate_low_available_power(clock_state_t *clock) { + // Set the LAP indicator if battery power is low + clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -137,9 +142,7 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void state->previous_date_time = date_time.reg; clock_check_battery_periodically(state, date_time); - - // Set the LAP indicator if battery power is low - if (state->battery_low) watch_set_indicator(WATCH_INDICATOR_LAP); + clock_indicate_low_available_power(state); if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { // everything before seconds is the same, don't waste cycles setting those segments. From f508cac46ae5b40c6944a4789ee575f686809c15 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 12:32:31 -0300 Subject: [PATCH 10/19] faces/clock: refactor low power tick function Simplifies the code by defining dedicated functions and separating the case from the main ones. Also use the snprintf function since the buffer size is known. --- movement/watch_faces/clock/clock_face.c | 38 +++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 08007a89a..1977ca75d 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -99,6 +99,22 @@ static void clock_indicate_low_available_power(clock_state_t *clock) { clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); } +static void clock_display_low_energy(watch_date_time date_time) { + char buf[11]; + + snprintf( + buf, + sizeof(buf), + "%s%2d%2d%02d ", + watch_utility_get_weekday(date_time), + date_time.unit.day, + date_time.unit.hour, + date_time.unit.minute + ); + + watch_display_string(buf, 0); +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -134,9 +150,12 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void watch_date_time date_time; uint32_t previous_date_time; switch (event.event_type) { - case EVENT_ACTIVATE: - case EVENT_TICK: case EVENT_LOW_ENERGY_UPDATE: + if (!watch_tick_animation_is_running()) watch_start_tick_animation(500); + clock_display_low_energy(watch_rtc_get_date_time()); + break; + case EVENT_TICK: + case EVENT_ACTIVATE: date_time = watch_rtc_get_date_time(); previous_date_time = state->previous_date_time; state->previous_date_time = date_time.reg; @@ -144,12 +163,12 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_check_battery_periodically(state, date_time); clock_indicate_low_available_power(state); - if ((date_time.reg >> 6) == (previous_date_time >> 6) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + if ((date_time.reg >> 6) == (previous_date_time >> 6)) { // everything before seconds is the same, don't waste cycles setting those segments. watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8); watch_display_character_lp_seconds('0' + date_time.unit.second % 10, 9); break; - } else if ((date_time.reg >> 12) == (previous_date_time >> 12) && event.event_type != EVENT_LOW_ENERGY_UPDATE) { + } else if ((date_time.reg >> 12) == (previous_date_time >> 12)) { // everything before minutes is the same. pos = 6; sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second); @@ -160,15 +179,10 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_indicate_pm(settings, date_time); date_time = clock_24h_to_12h(date_time); } - pos = 0; - if (event.event_type == EVENT_LOW_ENERGY_UPDATE) { - if (!watch_tick_animation_is_running()) watch_start_tick_animation(500); - sprintf(buf, "%s%2d%2d%02d ", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute); - } else { - sprintf(buf, "%s%2d%2d%02d%02d", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second); - } + sprintf(buf, "%s%2d%2d%02d%02d", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second); } - watch_display_string(buf, pos); + + watch_display_string(buf, 0); // handle alarm indicator clock_indicate_alarm(settings); From 86dcdad8c90946761a53201e24adbf17d018d18f Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 12:40:00 -0300 Subject: [PATCH 11/19] faces/clock: refactor tick tock animation code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 1977ca75d..82052133f 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -100,7 +100,7 @@ static void clock_indicate_low_available_power(clock_state_t *clock) { } static void clock_display_low_energy(watch_date_time date_time) { - char buf[11]; + char buf[10 + 1]; snprintf( buf, @@ -115,6 +115,18 @@ static void clock_display_low_energy(watch_date_time date_time) { watch_display_string(buf, 0); } +static void clock_start_tick_tock_animation(void) { + if (!watch_tick_animation_is_running()) { + watch_start_tick_animation(500); + } +} + +static void clock_stop_tick_tock_animation(void) { + if (watch_tick_animation_is_running()) { + watch_stop_tick_animation(); + } +} + void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { (void) settings; (void) watch_face_index; @@ -130,7 +142,7 @@ void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v void clock_face_activate(movement_settings_t *settings, void *context) { clock_state_t *clock = (clock_state_t *) context; - if (watch_tick_animation_is_running()) watch_stop_tick_animation(); + clock_stop_tick_tock_animation(); clock_indicate_time_signal(clock); clock_indicate_alarm(settings); @@ -151,7 +163,7 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void uint32_t previous_date_time; switch (event.event_type) { case EVENT_LOW_ENERGY_UPDATE: - if (!watch_tick_animation_is_running()) watch_start_tick_animation(500); + clock_start_tick_tock_animation(); clock_display_low_energy(watch_rtc_get_date_time()); break; case EVENT_TICK: From a86ccdcdfb49c3b8f6edf380ed95254bd4c5b763 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:00:50 -0300 Subject: [PATCH 12/19] faces/clock: refactor full time display code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 82052133f..5b6983412 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -99,6 +99,23 @@ static void clock_indicate_low_available_power(clock_state_t *clock) { clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); } +static void clock_display_all(watch_date_time date_time) { + char buf[10 + 1]; + + snprintf( + buf, + sizeof(buf), + "%s%2d%2d%02d%02d", + watch_utility_get_weekday(date_time), + date_time.unit.day, + date_time.unit.hour, + date_time.unit.minute, + date_time.unit.second + ); + + watch_display_string(buf, 0); +} + static void clock_display_low_energy(watch_date_time date_time) { char buf[10 + 1]; @@ -191,7 +208,8 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_indicate_pm(settings, date_time); date_time = clock_24h_to_12h(date_time); } - sprintf(buf, "%s%2d%2d%02d%02d", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second); + clock_display_all(date_time); + break; } watch_display_string(buf, 0); From dd7438d1c4c7a3383168dcaee9a7c8a744f5649e Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:31:17 -0300 Subject: [PATCH 13/19] faces/clock: refactor partial time display code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 64 +++++++++++++++---------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 5b6983412..36f21ff9e 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -116,6 +116,38 @@ static void clock_display_all(watch_date_time date_time) { watch_display_string(buf, 0); } +static bool clock_display_some(watch_date_time current, watch_date_time previous) { + if ((current.reg >> 6) == (previous.reg >> 6)) { + // everything before seconds is the same, don't waste cycles setting those segments. + + watch_display_character_lp_seconds('0' + current.unit.second / 10, 8); + watch_display_character_lp_seconds('0' + current.unit.second % 10, 9); + + return true; + + } else if ((current.reg >> 12) == (previous.reg >> 12)) { + // everything before minutes is the same. + + char buf[4 + 1]; + + snprintf( + buf, + sizeof(buf), + "%02d%02d", + current.unit.minute, + current.unit.second + ); + + watch_display_string(buf, 6); + + return true; + + } else { + // other stuff changed; let's do it all. + return false; + } +} + static void clock_display_low_energy(watch_date_time date_time) { char buf[10 + 1]; @@ -173,11 +205,8 @@ void clock_face_activate(movement_settings_t *settings, void *context) { bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { clock_state_t *state = (clock_state_t *) context; - char buf[11]; - uint8_t pos; + watch_date_time current, previous; - watch_date_time date_time; - uint32_t previous_date_time; switch (event.event_type) { case EVENT_LOW_ENERGY_UPDATE: clock_start_tick_tock_animation(); @@ -185,36 +214,23 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void break; case EVENT_TICK: case EVENT_ACTIVATE: - date_time = watch_rtc_get_date_time(); - previous_date_time = state->previous_date_time; - state->previous_date_time = date_time.reg; + current = watch_rtc_get_date_time(); + previous.reg = state->previous_date_time; + state->previous_date_time = current.reg; clock_check_battery_periodically(state, date_time); clock_indicate_low_available_power(state); - if ((date_time.reg >> 6) == (previous_date_time >> 6)) { - // everything before seconds is the same, don't waste cycles setting those segments. - watch_display_character_lp_seconds('0' + date_time.unit.second / 10, 8); - watch_display_character_lp_seconds('0' + date_time.unit.second % 10, 9); - break; - } else if ((date_time.reg >> 12) == (previous_date_time >> 12)) { - // everything before minutes is the same. - pos = 6; - sprintf(buf, "%02d%02d", date_time.unit.minute, date_time.unit.second); - } else { - // other stuff changed; let's do it all. + if (!clock_display_some(current, previous)) { if (!settings->bit.clock_mode_24h) { // if we are in 12 hour mode, do some cleanup. - clock_indicate_pm(settings, date_time); - date_time = clock_24h_to_12h(date_time); + clock_indicate_pm(settings, current); + current = clock_24h_to_12h(current); } - clock_display_all(date_time); - break; + clock_display_all(current); } - watch_display_string(buf, 0); - // handle alarm indicator clock_indicate_alarm(settings); break; From 01dd94ab95d757c68f8fef8d61eb01875b0a974c Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:31:28 -0300 Subject: [PATCH 14/19] faces/clock: reorder periodic battery check Check the battery after the time has been updated. Place all the indication code next to each other. --- movement/watch_faces/clock/clock_face.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 36f21ff9e..4fe02376f 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -218,9 +218,6 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void previous.reg = state->previous_date_time; state->previous_date_time = current.reg; - clock_check_battery_periodically(state, date_time); - clock_indicate_low_available_power(state); - if (!clock_display_some(current, previous)) { if (!settings->bit.clock_mode_24h) { // if we are in 12 hour mode, do some cleanup. @@ -230,8 +227,10 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_display_all(current); } + clock_check_battery_periodically(state, current); clock_indicate_alarm(settings); + clock_indicate_low_available_power(state); break; case EVENT_ALARM_LONG_PRESS: From 558ad701829aab943132ee33a7988ead1604e55f Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:06:19 -0300 Subject: [PATCH 15/19] faces/clock: refactor clock display code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 34 +++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 4fe02376f..7e4ec8162 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -35,7 +35,9 @@ #endif typedef struct { - uint32_t previous_date_time; + struct { + watch_date_time previous; + } date_time; uint8_t last_battery_check; uint8_t watch_face_index; bool time_signal_enabled; @@ -148,6 +150,17 @@ static bool clock_display_some(watch_date_time current, watch_date_time previous } } +static void clock_display_clock(movement_settings_t *settings, clock_state_t *clock, watch_date_time current) { + if (!clock_display_some(current, clock->date_time.previous)) { + if (!settings->bit.clock_mode_24h) { + // if we are in 12 hour mode, do some cleanup. + clock_indicate_pm(settings, current); + current = clock_24h_to_12h(current); + } + clock_display_all(current); + } +} + static void clock_display_low_energy(watch_date_time date_time) { char buf[10 + 1]; @@ -200,12 +213,12 @@ void clock_face_activate(movement_settings_t *settings, void *context) { watch_set_colon(); // this ensures that none of the timestamp fields will match, so we can re-render them all. - clock->previous_date_time = 0xFFFFFFFF; + clock->date_time.previous.reg = 0xFFFFFFFF; } bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { clock_state_t *state = (clock_state_t *) context; - watch_date_time current, previous; + watch_date_time current; switch (event.event_type) { case EVENT_LOW_ENERGY_UPDATE: @@ -215,23 +228,16 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void case EVENT_TICK: case EVENT_ACTIVATE: current = watch_rtc_get_date_time(); - previous.reg = state->previous_date_time; - state->previous_date_time = current.reg; - - if (!clock_display_some(current, previous)) { - if (!settings->bit.clock_mode_24h) { - // if we are in 12 hour mode, do some cleanup. - clock_indicate_pm(settings, current); - current = clock_24h_to_12h(current); - } - clock_display_all(current); - } + + clock_display_clock(settings, state, current); clock_check_battery_periodically(state, current); clock_indicate_alarm(settings); clock_indicate_low_available_power(state); + state->date_time.previous = current; + break; case EVENT_ALARM_LONG_PRESS: state->time_signal_enabled = !state->time_signal_enabled; From d9f2c88cea6595ba7f890308cca773823948a919 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:10:04 -0300 Subject: [PATCH 16/19] faces/clock: refactor time signal toggling code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 7e4ec8162..f6c3f3f46 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -101,6 +101,11 @@ static void clock_indicate_low_available_power(clock_state_t *clock) { clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); } +static void clock_toggle_time_signal(clock_state_t *clock) { + clock->time_signal_enabled = !clock->time_signal_enabled; + clock_indicate_time_signal(clock); +} + static void clock_display_all(watch_date_time date_time) { char buf[10 + 1]; @@ -240,8 +245,7 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void break; case EVENT_ALARM_LONG_PRESS: - state->time_signal_enabled = !state->time_signal_enabled; - clock_indicate_time_signal(state); + clock_toggle_time_signal(state); break; case EVENT_BACKGROUND_TASK: // uncomment this line to snap back to the clock face when the hour signal sounds: From 4bbc44b1d365c2f012c5ddbf6df8b490c5eff10a Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:11:07 -0300 Subject: [PATCH 17/19] faces/clock: indicate alarm only when necessary The alarm state is not modified within the clock face. Therefore, it only needs to be set when the face is activated. --- movement/watch_faces/clock/clock_face.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index f6c3f3f46..8a3965696 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -237,8 +237,6 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_display_clock(settings, state, current); clock_check_battery_periodically(state, current); - - clock_indicate_alarm(settings); clock_indicate_low_available_power(state); state->date_time.previous = current; From 115720b87b96a05c0af722630ea55385969f6775 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:14:26 -0300 Subject: [PATCH 18/19] faces/clock: indicate low power only when needed There is no need to set the indicator on every clock tick. Indicate only when the battery is checked. --- movement/watch_faces/clock/clock_face.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 8a3965696..27d9acc01 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -73,6 +73,11 @@ static void clock_indicate_pm(movement_settings_t *settings, watch_date_time dat clock_indicate(WATCH_INDICATOR_PM, clock_is_pm(date_time)); } +static void clock_indicate_low_available_power(clock_state_t *clock) { + // Set the LAP indicator if battery power is low + clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); +} + static watch_date_time clock_24h_to_12h(watch_date_time date_time) { date_time.unit.hour %= 12; @@ -94,11 +99,8 @@ static void clock_check_battery_periodically(clock_state_t *clock, watch_date_ti watch_disable_adc(); clock->battery_low = voltage < CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD; -} -static void clock_indicate_low_available_power(clock_state_t *clock) { - // Set the LAP indicator if battery power is low - clock_indicate(WATCH_INDICATOR_LAP, clock->battery_low); + clock_indicate_low_available_power(clock); } static void clock_toggle_time_signal(clock_state_t *clock) { @@ -237,7 +239,6 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void clock_display_clock(settings, state, current); clock_check_battery_periodically(state, current); - clock_indicate_low_available_power(state); state->date_time.previous = current; From 3e475f412fb195358445f393d500ab7e1b76865c Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:27:40 -0300 Subject: [PATCH 19/19] faces/clock: update copyrights and credits Update the copyrights to include full name attribution to all who contributed to the clock watch face, including myself. Also add an SPDX license identifier header comment to the files. --- movement/watch_faces/clock/clock_face.c | 10 +++++++++- movement/watch_faces/clock/clock_face.h | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 27d9acc01..6d40fe15d 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -1,7 +1,15 @@ +/* SPDX-License-Identifier: MIT */ + /* * MIT License * - * Copyright (c) 2022 Joey Castillo + * Copyright © 2021-2023 Joey Castillo + * Copyright © 2022 David Keck + * Copyright © 2022 TheOnePerson + * Copyright © 2023 Jeremy O'Brien + * Copyright © 2023 Mikhail Svarichevsky <3@14.by> + * Copyright © 2023 Wesley Aptekar-Cassels + * Copyright © 2024 Matheus Afonso Martins Moreira * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/movement/watch_faces/clock/clock_face.h b/movement/watch_faces/clock/clock_face.h index f973f2707..c4209e3bd 100644 --- a/movement/watch_faces/clock/clock_face.h +++ b/movement/watch_faces/clock/clock_face.h @@ -1,7 +1,13 @@ +/* SPDX-License-Identifier: MIT */ + /* * MIT License * - * Copyright (c) 2022 Joey Castillo + * Copyright © 2021-2022 Joey Castillo + * Copyright © 2022 Alexsander Akers + * Copyright © 2022 TheOnePerson + * Copyright © 2023 Alex Utter + * Copyright © 2024 Matheus Afonso Martins Moreira * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal