]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: slight reorganization
authorJoey Castillo <joeycastillo@utexas.edu>
Tue, 25 Jan 2022 22:04:07 +0000 (17:04 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Tue, 25 Jan 2022 22:04:07 +0000 (17:04 -0500)
49 files changed:
movement/make/Makefile
movement/watch_faces/complication/blinky_face.c [new file with mode: 0644]
movement/watch_faces/complication/blinky_face.h [new file with mode: 0644]
movement/watch_faces/complication/countdown_face.c [new file with mode: 0644]
movement/watch_faces/complication/countdown_face.h [new file with mode: 0644]
movement/watch_faces/complication/day_one_face.c [new file with mode: 0644]
movement/watch_faces/complication/day_one_face.h [new file with mode: 0644]
movement/watch_faces/complication/pulsometer_face.c [new file with mode: 0644]
movement/watch_faces/complication/pulsometer_face.h [new file with mode: 0644]
movement/watch_faces/complication/stopwatch_face.c [new file with mode: 0644]
movement/watch_faces/complication/stopwatch_face.h [new file with mode: 0644]
movement/watch_faces/complication/sunrise_sunset_face.c [new file with mode: 0644]
movement/watch_faces/complication/sunrise_sunset_face.h [new file with mode: 0644]
movement/watch_faces/complication/totp_face.c [new file with mode: 0644]
movement/watch_faces/complication/totp_face.h [new file with mode: 0644]
movement/watch_faces/complications/blinky_face.c [deleted file]
movement/watch_faces/complications/blinky_face.h [deleted file]
movement/watch_faces/complications/countdown_face.c [deleted file]
movement/watch_faces/complications/countdown_face.h [deleted file]
movement/watch_faces/complications/day_one_face.c [deleted file]
movement/watch_faces/complications/day_one_face.h [deleted file]
movement/watch_faces/complications/pulsometer_face.c [deleted file]
movement/watch_faces/complications/pulsometer_face.h [deleted file]
movement/watch_faces/complications/stopwatch_face.c [deleted file]
movement/watch_faces/complications/stopwatch_face.h [deleted file]
movement/watch_faces/complications/sunrise_sunset_face.c [deleted file]
movement/watch_faces/complications/sunrise_sunset_face.h [deleted file]
movement/watch_faces/complications/totp_face.c [deleted file]
movement/watch_faces/complications/totp_face.h [deleted file]
movement/watch_faces/demo/character_set_face.c [new file with mode: 0644]
movement/watch_faces/demo/character_set_face.h [new file with mode: 0644]
movement/watch_faces/demo/demo_face.c [new file with mode: 0644]
movement/watch_faces/demo/demo_face.h [new file with mode: 0644]
movement/watch_faces/demo/hello_there_face.c [new file with mode: 0644]
movement/watch_faces/demo/hello_there_face.h [new file with mode: 0644]
movement/watch_faces/demo/lis2dh_logging_face.c [new file with mode: 0644]
movement/watch_faces/demo/lis2dh_logging_face.h [new file with mode: 0644]
movement/watch_faces/demo/voltage_face.c [new file with mode: 0644]
movement/watch_faces/demo/voltage_face.h [new file with mode: 0644]
movement/watch_faces/demos/character_set_face.c [deleted file]
movement/watch_faces/demos/character_set_face.h [deleted file]
movement/watch_faces/demos/demo_face.c [deleted file]
movement/watch_faces/demos/demo_face.h [deleted file]
movement/watch_faces/demos/hello_there_face.c [deleted file]
movement/watch_faces/demos/hello_there_face.h [deleted file]
movement/watch_faces/demos/lis2dh_logging_face.c [deleted file]
movement/watch_faces/demos/lis2dh_logging_face.h [deleted file]
movement/watch_faces/demos/voltage_face.c [deleted file]
movement/watch_faces/demos/voltage_face.h [deleted file]

index e489a09a1f76ad013ab0f3143ba2e0f2e5a2d866..0834eec55ef908f7938ea577913f09e7d5990a60 100755 (executable)
@@ -13,9 +13,9 @@ INCLUDES += \
   -I../watch_faces/ \
   -I../watch_faces/clock/ \
   -I../watch_faces/settings/ \
-  -I../watch_faces/complications/ \
+  -I../watch_faces/complication/ \
   -I../watch_faces/thermistor/ \
-  -I../watch_faces/demos/ \
+  -I../watch_faces/demo/ \
   -I../lib/TOTP-MCU/ \
   -I../lib/sunriset/ \
 
@@ -35,21 +35,21 @@ SRCS += \
   ../watch_faces/clock/beats_face.c \
   ../watch_faces/settings/preferences_face.c \
   ../watch_faces/settings/set_time_face.c \
-  ../watch_faces/complications/pulsometer_face.c \
   ../watch_faces/thermistor/thermistor_driver.c \
   ../watch_faces/thermistor/thermistor_readout_face.c \
   ../watch_faces/thermistor/thermistor_logging_face.c \
-  ../watch_faces/demos/character_set_face.c \
-  ../watch_faces/demos/voltage_face.c \
-  ../watch_faces/demos/lis2dh_logging_face.c \
-  ../watch_faces/demos/demo_face.c \
-  ../watch_faces/demos/hello_there_face.c \
-  ../watch_faces/complications/day_one_face.c \
-  ../watch_faces/complications/stopwatch_face.c \
-  ../watch_faces/complications/totp_face.c \
-  ../watch_faces/complications/sunrise_sunset_face.c \
-  ../watch_faces/complications/countdown_face.c \
-  ../watch_faces/complications/blinky_face.c \
+  ../watch_faces/demo/character_set_face.c \
+  ../watch_faces/demo/voltage_face.c \
+  ../watch_faces/demo/lis2dh_logging_face.c \
+  ../watch_faces/demo/demo_face.c \
+  ../watch_faces/demo/hello_there_face.c \
+  ../watch_faces/complication/pulsometer_face.c \
+  ../watch_faces/complication/day_one_face.c \
+  ../watch_faces/complication/stopwatch_face.c \
+  ../watch_faces/complication/totp_face.c \
+  ../watch_faces/complication/sunrise_sunset_face.c \
+  ../watch_faces/complication/countdown_face.c \
+  ../watch_faces/complication/blinky_face.c \
 
 # Leave this line at the bottom of the file; it has all the targets for making your project.
 include $(TOP)/rules.mk
diff --git a/movement/watch_faces/complication/blinky_face.c b/movement/watch_faces/complication/blinky_face.c
new file mode 100644 (file)
index 0000000..4c17476
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "blinky_face.h"
+#include "watch.h"
+
+void blinky_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(blinky_face_state_t));
+        memset(*context_ptr, 0, sizeof(blinky_face_state_t));
+    }
+}
+
+void blinky_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    blinky_face_state_t *state = (blinky_face_state_t *)context;
+    state->active = false;
+}
+
+static void _blinky_face_update_lcd(blinky_face_state_t *state) {
+    char buf[11];
+    const char colors[][7] = {" red  ", " Green", " Yello"};
+    sprintf(buf, "BL %c%s", state->fast ? 'F' : 'S', colors[state->color]);
+    watch_display_string(buf, 0);
+}
+
+bool blinky_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    blinky_face_state_t *state = (blinky_face_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            _blinky_face_update_lcd(state);
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            if (!state->active) {
+                state->color = (state->color + 1) % 3;
+                _blinky_face_update_lcd(state);
+            }
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            if (!state->active) {
+                state->active = true;
+                watch_clear_display();
+                movement_request_tick_frequency(state->fast ? 8 : 2);            
+            } else {
+                state->active = false;
+                watch_set_led_off();
+                _blinky_face_update_lcd(state);
+            }
+            break;
+        case EVENT_ALARM_LONG_PRESS:
+            if (!state->active) {
+                state->fast = !state->fast;
+                _blinky_face_update_lcd(state);
+            }
+            break;
+        case EVENT_TICK:
+            if (state->active) {
+                if (event.subsecond % 2 == 0) watch_set_led_off();
+                else if (state->color == 0) watch_set_led_red();
+                else if (state->color == 1) watch_set_led_green();
+                else watch_set_led_yellow();
+            }
+            break;
+        case EVENT_TIMEOUT:
+            if (!state->active) movement_move_to_face(0);
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void blinky_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    watch_set_led_off();
+}
diff --git a/movement/watch_faces/complication/blinky_face.h b/movement/watch_faces/complication/blinky_face.h
new file mode 100644 (file)
index 0000000..e966ab1
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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 BLINKY_FACE_H_
+#define BLINKY_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    bool active;
+    bool fast;
+    uint8_t color;
+} blinky_face_state_t;
+
+void blinky_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void blinky_face_activate(movement_settings_t *settings, void *context);
+bool blinky_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void blinky_face_resign(movement_settings_t *settings, void *context);
+
+#define blinky_face ((const watch_face_t){ \
+    blinky_face_setup, \
+    blinky_face_activate, \
+    blinky_face_loop, \
+    blinky_face_resign, \
+    NULL, \
+})
+
+#endif // BLINKY_FACE_H_
diff --git a/movement/watch_faces/complication/countdown_face.c b/movement/watch_faces/complication/countdown_face.c
new file mode 100644 (file)
index 0000000..a910e96
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Wesley Ellis
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include "countdown_face.h"
+#include "watch.h"
+#include "watch_utility.h"
+
+
+#define CD_SELECTIONS 2
+#define DEFAULT_MINUTES 3
+
+
+static uint32_t offset_date_time(uint32_t now, int8_t hours, int8_t minutes, int8_t seconds) {
+    uint32_t new = now;
+    new += hours * 60 * 60;
+    new += minutes * 60;
+    new += seconds;
+    return new;
+}
+
+static inline int32_t get_tz_offset(movement_settings_t *settings) {
+    return movement_timezone_offsets[settings->bit.time_zone] * 60;
+}
+
+static void start(countdown_state_t *state, movement_settings_t *settings) {
+    watch_date_time now = watch_rtc_get_date_time();
+
+    state->mode = cd_running;
+    state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
+    state->target_ts = offset_date_time(state->now_ts, 0, state->minutes, state->seconds);
+    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
+    movement_schedule_background_task(target_dt);
+    watch_set_indicator(WATCH_INDICATOR_BELL);
+}
+
+static void draw(countdown_state_t *state, uint8_t subsecond) {
+    char buf[16];
+
+    uint32_t delta;
+    div_t result;
+    uint8_t min, sec;
+
+    switch (state->mode) {
+        case cd_running:
+            delta = state->target_ts - state->now_ts;
+            result = div(delta, 60);
+            min = result.quot;
+            sec = result.rem;
+
+            sprintf(buf, "CD    %2d%02d", min, sec);
+            break;
+        case cd_waiting:
+            sprintf(buf, "CD    %2d%02d", state->minutes, state->seconds);
+            break;
+        case cd_setting:
+            sprintf(buf, "CD    %2d%02d", state->minutes, state->seconds);
+            if (subsecond % 2) {
+                switch(state->selection) {
+                    case 0:
+                        buf[6] = buf[7] = ' ';
+                        break;
+                    case 1:
+                        buf[8] = buf[9] = ' ';
+                        break;
+                    default:
+                        break;
+                }
+            }
+            break;
+    }
+    watch_display_string(buf, 0);
+}
+
+static void reset(countdown_state_t *state) {
+    state->mode = cd_waiting;
+    movement_cancel_background_task();
+    watch_clear_indicator(WATCH_INDICATOR_BELL);
+}
+
+static void ring(countdown_state_t *state) {
+    movement_play_signal();
+    reset(state);
+}
+
+static void settings_increment(countdown_state_t *state) {
+    switch(state->selection) {
+        case 0:
+            state->minutes = (state->minutes + 1) % 100;
+            break;
+        case 1:
+            state->seconds = (state->seconds + 1) % 60;
+            break;
+        default:
+            // should never happen
+            break;
+    }
+    return;
+}
+
+void countdown_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(countdown_state_t));
+        countdown_state_t *state = (countdown_state_t *)*context_ptr;
+        memset(*context_ptr, 0, sizeof(countdown_state_t));
+        state->minutes = DEFAULT_MINUTES;
+    }
+}
+
+void countdown_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    countdown_state_t *state = (countdown_state_t *)context;
+    if(state->mode == cd_running) {
+        watch_date_time now = watch_rtc_get_date_time();
+        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
+    }
+}
+
+
+bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    countdown_state_t *state = (countdown_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            draw(state, event.subsecond);
+            break;
+        case EVENT_TICK:
+            if (state->mode == cd_running) {
+                state->now_ts++;
+            }
+            draw(state, event.subsecond);
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            switch(state->mode) {
+                case cd_running:
+                    movement_illuminate_led();
+                    break;
+                case cd_waiting:
+                    state->mode = cd_setting;
+                    movement_request_tick_frequency(4);
+                    break;
+                case cd_setting:
+                    state->selection++;
+                    if(state->selection >= CD_SELECTIONS) {
+                        state->selection = 0;
+                        state->mode = cd_waiting;
+                        movement_request_tick_frequency(1);
+                    }
+                    break;
+            }
+            draw(state, event.subsecond);
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            switch(state->mode) {
+                case cd_running:
+                    reset(state);
+                    break;
+                case cd_waiting:
+                    start(state, settings);
+                    break;
+                case cd_setting:
+                    settings_increment(state);
+                    break;
+            }
+            draw(state, event.subsecond);
+            break;
+        case EVENT_BACKGROUND_TASK:
+            ring(state);
+            break;
+        case EVENT_ALARM_LONG_PRESS:
+            if (state->mode == cd_setting) {
+                    state->minutes = DEFAULT_MINUTES;
+                    state->seconds = 0;
+                    draw(state, event.subsecond);
+                    break;
+            }
+            break;
+        case EVENT_TIMEOUT:
+            movement_move_to_face(0);
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+        default:
+          break;
+    }
+
+    return true;
+}
+
+void countdown_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    countdown_state_t *state = (countdown_state_t *)context;
+    if (state->mode == cd_setting) {
+        state->selection = 0;
+        state->mode = cd_waiting;
+    }
+}
diff --git a/movement/watch_faces/complication/countdown_face.h b/movement/watch_faces/complication/countdown_face.h
new file mode 100644 (file)
index 0000000..657c637
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2022 Wesley Ellis
+ *
+ * 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 COUNTDOWN_FACE_H_
+#define COUNTDOWN_FACE_H_
+
+#include "movement.h"
+
+/*
+A countdown/timer face
+
+Max countdown is 99 minutes and 59 seconds since we have to prevent the watch
+from going to deep sleep using movement_schedule_background_task
+*/
+
+
+typedef enum {
+    cd_waiting,
+    cd_running,
+    cd_setting
+} countdown_mode_t;
+
+typedef struct {
+    uint32_t target_ts;
+    uint32_t now_ts;
+    uint8_t minutes;
+    uint8_t seconds;
+    uint8_t selection;
+    countdown_mode_t mode;
+} countdown_state_t;
+
+
+void countdown_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void countdown_face_activate(movement_settings_t *settings, void *context);
+bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void countdown_face_resign(movement_settings_t *settings, void *context);
+
+#define countdown_face ((const watch_face_t){ \
+    countdown_face_setup, \
+    countdown_face_activate, \
+    countdown_face_loop, \
+    countdown_face_resign, \
+    NULL, \
+})
+
+#endif // COUNTDOWN_FACE_H_
diff --git a/movement/watch_faces/complication/day_one_face.c b/movement/watch_faces/complication/day_one_face.c
new file mode 100644 (file)
index 0000000..9943399
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "day_one_face.h"
+#include "watch.h"
+
+static uint32_t _day_one_face_juliandaynum(uint16_t year, uint16_t month, uint16_t day) {
+    // from here: https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
+    return (1461 * (year + 4800 + (month - 14) / 12)) / 4 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - (3 * ((year + 4900 + (month - 14) / 12) / 100))/4 + day - 32075;
+}
+
+static void _day_one_face_update(day_one_state_t state) {
+    char buf[14];
+    watch_date_time date_time = watch_rtc_get_date_time();
+    uint32_t julian_date = _day_one_face_juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day);
+    uint32_t julian_birthdate = _day_one_face_juliandaynum(state.birth_year, state.birth_month, state.birth_day);
+    sprintf(buf, "DA  %6lu", julian_date - julian_birthdate);
+    watch_display_string(buf, 0);
+}
+
+void day_one_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(day_one_state_t));
+        memset(*context_ptr, 0, sizeof(day_one_state_t));
+        movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
+        if (movement_birthdate.reg == 0) {
+            // if birth date is totally blank, set a reasonable starting date. this works well for anyone under 63, but
+            // you can keep pressing to go back to 1900; just pass the current year. also picked this date because if you
+            // set it to 1959-01-02, it counts up from the launch of Luna-1, the first spacecraft to leave the well.
+            movement_birthdate.bit.year = 1959;
+            movement_birthdate.bit.month = 1;
+            movement_birthdate.bit.day = 1;
+            watch_store_backup_data(movement_birthdate.reg, 2);
+        }
+    }
+}
+
+void day_one_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    day_one_state_t *state = (day_one_state_t *)context;
+
+    // stash the current year, useful in birthday setting mode.
+    watch_date_time date_time = watch_rtc_get_date_time();
+    state->current_year = date_time.unit.year + WATCH_RTC_REFERENCE_YEAR;
+    // reset the current page to 0, display days alive.
+    state->current_page = 0;
+
+    // fetch the user's birth date from the birthday register.
+    movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
+    state->birth_year = movement_birthdate.bit.year;
+    state->birth_month = movement_birthdate.bit.month;
+    state->birth_day = movement_birthdate.bit.day;
+}
+
+bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    day_one_state_t *state = (day_one_state_t *)context;
+
+    const uint8_t days_in_month[12] = {31, 29, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31};
+    char buf[6];
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            _day_one_face_update(*state);
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+        case EVENT_TICK:
+            if (state->current_page != 0) {
+                // if in settings mode, update whatever the current page is
+                switch (state->current_page) {
+                    case 1:
+                        watch_display_string("YR        ", 0);
+                        if (event.subsecond % 2) {
+                            sprintf(buf, "%4d", state->birth_year);
+                            watch_display_string(buf, 4);
+                        }
+                        break;
+                    case 2:
+                        watch_display_string("MO        ", 0);
+                        if (event.subsecond % 2) {
+                            sprintf(buf, "%2d", state->birth_month);
+                            watch_display_string(buf, 4);
+                        }
+                        break;
+                    case 3:
+                        watch_display_string("DA        ", 0);
+                        if (event.subsecond % 2) {
+                            sprintf(buf, "%2d", state->birth_day);
+                            watch_display_string(buf, 6);
+                        }
+                        break;
+                }
+            } else {
+                // otherwise, check if we have to update. the display only needs to change at midnight!
+                watch_date_time date_time = watch_rtc_get_date_time();
+                if (date_time.unit.hour == 0 &&  date_time.unit.minute == 0 && date_time.unit.second == 0) {
+                    _day_one_face_update(*state);
+                }
+            }
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            // only illuminate if we're in display mode
+            if (state->current_page == 0) movement_illuminate_led();
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            // otherwise use the light button to advance settings pages.
+            if (state->current_page != 0) {
+                // go to next setting page...
+                state->current_page = (state->current_page + 1) % 4;
+                if (state->current_page == 0) {
+                    // ...unless we've been pushed back to display mode.
+                    movement_request_tick_frequency(1);
+                    // force display since it normally won't update til midnight.
+                    _day_one_face_update(*state);
+                }
+            }
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            // if we are on a settings page, increment whatever value we're setting.
+            if (state->current_page != 0) {
+                state->birthday_changed = true;
+                switch (state->current_page) {
+                    case 1:
+                        state->birth_year = state->birth_year + 1;
+                        if (state->birth_year > state->current_year) state->birth_year = 1900;
+                        break;
+                    case 2:
+                        state->birth_month = (state->birth_month % 12) + 1;
+                        break;
+                    case 3:
+                        state->birth_day = state->birth_day + 1;
+                        if (state->birth_day == 0 || state->birth_day > days_in_month[state->birth_month - 1]) {
+                            state->birth_day = 1;
+                        }
+                        break;
+                }
+            }
+            break;
+        case EVENT_ALARM_LONG_PRESS:
+            // if we aren't already in settings mode, put us there.
+            if (state->current_page == 0) {
+                state->current_page++;
+                movement_request_tick_frequency(4);
+            }
+            break;
+        case EVENT_TIMEOUT:
+            // return home if we're on a settings page (this saves our changes when we resign).
+            if (state->current_page != 0) {
+                movement_move_to_face(0);
+            }
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void day_one_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    day_one_state_t *state = (day_one_state_t *)context;
+
+    // if the user changed their birth date, store it to the birth date register
+    if (state->birthday_changed) {
+        day_one_state_t *state = (day_one_state_t *)context;
+        movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
+        movement_birthdate.bit.year = state->birth_year;
+        movement_birthdate.bit.month = state->birth_month;
+        movement_birthdate.bit.day = state->birth_day;
+        watch_store_backup_data(movement_birthdate.reg, 2);
+        state->birthday_changed = false;
+    }
+}
diff --git a/movement/watch_faces/complication/day_one_face.h b/movement/watch_faces/complication/day_one_face.h
new file mode 100644 (file)
index 0000000..ab8372b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 DAY_ONE_FACE_H_
+#define DAY_ONE_FACE_H_
+
+#include "movement.h"
+
+// The Day One face is designed to count upwards from the wearer's date of birth. It also functions as an
+// interface for setting the birth date register, which other watch faces can use for various purposes.
+
+typedef struct {
+    uint8_t current_page;
+    uint16_t current_year;
+    uint16_t birth_year;
+    uint8_t birth_month;
+    uint8_t birth_day;
+    bool birthday_changed;
+} day_one_state_t;
+
+void day_one_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void day_one_face_activate(movement_settings_t *settings, void *context);
+bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void day_one_face_resign(movement_settings_t *settings, void *context);
+
+#define day_one_face ((const watch_face_t){ \
+    day_one_face_setup, \
+    day_one_face_activate, \
+    day_one_face_loop, \
+    day_one_face_resign, \
+    NULL, \
+})
+
+#endif // DAY_ONE_FACE_H_
diff --git a/movement/watch_faces/complication/pulsometer_face.c b/movement/watch_faces/complication/pulsometer_face.c
new file mode 100644 (file)
index 0000000..28ca1a5
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "pulsometer_face.h"
+#include "watch.h"
+
+#define PULSOMETER_FACE_FREQUENCY_FACTOR (4ul) // refresh rate will be 2 to this power Hz (0 for 1 Hz, 2 for 4 Hz, etc.)
+#define PULSOMETER_FACE_FREQUENCY (1 << PULSOMETER_FACE_FREQUENCY_FACTOR)
+
+void pulsometer_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(pulsometer_state_t));
+}
+
+void pulsometer_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    memset(context, 0, sizeof(pulsometer_state_t));
+}
+
+bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    pulsometer_state_t *pulsometer_state = (pulsometer_state_t *)context;
+    char buf[14];
+    switch (event.event_type) {
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            break;
+        case EVENT_ALARM_BUTTON_DOWN:
+            pulsometer_state->measuring = true;
+            pulsometer_state->pulse = 0xFFFF;
+            pulsometer_state->ticks = 0;
+            movement_request_tick_frequency(PULSOMETER_FACE_FREQUENCY);
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+        case EVENT_ALARM_LONG_PRESS:
+            pulsometer_state->measuring = false;
+            movement_request_tick_frequency(1);
+            break;
+        case EVENT_TICK:
+            if (pulsometer_state->pulse == 0 && !pulsometer_state->measuring) {
+                switch (pulsometer_state->ticks % 5) {
+                    case 0:
+                        watch_display_string("  Hold  ", 2);
+                        break;
+                    case 1:
+                        watch_display_string(" Alarn", 4);
+                        break;
+                    case 2:
+                        watch_display_string("+   Count ", 0);
+                        break;
+                    case 3:
+                        watch_display_string("  30Beats ", 0);
+                        break;
+                    case 4:
+                        watch_clear_display();
+                        break;
+                }
+                pulsometer_state->ticks = (pulsometer_state->ticks + 1) % 5;
+            } else {
+                if (pulsometer_state->measuring && pulsometer_state->ticks) {
+                    pulsometer_state->pulse = (int16_t)((30.0 * ((float)(60 << PULSOMETER_FACE_FREQUENCY_FACTOR) / (float)pulsometer_state->ticks)) + 0.5);
+                }
+                if (pulsometer_state->pulse > 240) {
+                    watch_display_string("        Hi", 0);
+                } else if (pulsometer_state->pulse < 40) {
+                    watch_display_string("        Lo", 0);
+                } else {
+                    sprintf(buf, "    %-3dbpn", pulsometer_state->pulse);
+                    watch_display_string(buf, 0);
+                }
+                if (pulsometer_state->measuring) pulsometer_state->ticks++;
+            }
+            break;
+        case EVENT_TIMEOUT:
+            movement_move_to_face(0);
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void pulsometer_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/complication/pulsometer_face.h b/movement/watch_faces/complication/pulsometer_face.h
new file mode 100644 (file)
index 0000000..600201e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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 PULSOMETER_FACE_H_
+#define PULSOMETER_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    bool measuring;
+    int16_t pulse;
+    int16_t ticks;
+} pulsometer_state_t;
+
+void pulsometer_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void pulsometer_face_activate(movement_settings_t *settings, void *context);
+bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void pulsometer_face_resign(movement_settings_t *settings, void *context);
+
+#define pulsometer_face ((const watch_face_t){ \
+    pulsometer_face_setup, \
+    pulsometer_face_activate, \
+    pulsometer_face_loop, \
+    pulsometer_face_resign, \
+    NULL, \
+})
+
+#endif // PULSOMETER_FACE_H_
diff --git a/movement/watch_faces/complication/stopwatch_face.c b/movement/watch_faces/complication/stopwatch_face.c
new file mode 100644 (file)
index 0000000..4a145ab
--- /dev/null
@@ -0,0 +1,77 @@
+#include <stdlib.h>
+#include <string.h>
+#include "stopwatch_face.h"
+#include "watch.h"
+
+void stopwatch_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(stopwatch_state_t));
+}
+
+void stopwatch_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    memset(context, 0, sizeof(stopwatch_state_t));
+}
+
+bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+
+    stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context;
+    char buf[14];
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            watch_set_colon();
+            stopwatch_state->running = false;
+            watch_display_string("st 00000", 0);
+            break;
+        case EVENT_TICK:
+            if (stopwatch_state->running) {
+                stopwatch_state->seconds++;
+                if (stopwatch_state->seconds == 60) {
+                    stopwatch_state->minutes++;
+                    stopwatch_state->seconds = 0;
+                }
+                if (stopwatch_state->minutes == 60) {
+                    stopwatch_state->hours++;
+                    stopwatch_state->minutes = 0;
+                }
+            }
+
+            sprintf(buf, "st%2d%02d%02d", stopwatch_state->hours, stopwatch_state->minutes, stopwatch_state->seconds);
+            watch_display_string(buf, 0);
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            if (!stopwatch_state->running) {
+                stopwatch_state->seconds = 0;
+                stopwatch_state->minutes = 0;
+                stopwatch_state->hours = 0;
+                watch_display_string("st 00000", 0);
+            }
+            break;
+        case EVENT_ALARM_BUTTON_DOWN:
+            stopwatch_state->running = !stopwatch_state->running;
+            break;
+        case EVENT_TIMEOUT:
+            // explicitly ignore the timeout event so we stay on screen
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+            stopwatch_state->running = false;
+            watch_set_indicator(WATCH_INDICATOR_BELL);
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void stopwatch_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
\ No newline at end of file
diff --git a/movement/watch_faces/complication/stopwatch_face.h b/movement/watch_faces/complication/stopwatch_face.h
new file mode 100644 (file)
index 0000000..c6e3aad
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef STOPWATCH_FACE_H_
+#define STOPWATCH_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    bool running;
+    uint8_t seconds;
+    uint8_t minutes;
+    uint8_t hours;
+} stopwatch_state_t;
+
+void stopwatch_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void stopwatch_face_activate(movement_settings_t *settings, void *context);
+bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void stopwatch_face_resign(movement_settings_t *settings, void *context);
+
+#define stopwatch_face ((const watch_face_t){ \
+    stopwatch_face_setup, \
+    stopwatch_face_activate, \
+    stopwatch_face_loop, \
+    stopwatch_face_resign, \
+    NULL, \
+})
+
+#endif // STOPWATCH_FACE_H_
diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c
new file mode 100644 (file)
index 0000000..5c47d5d
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * 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.
+ *
+ * Sunrise/sunset calculations are public domain code by Paul Schlyter, December 1992
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "sunrise_sunset_face.h"
+#include "watch.h"
+#include "watch_utility.h"
+#include "sunriset.h"
+
+static void _sunrise_sunset_face_update(movement_settings_t *settings) {
+    char buf[14];
+    double rise, set, minutes;
+    // TODO: allow user to set location, using New York for now.
+    movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
+
+    // TODO: account for time zone, currently only operates in GMT.
+    watch_date_time date_time = watch_rtc_get_date_time(); // the current date / time
+    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
+    watch_date_time scratch_time; // scratchpad, contains different values at different times
+    scratch_time.reg = date_time.reg;
+    int16_t lat_centi = (int16_t)movement_location.bit.latitude;
+    int16_t lon_centi = (int16_t)movement_location.bit.longitude;
+
+    double lat = (double)lat_centi / 100.0;
+    double lon = (double)lon_centi / 100.0;
+
+    for(int i = 0; i < 2; i++) {
+        uint8_t result = sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &rise, &set);
+
+        if (result != 0) {
+            watch_clear_colon();
+            watch_clear_indicator(WATCH_INDICATOR_PM);
+            watch_clear_indicator(WATCH_INDICATOR_24H);
+            sprintf(buf, "%s%d none ", (result == 1) ? "SE" : "rI", scratch_time.unit.day);
+            watch_display_string(buf, 0);
+            return;
+        }
+
+        watch_set_colon();
+        // TODO: account for user's 12H/24H preference
+        watch_set_indicator(WATCH_INDICATOR_24H);
+
+        minutes = 60.0 * fmod(rise, 1);
+        scratch_time.unit.hour = floor(rise);
+        scratch_time.unit.minute = floor(minutes);
+        scratch_time.unit.second = 60.0 * fmod(minutes, 1);
+
+        if (utc_now.reg < scratch_time.reg) {
+            // display today's sunrise, it hasn't happened yet
+            scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
+            sprintf(buf, "rI%2d%2d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
+            watch_display_string(buf, 0);
+            return;
+        }
+
+        minutes = 60.0 * fmod(set, 1);
+        scratch_time.unit.hour = floor(set);
+        scratch_time.unit.minute = floor(minutes);
+        scratch_time.unit.second = 60.0 * fmod(minutes, 1);
+
+        if (utc_now.reg < scratch_time.reg) {
+            // display today's sunset, it hasn't happened yet
+            scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
+            sprintf(buf, "SE%2d%02d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
+            watch_display_string(buf, 0);
+            return;
+        }
+
+
+        // it's after sunset. we need to display sunrise for tomorrow.
+        uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, 0);
+        timestamp += 86400;
+        scratch_time = watch_utility_date_time_from_unix_time(timestamp, 0);
+    }
+}
+
+static int16_t _sunrise_sunset_face_latlon_from_struct(sunrise_sunset_lat_lon_settings_t val) {
+    int16_t retval = (val.sign ? -1 : 1) *
+                        (
+                            val.hundreds * 10000 +
+                            val.tens * 1000 +
+                            val.ones * 100 +
+                            val.tenths * 10 +
+                            val.hundredths
+                        );
+    return retval;
+}
+
+static sunrise_sunset_lat_lon_settings_t _sunrise_sunset_face_struct_from_latlon(int16_t val) {
+    sunrise_sunset_lat_lon_settings_t retval;
+
+    if (val < 0) retval.sign = 1;
+    val = abs(val);
+    retval.hundredths = val % 10;
+    val /= 10;
+    retval.tenths = val % 10;
+    val /= 10;
+    retval.ones = val % 10;
+    val /= 10;
+    retval.tens = val % 10;
+    val /= 10;
+    retval.hundreds = val % 10;
+
+    return retval;
+}
+
+static void _sunrise_sunset_face_update_location_register(sunrise_sunset_state_t *state) {
+    if (state->location_changed) {
+        movement_location_t movement_location;
+        int16_t lat = _sunrise_sunset_face_latlon_from_struct(state->working_latitude);
+        int16_t lon = _sunrise_sunset_face_latlon_from_struct(state->working_longitude);
+        movement_location.bit.latitude = lat;
+        movement_location.bit.longitude = lon;
+        watch_store_backup_data(movement_location.reg, 1);
+        state->location_changed = false;
+    }
+}
+
+static void _sunrise_sunset_face_update_settings_display(movement_event_t event, sunrise_sunset_state_t *state) {
+    char buf[12];
+
+    switch (state->page) {
+        case 1:
+            sprintf(buf, "LA  %c %04d", state->working_latitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); // F looks sorta like a plus sign in position 1
+            break;
+        case 2:
+            sprintf(buf, "LO  %c%05d", state->working_longitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)));
+            break;
+    }
+    if (event.subsecond % 2) {
+        buf[state->active_digit + 4] = ' ';
+    }
+    watch_display_string(buf, 0);
+}
+
+static void _sunrise_sunset_face_advance_digit(sunrise_sunset_state_t *state) {
+    state->location_changed = true;
+    switch (state->page) {
+        case 1: // latitude
+            switch (state->active_digit) {
+                case 0:
+                    state->working_latitude.sign++;
+                    break;
+                case 1:
+                    // we skip this digit
+                    break;
+                case 2:
+                    state->working_latitude.tens = (state->working_latitude.tens + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) {
+                        // prevent latitude from going over Â±90.
+                        // TODO: perform these checks when advancing the digit?
+                        state->working_latitude.ones = 0;
+                        state->working_latitude.tenths = 0;
+                        state->working_latitude.hundredths = 0;
+                    }
+                    break;
+                case 3:
+                    state->working_latitude.ones = (state->working_latitude.ones + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.ones = 0;
+                    break;
+                case 4:
+                    state->working_latitude.tenths = (state->working_latitude.tenths + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.tenths = 0;
+                    break;
+                case 5:
+                    state->working_latitude.hundredths = (state->working_latitude.hundredths + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.hundredths = 0;
+                    break;
+            }
+            break;
+        case 2: // longitude
+            switch (state->active_digit) {
+                case 0:
+                    state->working_longitude.sign++;
+                    break;
+                case 1:
+                    state->working_longitude.hundreds = (state->working_longitude.hundreds + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) {
+                        // prevent longitude from going over Â±180
+                        state->working_longitude.tens = 8;
+                        state->working_longitude.ones = 0;
+                        state->working_longitude.tenths = 0;
+                        state->working_longitude.hundredths = 0;
+                    }
+                    break;
+                case 2:
+                    state->working_longitude.tens = (state->working_longitude.tens + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.tens = 0;
+                    break;
+                case 3:
+                    state->working_longitude.ones = (state->working_longitude.ones + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.ones = 0;
+                    break;
+                case 4:
+                    state->working_longitude.tenths = (state->working_longitude.tenths + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.tenths = 0;
+                    break;
+                case 5:
+                    state->working_longitude.hundredths = (state->working_longitude.hundredths + 1) % 10;
+                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.hundredths = 0;
+                    break;
+            }
+            break;
+    }
+}
+
+void sunrise_sunset_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(sunrise_sunset_state_t));
+        memset(*context_ptr, 0, sizeof(sunrise_sunset_state_t));
+    }
+}
+
+void sunrise_sunset_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
+    movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
+    state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude);
+    state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude);
+}
+
+bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+            _sunrise_sunset_face_update(settings);
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+        case EVENT_TICK:
+            if (state->page) _sunrise_sunset_face_update_settings_display(event, state);
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            if (state->page) {
+                state->active_digit++;
+                if (state->page == 1 && state->active_digit == 1) state->active_digit++; // max latitude is +- 90, no hundreds place
+                if (state->active_digit > 5) {
+                    state->active_digit = 0;
+                    state->page = (state->page + 1) % 3;
+                    _sunrise_sunset_face_update_location_register(state);
+                }
+                _sunrise_sunset_face_update_settings_display(event, context);
+            } else {
+                movement_illuminate_led();
+            }
+            if (state->page == 0) {
+                movement_request_tick_frequency(1);
+                _sunrise_sunset_face_update(settings);
+            }
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            if (state->page) {
+                _sunrise_sunset_face_advance_digit(state);
+                _sunrise_sunset_face_update_settings_display(event, context);
+            }
+            break;
+        case EVENT_ALARM_LONG_PRESS:
+            if (state->page == 0) {
+                state->page++;
+                watch_clear_display();
+                movement_request_tick_frequency(4);
+                _sunrise_sunset_face_update_settings_display(event, context);
+            }
+            break;
+        case EVENT_TIMEOUT:
+            if (state->page != 0) {
+                movement_move_to_face(0);
+            }
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void sunrise_sunset_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
+    state->page = 0;
+    state->active_digit = 0;
+    _sunrise_sunset_face_update_location_register(state);
+}
diff --git a/movement/watch_faces/complication/sunrise_sunset_face.h b/movement/watch_faces/complication/sunrise_sunset_face.h
new file mode 100644 (file)
index 0000000..826d5e9
--- /dev/null
@@ -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 SUNRISE_SUNSET_FACE_H_
+#define SUNRISE_SUNSET_FACE_H_
+
+#include "movement.h"
+
+// The Sunrise/Sunset face is designed to display the next sunrise or sunset for a given location.
+// TODO: It also functions as an interface for setting the location register, which other watch faces can use for various purposes.
+
+typedef struct {
+    uint8_t sign: 1;    // 0-1
+    uint8_t hundreds: 1;    // 0-1, ignored for latitude
+    uint8_t tens: 4;        // 0-9 (must wrap at 10)
+    uint8_t ones: 4;        // 0-9 (must wrap at 10)
+    uint8_t tenths: 4;      // 0-9 (must wrap at 10)
+    uint8_t hundredths: 4;  // 0-9 (must wrap at 10)
+} sunrise_sunset_lat_lon_settings_t;
+
+typedef struct {
+    uint8_t page;
+    uint8_t active_digit;
+    bool location_changed;
+    sunrise_sunset_lat_lon_settings_t working_latitude;
+    sunrise_sunset_lat_lon_settings_t working_longitude;
+} sunrise_sunset_state_t;
+
+void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void sunrise_sunset_face_activate(movement_settings_t *settings, void *context);
+bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void sunrise_sunset_face_resign(movement_settings_t *settings, void *context);
+
+#define sunrise_sunset_face ((const watch_face_t){ \
+    sunrise_sunset_face_setup, \
+    sunrise_sunset_face_activate, \
+    sunrise_sunset_face_loop, \
+    sunrise_sunset_face_resign, \
+    NULL, \
+})
+
+#endif // SUNRISE_SUNSET_FACE_H_
diff --git a/movement/watch_faces/complication/totp_face.c b/movement/watch_faces/complication/totp_face.c
new file mode 100644 (file)
index 0000000..468e6a8
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * TODO:
+ * - Support for multiple codes
+ */
+#include <stdlib.h>
+#include <string.h>
+#include "totp_face.h"
+#include "watch.h"
+#include "watch_utility.h"
+#include "TOTP.h"
+
+// test key: JBSWY3DPEHPK3PXP
+// Use https://cryptii.com/pipes/base32-to-hex to convert base32 to hex
+// Use https://totp.danhersam.com/ to generate test codes for verification
+static uint8_t hmacKey[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xde, 0xad, 0xbe, 0xef}; // Secret key
+
+
+static const uint32_t TIMESTEP = 30;
+
+void totp_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(totp_state_t));
+    TOTP(hmacKey, sizeof(hmacKey), TIMESTEP);
+}
+
+void totp_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    memset(context, 0, sizeof(totp_state_t));
+    totp_state_t *totp_state = (totp_state_t *)context;
+    totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
+    totp_state->current_code = getCodeFromTimestamp(totp_state->timestamp);
+}
+
+bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+
+    totp_state_t *totp_state = (totp_state_t *)context;
+    char buf[14];
+    uint8_t valid_for;
+    div_t result;
+
+    switch (event.event_type) {
+        case EVENT_TICK:
+            totp_state->timestamp++;
+            // fall through
+        case EVENT_ACTIVATE:
+            result = div(totp_state->timestamp, TIMESTEP);
+            if (result.quot != totp_state->steps) {
+                totp_state->current_code = getCodeFromTimestamp(totp_state->timestamp);
+                totp_state->steps = result.quot;
+            }
+            valid_for = TIMESTEP - result.rem;
+            sprintf(buf, "2f%2d%06lu", valid_for, totp_state->current_code);
+
+            watch_display_string(buf, 0);
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            break;
+        case EVENT_TIMEOUT:
+            movement_move_to_face(0);
+            break;
+        case EVENT_ALARM_BUTTON_DOWN:
+        case EVENT_ALARM_BUTTON_UP:
+        case EVENT_ALARM_LONG_PRESS:
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void totp_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/complication/totp_face.h b/movement/watch_faces/complication/totp_face.h
new file mode 100644 (file)
index 0000000..dfa4a6d
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef TOTP_FACE_H_
+#define TOTP_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    uint32_t timestamp;
+    uint8_t steps;
+    uint32_t current_code;
+
+} totp_state_t;
+
+void totp_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void totp_face_activate(movement_settings_t *settings, void *context);
+bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void totp_face_resign(movement_settings_t *settings, void *context);
+
+#define totp_face ((const watch_face_t){ \
+    totp_face_setup, \
+    totp_face_activate, \
+    totp_face_loop, \
+    totp_face_resign, \
+    NULL, \
+})
+
+#endif // TOTP_FACE_H_
diff --git a/movement/watch_faces/complications/blinky_face.c b/movement/watch_faces/complications/blinky_face.c
deleted file mode 100644 (file)
index 4c17476..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "blinky_face.h"
-#include "watch.h"
-
-void blinky_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(blinky_face_state_t));
-        memset(*context_ptr, 0, sizeof(blinky_face_state_t));
-    }
-}
-
-void blinky_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    blinky_face_state_t *state = (blinky_face_state_t *)context;
-    state->active = false;
-}
-
-static void _blinky_face_update_lcd(blinky_face_state_t *state) {
-    char buf[11];
-    const char colors[][7] = {" red  ", " Green", " Yello"};
-    sprintf(buf, "BL %c%s", state->fast ? 'F' : 'S', colors[state->color]);
-    watch_display_string(buf, 0);
-}
-
-bool blinky_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    blinky_face_state_t *state = (blinky_face_state_t *)context;
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-            _blinky_face_update_lcd(state);
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            if (!state->active) {
-                state->color = (state->color + 1) % 3;
-                _blinky_face_update_lcd(state);
-            }
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            if (!state->active) {
-                state->active = true;
-                watch_clear_display();
-                movement_request_tick_frequency(state->fast ? 8 : 2);            
-            } else {
-                state->active = false;
-                watch_set_led_off();
-                _blinky_face_update_lcd(state);
-            }
-            break;
-        case EVENT_ALARM_LONG_PRESS:
-            if (!state->active) {
-                state->fast = !state->fast;
-                _blinky_face_update_lcd(state);
-            }
-            break;
-        case EVENT_TICK:
-            if (state->active) {
-                if (event.subsecond % 2 == 0) watch_set_led_off();
-                else if (state->color == 0) watch_set_led_red();
-                else if (state->color == 1) watch_set_led_green();
-                else watch_set_led_yellow();
-            }
-            break;
-        case EVENT_TIMEOUT:
-            if (!state->active) movement_move_to_face(0);
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void blinky_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    watch_set_led_off();
-}
diff --git a/movement/watch_faces/complications/blinky_face.h b/movement/watch_faces/complications/blinky_face.h
deleted file mode 100644 (file)
index e966ab1..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 BLINKY_FACE_H_
-#define BLINKY_FACE_H_
-
-#include "movement.h"
-
-typedef struct {
-    bool active;
-    bool fast;
-    uint8_t color;
-} blinky_face_state_t;
-
-void blinky_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void blinky_face_activate(movement_settings_t *settings, void *context);
-bool blinky_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void blinky_face_resign(movement_settings_t *settings, void *context);
-
-#define blinky_face ((const watch_face_t){ \
-    blinky_face_setup, \
-    blinky_face_activate, \
-    blinky_face_loop, \
-    blinky_face_resign, \
-    NULL, \
-})
-
-#endif // BLINKY_FACE_H_
diff --git a/movement/watch_faces/complications/countdown_face.c b/movement/watch_faces/complications/countdown_face.c
deleted file mode 100644 (file)
index a910e96..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2022 Wesley Ellis
- *
- * 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 <stdlib.h>
-#include <string.h>
-#include "countdown_face.h"
-#include "watch.h"
-#include "watch_utility.h"
-
-
-#define CD_SELECTIONS 2
-#define DEFAULT_MINUTES 3
-
-
-static uint32_t offset_date_time(uint32_t now, int8_t hours, int8_t minutes, int8_t seconds) {
-    uint32_t new = now;
-    new += hours * 60 * 60;
-    new += minutes * 60;
-    new += seconds;
-    return new;
-}
-
-static inline int32_t get_tz_offset(movement_settings_t *settings) {
-    return movement_timezone_offsets[settings->bit.time_zone] * 60;
-}
-
-static void start(countdown_state_t *state, movement_settings_t *settings) {
-    watch_date_time now = watch_rtc_get_date_time();
-
-    state->mode = cd_running;
-    state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
-    state->target_ts = offset_date_time(state->now_ts, 0, state->minutes, state->seconds);
-    watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
-    movement_schedule_background_task(target_dt);
-    watch_set_indicator(WATCH_INDICATOR_BELL);
-}
-
-static void draw(countdown_state_t *state, uint8_t subsecond) {
-    char buf[16];
-
-    uint32_t delta;
-    div_t result;
-    uint8_t min, sec;
-
-    switch (state->mode) {
-        case cd_running:
-            delta = state->target_ts - state->now_ts;
-            result = div(delta, 60);
-            min = result.quot;
-            sec = result.rem;
-
-            sprintf(buf, "CD    %2d%02d", min, sec);
-            break;
-        case cd_waiting:
-            sprintf(buf, "CD    %2d%02d", state->minutes, state->seconds);
-            break;
-        case cd_setting:
-            sprintf(buf, "CD    %2d%02d", state->minutes, state->seconds);
-            if (subsecond % 2) {
-                switch(state->selection) {
-                    case 0:
-                        buf[6] = buf[7] = ' ';
-                        break;
-                    case 1:
-                        buf[8] = buf[9] = ' ';
-                        break;
-                    default:
-                        break;
-                }
-            }
-            break;
-    }
-    watch_display_string(buf, 0);
-}
-
-static void reset(countdown_state_t *state) {
-    state->mode = cd_waiting;
-    movement_cancel_background_task();
-    watch_clear_indicator(WATCH_INDICATOR_BELL);
-}
-
-static void ring(countdown_state_t *state) {
-    movement_play_signal();
-    reset(state);
-}
-
-static void settings_increment(countdown_state_t *state) {
-    switch(state->selection) {
-        case 0:
-            state->minutes = (state->minutes + 1) % 100;
-            break;
-        case 1:
-            state->seconds = (state->seconds + 1) % 60;
-            break;
-        default:
-            // should never happen
-            break;
-    }
-    return;
-}
-
-void countdown_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(countdown_state_t));
-        countdown_state_t *state = (countdown_state_t *)*context_ptr;
-        memset(*context_ptr, 0, sizeof(countdown_state_t));
-        state->minutes = DEFAULT_MINUTES;
-    }
-}
-
-void countdown_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    countdown_state_t *state = (countdown_state_t *)context;
-    if(state->mode == cd_running) {
-        watch_date_time now = watch_rtc_get_date_time();
-        state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
-    }
-}
-
-
-bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    countdown_state_t *state = (countdown_state_t *)context;
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-            draw(state, event.subsecond);
-            break;
-        case EVENT_TICK:
-            if (state->mode == cd_running) {
-                state->now_ts++;
-            }
-            draw(state, event.subsecond);
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            switch(state->mode) {
-                case cd_running:
-                    movement_illuminate_led();
-                    break;
-                case cd_waiting:
-                    state->mode = cd_setting;
-                    movement_request_tick_frequency(4);
-                    break;
-                case cd_setting:
-                    state->selection++;
-                    if(state->selection >= CD_SELECTIONS) {
-                        state->selection = 0;
-                        state->mode = cd_waiting;
-                        movement_request_tick_frequency(1);
-                    }
-                    break;
-            }
-            draw(state, event.subsecond);
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            switch(state->mode) {
-                case cd_running:
-                    reset(state);
-                    break;
-                case cd_waiting:
-                    start(state, settings);
-                    break;
-                case cd_setting:
-                    settings_increment(state);
-                    break;
-            }
-            draw(state, event.subsecond);
-            break;
-        case EVENT_BACKGROUND_TASK:
-            ring(state);
-            break;
-        case EVENT_ALARM_LONG_PRESS:
-            if (state->mode == cd_setting) {
-                    state->minutes = DEFAULT_MINUTES;
-                    state->seconds = 0;
-                    draw(state, event.subsecond);
-                    break;
-            }
-            break;
-        case EVENT_TIMEOUT:
-            movement_move_to_face(0);
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-        default:
-          break;
-    }
-
-    return true;
-}
-
-void countdown_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    countdown_state_t *state = (countdown_state_t *)context;
-    if (state->mode == cd_setting) {
-        state->selection = 0;
-        state->mode = cd_waiting;
-    }
-}
diff --git a/movement/watch_faces/complications/countdown_face.h b/movement/watch_faces/complications/countdown_face.h
deleted file mode 100644 (file)
index 657c637..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2022 Wesley Ellis
- *
- * 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 COUNTDOWN_FACE_H_
-#define COUNTDOWN_FACE_H_
-
-#include "movement.h"
-
-/*
-A countdown/timer face
-
-Max countdown is 99 minutes and 59 seconds since we have to prevent the watch
-from going to deep sleep using movement_schedule_background_task
-*/
-
-
-typedef enum {
-    cd_waiting,
-    cd_running,
-    cd_setting
-} countdown_mode_t;
-
-typedef struct {
-    uint32_t target_ts;
-    uint32_t now_ts;
-    uint8_t minutes;
-    uint8_t seconds;
-    uint8_t selection;
-    countdown_mode_t mode;
-} countdown_state_t;
-
-
-void countdown_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void countdown_face_activate(movement_settings_t *settings, void *context);
-bool countdown_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void countdown_face_resign(movement_settings_t *settings, void *context);
-
-#define countdown_face ((const watch_face_t){ \
-    countdown_face_setup, \
-    countdown_face_activate, \
-    countdown_face_loop, \
-    countdown_face_resign, \
-    NULL, \
-})
-
-#endif // COUNTDOWN_FACE_H_
diff --git a/movement/watch_faces/complications/day_one_face.c b/movement/watch_faces/complications/day_one_face.c
deleted file mode 100644 (file)
index 9943399..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "day_one_face.h"
-#include "watch.h"
-
-static uint32_t _day_one_face_juliandaynum(uint16_t year, uint16_t month, uint16_t day) {
-    // from here: https://en.wikipedia.org/wiki/Julian_day#Julian_day_number_calculation
-    return (1461 * (year + 4800 + (month - 14) / 12)) / 4 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 - (3 * ((year + 4900 + (month - 14) / 12) / 100))/4 + day - 32075;
-}
-
-static void _day_one_face_update(day_one_state_t state) {
-    char buf[14];
-    watch_date_time date_time = watch_rtc_get_date_time();
-    uint32_t julian_date = _day_one_face_juliandaynum(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day);
-    uint32_t julian_birthdate = _day_one_face_juliandaynum(state.birth_year, state.birth_month, state.birth_day);
-    sprintf(buf, "DA  %6lu", julian_date - julian_birthdate);
-    watch_display_string(buf, 0);
-}
-
-void day_one_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(day_one_state_t));
-        memset(*context_ptr, 0, sizeof(day_one_state_t));
-        movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
-        if (movement_birthdate.reg == 0) {
-            // if birth date is totally blank, set a reasonable starting date. this works well for anyone under 63, but
-            // you can keep pressing to go back to 1900; just pass the current year. also picked this date because if you
-            // set it to 1959-01-02, it counts up from the launch of Luna-1, the first spacecraft to leave the well.
-            movement_birthdate.bit.year = 1959;
-            movement_birthdate.bit.month = 1;
-            movement_birthdate.bit.day = 1;
-            watch_store_backup_data(movement_birthdate.reg, 2);
-        }
-    }
-}
-
-void day_one_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    day_one_state_t *state = (day_one_state_t *)context;
-
-    // stash the current year, useful in birthday setting mode.
-    watch_date_time date_time = watch_rtc_get_date_time();
-    state->current_year = date_time.unit.year + WATCH_RTC_REFERENCE_YEAR;
-    // reset the current page to 0, display days alive.
-    state->current_page = 0;
-
-    // fetch the user's birth date from the birthday register.
-    movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
-    state->birth_year = movement_birthdate.bit.year;
-    state->birth_month = movement_birthdate.bit.month;
-    state->birth_day = movement_birthdate.bit.day;
-}
-
-bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    day_one_state_t *state = (day_one_state_t *)context;
-
-    const uint8_t days_in_month[12] = {31, 29, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31};
-    char buf[6];
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-            _day_one_face_update(*state);
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-        case EVENT_TICK:
-            if (state->current_page != 0) {
-                // if in settings mode, update whatever the current page is
-                switch (state->current_page) {
-                    case 1:
-                        watch_display_string("YR        ", 0);
-                        if (event.subsecond % 2) {
-                            sprintf(buf, "%4d", state->birth_year);
-                            watch_display_string(buf, 4);
-                        }
-                        break;
-                    case 2:
-                        watch_display_string("MO        ", 0);
-                        if (event.subsecond % 2) {
-                            sprintf(buf, "%2d", state->birth_month);
-                            watch_display_string(buf, 4);
-                        }
-                        break;
-                    case 3:
-                        watch_display_string("DA        ", 0);
-                        if (event.subsecond % 2) {
-                            sprintf(buf, "%2d", state->birth_day);
-                            watch_display_string(buf, 6);
-                        }
-                        break;
-                }
-            } else {
-                // otherwise, check if we have to update. the display only needs to change at midnight!
-                watch_date_time date_time = watch_rtc_get_date_time();
-                if (date_time.unit.hour == 0 &&  date_time.unit.minute == 0 && date_time.unit.second == 0) {
-                    _day_one_face_update(*state);
-                }
-            }
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            // only illuminate if we're in display mode
-            if (state->current_page == 0) movement_illuminate_led();
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            // otherwise use the light button to advance settings pages.
-            if (state->current_page != 0) {
-                // go to next setting page...
-                state->current_page = (state->current_page + 1) % 4;
-                if (state->current_page == 0) {
-                    // ...unless we've been pushed back to display mode.
-                    movement_request_tick_frequency(1);
-                    // force display since it normally won't update til midnight.
-                    _day_one_face_update(*state);
-                }
-            }
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            // if we are on a settings page, increment whatever value we're setting.
-            if (state->current_page != 0) {
-                state->birthday_changed = true;
-                switch (state->current_page) {
-                    case 1:
-                        state->birth_year = state->birth_year + 1;
-                        if (state->birth_year > state->current_year) state->birth_year = 1900;
-                        break;
-                    case 2:
-                        state->birth_month = (state->birth_month % 12) + 1;
-                        break;
-                    case 3:
-                        state->birth_day = state->birth_day + 1;
-                        if (state->birth_day == 0 || state->birth_day > days_in_month[state->birth_month - 1]) {
-                            state->birth_day = 1;
-                        }
-                        break;
-                }
-            }
-            break;
-        case EVENT_ALARM_LONG_PRESS:
-            // if we aren't already in settings mode, put us there.
-            if (state->current_page == 0) {
-                state->current_page++;
-                movement_request_tick_frequency(4);
-            }
-            break;
-        case EVENT_TIMEOUT:
-            // return home if we're on a settings page (this saves our changes when we resign).
-            if (state->current_page != 0) {
-                movement_move_to_face(0);
-            }
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void day_one_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    day_one_state_t *state = (day_one_state_t *)context;
-
-    // if the user changed their birth date, store it to the birth date register
-    if (state->birthday_changed) {
-        day_one_state_t *state = (day_one_state_t *)context;
-        movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
-        movement_birthdate.bit.year = state->birth_year;
-        movement_birthdate.bit.month = state->birth_month;
-        movement_birthdate.bit.day = state->birth_day;
-        watch_store_backup_data(movement_birthdate.reg, 2);
-        state->birthday_changed = false;
-    }
-}
diff --git a/movement/watch_faces/complications/day_one_face.h b/movement/watch_faces/complications/day_one_face.h
deleted file mode 100644 (file)
index ab8372b..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 DAY_ONE_FACE_H_
-#define DAY_ONE_FACE_H_
-
-#include "movement.h"
-
-// The Day One face is designed to count upwards from the wearer's date of birth. It also functions as an
-// interface for setting the birth date register, which other watch faces can use for various purposes.
-
-typedef struct {
-    uint8_t current_page;
-    uint16_t current_year;
-    uint16_t birth_year;
-    uint8_t birth_month;
-    uint8_t birth_day;
-    bool birthday_changed;
-} day_one_state_t;
-
-void day_one_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void day_one_face_activate(movement_settings_t *settings, void *context);
-bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void day_one_face_resign(movement_settings_t *settings, void *context);
-
-#define day_one_face ((const watch_face_t){ \
-    day_one_face_setup, \
-    day_one_face_activate, \
-    day_one_face_loop, \
-    day_one_face_resign, \
-    NULL, \
-})
-
-#endif // DAY_ONE_FACE_H_
diff --git a/movement/watch_faces/complications/pulsometer_face.c b/movement/watch_faces/complications/pulsometer_face.c
deleted file mode 100644 (file)
index 28ca1a5..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "pulsometer_face.h"
-#include "watch.h"
-
-#define PULSOMETER_FACE_FREQUENCY_FACTOR (4ul) // refresh rate will be 2 to this power Hz (0 for 1 Hz, 2 for 4 Hz, etc.)
-#define PULSOMETER_FACE_FREQUENCY (1 << PULSOMETER_FACE_FREQUENCY_FACTOR)
-
-void pulsometer_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(pulsometer_state_t));
-}
-
-void pulsometer_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    memset(context, 0, sizeof(pulsometer_state_t));
-}
-
-bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    pulsometer_state_t *pulsometer_state = (pulsometer_state_t *)context;
-    char buf[14];
-    switch (event.event_type) {
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            break;
-        case EVENT_ALARM_BUTTON_DOWN:
-            pulsometer_state->measuring = true;
-            pulsometer_state->pulse = 0xFFFF;
-            pulsometer_state->ticks = 0;
-            movement_request_tick_frequency(PULSOMETER_FACE_FREQUENCY);
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-        case EVENT_ALARM_LONG_PRESS:
-            pulsometer_state->measuring = false;
-            movement_request_tick_frequency(1);
-            break;
-        case EVENT_TICK:
-            if (pulsometer_state->pulse == 0 && !pulsometer_state->measuring) {
-                switch (pulsometer_state->ticks % 5) {
-                    case 0:
-                        watch_display_string("  Hold  ", 2);
-                        break;
-                    case 1:
-                        watch_display_string(" Alarn", 4);
-                        break;
-                    case 2:
-                        watch_display_string("+   Count ", 0);
-                        break;
-                    case 3:
-                        watch_display_string("  30Beats ", 0);
-                        break;
-                    case 4:
-                        watch_clear_display();
-                        break;
-                }
-                pulsometer_state->ticks = (pulsometer_state->ticks + 1) % 5;
-            } else {
-                if (pulsometer_state->measuring && pulsometer_state->ticks) {
-                    pulsometer_state->pulse = (int16_t)((30.0 * ((float)(60 << PULSOMETER_FACE_FREQUENCY_FACTOR) / (float)pulsometer_state->ticks)) + 0.5);
-                }
-                if (pulsometer_state->pulse > 240) {
-                    watch_display_string("        Hi", 0);
-                } else if (pulsometer_state->pulse < 40) {
-                    watch_display_string("        Lo", 0);
-                } else {
-                    sprintf(buf, "    %-3dbpn", pulsometer_state->pulse);
-                    watch_display_string(buf, 0);
-                }
-                if (pulsometer_state->measuring) pulsometer_state->ticks++;
-            }
-            break;
-        case EVENT_TIMEOUT:
-            movement_move_to_face(0);
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void pulsometer_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-}
diff --git a/movement/watch_faces/complications/pulsometer_face.h b/movement/watch_faces/complications/pulsometer_face.h
deleted file mode 100644 (file)
index 600201e..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 PULSOMETER_FACE_H_
-#define PULSOMETER_FACE_H_
-
-#include "movement.h"
-
-typedef struct {
-    bool measuring;
-    int16_t pulse;
-    int16_t ticks;
-} pulsometer_state_t;
-
-void pulsometer_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void pulsometer_face_activate(movement_settings_t *settings, void *context);
-bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void pulsometer_face_resign(movement_settings_t *settings, void *context);
-
-#define pulsometer_face ((const watch_face_t){ \
-    pulsometer_face_setup, \
-    pulsometer_face_activate, \
-    pulsometer_face_loop, \
-    pulsometer_face_resign, \
-    NULL, \
-})
-
-#endif // PULSOMETER_FACE_H_
diff --git a/movement/watch_faces/complications/stopwatch_face.c b/movement/watch_faces/complications/stopwatch_face.c
deleted file mode 100644 (file)
index 4a145ab..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "stopwatch_face.h"
-#include "watch.h"
-
-void stopwatch_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(stopwatch_state_t));
-}
-
-void stopwatch_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    memset(context, 0, sizeof(stopwatch_state_t));
-}
-
-bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-
-    stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context;
-    char buf[14];
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-            watch_set_colon();
-            stopwatch_state->running = false;
-            watch_display_string("st 00000", 0);
-            break;
-        case EVENT_TICK:
-            if (stopwatch_state->running) {
-                stopwatch_state->seconds++;
-                if (stopwatch_state->seconds == 60) {
-                    stopwatch_state->minutes++;
-                    stopwatch_state->seconds = 0;
-                }
-                if (stopwatch_state->minutes == 60) {
-                    stopwatch_state->hours++;
-                    stopwatch_state->minutes = 0;
-                }
-            }
-
-            sprintf(buf, "st%2d%02d%02d", stopwatch_state->hours, stopwatch_state->minutes, stopwatch_state->seconds);
-            watch_display_string(buf, 0);
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            if (!stopwatch_state->running) {
-                stopwatch_state->seconds = 0;
-                stopwatch_state->minutes = 0;
-                stopwatch_state->hours = 0;
-                watch_display_string("st 00000", 0);
-            }
-            break;
-        case EVENT_ALARM_BUTTON_DOWN:
-            stopwatch_state->running = !stopwatch_state->running;
-            break;
-        case EVENT_TIMEOUT:
-            // explicitly ignore the timeout event so we stay on screen
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-            stopwatch_state->running = false;
-            watch_set_indicator(WATCH_INDICATOR_BELL);
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void stopwatch_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-}
\ No newline at end of file
diff --git a/movement/watch_faces/complications/stopwatch_face.h b/movement/watch_faces/complications/stopwatch_face.h
deleted file mode 100644 (file)
index c6e3aad..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef STOPWATCH_FACE_H_
-#define STOPWATCH_FACE_H_
-
-#include "movement.h"
-
-typedef struct {
-    bool running;
-    uint8_t seconds;
-    uint8_t minutes;
-    uint8_t hours;
-} stopwatch_state_t;
-
-void stopwatch_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void stopwatch_face_activate(movement_settings_t *settings, void *context);
-bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void stopwatch_face_resign(movement_settings_t *settings, void *context);
-
-#define stopwatch_face ((const watch_face_t){ \
-    stopwatch_face_setup, \
-    stopwatch_face_activate, \
-    stopwatch_face_loop, \
-    stopwatch_face_resign, \
-    NULL, \
-})
-
-#endif // STOPWATCH_FACE_H_
diff --git a/movement/watch_faces/complications/sunrise_sunset_face.c b/movement/watch_faces/complications/sunrise_sunset_face.c
deleted file mode 100644 (file)
index 5c47d5d..0000000
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * 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.
- *
- * Sunrise/sunset calculations are public domain code by Paul Schlyter, December 1992
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include "sunrise_sunset_face.h"
-#include "watch.h"
-#include "watch_utility.h"
-#include "sunriset.h"
-
-static void _sunrise_sunset_face_update(movement_settings_t *settings) {
-    char buf[14];
-    double rise, set, minutes;
-    // TODO: allow user to set location, using New York for now.
-    movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
-
-    // TODO: account for time zone, currently only operates in GMT.
-    watch_date_time date_time = watch_rtc_get_date_time(); // the current date / time
-    watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0); // the current date / time in UTC
-    watch_date_time scratch_time; // scratchpad, contains different values at different times
-    scratch_time.reg = date_time.reg;
-    int16_t lat_centi = (int16_t)movement_location.bit.latitude;
-    int16_t lon_centi = (int16_t)movement_location.bit.longitude;
-
-    double lat = (double)lat_centi / 100.0;
-    double lon = (double)lon_centi / 100.0;
-
-    for(int i = 0; i < 2; i++) {
-        uint8_t result = sun_rise_set(scratch_time.unit.year + WATCH_RTC_REFERENCE_YEAR, scratch_time.unit.month, scratch_time.unit.day, lon, lat, &rise, &set);
-
-        if (result != 0) {
-            watch_clear_colon();
-            watch_clear_indicator(WATCH_INDICATOR_PM);
-            watch_clear_indicator(WATCH_INDICATOR_24H);
-            sprintf(buf, "%s%d none ", (result == 1) ? "SE" : "rI", scratch_time.unit.day);
-            watch_display_string(buf, 0);
-            return;
-        }
-
-        watch_set_colon();
-        // TODO: account for user's 12H/24H preference
-        watch_set_indicator(WATCH_INDICATOR_24H);
-
-        minutes = 60.0 * fmod(rise, 1);
-        scratch_time.unit.hour = floor(rise);
-        scratch_time.unit.minute = floor(minutes);
-        scratch_time.unit.second = 60.0 * fmod(minutes, 1);
-
-        if (utc_now.reg < scratch_time.reg) {
-            // display today's sunrise, it hasn't happened yet
-            scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
-            sprintf(buf, "rI%2d%2d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
-            watch_display_string(buf, 0);
-            return;
-        }
-
-        minutes = 60.0 * fmod(set, 1);
-        scratch_time.unit.hour = floor(set);
-        scratch_time.unit.minute = floor(minutes);
-        scratch_time.unit.second = 60.0 * fmod(minutes, 1);
-
-        if (utc_now.reg < scratch_time.reg) {
-            // display today's sunset, it hasn't happened yet
-            scratch_time = watch_utility_date_time_convert_zone(scratch_time, 0, movement_timezone_offsets[settings->bit.time_zone] * 60);
-            sprintf(buf, "SE%2d%02d%02d%02d", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, scratch_time.unit.second);
-            watch_display_string(buf, 0);
-            return;
-        }
-
-
-        // it's after sunset. we need to display sunrise for tomorrow.
-        uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, 0);
-        timestamp += 86400;
-        scratch_time = watch_utility_date_time_from_unix_time(timestamp, 0);
-    }
-}
-
-static int16_t _sunrise_sunset_face_latlon_from_struct(sunrise_sunset_lat_lon_settings_t val) {
-    int16_t retval = (val.sign ? -1 : 1) *
-                        (
-                            val.hundreds * 10000 +
-                            val.tens * 1000 +
-                            val.ones * 100 +
-                            val.tenths * 10 +
-                            val.hundredths
-                        );
-    return retval;
-}
-
-static sunrise_sunset_lat_lon_settings_t _sunrise_sunset_face_struct_from_latlon(int16_t val) {
-    sunrise_sunset_lat_lon_settings_t retval;
-
-    if (val < 0) retval.sign = 1;
-    val = abs(val);
-    retval.hundredths = val % 10;
-    val /= 10;
-    retval.tenths = val % 10;
-    val /= 10;
-    retval.ones = val % 10;
-    val /= 10;
-    retval.tens = val % 10;
-    val /= 10;
-    retval.hundreds = val % 10;
-
-    return retval;
-}
-
-static void _sunrise_sunset_face_update_location_register(sunrise_sunset_state_t *state) {
-    if (state->location_changed) {
-        movement_location_t movement_location;
-        int16_t lat = _sunrise_sunset_face_latlon_from_struct(state->working_latitude);
-        int16_t lon = _sunrise_sunset_face_latlon_from_struct(state->working_longitude);
-        movement_location.bit.latitude = lat;
-        movement_location.bit.longitude = lon;
-        watch_store_backup_data(movement_location.reg, 1);
-        state->location_changed = false;
-    }
-}
-
-static void _sunrise_sunset_face_update_settings_display(movement_event_t event, sunrise_sunset_state_t *state) {
-    char buf[12];
-
-    switch (state->page) {
-        case 1:
-            sprintf(buf, "LA  %c %04d", state->working_latitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); // F looks sorta like a plus sign in position 1
-            break;
-        case 2:
-            sprintf(buf, "LO  %c%05d", state->working_longitude.sign ? '-' : 'F', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)));
-            break;
-    }
-    if (event.subsecond % 2) {
-        buf[state->active_digit + 4] = ' ';
-    }
-    watch_display_string(buf, 0);
-}
-
-static void _sunrise_sunset_face_advance_digit(sunrise_sunset_state_t *state) {
-    state->location_changed = true;
-    switch (state->page) {
-        case 1: // latitude
-            switch (state->active_digit) {
-                case 0:
-                    state->working_latitude.sign++;
-                    break;
-                case 1:
-                    // we skip this digit
-                    break;
-                case 2:
-                    state->working_latitude.tens = (state->working_latitude.tens + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) {
-                        // prevent latitude from going over Â±90.
-                        // TODO: perform these checks when advancing the digit?
-                        state->working_latitude.ones = 0;
-                        state->working_latitude.tenths = 0;
-                        state->working_latitude.hundredths = 0;
-                    }
-                    break;
-                case 3:
-                    state->working_latitude.ones = (state->working_latitude.ones + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.ones = 0;
-                    break;
-                case 4:
-                    state->working_latitude.tenths = (state->working_latitude.tenths + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.tenths = 0;
-                    break;
-                case 5:
-                    state->working_latitude.hundredths = (state->working_latitude.hundredths + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)) > 9000) state->working_latitude.hundredths = 0;
-                    break;
-            }
-            break;
-        case 2: // longitude
-            switch (state->active_digit) {
-                case 0:
-                    state->working_longitude.sign++;
-                    break;
-                case 1:
-                    state->working_longitude.hundreds = (state->working_longitude.hundreds + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) {
-                        // prevent longitude from going over Â±180
-                        state->working_longitude.tens = 8;
-                        state->working_longitude.ones = 0;
-                        state->working_longitude.tenths = 0;
-                        state->working_longitude.hundredths = 0;
-                    }
-                    break;
-                case 2:
-                    state->working_longitude.tens = (state->working_longitude.tens + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.tens = 0;
-                    break;
-                case 3:
-                    state->working_longitude.ones = (state->working_longitude.ones + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.ones = 0;
-                    break;
-                case 4:
-                    state->working_longitude.tenths = (state->working_longitude.tenths + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.tenths = 0;
-                    break;
-                case 5:
-                    state->working_longitude.hundredths = (state->working_longitude.hundredths + 1) % 10;
-                    if (abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)) > 18000) state->working_longitude.hundredths = 0;
-                    break;
-            }
-            break;
-    }
-}
-
-void sunrise_sunset_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(sunrise_sunset_state_t));
-        memset(*context_ptr, 0, sizeof(sunrise_sunset_state_t));
-    }
-}
-
-void sunrise_sunset_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
-    movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
-    state->working_latitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.latitude);
-    state->working_longitude = _sunrise_sunset_face_struct_from_latlon(movement_location.bit.longitude);
-}
-
-bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-            _sunrise_sunset_face_update(settings);
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-        case EVENT_TICK:
-            if (state->page) _sunrise_sunset_face_update_settings_display(event, state);
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            if (state->page) {
-                state->active_digit++;
-                if (state->page == 1 && state->active_digit == 1) state->active_digit++; // max latitude is +- 90, no hundreds place
-                if (state->active_digit > 5) {
-                    state->active_digit = 0;
-                    state->page = (state->page + 1) % 3;
-                    _sunrise_sunset_face_update_location_register(state);
-                }
-                _sunrise_sunset_face_update_settings_display(event, context);
-            } else {
-                movement_illuminate_led();
-            }
-            if (state->page == 0) {
-                movement_request_tick_frequency(1);
-                _sunrise_sunset_face_update(settings);
-            }
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            if (state->page) {
-                _sunrise_sunset_face_advance_digit(state);
-                _sunrise_sunset_face_update_settings_display(event, context);
-            }
-            break;
-        case EVENT_ALARM_LONG_PRESS:
-            if (state->page == 0) {
-                state->page++;
-                watch_clear_display();
-                movement_request_tick_frequency(4);
-                _sunrise_sunset_face_update_settings_display(event, context);
-            }
-            break;
-        case EVENT_TIMEOUT:
-            if (state->page != 0) {
-                movement_move_to_face(0);
-            }
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void sunrise_sunset_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    sunrise_sunset_state_t *state = (sunrise_sunset_state_t *)context;
-    state->page = 0;
-    state->active_digit = 0;
-    _sunrise_sunset_face_update_location_register(state);
-}
diff --git a/movement/watch_faces/complications/sunrise_sunset_face.h b/movement/watch_faces/complications/sunrise_sunset_face.h
deleted file mode 100644 (file)
index 826d5e9..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 SUNRISE_SUNSET_FACE_H_
-#define SUNRISE_SUNSET_FACE_H_
-
-#include "movement.h"
-
-// The Sunrise/Sunset face is designed to display the next sunrise or sunset for a given location.
-// TODO: It also functions as an interface for setting the location register, which other watch faces can use for various purposes.
-
-typedef struct {
-    uint8_t sign: 1;    // 0-1
-    uint8_t hundreds: 1;    // 0-1, ignored for latitude
-    uint8_t tens: 4;        // 0-9 (must wrap at 10)
-    uint8_t ones: 4;        // 0-9 (must wrap at 10)
-    uint8_t tenths: 4;      // 0-9 (must wrap at 10)
-    uint8_t hundredths: 4;  // 0-9 (must wrap at 10)
-} sunrise_sunset_lat_lon_settings_t;
-
-typedef struct {
-    uint8_t page;
-    uint8_t active_digit;
-    bool location_changed;
-    sunrise_sunset_lat_lon_settings_t working_latitude;
-    sunrise_sunset_lat_lon_settings_t working_longitude;
-} sunrise_sunset_state_t;
-
-void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void sunrise_sunset_face_activate(movement_settings_t *settings, void *context);
-bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void sunrise_sunset_face_resign(movement_settings_t *settings, void *context);
-
-#define sunrise_sunset_face ((const watch_face_t){ \
-    sunrise_sunset_face_setup, \
-    sunrise_sunset_face_activate, \
-    sunrise_sunset_face_loop, \
-    sunrise_sunset_face_resign, \
-    NULL, \
-})
-
-#endif // SUNRISE_SUNSET_FACE_H_
diff --git a/movement/watch_faces/complications/totp_face.c b/movement/watch_faces/complications/totp_face.c
deleted file mode 100644 (file)
index 468e6a8..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * TODO:
- * - Support for multiple codes
- */
-#include <stdlib.h>
-#include <string.h>
-#include "totp_face.h"
-#include "watch.h"
-#include "watch_utility.h"
-#include "TOTP.h"
-
-// test key: JBSWY3DPEHPK3PXP
-// Use https://cryptii.com/pipes/base32-to-hex to convert base32 to hex
-// Use https://totp.danhersam.com/ to generate test codes for verification
-static uint8_t hmacKey[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xde, 0xad, 0xbe, 0xef}; // Secret key
-
-
-static const uint32_t TIMESTEP = 30;
-
-void totp_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(totp_state_t));
-    TOTP(hmacKey, sizeof(hmacKey), TIMESTEP);
-}
-
-void totp_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    memset(context, 0, sizeof(totp_state_t));
-    totp_state_t *totp_state = (totp_state_t *)context;
-    totp_state->timestamp = watch_utility_date_time_to_unix_time(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60);
-    totp_state->current_code = getCodeFromTimestamp(totp_state->timestamp);
-}
-
-bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-
-    totp_state_t *totp_state = (totp_state_t *)context;
-    char buf[14];
-    uint8_t valid_for;
-    div_t result;
-
-    switch (event.event_type) {
-        case EVENT_TICK:
-            totp_state->timestamp++;
-            // fall through
-        case EVENT_ACTIVATE:
-            result = div(totp_state->timestamp, TIMESTEP);
-            if (result.quot != totp_state->steps) {
-                totp_state->current_code = getCodeFromTimestamp(totp_state->timestamp);
-                totp_state->steps = result.quot;
-            }
-            valid_for = TIMESTEP - result.rem;
-            sprintf(buf, "2f%2d%06lu", valid_for, totp_state->current_code);
-
-            watch_display_string(buf, 0);
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            break;
-        case EVENT_TIMEOUT:
-            movement_move_to_face(0);
-            break;
-        case EVENT_ALARM_BUTTON_DOWN:
-        case EVENT_ALARM_BUTTON_UP:
-        case EVENT_ALARM_LONG_PRESS:
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void totp_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-}
diff --git a/movement/watch_faces/complications/totp_face.h b/movement/watch_faces/complications/totp_face.h
deleted file mode 100644 (file)
index dfa4a6d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef TOTP_FACE_H_
-#define TOTP_FACE_H_
-
-#include "movement.h"
-
-typedef struct {
-    uint32_t timestamp;
-    uint8_t steps;
-    uint32_t current_code;
-
-} totp_state_t;
-
-void totp_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void totp_face_activate(movement_settings_t *settings, void *context);
-bool totp_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void totp_face_resign(movement_settings_t *settings, void *context);
-
-#define totp_face ((const watch_face_t){ \
-    totp_face_setup, \
-    totp_face_activate, \
-    totp_face_loop, \
-    totp_face_resign, \
-    NULL, \
-})
-
-#endif // TOTP_FACE_H_
diff --git a/movement/watch_faces/demo/character_set_face.c b/movement/watch_faces/demo/character_set_face.c
new file mode 100644 (file)
index 0000000..6aa4208
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "character_set_face.h"
+#include "watch.h"
+
+void character_set_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(char));
+}
+
+void character_set_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    char *c = (char *)context;
+    *c = '@';
+    movement_request_tick_frequency(0);
+}
+
+bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    char *c = (char *)context;
+    char buf[11];
+    switch (event.event_type) {
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            *c = (*c) + 1;
+            if (*c & 0x80) *c = ' ';
+            // fall through
+        case EVENT_ACTIVATE:
+            sprintf(buf, "%c%c%c%c%c%c%c%c%c%c", *c, *c, *c, *c, *c, *c, *c, *c, *c, *c);
+            watch_display_string(buf, 0);
+            break;
+        case EVENT_TIMEOUT:
+            movement_move_to_face(0);
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void character_set_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/demo/character_set_face.h b/movement/watch_faces/demo/character_set_face.h
new file mode 100644 (file)
index 0000000..82627ae
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 CHARACTER_SET_FACE_H_
+#define CHARACTER_SET_FACE_H_
+
+#include "movement.h"
+
+void character_set_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void character_set_face_activate(movement_settings_t *settings, void *context);
+bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void character_set_face_resign(movement_settings_t *settings, void *context);
+
+#define character_set_face ((const watch_face_t){ \
+    character_set_face_setup, \
+    character_set_face_activate, \
+    character_set_face_loop, \
+    character_set_face_resign, \
+    NULL, \
+})
+
+#endif // CHARACTER_SET_FACE_H_
diff --git a/movement/watch_faces/demo/demo_face.c b/movement/watch_faces/demo/demo_face.c
new file mode 100644 (file)
index 0000000..c9a929a
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "demo_face.h"
+#include "watch.h"
+
+typedef enum {
+    DEMO_FACE_TIME = 0,
+    DEMO_FACE_WORLD_TIME,
+    DEMO_FACE_BEATS,
+    DEMO_FACE_TOTP,
+    DEMO_FACE_TEMP_F,
+    DEMO_FACE_TEMP_C,
+    DEMO_FACE_TEMP_LOG_1,
+    DEMO_FACE_TEMP_LOG_2,
+    DEMO_FACE_DAY_ONE,
+    DEMO_FACE_STOPWATCH,
+    DEMO_FACE_PULSOMETER,
+    DEMO_FACE_BATTERY_VOLTAGE,
+    DEMO_FACE_NUM_FACES
+} demo_face_index_t;
+
+void demo_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(demo_face_index_t));
+        memset(*context_ptr, 0, sizeof(demo_face_index_t));
+    }
+}
+
+void demo_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    movement_request_tick_frequency(0);
+    // ensure the watch never enters low energy mode
+    settings->bit.le_interval = 0;
+    settings->bit.led_duration = 3;
+}
+
+bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    demo_face_index_t *screen = (demo_face_index_t *)context;
+    switch (event.event_type) {
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            *screen = ((*screen) + 1) % DEMO_FACE_NUM_FACES;
+            // fall through
+        case EVENT_ACTIVATE:
+            switch (*screen) {
+                case DEMO_FACE_TIME:
+                    watch_display_string("TH10101036", 0);
+                    watch_set_colon();
+                    break;
+                case DEMO_FACE_WORLD_TIME:
+                    watch_display_string("UT10 21036", 0);
+                    watch_set_indicator(WATCH_INDICATOR_PM);
+                    break;
+                case DEMO_FACE_BEATS:
+                    watch_display_string("bt   64125", 0);
+                    watch_clear_indicator(WATCH_INDICATOR_PM);
+                    watch_clear_colon();
+                    break;
+                case DEMO_FACE_TOTP:
+                    watch_display_string("2F29808494", 0);
+                    break;
+                case DEMO_FACE_TEMP_F:
+                    watch_display_string("TE  72.1#F", 0);
+                    break;
+                case DEMO_FACE_TEMP_C:
+                    watch_display_string("TE  22.3#C", 0);
+                    break;
+                case DEMO_FACE_TEMP_LOG_1:
+                    watch_display_string("TL  43.6#F", 0);
+                    break;
+                case DEMO_FACE_TEMP_LOG_2:
+                    watch_display_string("AT 6100000", 0);
+                    watch_set_colon();
+                    break;
+                case DEMO_FACE_DAY_ONE:
+                    watch_clear_colon();
+                    watch_display_string("DA   12879", 0);
+                    break;
+                case DEMO_FACE_STOPWATCH:
+                    watch_display_string("ST 01042  ", 0);
+                    watch_set_colon();
+                    break;
+                case DEMO_FACE_PULSOMETER:
+                    watch_display_string("    68 bpn", 0);
+                    watch_clear_colon();
+                    break;
+                case DEMO_FACE_BATTERY_VOLTAGE:
+                    watch_display_string("BA  2.97 V", 0);
+                    break;
+                case DEMO_FACE_NUM_FACES:
+                    // we won't get here, but silence the warning
+                    break;
+            }
+            break;
+        case EVENT_TIMEOUT:
+            // ignore timeout
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void demo_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/demo/demo_face.h b/movement/watch_faces/demo/demo_face.h
new file mode 100644 (file)
index 0000000..026e0d1
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 DEMO_FACE_H_
+#define DEMO_FACE_H_
+
+#include "movement.h"
+
+void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void demo_face_activate(movement_settings_t *settings, void *context);
+bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void demo_face_resign(movement_settings_t *settings, void *context);
+
+#define demo_face ((const watch_face_t){ \
+    demo_face_setup, \
+    demo_face_activate, \
+    demo_face_loop, \
+    demo_face_resign, \
+    NULL, \
+})
+
+#endif // DEMO_FACE_H_
diff --git a/movement/watch_faces/demo/hello_there_face.c b/movement/watch_faces/demo/hello_there_face.c
new file mode 100644 (file)
index 0000000..f21cb76
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "hello_there_face.h"
+#include "watch.h"
+
+void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+    // These next two lines just silence the compiler warnings associated with unused parameters.
+    // We have no use for the settings or the watch_face_index, so we make that explicit here.
+    (void) settings;
+    (void) watch_face_index;
+    // At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context.
+    if (*context_ptr == NULL) {
+        // in this case, we allocate an area of memory sufficient to store the stuff we need to track.
+        *context_ptr = malloc(sizeof(hello_there_state_t));
+    }
+}
+
+void hello_there_face_activate(movement_settings_t *settings, void *context) {
+    // same as above: silence the warning, we don't need to check the settings.
+    (void) settings;
+    // we do however need to set some things in our context. Here we cast it to the correct type...
+    hello_there_state_t *state = (hello_there_state_t *)context;
+    // ...and set the initial state of our watch face. We start out displaying the word 'Hello',
+    state->current_word = 0;
+    // and animate by default.
+    state->animating = true;
+}
+
+bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    hello_there_state_t *state = (hello_there_state_t *)context;
+
+    switch (event.event_type) {
+        case EVENT_ACTIVATE:
+        case EVENT_TICK:
+            // on activate and tick, if we are animating,
+            if (state->animating) {
+                // we display the current word,
+                if (state->current_word == 0) watch_display_string("Hello ", 4);
+                else watch_display_string(" there", 4);
+                // and increment it so that it will update on the next tick.
+                state->current_word = (state->current_word + 1) % 2;
+            }
+            break;
+        case EVENT_LIGHT_BUTTON_UP:
+            // when the user presses 'light', we illuminate the LED. We could override this if
+            // our UI needed an additional button for input, consuming the light button press
+            // but not illuminating the LED.
+            movement_illuminate_led();
+            break;
+        case EVENT_MODE_BUTTON_UP:
+            // when the user presses 'mode', we tell movement to move to the next watch face.
+            // movement will call our resign function, clear the screen, and transfer control
+            // to the next watch face in the list.
+            movement_move_to_next_face();
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            // when the user presses 'alarm', we toggle the state of the animation. If animating,
+            // we stop; if stopped, we resume.
+            state->animating = !state->animating;   
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+            // This low energy mode update occurs once a minute, if the watch face is in the
+            // foreground when Movement enters low energy mode. We have the option of supporting
+            // this mode, but since our watch face animates once a second, the "Hello there" face
+            // isn't very useful in this mode. So we choose not to support it. (continued below)
+            break;
+        case EVENT_TIMEOUT:
+            // ... Instead, we respond to the timeout event. This event happens after a configurable
+            // interval on screen (1-30 minutes). The watch will give us this event as a chance to
+            // resign control if we want to, and in this case, we do.
+            // This function will return the watch to the first screen (usually a simple clock),
+            // and it will do it long before the watch enters low energy mode. This ensures we
+            // won't be on screen, and thus opts us out of getting the EVENT_LOW_ENERGY_UPDATE above.
+            movement_move_to_face(0);
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void hello_there_face_resign(movement_settings_t *settings, void *context) {
+    // our watch face, like most watch faces, has nothing special to do when resigning.
+    // watch faces that enable a peripheral or interact with a sensor may want to turn it off here.
+    (void) settings;
+    (void) context;
+}
diff --git a/movement/watch_faces/demo/hello_there_face.h b/movement/watch_faces/demo/hello_there_face.h
new file mode 100644 (file)
index 0000000..1140bb2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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 HELLO_THERE_FACE_H_
+#define HELLO_THERE_FACE_H_
+
+#include "movement.h"
+
+typedef struct {
+    uint8_t current_word;
+    bool animating;
+} hello_there_state_t;
+
+void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void hello_there_face_activate(movement_settings_t *settings, void *context);
+bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void hello_there_face_resign(movement_settings_t *settings, void *context);
+
+#define hello_there_face ((const watch_face_t){ \
+    hello_there_face_setup, \
+    hello_there_face_activate, \
+    hello_there_face_loop, \
+    hello_there_face_resign, \
+    NULL, \
+})
+
+#endif // HELLO_THERE_FACE_H_
diff --git a/movement/watch_faces/demo/lis2dh_logging_face.c b/movement/watch_faces/demo/lis2dh_logging_face.c
new file mode 100644 (file)
index 0000000..31d1cad
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "lis2dh_logging_face.h"
+#include "lis2dh.h"
+#include "watch.h"
+
+// This watch face is just for testing; if we want to build accelerometer support, it will likely have to be part of Movement itself.
+// The watch face only logs events when it is on screen and not in low energy mode, so you should set LE mode to Never when using it
+// and make it the first watch face in the list (so we come back to it from other modes).
+// On an interrupt, it flashes the Signal icon, and displays the axis or axes that were over the threshold.
+// The main display contains, from left to right, the number of interrupt events that were detected in each of the last three minutes.
+// Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last
+// 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode)
+
+static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state) {
+    char buf[14];
+    char time_indication_character;
+    int8_t pos;
+    watch_date_time date_time;
+
+    if (logger_state->log_ticks) {
+        pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DH_LOGGING_NUM_DATA_POINTS;
+        if (pos < 0) {
+            watch_clear_colon();
+            sprintf(buf, "NO   data ");
+        } else {
+            date_time = logger_state->data[pos].timestamp;
+            watch_set_colon();
+            if (settings->bit.clock_mode_24h) {
+                watch_set_indicator(WATCH_INDICATOR_24H);
+            } else {
+                if (date_time.unit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM);
+                date_time.unit.hour %= 12;
+                if (date_time.unit.hour == 0) date_time.unit.hour = 12;
+            }
+            switch (logger_state->axis_index) {
+                case 0:
+                    sprintf(buf, "3A%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts + logger_state->data[pos].y_interrupts + logger_state->data[pos].z_interrupts);
+                    break;
+                case 1:
+                    sprintf(buf, "XA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts);
+                    break;
+                case 2:
+                    sprintf(buf, "YA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].y_interrupts);
+                    break;
+                case 3:
+                    sprintf(buf, "ZA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].z_interrupts);
+                    break;
+            }
+        }
+    } else {
+        date_time = watch_rtc_get_date_time();
+        watch_clear_colon();
+        watch_clear_indicator(WATCH_INDICATOR_PM);
+        watch_clear_indicator(WATCH_INDICATOR_24H);
+        if ((59 - date_time.unit.second) < 10) time_indication_character = '0' + (59 - date_time.unit.second);
+        else time_indication_character = (date_time.unit.second % 2) ? 'i' : '_';
+        sprintf(buf, "%c%c%c%c%2d%2d%2d",
+            (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) ? 'Y' : ' ',
+            (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) ? 'X' : ' ',
+            (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) ? 'Z' : ' ',
+            time_indication_character,
+            logger_state->interrupts[0],
+            logger_state->interrupts[1],
+            logger_state->interrupts[2]);
+    }
+    watch_display_string(buf, 0);
+}
+
+static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) {
+    watch_date_time date_time = watch_rtc_get_date_time();
+    // we get this call 15 minutes late; i.e. at 6:15 we're logging events for 6:00.
+    // so: if we're at the top of the hour, roll the hour back too (7:00 task logs data for 6:45)
+    if (date_time.unit.minute == 0) date_time.unit.hour = (date_time.unit.hour + 23) % 24;
+
+    // // then roll the minute back.
+    date_time.unit.minute = (date_time.unit.minute + 45) % 60;
+
+    size_t pos = logger_state->data_points % LIS2DH_LOGGING_NUM_DATA_POINTS;
+    logger_state->data[pos].timestamp.reg = date_time.reg;
+    logger_state->data[pos].x_interrupts = logger_state->x_interrupts_this_hour;
+    logger_state->data[pos].y_interrupts = logger_state->y_interrupts_this_hour;
+    logger_state->data[pos].z_interrupts = logger_state->z_interrupts_this_hour;
+    logger_state->data_points++;
+    logger_state->x_interrupts_this_hour = 0;
+    logger_state->y_interrupts_this_hour = 0;
+    logger_state->z_interrupts_this_hour = 0;
+}
+
+void lis2dh_logging_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(lis2dh_logger_state_t));
+        memset(*context_ptr, 0, sizeof(lis2dh_logger_state_t));
+        gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT);
+        gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF);
+        gpio_set_pin_level(A0, true);
+        watch_enable_i2c();
+        lis2dh_begin();
+        lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ);
+        lis2dh_configure_aoi_int1(
+            LIS2DH_INTERRUPT_CONFIGURATION_OR |
+            LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE |
+            LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE |
+            LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE, 96, 0, true);
+    }
+}
+
+void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) {
+    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
+    // force two settings: never enter low energy mode, and always snap back to screen 0.
+    // this assumes the accelerometer face is first in the watch_faces list.
+    settings->bit.le_interval = 0;
+    settings->bit.to_always = true;
+
+    logger_state->display_index = 0;
+    logger_state->log_ticks = 0;
+    watch_enable_digital_input(A1);
+}
+
+bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
+    lis2dh_interrupt_state interrupt_state = 0;
+
+    switch (event.event_type) {
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_LONG_PRESS:
+            movement_illuminate_led();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            logger_state->axis_index = (logger_state->axis_index + 1) % 4;
+            logger_state->log_ticks = 255;
+            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+            break;
+        case EVENT_ALARM_BUTTON_UP:
+            if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DH_LOGGING_NUM_DATA_POINTS;
+            logger_state->log_ticks = 255;
+            logger_state->axis_index = 0;
+            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+            break;
+        case EVENT_ACTIVATE:
+        case EVENT_TICK:
+            if (logger_state->log_ticks > 0) {
+                logger_state->log_ticks--;
+            } else {
+                logger_state->display_index = 0;
+            }
+            if (watch_get_pin_level(A1)) {
+                watch_set_indicator(WATCH_INDICATOR_SIGNAL);
+                interrupt_state = lis2dh_get_int1_state();
+                logger_state->interrupts[0]++;
+                if (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) logger_state->x_interrupts_this_hour++;
+                if (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) logger_state->y_interrupts_this_hour++;
+                if (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) logger_state->z_interrupts_this_hour++;
+            } else {
+                watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
+            }
+            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
+            break;
+        case EVENT_BACKGROUND_TASK:
+            _lis2dh_logging_face_log_data(logger_state);
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void lis2dh_logging_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    watch_disable_digital_input(A1);
+}
+
+bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
+    (void) settings;
+    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
+    watch_date_time date_time = watch_rtc_get_date_time();
+
+    // this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over.
+    logger_state->interrupts[2] = logger_state->interrupts[1];
+    logger_state->interrupts[1] = logger_state->interrupts[0];
+    logger_state->interrupts[0] = 0;
+
+    // and do our logging task every 15 minutes
+    return (date_time.unit.minute % 15) == 0;
+}
diff --git a/movement/watch_faces/demo/lis2dh_logging_face.h b/movement/watch_faces/demo/lis2dh_logging_face.h
new file mode 100644 (file)
index 0000000..4936654
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 LIS2DH_LOGGING_FACE_H_
+#define LIS2DH_LOGGING_FACE_H_
+
+#include "movement.h"
+#include "watch.h"
+
+#define LIS2DH_LOGGING_NUM_DATA_POINTS (96)
+
+typedef struct {
+    watch_date_time timestamp;
+    uint32_t x_interrupts;
+    uint32_t y_interrupts;
+    uint32_t z_interrupts;
+} lis2dh_logger_data_point_t;
+
+typedef struct {
+    uint8_t display_index;  // the index we are displaying on screen
+    uint8_t axis_index;     // the index we are displaying on screen
+    uint8_t log_ticks;      // when the user taps the ALARM button, we enter log mode
+    int32_t data_points;    // the absolute number of data points logged
+    uint8_t interrupts[3];  // the number of interrupts we have logged in each of the last 3 minutes
+    uint32_t x_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
+    uint32_t y_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
+    uint32_t z_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
+    lis2dh_logger_data_point_t data[LIS2DH_LOGGING_NUM_DATA_POINTS];
+} lis2dh_logger_state_t;
+
+void lis2dh_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void lis2dh_logging_face_activate(movement_settings_t *settings, void *context);
+bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void lis2dh_logging_face_resign(movement_settings_t *settings, void *context);
+bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context);
+
+#define lis2dh_logging_face ((const watch_face_t){ \
+    lis2dh_logging_face_setup, \
+    lis2dh_logging_face_activate, \
+    lis2dh_logging_face_loop, \
+    lis2dh_logging_face_resign, \
+    lis2dh_logging_face_wants_background_task, \
+})
+
+#endif // LIS2DH_LOGGING_FACE_H_
diff --git a/movement/watch_faces/demo/voltage_face.c b/movement/watch_faces/demo/voltage_face.c
new file mode 100644 (file)
index 0000000..24346aa
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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 <stdlib.h>
+#include <string.h>
+#include "voltage_face.h"
+#include "watch.h"
+
+static void _voltage_face_update_display(void) {
+    char buf[14];
+    float voltage = (float)watch_get_vcc_voltage() / 1000.0;
+    sprintf(buf, "BA  %4.2f V", voltage);
+    // printf("%s\n", buf);
+    watch_display_string(buf, 0);
+}
+
+void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
+    (void) settings;
+    (void) watch_face_index;
+    (void) context_ptr;
+}
+
+void voltage_face_activate(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    watch_enable_adc();
+    // if we set the reference voltage here, watch_get_vcc_voltage won't do it over and over
+    watch_set_analog_reference_voltage(ADC_REFERENCE_INTREF);
+}
+
+bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    watch_date_time date_time;
+    switch (event.event_type) {
+        case EVENT_MODE_BUTTON_UP:
+            movement_move_to_next_face();
+            break;
+        case EVENT_LIGHT_BUTTON_DOWN:
+            movement_illuminate_led();
+            break;
+        case EVENT_ACTIVATE:
+            _voltage_face_update_display();
+            break;
+        case EVENT_TICK:
+            date_time = watch_rtc_get_date_time();
+            if (date_time.unit.second % 5 == 4) {
+                watch_set_indicator(WATCH_INDICATOR_SIGNAL);
+            } else if (date_time.unit.second % 5 == 0) {
+                _voltage_face_update_display();
+                watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
+            }
+            break;
+        case EVENT_LOW_ENERGY_UPDATE:
+            watch_display_string("BA  SLEEP ", 0);
+            break;
+        default:
+            break;
+    }
+
+    return true;
+}
+
+void voltage_face_resign(movement_settings_t *settings, void *context) {
+    (void) settings;
+    (void) context;
+    // make sure to restore the default in the end.
+    watch_set_analog_reference_voltage(ADC_REFERENCE_VCC);
+    watch_disable_adc();
+}
diff --git a/movement/watch_faces/demo/voltage_face.h b/movement/watch_faces/demo/voltage_face.h
new file mode 100644 (file)
index 0000000..dc5e631
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 VOLTAGE_FACE_H_
+#define VOLTAGE_FACE_H_
+
+#include "movement.h"
+
+void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void voltage_face_activate(movement_settings_t *settings, void *context);
+bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void voltage_face_resign(movement_settings_t *settings, void *context);
+
+#define voltage_face ((const watch_face_t){ \
+    voltage_face_setup, \
+    voltage_face_activate, \
+    voltage_face_loop, \
+    voltage_face_resign, \
+    NULL, \
+})
+
+#endif // VOLTAGE_FACE_H_
diff --git a/movement/watch_faces/demos/character_set_face.c b/movement/watch_faces/demos/character_set_face.c
deleted file mode 100644 (file)
index 6aa4208..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "character_set_face.h"
-#include "watch.h"
-
-void character_set_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(char));
-}
-
-void character_set_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    char *c = (char *)context;
-    *c = '@';
-    movement_request_tick_frequency(0);
-}
-
-bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    char *c = (char *)context;
-    char buf[11];
-    switch (event.event_type) {
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            *c = (*c) + 1;
-            if (*c & 0x80) *c = ' ';
-            // fall through
-        case EVENT_ACTIVATE:
-            sprintf(buf, "%c%c%c%c%c%c%c%c%c%c", *c, *c, *c, *c, *c, *c, *c, *c, *c, *c);
-            watch_display_string(buf, 0);
-            break;
-        case EVENT_TIMEOUT:
-            movement_move_to_face(0);
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void character_set_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-}
diff --git a/movement/watch_faces/demos/character_set_face.h b/movement/watch_faces/demos/character_set_face.h
deleted file mode 100644 (file)
index 82627ae..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 CHARACTER_SET_FACE_H_
-#define CHARACTER_SET_FACE_H_
-
-#include "movement.h"
-
-void character_set_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void character_set_face_activate(movement_settings_t *settings, void *context);
-bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void character_set_face_resign(movement_settings_t *settings, void *context);
-
-#define character_set_face ((const watch_face_t){ \
-    character_set_face_setup, \
-    character_set_face_activate, \
-    character_set_face_loop, \
-    character_set_face_resign, \
-    NULL, \
-})
-
-#endif // CHARACTER_SET_FACE_H_
diff --git a/movement/watch_faces/demos/demo_face.c b/movement/watch_faces/demos/demo_face.c
deleted file mode 100644 (file)
index c9a929a..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "demo_face.h"
-#include "watch.h"
-
-typedef enum {
-    DEMO_FACE_TIME = 0,
-    DEMO_FACE_WORLD_TIME,
-    DEMO_FACE_BEATS,
-    DEMO_FACE_TOTP,
-    DEMO_FACE_TEMP_F,
-    DEMO_FACE_TEMP_C,
-    DEMO_FACE_TEMP_LOG_1,
-    DEMO_FACE_TEMP_LOG_2,
-    DEMO_FACE_DAY_ONE,
-    DEMO_FACE_STOPWATCH,
-    DEMO_FACE_PULSOMETER,
-    DEMO_FACE_BATTERY_VOLTAGE,
-    DEMO_FACE_NUM_FACES
-} demo_face_index_t;
-
-void demo_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(demo_face_index_t));
-        memset(*context_ptr, 0, sizeof(demo_face_index_t));
-    }
-}
-
-void demo_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    movement_request_tick_frequency(0);
-    // ensure the watch never enters low energy mode
-    settings->bit.le_interval = 0;
-    settings->bit.led_duration = 3;
-}
-
-bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    demo_face_index_t *screen = (demo_face_index_t *)context;
-    switch (event.event_type) {
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            *screen = ((*screen) + 1) % DEMO_FACE_NUM_FACES;
-            // fall through
-        case EVENT_ACTIVATE:
-            switch (*screen) {
-                case DEMO_FACE_TIME:
-                    watch_display_string("TH10101036", 0);
-                    watch_set_colon();
-                    break;
-                case DEMO_FACE_WORLD_TIME:
-                    watch_display_string("UT10 21036", 0);
-                    watch_set_indicator(WATCH_INDICATOR_PM);
-                    break;
-                case DEMO_FACE_BEATS:
-                    watch_display_string("bt   64125", 0);
-                    watch_clear_indicator(WATCH_INDICATOR_PM);
-                    watch_clear_colon();
-                    break;
-                case DEMO_FACE_TOTP:
-                    watch_display_string("2F29808494", 0);
-                    break;
-                case DEMO_FACE_TEMP_F:
-                    watch_display_string("TE  72.1#F", 0);
-                    break;
-                case DEMO_FACE_TEMP_C:
-                    watch_display_string("TE  22.3#C", 0);
-                    break;
-                case DEMO_FACE_TEMP_LOG_1:
-                    watch_display_string("TL  43.6#F", 0);
-                    break;
-                case DEMO_FACE_TEMP_LOG_2:
-                    watch_display_string("AT 6100000", 0);
-                    watch_set_colon();
-                    break;
-                case DEMO_FACE_DAY_ONE:
-                    watch_clear_colon();
-                    watch_display_string("DA   12879", 0);
-                    break;
-                case DEMO_FACE_STOPWATCH:
-                    watch_display_string("ST 01042  ", 0);
-                    watch_set_colon();
-                    break;
-                case DEMO_FACE_PULSOMETER:
-                    watch_display_string("    68 bpn", 0);
-                    watch_clear_colon();
-                    break;
-                case DEMO_FACE_BATTERY_VOLTAGE:
-                    watch_display_string("BA  2.97 V", 0);
-                    break;
-                case DEMO_FACE_NUM_FACES:
-                    // we won't get here, but silence the warning
-                    break;
-            }
-            break;
-        case EVENT_TIMEOUT:
-            // ignore timeout
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void demo_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-}
diff --git a/movement/watch_faces/demos/demo_face.h b/movement/watch_faces/demos/demo_face.h
deleted file mode 100644 (file)
index 026e0d1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 DEMO_FACE_H_
-#define DEMO_FACE_H_
-
-#include "movement.h"
-
-void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void demo_face_activate(movement_settings_t *settings, void *context);
-bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void demo_face_resign(movement_settings_t *settings, void *context);
-
-#define demo_face ((const watch_face_t){ \
-    demo_face_setup, \
-    demo_face_activate, \
-    demo_face_loop, \
-    demo_face_resign, \
-    NULL, \
-})
-
-#endif // DEMO_FACE_H_
diff --git a/movement/watch_faces/demos/hello_there_face.c b/movement/watch_faces/demos/hello_there_face.c
deleted file mode 100644 (file)
index f21cb76..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "hello_there_face.h"
-#include "watch.h"
-
-void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
-    // These next two lines just silence the compiler warnings associated with unused parameters.
-    // We have no use for the settings or the watch_face_index, so we make that explicit here.
-    (void) settings;
-    (void) watch_face_index;
-    // At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context.
-    if (*context_ptr == NULL) {
-        // in this case, we allocate an area of memory sufficient to store the stuff we need to track.
-        *context_ptr = malloc(sizeof(hello_there_state_t));
-    }
-}
-
-void hello_there_face_activate(movement_settings_t *settings, void *context) {
-    // same as above: silence the warning, we don't need to check the settings.
-    (void) settings;
-    // we do however need to set some things in our context. Here we cast it to the correct type...
-    hello_there_state_t *state = (hello_there_state_t *)context;
-    // ...and set the initial state of our watch face. We start out displaying the word 'Hello',
-    state->current_word = 0;
-    // and animate by default.
-    state->animating = true;
-}
-
-bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    hello_there_state_t *state = (hello_there_state_t *)context;
-
-    switch (event.event_type) {
-        case EVENT_ACTIVATE:
-        case EVENT_TICK:
-            // on activate and tick, if we are animating,
-            if (state->animating) {
-                // we display the current word,
-                if (state->current_word == 0) watch_display_string("Hello ", 4);
-                else watch_display_string(" there", 4);
-                // and increment it so that it will update on the next tick.
-                state->current_word = (state->current_word + 1) % 2;
-            }
-            break;
-        case EVENT_LIGHT_BUTTON_UP:
-            // when the user presses 'light', we illuminate the LED. We could override this if
-            // our UI needed an additional button for input, consuming the light button press
-            // but not illuminating the LED.
-            movement_illuminate_led();
-            break;
-        case EVENT_MODE_BUTTON_UP:
-            // when the user presses 'mode', we tell movement to move to the next watch face.
-            // movement will call our resign function, clear the screen, and transfer control
-            // to the next watch face in the list.
-            movement_move_to_next_face();
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            // when the user presses 'alarm', we toggle the state of the animation. If animating,
-            // we stop; if stopped, we resume.
-            state->animating = !state->animating;   
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-            // This low energy mode update occurs once a minute, if the watch face is in the
-            // foreground when Movement enters low energy mode. We have the option of supporting
-            // this mode, but since our watch face animates once a second, the "Hello there" face
-            // isn't very useful in this mode. So we choose not to support it. (continued below)
-            break;
-        case EVENT_TIMEOUT:
-            // ... Instead, we respond to the timeout event. This event happens after a configurable
-            // interval on screen (1-30 minutes). The watch will give us this event as a chance to
-            // resign control if we want to, and in this case, we do.
-            // This function will return the watch to the first screen (usually a simple clock),
-            // and it will do it long before the watch enters low energy mode. This ensures we
-            // won't be on screen, and thus opts us out of getting the EVENT_LOW_ENERGY_UPDATE above.
-            movement_move_to_face(0);
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void hello_there_face_resign(movement_settings_t *settings, void *context) {
-    // our watch face, like most watch faces, has nothing special to do when resigning.
-    // watch faces that enable a peripheral or interact with a sensor may want to turn it off here.
-    (void) settings;
-    (void) context;
-}
diff --git a/movement/watch_faces/demos/hello_there_face.h b/movement/watch_faces/demos/hello_there_face.h
deleted file mode 100644 (file)
index 1140bb2..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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 HELLO_THERE_FACE_H_
-#define HELLO_THERE_FACE_H_
-
-#include "movement.h"
-
-typedef struct {
-    uint8_t current_word;
-    bool animating;
-} hello_there_state_t;
-
-void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void hello_there_face_activate(movement_settings_t *settings, void *context);
-bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void hello_there_face_resign(movement_settings_t *settings, void *context);
-
-#define hello_there_face ((const watch_face_t){ \
-    hello_there_face_setup, \
-    hello_there_face_activate, \
-    hello_there_face_loop, \
-    hello_there_face_resign, \
-    NULL, \
-})
-
-#endif // HELLO_THERE_FACE_H_
diff --git a/movement/watch_faces/demos/lis2dh_logging_face.c b/movement/watch_faces/demos/lis2dh_logging_face.c
deleted file mode 100644 (file)
index 31d1cad..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "lis2dh_logging_face.h"
-#include "lis2dh.h"
-#include "watch.h"
-
-// This watch face is just for testing; if we want to build accelerometer support, it will likely have to be part of Movement itself.
-// The watch face only logs events when it is on screen and not in low energy mode, so you should set LE mode to Never when using it
-// and make it the first watch face in the list (so we come back to it from other modes).
-// On an interrupt, it flashes the Signal icon, and displays the axis or axes that were over the threshold.
-// The main display contains, from left to right, the number of interrupt events that were detected in each of the last three minutes.
-// Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last
-// 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode)
-
-static void _lis2dh_logging_face_update_display(movement_settings_t *settings, lis2dh_logger_state_t *logger_state, lis2dh_interrupt_state interrupt_state) {
-    char buf[14];
-    char time_indication_character;
-    int8_t pos;
-    watch_date_time date_time;
-
-    if (logger_state->log_ticks) {
-        pos = (logger_state->data_points - 1 - logger_state->display_index) % LIS2DH_LOGGING_NUM_DATA_POINTS;
-        if (pos < 0) {
-            watch_clear_colon();
-            sprintf(buf, "NO   data ");
-        } else {
-            date_time = logger_state->data[pos].timestamp;
-            watch_set_colon();
-            if (settings->bit.clock_mode_24h) {
-                watch_set_indicator(WATCH_INDICATOR_24H);
-            } else {
-                if (date_time.unit.hour > 11) watch_set_indicator(WATCH_INDICATOR_PM);
-                date_time.unit.hour %= 12;
-                if (date_time.unit.hour == 0) date_time.unit.hour = 12;
-            }
-            switch (logger_state->axis_index) {
-                case 0:
-                    sprintf(buf, "3A%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts + logger_state->data[pos].y_interrupts + logger_state->data[pos].z_interrupts);
-                    break;
-                case 1:
-                    sprintf(buf, "XA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].x_interrupts);
-                    break;
-                case 2:
-                    sprintf(buf, "YA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].y_interrupts);
-                    break;
-                case 3:
-                    sprintf(buf, "ZA%2d%02d%4lu", date_time.unit.hour, date_time.unit.minute, logger_state->data[pos].z_interrupts);
-                    break;
-            }
-        }
-    } else {
-        date_time = watch_rtc_get_date_time();
-        watch_clear_colon();
-        watch_clear_indicator(WATCH_INDICATOR_PM);
-        watch_clear_indicator(WATCH_INDICATOR_24H);
-        if ((59 - date_time.unit.second) < 10) time_indication_character = '0' + (59 - date_time.unit.second);
-        else time_indication_character = (date_time.unit.second % 2) ? 'i' : '_';
-        sprintf(buf, "%c%c%c%c%2d%2d%2d",
-            (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) ? 'Y' : ' ',
-            (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) ? 'X' : ' ',
-            (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) ? 'Z' : ' ',
-            time_indication_character,
-            logger_state->interrupts[0],
-            logger_state->interrupts[1],
-            logger_state->interrupts[2]);
-    }
-    watch_display_string(buf, 0);
-}
-
-static void _lis2dh_logging_face_log_data(lis2dh_logger_state_t *logger_state) {
-    watch_date_time date_time = watch_rtc_get_date_time();
-    // we get this call 15 minutes late; i.e. at 6:15 we're logging events for 6:00.
-    // so: if we're at the top of the hour, roll the hour back too (7:00 task logs data for 6:45)
-    if (date_time.unit.minute == 0) date_time.unit.hour = (date_time.unit.hour + 23) % 24;
-
-    // // then roll the minute back.
-    date_time.unit.minute = (date_time.unit.minute + 45) % 60;
-
-    size_t pos = logger_state->data_points % LIS2DH_LOGGING_NUM_DATA_POINTS;
-    logger_state->data[pos].timestamp.reg = date_time.reg;
-    logger_state->data[pos].x_interrupts = logger_state->x_interrupts_this_hour;
-    logger_state->data[pos].y_interrupts = logger_state->y_interrupts_this_hour;
-    logger_state->data[pos].z_interrupts = logger_state->z_interrupts_this_hour;
-    logger_state->data_points++;
-    logger_state->x_interrupts_this_hour = 0;
-    logger_state->y_interrupts_this_hour = 0;
-    logger_state->z_interrupts_this_hour = 0;
-}
-
-void lis2dh_logging_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(lis2dh_logger_state_t));
-        memset(*context_ptr, 0, sizeof(lis2dh_logger_state_t));
-        gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT);
-        gpio_set_pin_function(A0, GPIO_PIN_FUNCTION_OFF);
-        gpio_set_pin_level(A0, true);
-        watch_enable_i2c();
-        lis2dh_begin();
-        lis2dh_set_data_rate(LIS2DH_DATA_RATE_10_HZ);
-        lis2dh_configure_aoi_int1(
-            LIS2DH_INTERRUPT_CONFIGURATION_OR |
-            LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE |
-            LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE |
-            LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE, 96, 0, true);
-    }
-}
-
-void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) {
-    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
-    // force two settings: never enter low energy mode, and always snap back to screen 0.
-    // this assumes the accelerometer face is first in the watch_faces list.
-    settings->bit.le_interval = 0;
-    settings->bit.to_always = true;
-
-    logger_state->display_index = 0;
-    logger_state->log_ticks = 0;
-    watch_enable_digital_input(A1);
-}
-
-bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
-    lis2dh_interrupt_state interrupt_state = 0;
-
-    switch (event.event_type) {
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_LONG_PRESS:
-            movement_illuminate_led();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            logger_state->axis_index = (logger_state->axis_index + 1) % 4;
-            logger_state->log_ticks = 255;
-            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
-            break;
-        case EVENT_ALARM_BUTTON_UP:
-            if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DH_LOGGING_NUM_DATA_POINTS;
-            logger_state->log_ticks = 255;
-            logger_state->axis_index = 0;
-            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
-            break;
-        case EVENT_ACTIVATE:
-        case EVENT_TICK:
-            if (logger_state->log_ticks > 0) {
-                logger_state->log_ticks--;
-            } else {
-                logger_state->display_index = 0;
-            }
-            if (watch_get_pin_level(A1)) {
-                watch_set_indicator(WATCH_INDICATOR_SIGNAL);
-                interrupt_state = lis2dh_get_int1_state();
-                logger_state->interrupts[0]++;
-                if (interrupt_state & LIS2DH_INTERRUPT_STATE_X_HIGH) logger_state->x_interrupts_this_hour++;
-                if (interrupt_state & LIS2DH_INTERRUPT_STATE_Y_HIGH) logger_state->y_interrupts_this_hour++;
-                if (interrupt_state & LIS2DH_INTERRUPT_STATE_Z_HIGH) logger_state->z_interrupts_this_hour++;
-            } else {
-                watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
-            }
-            _lis2dh_logging_face_update_display(settings, logger_state, interrupt_state);
-            break;
-        case EVENT_BACKGROUND_TASK:
-            _lis2dh_logging_face_log_data(logger_state);
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void lis2dh_logging_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    watch_disable_digital_input(A1);
-}
-
-bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
-    (void) settings;
-    lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
-    watch_date_time date_time = watch_rtc_get_date_time();
-
-    // this is kind of an abuse of the API, but, let's use the 1 minute tick to shift all our data over.
-    logger_state->interrupts[2] = logger_state->interrupts[1];
-    logger_state->interrupts[1] = logger_state->interrupts[0];
-    logger_state->interrupts[0] = 0;
-
-    // and do our logging task every 15 minutes
-    return (date_time.unit.minute % 15) == 0;
-}
diff --git a/movement/watch_faces/demos/lis2dh_logging_face.h b/movement/watch_faces/demos/lis2dh_logging_face.h
deleted file mode 100644 (file)
index 4936654..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 LIS2DH_LOGGING_FACE_H_
-#define LIS2DH_LOGGING_FACE_H_
-
-#include "movement.h"
-#include "watch.h"
-
-#define LIS2DH_LOGGING_NUM_DATA_POINTS (96)
-
-typedef struct {
-    watch_date_time timestamp;
-    uint32_t x_interrupts;
-    uint32_t y_interrupts;
-    uint32_t z_interrupts;
-} lis2dh_logger_data_point_t;
-
-typedef struct {
-    uint8_t display_index;  // the index we are displaying on screen
-    uint8_t axis_index;     // the index we are displaying on screen
-    uint8_t log_ticks;      // when the user taps the ALARM button, we enter log mode
-    int32_t data_points;    // the absolute number of data points logged
-    uint8_t interrupts[3];  // the number of interrupts we have logged in each of the last 3 minutes
-    uint32_t x_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
-    uint32_t y_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
-    uint32_t z_interrupts_this_hour;  // the number of interrupts we have logged in the last hour
-    lis2dh_logger_data_point_t data[LIS2DH_LOGGING_NUM_DATA_POINTS];
-} lis2dh_logger_state_t;
-
-void lis2dh_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void lis2dh_logging_face_activate(movement_settings_t *settings, void *context);
-bool lis2dh_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void lis2dh_logging_face_resign(movement_settings_t *settings, void *context);
-bool lis2dh_logging_face_wants_background_task(movement_settings_t *settings, void *context);
-
-#define lis2dh_logging_face ((const watch_face_t){ \
-    lis2dh_logging_face_setup, \
-    lis2dh_logging_face_activate, \
-    lis2dh_logging_face_loop, \
-    lis2dh_logging_face_resign, \
-    lis2dh_logging_face_wants_background_task, \
-})
-
-#endif // LIS2DH_LOGGING_FACE_H_
diff --git a/movement/watch_faces/demos/voltage_face.c b/movement/watch_faces/demos/voltage_face.c
deleted file mode 100644 (file)
index 24346aa..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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 <stdlib.h>
-#include <string.h>
-#include "voltage_face.h"
-#include "watch.h"
-
-static void _voltage_face_update_display(void) {
-    char buf[14];
-    float voltage = (float)watch_get_vcc_voltage() / 1000.0;
-    sprintf(buf, "BA  %4.2f V", voltage);
-    // printf("%s\n", buf);
-    watch_display_string(buf, 0);
-}
-
-void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
-    (void) settings;
-    (void) watch_face_index;
-    (void) context_ptr;
-}
-
-void voltage_face_activate(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    watch_enable_adc();
-    // if we set the reference voltage here, watch_get_vcc_voltage won't do it over and over
-    watch_set_analog_reference_voltage(ADC_REFERENCE_INTREF);
-}
-
-bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    watch_date_time date_time;
-    switch (event.event_type) {
-        case EVENT_MODE_BUTTON_UP:
-            movement_move_to_next_face();
-            break;
-        case EVENT_LIGHT_BUTTON_DOWN:
-            movement_illuminate_led();
-            break;
-        case EVENT_ACTIVATE:
-            _voltage_face_update_display();
-            break;
-        case EVENT_TICK:
-            date_time = watch_rtc_get_date_time();
-            if (date_time.unit.second % 5 == 4) {
-                watch_set_indicator(WATCH_INDICATOR_SIGNAL);
-            } else if (date_time.unit.second % 5 == 0) {
-                _voltage_face_update_display();
-                watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
-            }
-            break;
-        case EVENT_LOW_ENERGY_UPDATE:
-            watch_display_string("BA  SLEEP ", 0);
-            break;
-        default:
-            break;
-    }
-
-    return true;
-}
-
-void voltage_face_resign(movement_settings_t *settings, void *context) {
-    (void) settings;
-    (void) context;
-    // make sure to restore the default in the end.
-    watch_set_analog_reference_voltage(ADC_REFERENCE_VCC);
-    watch_disable_adc();
-}
diff --git a/movement/watch_faces/demos/voltage_face.h b/movement/watch_faces/demos/voltage_face.h
deleted file mode 100644 (file)
index dc5e631..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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 VOLTAGE_FACE_H_
-#define VOLTAGE_FACE_H_
-
-#include "movement.h"
-
-void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
-void voltage_face_activate(movement_settings_t *settings, void *context);
-bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
-void voltage_face_resign(movement_settings_t *settings, void *context);
-
-#define voltage_face ((const watch_face_t){ \
-    voltage_face_setup, \
-    voltage_face_activate, \
-    voltage_face_loop, \
-    voltage_face_resign, \
-    NULL, \
-})
-
-#endif // VOLTAGE_FACE_H_