summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--movement/make/Makefile4
-rwxr-xr-xmovement/make/make_alternate_fw.sh4
-rw-r--r--movement/movement.c106
-rw-r--r--movement/movement.h5
-rw-r--r--movement/movement_config.h2
-rw-r--r--movement/movement_faces.h4
-rw-r--r--movement/template/template.c1
-rw-r--r--movement/watch_faces/clock/day_night_percentage_face.c139
-rw-r--r--movement/watch_faces/clock/day_night_percentage_face.h66
-rw-r--r--movement/watch_faces/clock/repetition_minute_face.c2
-rw-r--r--movement/watch_faces/clock/simple_clock_face.c4
-rw-r--r--movement/watch_faces/clock/wyoscan_face.c2
-rw-r--r--movement/watch_faces/complication/simple_coin_flip_face.c139
-rw-r--r--movement/watch_faces/complication/simple_coin_flip_face.h62
-rw-r--r--movement/watch_faces/complication/solstice_face.c236
-rw-r--r--movement/watch_faces/complication/solstice_face.h64
-rw-r--r--movement/watch_faces/complication/sunrise_sunset_face.c2
-rw-r--r--movement/watch_faces/complication/tomato_face.c10
-rw-r--r--movement/watch_faces/complication/tomato_face.h1
-rw-r--r--movement/watch_faces/settings/nanosec_face.c1
-rw-r--r--movement/watch_faces/settings/preferences_face.c12
-rw-r--r--movement/watch_faces/settings/save_load_face.c152
-rw-r--r--movement/watch_faces/settings/save_load_face.h82
-rw-r--r--watch-library/hardware/watch/watch_buzzer.c1
-rw-r--r--watch-library/shared/watch/watch_buzzer.h2
-rw-r--r--watch-library/shared/watch/watch_private_buzzer.c13
-rw-r--r--watch-library/shared/watch/watch_private_buzzer.h33
-rw-r--r--watch-library/simulator/watch/watch_buzzer.c1
28 files changed, 1088 insertions, 62 deletions
diff --git a/movement/make/Makefile b/movement/make/Makefile
index 512f2ea8..42dfc644 100644
--- a/movement/make/Makefile
+++ b/movement/make/Makefile
@@ -118,6 +118,10 @@ SRCS += \
../watch_faces/complication/flashlight_face.c \
../watch_faces/clock/decimal_time_face.c \
../watch_faces/clock/wyoscan_face.c \
+ ../watch_faces/settings/save_load_face.c \
+ ../watch_faces/clock/day_night_percentage_face.c \
+ ../watch_faces/complication/simple_coin_flip_face.c \
+ ../watch_faces/complication/solstice_face.c \
../watch_faces/complication/couch_to_5k_face.c \
../watch_faces/clock/minute_repeater_decimal_face.c \
../watch_faces/complication/tuning_tones_face.c \
diff --git a/movement/make/make_alternate_fw.sh b/movement/make/make_alternate_fw.sh
index c65e72d3..df27403f 100755
--- a/movement/make/make_alternate_fw.sh
+++ b/movement/make/make_alternate_fw.sh
@@ -21,12 +21,12 @@ do
for color in "${colors[@]}"
do
COLOR=$(echo "$color" | tr '[:lower:]' '[:upper:]')
- make clean
+ make COLOR=$COLOR clean
make COLOR=$COLOR FIRMWARE=$VARIANT
mv "build/watch.uf2" "$fw_dir/$variant-$color.uf2"
done
rm -rf ./build-sim
- emmake make FIRMWARE=$VARIANT
+ emmake make COLOR=GREEN FIRMWARE=$VARIANT
mkdir "$sim_dir/$variant/"
mv "build-sim/watch.wasm" "$sim_dir/$variant/"
mv "build-sim/watch.js" "$sim_dir/$variant/"
diff --git a/movement/movement.c b/movement/movement.c
index f0868416..d780a2f3 100644
--- a/movement/movement.c
+++ b/movement/movement.c
@@ -76,7 +76,7 @@
movement_state_t movement_state;
void * watch_face_contexts[MOVEMENT_NUM_FACES];
watch_date_time scheduled_tasks[MOVEMENT_NUM_FACES];
-const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
+const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 600, 3600, 7200, 21600, 43200, 86400, 604800};
const int16_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800};
movement_event_t event;
@@ -232,7 +232,7 @@ bool movement_default_loop_handler(movement_event_t event, movement_settings_t *
movement_illuminate_led();
break;
case EVENT_MODE_LONG_PRESS:
- if (MOVEMENT_SECONDARY_FACE_INDEX && movement_state.current_watch_face == 0) {
+ if (MOVEMENT_SECONDARY_FACE_INDEX && movement_state.current_face_idx == 0) {
movement_move_to_face(MOVEMENT_SECONDARY_FACE_INDEX);
} else {
movement_move_to_face(0);
@@ -247,25 +247,25 @@ bool movement_default_loop_handler(movement_event_t event, movement_settings_t *
void movement_move_to_face(uint8_t watch_face_index) {
movement_state.watch_face_changed = true;
- movement_state.next_watch_face = watch_face_index;
+ movement_state.next_face_idx = watch_face_index;
}
void movement_move_to_next_face(void) {
uint16_t face_max;
if (MOVEMENT_SECONDARY_FACE_INDEX) {
- face_max = (movement_state.current_watch_face < (int16_t)MOVEMENT_SECONDARY_FACE_INDEX) ? MOVEMENT_SECONDARY_FACE_INDEX : MOVEMENT_NUM_FACES;
+ face_max = (movement_state.current_face_idx < (int16_t)MOVEMENT_SECONDARY_FACE_INDEX) ? MOVEMENT_SECONDARY_FACE_INDEX : MOVEMENT_NUM_FACES;
} else {
face_max = MOVEMENT_NUM_FACES;
}
- movement_move_to_face((movement_state.current_watch_face + 1) % face_max);
+ movement_move_to_face((movement_state.current_face_idx + 1) % face_max);
}
void movement_schedule_background_task(watch_date_time date_time) {
- movement_schedule_background_task_for_face(movement_state.current_watch_face, date_time);
+ movement_schedule_background_task_for_face(movement_state.current_face_idx, date_time);
}
void movement_cancel_background_task(void) {
- movement_cancel_background_task_for_face(movement_state.current_watch_face);
+ movement_cancel_background_task_for_face(movement_state.current_face_idx);
}
void movement_schedule_background_task_for_face(uint8_t watch_face_index, watch_date_time date_time) {
@@ -293,25 +293,31 @@ void movement_request_wake() {
_movement_reset_inactivity_countdown();
}
-void movement_play_signal(void) {
- bool buzzer_enabled = watch_is_buzzer_or_led_enabled();
- if (!buzzer_enabled) {
- watch_enable_buzzer();
- }
- watch_buzzer_play_note(BUZZER_NOTE_C8, 75);
- watch_buzzer_play_note(BUZZER_NOTE_REST, 100);
- watch_buzzer_play_note(BUZZER_NOTE_C8, 100);
- if (!buzzer_enabled) {
- watch_disable_buzzer();
- }
+void end_buzzing() {
+ movement_state.is_buzzing = false;
}
-void movement_play_tune(void) {
- if (!watch_is_buzzer_or_led_enabled()) {
- watch_enable_buzzer();
- watch_buzzer_play_sequence(signal_tune, watch_disable_buzzer);
+void end_buzzing_and_disable_buzzer(void) {
+ end_buzzing();
+ watch_disable_buzzer();
+}
+
+void movement_play_signal(void) {
+ void *maybe_disable_buzzer = end_buzzing_and_disable_buzzer;
+ if (watch_is_buzzer_or_led_enabled()) {
+ maybe_disable_buzzer = end_buzzing;
} else {
- watch_buzzer_play_sequence(signal_tune, NULL);
+ watch_enable_buzzer();
+ }
+ movement_state.is_buzzing = true;
+ watch_buzzer_play_sequence(signal_tune, maybe_disable_buzzer);
+ if (movement_state.le_mode_ticks == -1) {
+ // the watch is asleep. wake it up for "1" round through the main loop.
+ // the sleep_mode_app_loop will notice the is_buzzing and note that it
+ // only woke up to beep and then it will spinlock until the callback
+ // turns off the is_buzzing flag.
+ movement_state.needs_wake = true;
+ movement_state.le_mode_ticks = 1;
}
}
@@ -348,7 +354,7 @@ void app_init(void) {
movement_state.settings.bit.led_red_color = MOVEMENT_DEFAULT_RED_COLOR;
movement_state.settings.bit.led_green_color = MOVEMENT_DEFAULT_GREEN_COLOR;
movement_state.settings.bit.button_should_sound = true;
- movement_state.settings.bit.le_interval = 1;
+ movement_state.settings.bit.le_interval = 2;
movement_state.settings.bit.led_duration = 1;
movement_state.light_ticks = -1;
movement_state.alarm_ticks = -1;
@@ -414,7 +420,7 @@ void app_setup(void) {
watch_faces[i].setup(&movement_state.settings, i, &watch_face_contexts[i]);
}
- watch_faces[movement_state.current_watch_face].activate(&movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
+ watch_faces[movement_state.current_face_idx].activate(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
event.subsecond = 0;
event.event_type = EVENT_ACTIVATE;
}
@@ -434,7 +440,7 @@ static void _sleep_mode_app_loop(void) {
if (movement_state.needs_background_tasks_handled) _movement_handle_background_tasks();
event.event_type = EVENT_LOW_ENERGY_UPDATE;
- watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
+ watch_faces[movement_state.current_face_idx].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
// if we need to wake immediately, do it!
if (movement_state.needs_wake) return;
@@ -444,16 +450,20 @@ static void _sleep_mode_app_loop(void) {
}
bool app_loop(void) {
+ const watch_face_t *wf = &watch_faces[movement_state.current_face_idx];
+ bool woke_up_for_buzzer = false;
if (movement_state.watch_face_changed) {
if (movement_state.settings.bit.button_should_sound) {
// low note for nonzero case, high note for return to watch_face 0
- watch_buzzer_play_note(movement_state.next_watch_face ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50);
+ watch_buzzer_play_note(movement_state.next_face_idx ? BUZZER_NOTE_C7 : BUZZER_NOTE_C8, 50);
}
- watch_faces[movement_state.current_watch_face].resign(&movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
- movement_state.current_watch_face = movement_state.next_watch_face;
+ wf->resign(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
+ movement_state.current_face_idx = movement_state.next_face_idx;
+ // we have just updated the face idx, so we must recache the watch face pointer.
+ wf = &watch_faces[movement_state.current_face_idx];
watch_clear_display();
movement_request_tick_frequency(1);
- watch_faces[movement_state.current_watch_face].activate(&movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
+ wf->activate(&movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
event.subsecond = 0;
event.event_type = EVENT_ACTIVATE;
movement_state.watch_face_changed = false;
@@ -487,18 +497,24 @@ bool app_loop(void) {
// _sleep_mode_app_loop takes over at this point and loops until le_mode_ticks is reset by the extwake handler,
// or wake is requested using the movement_request_wake function.
_sleep_mode_app_loop();
- // as soon as _sleep_mode_app_loop returns, we reactivate ourselves.
+ // as soon as _sleep_mode_app_loop returns, we prepare to reactivate
+ // ourselves, but first, we check to see if we woke up for the buzzer:
+ if (movement_state.is_buzzing) {
+ woke_up_for_buzzer = true;
+ }
event.event_type = EVENT_ACTIVATE;
// this is a hack tho: waking from sleep mode, app_setup does get called, but it happens before we have reset our ticks.
// need to figure out if there's a better heuristic for determining how we woke up.
app_setup();
}
+ // default to being allowed to sleep by the face.
static bool can_sleep = true;
if (event.event_type) {
event.subsecond = movement_state.subsecond;
- can_sleep = watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
+ // the first trip through the loop overrides the can_sleep state
+ can_sleep = wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
event.event_type = EVENT_NONE;
}
@@ -510,9 +526,16 @@ bool app_loop(void) {
event.event_type = EVENT_TIMEOUT;
}
event.subsecond = movement_state.subsecond;
- watch_faces[movement_state.current_watch_face].loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_watch_face]);
+ // if we run through the loop again to time out, we need to reconsider whether or not we can sleep.
+ // if the first trip said true, but this trip said false, we need the false to override, thus
+ // we will be using boolean AND:
+ //
+ // first trip | can sleep | cannot sleep | can sleep | cannot sleep
+ // second trip | can sleep | cannot sleep | cannot sleep | can sleep
+ // && | can sleep | cannot sleep | cannot sleep | cannot sleep
+ can_sleep = can_sleep && wf->loop(event, &movement_state.settings, watch_face_contexts[movement_state.current_face_idx]);
event.event_type = EVENT_NONE;
- if (movement_state.settings.bit.to_always && movement_state.current_watch_face != 0) {
+ if (movement_state.settings.bit.to_always && movement_state.current_face_idx != 0) {
// ...but if the user has "timeout always" set, give it the boot.
movement_move_to_face(0);
}
@@ -569,8 +592,13 @@ bool app_loop(void) {
// if the watch face changed, we can't sleep because we need to update the display.
if (movement_state.watch_face_changed) can_sleep = false;
- // if the buzzer or the LED is on, we need to stay awake to keep the TCC running.
- if (movement_state.is_buzzing || movement_state.light_ticks != -1) can_sleep = false;
+ // if we woke up for the buzzer, stay awake until it's finished.
+ if (woke_up_for_buzzer) {
+ while(watch_is_buzzer_or_led_enabled());
+ }
+
+ // if the LED is on, we need to stay awake to keep the TCC running.
+ if (movement_state.light_ticks != -1) can_sleep = false;
return can_sleep;
}
@@ -633,13 +661,13 @@ void cb_fast_tick(void) {
// Notice: is it possible that two or more buttons have an identical timestamp? In this case
// only one of these buttons would receive the long press event. Don't bother for now...
if (movement_state.light_down_timestamp > 0)
- if (movement_state.fast_ticks - movement_state.light_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
+ if (movement_state.fast_ticks - movement_state.light_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
event.event_type = EVENT_LIGHT_LONG_PRESS;
if (movement_state.mode_down_timestamp > 0)
- if (movement_state.fast_ticks - movement_state.mode_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
+ if (movement_state.fast_ticks - movement_state.mode_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
event.event_type = EVENT_MODE_LONG_PRESS;
if (movement_state.alarm_down_timestamp > 0)
- if (movement_state.fast_ticks - movement_state.alarm_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
+ if (movement_state.fast_ticks - movement_state.alarm_down_timestamp == MOVEMENT_LONG_PRESS_TICKS + 1)
event.event_type = EVENT_ALARM_LONG_PRESS;
// this is just a fail-safe; fast tick should be disabled as soon as the button is up, the LED times out, and/or the alarm finishes.
// but if for whatever reason it isn't, this forces the fast tick off after 20 seconds.
diff --git a/movement/movement.h b/movement/movement.h
index 5f30dfb8..1dabfbc5 100644
--- a/movement/movement.h
+++ b/movement/movement.h
@@ -244,8 +244,8 @@ typedef struct {
movement_settings_t settings;
// transient properties
- int16_t current_watch_face;
- int16_t next_watch_face;
+ int16_t current_face_idx;
+ int16_t next_face_idx;
bool watch_face_changed;
bool fast_tick_enabled;
int16_t fast_ticks;
@@ -307,7 +307,6 @@ void movement_cancel_background_task_for_face(uint8_t watch_face_index);
void movement_request_wake(void);
void movement_play_signal(void);
-void movement_play_tune(void);
void movement_play_alarm(void);
void movement_play_alarm_beeps(uint8_t rounds, BuzzerNote alarm_note);
diff --git a/movement/movement_config.h b/movement/movement_config.h
index 6a7f87e0..067ca44b 100644
--- a/movement/movement_config.h
+++ b/movement/movement_config.h
@@ -49,7 +49,7 @@ const watch_face_t watch_faces[] = {
*/
#define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0)
-/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options */
+/* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */
#define SIGNAL_TUNE_DEFAULT
#endif // MOVEMENT_CONFIG_H_
diff --git a/movement/movement_faces.h b/movement/movement_faces.h
index be3a015c..7feb0f40 100644
--- a/movement/movement_faces.h
+++ b/movement/movement_faces.h
@@ -95,6 +95,10 @@
#include "flashlight_face.h"
#include "decimal_time_face.h"
#include "wyoscan_face.h"
+#include "save_load_face.h"
+#include "day_night_percentage_face.h"
+#include "simple_coin_flip_face.h"
+#include "solstice_face.h"
#include "couch_to_5k_face.h"
#include "minute_repeater_decimal_face.h"
#include "tuning_tones_face.h"
diff --git a/movement/template/template.c b/movement/template/template.c
index e03db561..fe2723b8 100644
--- a/movement/template/template.c
+++ b/movement/template/template.c
@@ -28,6 +28,7 @@
void <#watch_face_name#>_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(<#watch_face_name#>_state_t));
memset(*context_ptr, 0, sizeof(<#watch_face_name#>_state_t));
diff --git a/movement/watch_faces/clock/day_night_percentage_face.c b/movement/watch_faces/clock/day_night_percentage_face.c
new file mode 100644
index 00000000..86f07f9d
--- /dev/null
+++ b/movement/watch_faces/clock/day_night_percentage_face.c
@@ -0,0 +1,139 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 <math.h>
+#include "day_night_percentage_face.h"
+#include "watch_utility.h"
+#include "sunriset.h"
+
+// fmod but handle negatives right
+static double better_fmod(double x, double y) {
+ return fmod(fmod(x, y) + y, y);
+}
+
+static void recalculate(watch_date_time utc_now, day_night_percentage_state_t *state) {
+ movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
+
+ if (movement_location.reg == 0) {
+ state->result = -2;
+ return;
+ }
+
+ // Weird quirky unsigned things were happening when I tried to cast these directly to doubles below.
+ // it looks redundant, but extracting them to local int16's seemed to fix it.
+ 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;
+
+ state->daylen = day_length(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat);
+
+ state->result = sun_rise_set(utc_now.unit.year + WATCH_RTC_REFERENCE_YEAR, utc_now.unit.month, utc_now.unit.day, lon, lat, &state->rise, &state->set);
+}
+
+void day_night_percentage_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_night_percentage_state_t));
+ day_night_percentage_state_t *state = (day_night_percentage_state_t *)*context_ptr;
+ watch_date_time utc_now = watch_utility_date_time_convert_zone(watch_rtc_get_date_time(), movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
+ recalculate(utc_now, state);
+ }
+}
+
+void day_night_percentage_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ day_night_percentage_state_t *state = (day_night_percentage_state_t *)context;
+
+ char buf[12];
+ watch_date_time date_time = watch_rtc_get_date_time();
+ watch_date_time utc_now = watch_utility_date_time_convert_zone(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60, 0);
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ case EVENT_TICK:
+ case EVENT_LOW_ENERGY_UPDATE:
+ if ((utc_now.unit.hour == 0 && utc_now.unit.minute == 0 && utc_now.unit.second == 0) || state->result == -2) {
+ recalculate(utc_now, state);
+ }
+
+ if (state->result == -2) {
+ watch_display_string(" no Loc", 0);
+ break;
+ }
+
+ const char* weekday = watch_utility_get_weekday(date_time);
+ if (state->result != 0) {
+ if (state->result == 1) {
+ watch_clear_indicator(WATCH_INDICATOR_PM);
+ } else {
+ watch_set_indicator(WATCH_INDICATOR_PM);
+ }
+ sprintf(buf, "%s%2dEtrnal", weekday, date_time.unit.day);
+ watch_display_string(buf, 0);
+ } else {
+ double day_hours_decimal = utc_now.unit.hour + (utc_now.unit.minute + (utc_now.unit.second / 60.0)) / 60.0;
+
+ double day_percentage = (24.0 - better_fmod(state->rise - day_hours_decimal, 24.0)) / state->daylen;
+ double night_percentage = (24.0 - better_fmod(state->set - day_hours_decimal, 24.0)) / (24 - state->daylen);
+
+ uint16_t percentage;
+ if (day_percentage > 0.0 && day_percentage < 1.0) {
+ percentage = day_percentage * 10000;
+ watch_clear_indicator(WATCH_INDICATOR_PM);
+ } else {
+ percentage = night_percentage * 10000;
+ watch_set_indicator(WATCH_INDICATOR_PM);
+ }
+ if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
+ if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
+ sprintf(buf, "%s%2d %02d ", weekday, date_time.unit.day, percentage / 100);
+ } else {
+ sprintf(buf, "%s%2d %04d", weekday, date_time.unit.day, percentage);
+ }
+ watch_display_string(buf, 0);
+ }
+
+ break;
+ default:
+ return movement_default_loop_handler(event, settings);
+ }
+
+ return true;
+}
+
+void day_night_percentage_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/clock/day_night_percentage_face.h b/movement/watch_faces/clock/day_night_percentage_face.h
new file mode 100644
index 00000000..d172c748
--- /dev/null
+++ b/movement/watch_faces/clock/day_night_percentage_face.h
@@ -0,0 +1,66 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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_NIGHT_PERCENTAGE_FACE_H_
+#define DAY_NIGHT_PERCENTAGE_FACE_H_
+
+#include "movement.h"
+
+/*
+ * Day/night percentage face
+ *
+ * Shows the percentage of the way through the day/night the current time is.
+ *
+ * The time digits show the percentage of the way through the day/night it is,
+ * with decimals in the smaller seconds digits. If the day or night will last
+ * for a full 24 hours, the text "Etrnal" is displayed instead of a percentage.
+ * The "PM" indicator is set when it is currently nighttime. The weekday and
+ * day digits display the weekday and day, as one would expect.
+ *
+ * This face does not currently offer any configuration. You must set the
+ * location register with some other face.
+ */
+
+typedef struct {
+ int result; // -1, 0, 1: result from sun_rise_set, -2: no location set
+ double rise;
+ double set;
+ double daylen;
+} day_night_percentage_state_t;
+
+void day_night_percentage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void day_night_percentage_face_activate(movement_settings_t *settings, void *context);
+bool day_night_percentage_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void day_night_percentage_face_resign(movement_settings_t *settings, void *context);
+
+#define day_night_percentage_face ((const watch_face_t){ \
+ day_night_percentage_face_setup, \
+ day_night_percentage_face_activate, \
+ day_night_percentage_face_loop, \
+ day_night_percentage_face_resign, \
+ NULL, \
+})
+
+#endif // DAY_NIGHT_PERCENTAGE_FACE_H_
+
diff --git a/movement/watch_faces/clock/repetition_minute_face.c b/movement/watch_faces/clock/repetition_minute_face.c
index fc78b2d8..e9e5e319 100644
--- a/movement/watch_faces/clock/repetition_minute_face.c
+++ b/movement/watch_faces/clock/repetition_minute_face.c
@@ -151,6 +151,8 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se
else watch_clear_indicator(WATCH_INDICATOR_BELL);
break;
case EVENT_BACKGROUND_TASK:
+ // uncomment this line to snap back to the clock face when the hour signal sounds:
+ // movement_move_to_face(state->watch_face_index);
movement_play_signal();
break;
case EVENT_LIGHT_LONG_UP:
diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c
index ac9a97b2..fbc2c4b3 100644
--- a/movement/watch_faces/clock/simple_clock_face.c
+++ b/movement/watch_faces/clock/simple_clock_face.c
@@ -136,11 +136,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
case EVENT_BACKGROUND_TASK:
// uncomment this line to snap back to the clock face when the hour signal sounds:
// movement_move_to_face(state->watch_face_index);
- #ifdef SIGNAL_TUNE_DEFAULT
movement_play_signal();
- #else
- movement_play_tune();
- #endif
break;
default:
return movement_default_loop_handler(event, settings);
diff --git a/movement/watch_faces/clock/wyoscan_face.c b/movement/watch_faces/clock/wyoscan_face.c
index fd87b911..66a5d466 100644
--- a/movement/watch_faces/clock/wyoscan_face.c
+++ b/movement/watch_faces/clock/wyoscan_face.c
@@ -60,7 +60,7 @@ a line you've already drawn. It is vaguely top to bottom and counter,
clockwise when possible.
*/
static char *segment_map[] = {
- "AXFEDCBX", // 0
+ "AXFBDEXC", // 0
"BXXXCXXX", // 1
"ABGEXXXD", // 2
"ABGXXXCD", // 3
diff --git a/movement/watch_faces/complication/simple_coin_flip_face.c b/movement/watch_faces/complication/simple_coin_flip_face.c
new file mode 100644
index 00000000..64431f9d
--- /dev/null
+++ b/movement/watch_faces/complication/simple_coin_flip_face.c
@@ -0,0 +1,139 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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.
+ */
+
+#if __EMSCRIPTEN__
+#include <time.h>
+#else
+#include "saml22j18a.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include "simple_coin_flip_face.h"
+
+#define SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP true
+
+void simple_coin_flip_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(simple_coin_flip_state_t));
+ memset(*context_ptr, 0, sizeof(simple_coin_flip_state_t));
+ }
+}
+
+void simple_coin_flip_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+static uint32_t get_random(uint32_t max) {
+ #if __EMSCRIPTEN__
+ return rand() % max;
+ #else
+ return arc4random_uniform(max);
+ #endif
+}
+
+static void animation_0() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(0, 3);
+ watch_set_pixel(0, 6);
+}
+
+static void animation_1() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(1, 3);
+ watch_set_pixel(1, 5);
+}
+
+static void animation_2() {
+ watch_display_string(" ", 8);
+ watch_set_pixel(2, 2);
+ watch_set_pixel(2, 4);
+}
+
+bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ simple_coin_flip_state_t *state = (simple_coin_flip_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ watch_display_string("flip", 5);
+ state->animation_frame = 0;
+ break;
+ case EVENT_TICK:
+ switch (state->animation_frame) {
+ case 0:
+ case 7:
+ return true;
+ case 1:
+ movement_request_tick_frequency(8);
+ watch_display_string(" ", 4);
+ // fallthrough
+ case 5:
+ animation_0();
+ break;
+ case 2:
+ case 4:
+ animation_1();
+ break;
+ case 3:
+ animation_2();
+ break;
+ case 6:
+ movement_request_tick_frequency(1);
+ if (get_random(2)) {
+ watch_display_string("Heads ", 4);
+ } else {
+ watch_display_string(" Tails", 4);
+ }
+ break;
+ }
+ state->animation_frame++;
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ case EVENT_ALARM_BUTTON_UP:
+ if (!SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP || state->animation_frame == 0) {
+ state->animation_frame = 1;
+ }
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ case EVENT_LIGHT_LONG_PRESS:
+ state->animation_frame = 1;
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ return movement_default_loop_handler(event, settings);
+ }
+
+ return true;
+}
+
+void simple_coin_flip_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/complication/simple_coin_flip_face.h b/movement/watch_faces/complication/simple_coin_flip_face.h
new file mode 100644
index 00000000..f5e223b8
--- /dev/null
+++ b/movement/watch_faces/complication/simple_coin_flip_face.h
@@ -0,0 +1,62 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 SIMPLE_COIN_FLIP_FACE_H_
+#define SIMPLE_COIN_FLIP_FACE_H_
+
+#include "movement.h"
+
+/*
+ * A extremely simple coin flip face.
+ *
+ * Press ALARM or LIGHT to flip a coin, after a short animation it will display
+ * "Heads" or "Tails". Long-press to flip again (you can change a #define to
+ * allow a short-press to reflip as well, if you'd like).
+ *
+ * This is for people who want a simpler UI than probability_face or
+ * randonaut_face. While those have more features, this one is more immediately
+ * obvious - useful, for instance, if you are using a coin flip to agree on
+ * something with someone, and want the operation to be clear to someone who
+ * has not had anything explained to them.
+ */
+
+typedef struct {
+ uint8_t animation_frame;
+} simple_coin_flip_state_t;
+
+void simple_coin_flip_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void simple_coin_flip_face_activate(movement_settings_t *settings, void *context);
+bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void simple_coin_flip_face_resign(movement_settings_t *settings, void *context);
+
+#define simple_coin_flip_face ((const watch_face_t){ \
+ simple_coin_flip_face_setup, \
+ simple_coin_flip_face_activate, \
+ simple_coin_flip_face_loop, \
+ simple_coin_flip_face_resign, \
+ NULL, \
+})
+
+#endif // SIMPLE_COIN_FLIP_FACE_H_
+
diff --git a/movement/watch_faces/complication/solstice_face.c b/movement/watch_faces/complication/solstice_face.c
new file mode 100644
index 00000000..e74f8789
--- /dev/null
+++ b/movement/watch_faces/complication/solstice_face.c
@@ -0,0 +1,236 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 <math.h>
+#include "watch_utility.h"
+#include "solstice_face.h"
+
+// Find solstice or equinox time in JDE for a given year, via method from Meeus Ch 27
+static double calculate_solstice_equinox(uint16_t year, uint8_t k) {
+ double Y = ((double)year - 2000) / 1000;
+ double approx_terms[4][5] = {
+ {2451623.80984, 365242.37404, 0.05169, -0.00411, -0.00057}, // March equinox
+ {2451716.56767, 365241.62603, 0.00325, 0.00888, -0.00030}, // June solstice
+ {2451810.21715, 365242.01767, -0.11575, 0.00337, 0.00078}, // September equinox
+ {2451900.05952, 365242.74049, -0.06223, -0.00823, 0.00032}, // December solstice
+ };
+ double JDE0 = approx_terms[k][0] + Y * (approx_terms[k][1] + Y * (approx_terms[k][2] + Y * (approx_terms[k][3] + Y * approx_terms[k][4])));
+ double T = (JDE0 - 2451545.0) / 36525;
+ double W = 35999.373 * T - 2.47;
+ double dlambda = 1 + (0.0334 * cos(W * M_PI / 180.0)) + (0.0007 * cos(2 * W * M_PI / 180.0));
+ double correction_terms[25][3] = {
+ {485,324.96,1934.136},
+ {203,337.23,32964.467},
+ {199,342.08,20.186},
+ {182,27.85,445267.112},
+ {156,73.14,45036.886},
+ {136,171.52,22518.443},
+ {77,222.54,65928.934},
+ {74,296.72,3034.906},
+ {70,243.58,9037.513},
+ {58,119.81,33718.147},
+ {52,297.17,150.678},
+ {50,21.02,2281.226},
+ {45,247.54,29929.562},
+ {44,325.15,31555.956},
+ {29,60.93,4443.417},
+ {18,155.12,67555.328},
+ {17,288.79,4562.452},
+ {16,198.04,62894.029},
+ {14,199.76,31436.921},
+ {12,95.39,14577.848},
+ {12,287.11,31931.756},
+ {12,320.81,34777.259},
+ {9,227.73,1222.114},
+ {8,15.45,16859.074},
+ };
+ double S = 0;
+ for (int i = 0; i < 25; i++) {
+ S += correction_terms[i][0] * cos((correction_terms[i][1] + correction_terms[i][2] * T) * M_PI / 180.0);
+ }
+ double JDE = JDE0 + (0.00001 * S) / dlambda;
+
+ return JDE;
+}
+
+// Convert JDE to Gergorian datetime as per Meeus Ch 7
+static watch_date_time jde_to_date_time(double JDE) {
+ double tmp = JDE + 0.5;
+ double Z = floor(tmp);
+ double F = fmod(tmp, 1);
+ double A;
+ if (Z < 2299161) {
+ A = Z;
+ } else {
+ double alpha = floor((Z - 1867216.25) / 36524.25);
+ A = Z + 1 + alpha - floor(alpha / 4);
+ }
+ double B = A + 1524;
+ double C = floor((B - 122.1) / 365.25);
+ double D = floor(365.25 * C);
+ double E = floor((B - D) / 30.6001);
+ double day = B - D - floor(30.6001 * E) + F;
+ double month;
+ if (E < 14) {
+ month = E - 1;
+ } else {
+ month = E - 13;
+ }
+ double year;
+ if (month > 2) {
+ year = C - 4716;
+ } else {
+ year = C - 4715;
+ }
+
+ double hours = fmod(day, 1) * 24;
+ double minutes = fmod(hours, 1) * 60;
+ double seconds = fmod(minutes, 1) * 60;
+
+ watch_date_time result = {.unit = {
+ floor(seconds),
+ floor(minutes),
+ floor(hours),
+ floor(day),
+ floor(month),
+ floor(year - 2020)
+ }};
+
+ return result;
+}
+
+static void calculate_datetimes(solstice_state_t *state, movement_settings_t *settings) {
+ for (int i = 0; i < 4; i++) {
+ // TODO: handle DST changes
+ state->datetimes[i] = jde_to_date_time(calculate_solstice_equinox(2020 + state->year, i) + (movement_timezone_offsets[settings->bit.time_zone] / (60.0*24.0)));
+ }
+}
+
+void solstice_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(solstice_state_t));
+ solstice_state_t *state = (solstice_state_t *)*context_ptr;
+
+ watch_date_time now = watch_rtc_get_date_time();
+ state->year = now.unit.year;
+ state->index = 0;
+ calculate_datetimes(state, settings);
+
+ uint32_t now_unix = watch_utility_date_time_to_unix_time(now, 0);
+ for (int i = 0; i < 4; i++) {
+ if (state->index == 0 && watch_utility_date_time_to_unix_time(state->datetimes[i], 0) > now_unix) {
+ state->index = i;
+ }
+ }
+ }
+}
+
+void solstice_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
+static void show_main_screen(solstice_state_t *state) {
+ char buf[11];
+ watch_date_time date_time = state->datetimes[state->index];
+ sprintf(buf, " %2d %2d%02d", date_time.unit.year + 20, date_time.unit.month, date_time.unit.day);
+ watch_display_string(buf, 0);
+}
+
+static void show_date_time(movement_settings_t *settings, solstice_state_t *state) {
+ char buf[11];
+ watch_date_time date_time = state->datetimes[state->index];
+ if (!settings->bit.clock_mode_24h) {
+ if (date_time.unit.hour < 12) {
+ watch_clear_indicator(WATCH_INDICATOR_PM);
+ } else {
+ watch_set_indicator(WATCH_INDICATOR_PM);
+ }
+ date_time.unit.hour %= 12;
+ if (date_time.unit.hour == 0) date_time.unit.hour = 12;
+ }
+ sprintf(buf, "%s%2d%2d%02d%02d", watch_utility_get_weekday(date_time), date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
+ watch_set_colon();
+ watch_display_string(buf, 0);
+}
+
+bool solstice_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ solstice_state_t *state = (solstice_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ALARM_LONG_PRESS:
+ show_date_time(settings, state);
+ break;
+ case EVENT_LIGHT_BUTTON_UP:
+ if (state->index == 0) {
+ if (state->year == 0) {
+ break;
+ }
+ state->year--;
+ state->index = 3;
+ calculate_datetimes(state, settings);
+ } else {
+ state->index--;
+ }
+ show_main_screen(state);
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ state->index++;
+ if (state->index > 3) {
+ if (state->year == 83) {
+ break;
+ }
+ state->year++;
+ state->index = 0;
+ calculate_datetimes(state, settings);
+ }
+ show_main_screen(state);
+ break;
+ case EVENT_ALARM_LONG_UP:
+ watch_clear_colon();
+ watch_clear_indicator(WATCH_INDICATOR_PM);
+ show_main_screen(state);
+ break;
+ case EVENT_ACTIVATE:
+ show_main_screen(state);
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ return movement_default_loop_handler(event, settings);
+ }
+
+ return true;
+}
+
+void solstice_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+}
+
diff --git a/movement/watch_faces/complication/solstice_face.h b/movement/watch_faces/complication/solstice_face.h
new file mode 100644
index 00000000..ec537c09
--- /dev/null
+++ b/movement/watch_faces/complication/solstice_face.h
@@ -0,0 +1,64 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 SOLSTICE_FACE_H_
+#define SOLSTICE_FACE_H_
+
+#include "movement.h"
+
+/*
+ * A face for telling the dates and times of solstices and equinoxes
+ *
+ * It shows the upcoming solstice or equinox by default. The upper right number
+ * is the year, and the bottom numbers are the date in MMDD format. Use the
+ * alarm / light buttons to go forwards / backwards in time. Long press the
+ * alarm button to show the time of the event, including what weekday it is on,
+ * in your local timezone (DST is not handled).
+ *
+ * Supports the years 2020 - 2083. The calculations are reasonably accurate for
+ * years between 1000 and 3000, but limitations in the sensor watch libraries
+ * (which could easily be worked around) prevent making use of that.
+ */
+
+typedef struct {
+ watch_date_time datetimes[4];
+ uint8_t year;
+ uint8_t index;
+} solstice_state_t;
+
+void solstice_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void solstice_face_activate(movement_settings_t *settings, void *context);
+bool solstice_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void solstice_face_resign(movement_settings_t *settings, void *context);
+
+#define solstice_face ((const watch_face_t){ \
+ solstice_face_setup, \
+ solstice_face_activate, \
+ solstice_face_loop, \
+ solstice_face_resign, \
+ NULL, \
+})
+
+#endif // SOLSTICE_FACE_H_
+
diff --git a/movement/watch_faces/complication/sunrise_sunset_face.c b/movement/watch_faces/complication/sunrise_sunset_face.c
index 82de9c6e..7330c42c 100644
--- a/movement/watch_faces/complication/sunrise_sunset_face.c
+++ b/movement/watch_faces/complication/sunrise_sunset_face.c
@@ -197,6 +197,8 @@ static void _sunrise_sunset_face_update_settings_display(movement_event_t event,
char buf[12];
switch (state->page) {
+ case 0:
+ return;
case 1:
sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)));
break;
diff --git a/movement/watch_faces/complication/tomato_face.c b/movement/watch_faces/complication/tomato_face.c
index 698301e1..3d46ba94 100644
--- a/movement/watch_faces/complication/tomato_face.c
+++ b/movement/watch_faces/complication/tomato_face.c
@@ -84,8 +84,10 @@ static void tomato_draw(tomato_state_t *state) {
sec = 0;
break;
}
- sprintf(buf, "TO %c%2d%02d%2d", kind, min, sec, state->done_count);
- watch_display_string(buf, 0);
+ if (state->visible) {
+ sprintf(buf, "TO %c%2d%02d%2d", kind, min, sec, state->done_count);
+ watch_display_string(buf, 0);
+ }
}
static void tomato_reset(tomato_state_t *state) {
@@ -116,6 +118,7 @@ void tomato_face_setup(movement_settings_t *settings, uint8_t watch_face_index,
state->mode=tomato_ready;
state->kind= tomato_focus;
state->done_count = 0;
+ state->visible = true;
}
}
@@ -127,6 +130,7 @@ void tomato_face_activate(movement_settings_t *settings, void *context) {
watch_set_indicator(WATCH_INDICATOR_BELL);
}
watch_set_colon();
+ state->visible = true;
}
bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
@@ -184,6 +188,8 @@ bool tomato_face_loop(movement_event_t event, movement_settings_t *settings, voi
}
void tomato_face_resign(movement_settings_t *settings, void *context) {
+ tomato_state_t *state = (tomato_state_t *)context;
+ state->visible = false;
(void) settings;
(void) context;
}
diff --git a/movement/watch_faces/complication/tomato_face.h b/movement/watch_faces/complication/tomato_face.h
index 33a086c6..25f7db0e 100644
--- a/movement/watch_faces/complication/tomato_face.h
+++ b/movement/watch_faces/complication/tomato_face.h
@@ -64,6 +64,7 @@ typedef struct {
tomato_mode mode;
tomato_kind kind;
uint8_t done_count;
+ bool visible;
} tomato_state_t;
void tomato_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
diff --git a/movement/watch_faces/settings/nanosec_face.c b/movement/watch_faces/settings/nanosec_face.c
index 72fdb729..37dd08ef 100644
--- a/movement/watch_faces/settings/nanosec_face.c
+++ b/movement/watch_faces/settings/nanosec_face.c
@@ -245,7 +245,6 @@ static void value_increase(int16_t delta) {
nanosec_state.correction_cadence = (delta > 0) ? 1 : 20;
break;
}
- nanosec_state.correction_profile = (nanosec_state.correction_profile + delta) % nanosec_profile_count;
break;
case 6: // Aging
nanosec_state.aging_ppm_pa += delta;
diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c
index b0e328b3..c96e8d1f 100644
--- a/movement/watch_faces/settings/preferences_face.c
+++ b/movement/watch_faces/settings/preferences_face.c
@@ -136,22 +136,22 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
watch_display_string(" Never", 4);
break;
case 1:
- watch_display_string("1 hour", 4);
+ watch_display_string("10n&in", 4);
break;
case 2:
- watch_display_string("2 hour", 4);
+ watch_display_string("1 hour", 4);
break;
case 3:
- watch_display_string("6 hour", 4);
+ watch_display_string("2 hour", 4);
break;
case 4:
- watch_display_string("12 hr", 4);
+ watch_display_string("6 hour", 4);
break;
case 5:
- watch_display_string(" 1 day", 4);
+ watch_display_string("12 hr", 4);
break;
case 6:
- watch_display_string(" 2 day", 4);
+ watch_display_string(" 1 day", 4);
break;
case 7:
watch_display_string(" 7 day", 4);
diff --git a/movement/watch_faces/settings/save_load_face.c b/movement/watch_faces/settings/save_load_face.c
new file mode 100644
index 00000000..7b4be4d8
--- /dev/null
+++ b/movement/watch_faces/settings/save_load_face.c
@@ -0,0 +1,152 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 "save_load_face.h"
+#include "filesystem.h"
+
+static void save(save_load_state_t *state) {
+ savefile_t savefile = {
+ 1,
+ watch_get_backup_data(0),
+ watch_get_backup_data(1),
+ watch_get_backup_data(2),
+ watch_get_backup_data(3),
+ watch_get_backup_data(4),
+ watch_get_backup_data(5),
+ watch_get_backup_data(6),
+ watch_get_backup_data(7),
+ watch_rtc_get_date_time(),
+ };
+ state->slot[state->index] = savefile;
+ char filename[23];
+ sprintf(filename, "save_load_face_%d.bin", state->index);
+ filesystem_write_file(filename, (char*)&savefile, sizeof(savefile_t));
+}
+
+static void load(save_load_state_t *state, movement_settings_t *settings) {
+ watch_store_backup_data(state->slot[state->index].b0, 0);
+ settings->reg = state->slot[state->index].b0;
+ watch_store_backup_data(state->slot[state->index].b1, 1);
+ watch_store_backup_data(state->slot[state->index].b2, 2);
+ watch_store_backup_data(state->slot[state->index].b3, 3);
+ watch_store_backup_data(state->slot[state->index].b4, 4);
+ watch_store_backup_data(state->slot[state->index].b5, 5);
+ watch_store_backup_data(state->slot[state->index].b6, 6);
+ watch_store_backup_data(state->slot[state->index].b7, 7);
+}
+
+static void load_saves_to_state(save_load_state_t *state) {
+ for (uint8_t i = 0; i < SAVE_LOAD_SLOTS; i++) {
+ char filename[23];
+ sprintf(filename, "save_load_face_%d.bin", i);
+ if (filesystem_get_file_size(filename) != sizeof(savefile_t)) {
+ state->slot[i].version = 0;
+ continue;
+ }
+ filesystem_read_file(filename, (char*)&state->slot[i], sizeof(savefile_t));
+ if (state->slot[i].version != 1) {
+ state->slot[i].version = 0;
+ }
+ }
+}
+
+void save_load_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(save_load_state_t));
+ memset(*context_ptr, 0, sizeof(save_load_state_t));
+ }
+}
+
+void save_load_face_activate(movement_settings_t *settings, void *context) {
+ (void) settings;
+ save_load_state_t *state = (save_load_state_t *)context;
+ state->index = 0;
+ state->update_timeout = 0;
+ load_saves_to_state(state);
+}
+
+static void update_display(save_load_state_t *state) {
+ char buf[11];
+ sprintf(buf, "SL %1d", state->index);
+ watch_display_string(buf, 0);
+
+ if (state->slot[state->index].version) {
+ sprintf(buf, "%02d%02d%02d", state->slot[state->index].rtc.unit.year + 20, state->slot[state->index].rtc.unit.month, state->slot[state->index].rtc.unit.day);
+ watch_display_string(buf, 4);
+ } else {
+ watch_display_string("no dat", 4);
+ }
+}
+
+bool save_load_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
+ save_load_state_t *state = (save_load_state_t *)context;
+
+ switch (event.event_type) {
+ case EVENT_ACTIVATE:
+ update_display(state);
+ break;
+ case EVENT_TICK:
+ if (state->update_timeout) {
+ if (!--state->update_timeout) {
+ update_display(state);
+ }
+ }
+ break;
+ case EVENT_ALARM_BUTTON_UP:
+ state->index = (state->index + 1) % SAVE_LOAD_SLOTS;
+ update_display(state);
+ break;
+ case EVENT_LIGHT_LONG_PRESS:
+ save(state);
+ watch_display_string("Saved ", 4);
+ state->update_timeout = 3;
+ break;
+ case EVENT_ALARM_LONG_PRESS:
+ if (state->slot[state->index].version) {
+ load(state, settings);
+ watch_display_string("Loaded", 4);
+ state->update_timeout = 3;
+ }
+ break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
+ default:
+ return movement_default_loop_handler(event, settings);
+ }
+
+ return true;
+}
+
+void save_load_face_resign(movement_settings_t *settings, void *context) {
+ (void) settings;
+ (void) context;
+
+ // handle any cleanup before your watch face goes off-screen.
+}
+
diff --git a/movement/watch_faces/settings/save_load_face.h b/movement/watch_faces/settings/save_load_face.h
new file mode 100644
index 00000000..fc155317
--- /dev/null
+++ b/movement/watch_faces/settings/save_load_face.h
@@ -0,0 +1,82 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 SAVE_LOAD_FACE_H_
+#define SAVE_LOAD_FACE_H_
+
+#include "movement.h"
+#include "watch_rtc.h"
+
+/*
+ * Save/Load face
+ *
+ * This allows you to save your settings (including location, birthday, etc) to
+ * LFS, which is not wiped when firmware is updated, and then load them again.
+ * It provides multiple save slots (four by default).
+ *
+ * Press ALARM to cycle through save slots. Long press LIGHT to save to the
+ * current slot. Long press ALARM to load from the current slot. The date that
+ * a save was taken is shown in YYMMDD format , or "no dat" if the slot is
+ * empty. The index of the current slot is displayed in the upper right corner.
+ *
+ * While the time that a save was taken is recorded, it is not currently
+ * restored.
+ */
+
+typedef struct savefile {
+ uint8_t version;
+ uint32_t b0;
+ uint32_t b1;
+ uint32_t b2;
+ uint32_t b3;
+ uint32_t b4;
+ uint32_t b5;
+ uint32_t b6;
+ uint32_t b7;
+ watch_date_time rtc;
+} savefile_t;
+
+#define SAVE_LOAD_SLOTS 4
+
+typedef struct {
+ uint8_t index;
+ uint8_t update_timeout;
+ savefile_t slot[SAVE_LOAD_SLOTS];
+} save_load_state_t;
+
+void save_load_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
+void save_load_face_activate(movement_settings_t *settings, void *context);
+bool save_load_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
+void save_load_face_resign(movement_settings_t *settings, void *context);
+
+#define save_load_face ((const watch_face_t){ \
+ save_load_face_setup, \
+ save_load_face_activate, \
+ save_load_face_loop, \
+ save_load_face_resign, \
+ NULL, \
+})
+
+#endif // SAVE_LOAD_FACE_H_
+
diff --git a/watch-library/hardware/watch/watch_buzzer.c b/watch-library/hardware/watch/watch_buzzer.c
index 18fb4db0..2dce8d23 100644
--- a/watch-library/hardware/watch/watch_buzzer.c
+++ b/watch-library/hardware/watch/watch_buzzer.c
@@ -23,6 +23,7 @@
*/
#include "watch_buzzer.h"
+#include "watch_private_buzzer.h"
#include "../../../watch-library/hardware/include/saml22j18a.h"
#include "../../../watch-library/hardware/include/component/tc.h"
#include "../../../watch-library/hardware/hri/hri_tc_l22.h"
diff --git a/watch-library/shared/watch/watch_buzzer.h b/watch-library/shared/watch/watch_buzzer.h
index 7ba9a52e..4c39475c 100644
--- a/watch-library/shared/watch/watch_buzzer.h
+++ b/watch-library/shared/watch/watch_buzzer.h
@@ -175,6 +175,8 @@ extern const uint16_t NotePeriods[108];
*/
void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void));
+uint16_t sequence_length(int8_t *sequence);
+
/** @brief Aborts a playing sequence.
*/
void watch_buzzer_abort_sequence(void);
diff --git a/watch-library/shared/watch/watch_private_buzzer.c b/watch-library/shared/watch/watch_private_buzzer.c
index 0618f425..def54a46 100644
--- a/watch-library/shared/watch/watch_private_buzzer.c
+++ b/watch-library/shared/watch/watch_private_buzzer.c
@@ -23,6 +23,13 @@
*/
#include "driver_init.h"
-// note: the buzzer uses a 1 MHz clock. these values were determined by dividing 1,000,000 by the target frequency.
-// i.e. for a 440 Hz tone (A4 on the piano), 1MHz/440Hz = 2273
-const uint16_t NotePeriods[108] = {18182,17161,16197,15288,14430,13620,12857,12134,11453,10811,10204,9631,9091,8581,8099,7645,7216,6811,6428,6068,5727,5405,5102,4816,4545,4290,4050,3822,3608,3405,3214,3034,2863,2703,2551,2408,2273,2145,2025,1911,1804,1703,1607,1517,1432,1351,1276,1204,1136,1073,1012,956,902,851,804,758,716,676,638,602,568,536,506,478,451,426,402,379,358,338,319,301,284,268,253,239,225,213,201,190,179,169,159,150,142,134,127};
+uint16_t sequence_length(int8_t *sequence) {
+ uint16_t result = 0;
+
+ while (*sequence != 0){
+ result += *(sequence + 1);
+ sequence += 2;
+ }
+
+ return result;
+}
diff --git a/watch-library/shared/watch/watch_private_buzzer.h b/watch-library/shared/watch/watch_private_buzzer.h
new file mode 100644
index 00000000..3017bbb5
--- /dev/null
+++ b/watch-library/shared/watch/watch_private_buzzer.h
@@ -0,0 +1,33 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Wesley Aptekar-Cassels
+ *
+ * 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 _WATCH_PRIVATE_BUZZER_H_INCLUDED
+#define _WATCH_PRIVATE_BUZZER_H_INCLUDED
+
+// note: the buzzer uses a 1 MHz clock. these values were determined by dividing 1,000,000 by the target frequency.
+// i.e. for a 440 Hz tone (A4 on the piano), 1MHz/440Hz = 2273
+const uint16_t NotePeriods[108] = {18182,17161,16197,15288,14430,13620,12857,12134,11453,10811,10204,9631,9091,8581,8099,7645,7216,6811,6428,6068,5727,5405,5102,4816,4545,4290,4050,3822,3608,3405,3214,3034,2863,2703,2551,2408,2273,2145,2025,1911,1804,1703,1607,1517,1432,1351,1276,1204,1136,1073,1012,956,902,851,804,758,716,676,638,602,568,536,506,478,451,426,402,379,358,338,319,301,284,268,253,239,225,213,201,190,179,169,159,150,142,134,127};
+
+uint16_t sequence_length(int8_t *sequence);
+
+#endif
diff --git a/watch-library/simulator/watch/watch_buzzer.c b/watch-library/simulator/watch/watch_buzzer.c
index 211235df..7ccb8545 100644
--- a/watch-library/simulator/watch/watch_buzzer.c
+++ b/watch-library/simulator/watch/watch_buzzer.c
@@ -23,6 +23,7 @@
*/
#include "watch_buzzer.h"
+#include "watch_private_buzzer.h"
#include "watch_main_loop.h"
#include <emscripten.h>