summaryrefslogtreecommitdiffstats
path: root/main/day-night-percent.patch
blob: 5593cd603510a7f549061856ad8656ec9c759e49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
diff --git a/movement/watch_faces/clock/day_night_percentage_face.c b/movement/watch_faces/clock/day_night_percentage_face.c
index 86f07f9..76265ff 100644
--- a/movement/watch_faces/clock/day_night_percentage_face.c
+++ b/movement/watch_faces/clock/day_night_percentage_face.c
@@ -53,6 +53,7 @@ static void recalculate(watch_date_time utc_now, day_night_percentage_state_t *s
     state->daylen = day_length(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat);
 
     state->result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &state->rise, &state->set);
+    state->last_min = utc_now.unit.minute;
 }
 
 void day_night_percentage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
@@ -68,8 +69,10 @@ void day_night_percentage_face_setup(movement_settings_t *settings, uint8_t watc
 }
 
 void day_night_percentage_face_activate(movement_settings_t *settings, void *context) {
+    day_night_percentage_state_t *state = (day_night_percentage_state_t *)context;
     (void) settings;
-    (void) context;
+
+    state->last_min=-1;
 }
 
 bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
@@ -83,7 +86,8 @@ bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t
         case EVENT_ACTIVATE:
         case EVENT_TICK:
         case EVENT_LOW_ENERGY_UPDATE:
-            if ((utc_now.unit.hour == 0 && utc_now.unit.minute == 0 && utc_now.unit.second == 0) || state->result == -2) {
+            if ((utc_now.unit.hour == 0 && utc_now.unit.minute == 0 && utc_now.unit.second == 0) || (state->result == -2) || (state->last_min 
+!= utc_now.unit.minute)) {
                 recalculate(utc_now, state);
             }
 
@@ -106,6 +110,7 @@ bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t
 
                 double day_percentage = (24.0 - better_fmod(state->rise - day_hours_decimal, 24.0)) / state->daylen;
                 double night_percentage = (24.0 - better_fmod(state->set - day_hours_decimal, 24.0)) / (24 - state->daylen);
+                bool day = true;
 
                 uint16_t percentage;
                 if (day_percentage > 0.0 && day_percentage < 1.0) {
@@ -113,13 +118,15 @@ bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t
                     watch_clear_indicator(WATCH_INDICATOR_PM);
                 } else {
                     percentage = night_percentage * 10000;
-                    watch_set_indicator(WATCH_INDICATOR_PM);
+                    //watch_set_indicator(WATCH_INDICATOR_PM);
+                    watch_clear_indicator(WATCH_INDICATOR_PM);
+                    day = false;
                 }
                 if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
                     if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
-                    sprintf(buf, "%s%2d  %02d  ", weekday, date_time.unit.day, percentage / 100);
+                    sprintf(buf, "%s%2d%s%02d  ", weekday, date_time.unit.day, day ? " d":"ni", percentage / 100);
                 } else {
-                    sprintf(buf, "%s%2d  %04d", weekday, date_time.unit.day, percentage);
+                    sprintf(buf, "%s%2d%s%04d", weekday, date_time.unit.day, day ? " d":"ni", percentage);
                 }
                 watch_display_string(buf, 0);
             }
diff --git a/movement/watch_faces/clock/day_night_percentage_face.h b/movement/watch_faces/clock/day_night_percentage_face.h
index d172c74..f6d9a54 100644
--- a/movement/watch_faces/clock/day_night_percentage_face.h
+++ b/movement/watch_faces/clock/day_night_percentage_face.h
@@ -44,6 +44,7 @@
 
 typedef struct {
     int result; // -1, 0, 1: result from sun_rise_set, -2: no location set
+    int8_t last_min;
     double rise;
     double set;
     double daylen;