diff options
author | Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> | 2024-02-24 20:13:07 -0300 |
---|---|---|
committer | Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> | 2024-02-25 15:24:14 -0300 |
commit | 91713392a5524bf9d10ccd39066643e39ab83b37 (patch) | |
tree | 5b551e68eeb63919e7a089a78ca5f3cdeed0f18b | |
parent | 113b4bba9c33bd113becbc49ac1add7fc608986b (diff) | |
download | Sensor-Watch-91713392a5524bf9d10ccd39066643e39ab83b37.tar.gz Sensor-Watch-91713392a5524bf9d10ccd39066643e39ab83b37.tar.bz2 Sensor-Watch-91713392a5524bf9d10ccd39066643e39ab83b37.zip |
faces/clock: simplify PM indication function
Simplifies the code by adding dedicated functions for this.
-rw-r--r-- | movement/watch_faces/clock/clock_face.c | 28 |
1 files 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) { |