]> git.earman.xyz Git - sensor-watch.git/commitdiff
faces/clock: simplify PM indication function
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Sat, 24 Feb 2024 23:13:07 +0000 (20:13 -0300)
committerMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Sun, 25 Feb 2024 18:24:14 +0000 (15:24 -0300)
Simplifies the code by adding dedicated functions for this.

movement/watch_faces/clock/clock_face.c

index 9eca88e97747865abab191d44ceb9b6c899f4d1c..8ed0e6a89d5c01d36781737860946cc35a830b46 100644 (file)
@@ -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) {