summaryrefslogtreecommitdiffstats
path: root/movement/watch_faces/complication
diff options
context:
space:
mode:
Diffstat (limited to 'movement/watch_faces/complication')
-rw-r--r--movement/watch_faces/complication/blinky_face.c107
-rw-r--r--movement/watch_faces/complication/blinky_face.h49
-rw-r--r--movement/watch_faces/complication/countdown_face.c227
-rw-r--r--movement/watch_faces/complication/countdown_face.h69
-rw-r--r--movement/watch_faces/complication/day_one_face.c200
-rw-r--r--movement/watch_faces/complication/day_one_face.h55
-rw-r--r--movement/watch_faces/complication/pulsometer_face.c114
-rw-r--r--movement/watch_faces/complication/pulsometer_face.h49
-rw-r--r--movement/watch_faces/complication/stopwatch_face.c77
-rw-r--r--movement/watch_faces/complication/stopwatch_face.h26
-rw-r--r--movement/watch_faces/complication/sunrise_sunset_face.c315
-rw-r--r--movement/watch_faces/complication/sunrise_sunset_face.h63
-rw-r--r--movement/watch_faces/complication/totp_face.c80
-rw-r--r--movement/watch_faces/complication/totp_face.h26
14 files changed, 1457 insertions, 0 deletions
diff --git a/movement/watch_faces/complication/blinky_face.c b/movement/watch_faces/complication/blinky_face.c
new file mode 100644
index 00000000..4c17476e
--- /dev/null
+++ b/movement/watch_faces/complication/blinky_face.c
@@ -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
index 00000000..e966ab1d
--- /dev/null
+++ b/movement/watch_faces/complication/blinky_face.h
@@ -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
index 00000000..a910e96c
--- /dev/null
+++ b/movement/watch_faces/complication/countdown_face.c
@@ -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
index 00000000..657c6377
--- /dev/null
+++ b/movement/watch_faces/complication/countdown_face.h
@@ -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
index 00000000..99433990
--- /dev/null
+++ b/movement/watch_faces/complication/day_one_face.c
@@ -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
index 00000000..ab8372bf
--- /dev/null
+++ b/movement/watch_faces/complication/day_one_face.h
@@ -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
index 00000000..28ca1a50
--- /dev/null
+++ b/movement/watch_faces/complication/pulsometer_face.c
@@ -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
index 00000000..600201e9
--- /dev/null
+++ b/movement/watch_faces/complication/pulsometer_face.h
@@ -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
index 00000000..4a145abf
--- /dev/null
+++ b/movement/watch_faces/complication/stopwatch_face.c
@@ -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
index 00000000..c6e3aadb
--- /dev/null
+++ b/movement/watch_faces/complication/stopwatch_face.h
@@ -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
index 00000000..5c47d5d0
--- /dev/null
+++ b/movement/watch_faces/complication/sunrise_sunset_face.c
@@ -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
index 00000000..826d5e95
--- /dev/null
+++ b/movement/watch_faces/complication/sunrise_sunset_face.h
@@ -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
index 00000000..468e6a8c
--- /dev/null
+++ b/movement/watch_faces/complication/totp_face.c
@@ -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
index 00000000..dfa4a6d0
--- /dev/null
+++ b/movement/watch_faces/complication/totp_face.h
@@ -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_