From 8f040252fd6bfd5c95437a52a07634a19c487086 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:19:12 -0300 Subject: [PATCH 01/20] faces: rename simple_clock_face to clock_face It's not actually so simple and will only gain features from now on. Just "clock face" also feels more canonical. --- movement/make/Makefile | 2 +- movement/movement_config.h | 2 +- movement/movement_faces.h | 2 +- .../{simple_clock_face.c => clock_face.c} | 24 ++++++------- .../{simple_clock_face.h => clock_face.h} | 35 ++++++++++--------- 5 files changed, 33 insertions(+), 32 deletions(-) rename movement/watch_faces/clock/{simple_clock_face.c => clock_face.c} (88%) rename movement/watch_faces/clock/{simple_clock_face.h => clock_face.h} (63%) diff --git a/movement/make/Makefile b/movement/make/Makefile index 42dfc644..8573c585 100644 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -49,7 +49,7 @@ SRCS += \ ../../littlefs/lfs_util.c \ ../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_config.h b/movement/movement_config.h index 067ca44b..d235e4a1 100644 --- a/movement/movement_config.h +++ b/movement/movement_config.h @@ -28,7 +28,7 @@ #include "movement_faces.h" const watch_face_t watch_faces[] = { - simple_clock_face, + clock_face, world_clock_face, sunrise_sunset_face, moon_phase_face, diff --git a/movement/movement_faces.h b/movement/movement_faces.h index 7feb0f40..949a071a 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -25,7 +25,7 @@ #ifndef MOVEMENT_FACES_H_ #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/simple_clock_face.c b/movement/watch_faces/clock/clock_face.c similarity index 88% rename from movement/watch_faces/clock/simple_clock_face.c rename to movement/watch_faces/clock/clock_face.c index fbc2c4b3..a18bc3a1 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -23,31 +23,31 @@ */ #include -#include "simple_clock_face.h" +#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, simple_clock_state_t *state) { +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 simple_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) { +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(simple_clock_state_t)); - simple_clock_state_t *state = (simple_clock_state_t *)*context_ptr; + *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 simple_clock_face_activate(movement_settings_t *settings, void *context) { - simple_clock_state_t *state = (simple_clock_state_t *)context; +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(); @@ -66,8 +66,8 @@ void simple_clock_face_activate(movement_settings_t *settings, void *context) { state->previous_date_time = 0xFFFFFFFF; } -bool simple_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { - simple_clock_state_t *state = (simple_clock_state_t *)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; @@ -145,14 +145,14 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting return true; } -void simple_clock_face_resign(movement_settings_t *settings, void *context) { +void clock_face_resign(movement_settings_t *settings, void *context) { (void) settings; (void) context; } -bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) { +bool clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; - simple_clock_state_t *state = (simple_clock_state_t *)context; + clock_state_t *state = (clock_state_t *) context; if (!state->signal_enabled) return false; watch_date_time date_time = watch_rtc_get_date_time(); diff --git a/movement/watch_faces/clock/simple_clock_face.h b/movement/watch_faces/clock/clock_face.h similarity index 63% rename from movement/watch_faces/clock/simple_clock_face.h rename to movement/watch_faces/clock/clock_face.h index e74a6e86..d2aa5ecb 100644 --- a/movement/watch_faces/clock/simple_clock_face.h +++ b/movement/watch_faces/clock/clock_face.h @@ -22,16 +22,17 @@ * SOFTWARE. */ -#ifndef SIMPLE_CLOCK_FACE_H_ -#define SIMPLE_CLOCK_FACE_H_ +#ifndef CLOCK_FACE_H_ +#define CLOCK_FACE_H_ /* - * SIMPLE CLOCK FACE + * CLOCK FACE * - * Displays the current time, matching the original operation of the watch. + * 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" @@ -43,20 +44,20 @@ typedef struct { bool signal_enabled; bool battery_low; bool alarm_enabled; -} simple_clock_state_t; +} clock_state_t; -void simple_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); -void simple_clock_face_activate(movement_settings_t *settings, void *context); -bool simple_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context); -void simple_clock_face_resign(movement_settings_t *settings, void *context); -bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context); +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 simple_clock_face ((const watch_face_t){ \ - simple_clock_face_setup, \ - simple_clock_face_activate, \ - simple_clock_face_loop, \ - simple_clock_face_resign, \ - simple_clock_face_wants_background_task, \ +#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 // SIMPLE_CLOCK_FACE_H_ +#endif // CLOCK_FACE_H_ From 01312c2deb1061aeb04fdceb27b2e16608de487b Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:40:21 -0300 Subject: [PATCH 02/20] 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 a18bc3a1..070968a7 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 d2aa5ecb..f973f270 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 e6d8b6aaff4e67aee68c34156f3a781aaa8c2709 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:16:06 -0300 Subject: [PATCH 03/20] 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 070968a7..24e33c9c 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 e2cba9f2f2ed43a9ec4f35749867190aa08de9f9 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:36:34 -0300 Subject: [PATCH 04/20] 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 24e33c9c..ec0afe86 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 2132320d5cd75340a1fca7238c61f4b3e7ecd069 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:44:52 -0300 Subject: [PATCH 05/20] 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 ec0afe86..8fa15449 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 113b4bba9c33bd113becbc49ac1add7fc608986b Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 19:52:51 -0300 Subject: [PATCH 06/20] 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 8fa15449..9eca88e9 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 91713392a5524bf9d10ccd39066643e39ab83b37 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 20:13:07 -0300 Subject: [PATCH 07/20] 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 9eca88e9..8ed0e6a8 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 0773439a4930f644924c10d42786aaa20b3060bd Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 22:31:12 -0300 Subject: [PATCH 08/20] 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 8ed0e6a8..537104a4 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 e7052fe4e27361dce45a3eff4ee1f7c21f69aca2 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 22:38:28 -0300 Subject: [PATCH 09/20] 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 537104a4..08007a89 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 1d79930ab79835222e76567f520a53379ad0546b Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 12:32:31 -0300 Subject: [PATCH 10/20] 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 08007a89..1977ca75 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 76add5a2da6c28e1701d0a69244fc3b3a71c1e67 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 12:40:00 -0300 Subject: [PATCH 11/20] 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 1977ca75..82052133 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 8f0719205332e933219a52001ba31fba78fa12a1 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:00:50 -0300 Subject: [PATCH 12/20] 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 82052133..5b698341 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 bf4d7a3f2bee213e4ef07b27e10436e6402efd3a Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:31:17 -0300 Subject: [PATCH 13/20] 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 5b698341..36f21ff9 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 830200f9c3e7635cf88d42f42f1f0f6e4b0c99a6 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 13:31:28 -0300 Subject: [PATCH 14/20] 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 36f21ff9..4fe02376 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 1e2c23cf13530597b48b838c94dd7711cda8a095 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:06:19 -0300 Subject: [PATCH 15/20] faces/clock: refactor clock display code Simplifies the code by defining dedicated functions for this. --- movement/watch_faces/clock/clock_face.c | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 4fe02376..7e4ec816 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 2df6b2879ad134a56b8486b7224f866c689876cd Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:10:04 -0300 Subject: [PATCH 16/20] 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 7e4ec816..f6c3f3f4 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 5c376d9b9a880e10f3b635508aa21847ea347e6f Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:11:07 -0300 Subject: [PATCH 17/20] 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 f6c3f3f4..8a396569 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 69639a5736aa968cf69509d8ed0adf86f4605a11 Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 14:14:26 -0300 Subject: [PATCH 18/20] 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 8a396569..27d9acc0 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 4cca3a0fac642897bdec06307522f171aa7d9f3b Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sat, 24 Feb 2024 18:27:40 -0300 Subject: [PATCH 19/20] 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 27d9acc0..6d40fe15 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 f973f270..c4209e3b 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 From 4a66035f77a116f1b360110fe1f3f413f9af741e Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 25 Feb 2024 15:18:45 -0300 Subject: [PATCH 20/20] faces/clock: add 24h only feature The clock watch face can now be configured at build time to only display the time in 24h mode. Also enabled in forced 24h mode. This should result in smaller code size due to dead code elimination. --- make.mk | 6 ++++++ movement/watch_faces/clock/clock_face.c | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/make.mk b/make.mk index 955ea310..995acfb6 100644 --- a/make.mk +++ b/make.mk @@ -229,3 +229,9 @@ endif ifeq ($(BOARD), OSO-FEAL-A1-00) CFLAGS += -DCRYSTALLESS endif + +# Build options to customize movement and faces + +ifdef CLOCK_FACE_24H_ONLY +CFLAGS += -DCLOCK_FACE_24H_ONLY +endif diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index 6d40fe15..eab5cd8d 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -42,6 +42,10 @@ #define CLOCK_FACE_LOW_BATTERY_VOLTAGE_THRESHOLD 2200 #endif +#ifndef CLOCK_FACE_24H_ONLY +#define CLOCK_FACE_24H_ONLY 0 +#endif + typedef struct { struct { watch_date_time previous; @@ -52,6 +56,11 @@ typedef struct { bool battery_low; } clock_state_t; +static bool clock_is_in_24h_mode(movement_settings_t *settings) { + if (CLOCK_FACE_24H_ONLY) { return true; } + return settings->bit.clock_mode_24h; +} + static void clock_indicate(WatchIndicatorSegment indicator, bool on) { if (on) { watch_set_indicator(indicator); @@ -69,7 +78,7 @@ static void clock_indicate_time_signal(clock_state_t *clock) { } static void clock_indicate_24h(movement_settings_t *settings) { - clock_indicate(WATCH_INDICATOR_24H, settings->bit.clock_mode_24h); + clock_indicate(WATCH_INDICATOR_24H, clock_is_in_24h_mode(settings)); } static bool clock_is_pm(watch_date_time date_time) { @@ -167,7 +176,7 @@ 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 (!clock_is_in_24h_mode(settings)) { // if we are in 12 hour mode, do some cleanup. clock_indicate_pm(settings, current); current = clock_24h_to_12h(current);