Merge branch 'main' of github.com:joeycastillo/Sensor-Watch into main

This commit is contained in:
Slim
2022-12-02 19:53:56 +01:00
10 changed files with 79 additions and 22 deletions

View File

@@ -29,6 +29,12 @@
#include "watch.h"
#include "watch_utility.h"
// distant future for background task: January 1, 2083
// see stopwatch_face_activate for details
static const watch_date_time distant_future = {
.unit = {0, 0, 0, 1, 1, 63}
};
void stopwatch_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
(void) watch_face_index;
@@ -49,6 +55,7 @@ static void _stopwatch_face_update_display(stopwatch_state_t *stopwatch_state, b
if (stopwatch_state->seconds_counted >= 3456000) {
// display maxes out just shy of 40 days, thanks to the limit on the day digits (0-39)
stopwatch_state->running = false;
movement_cancel_background_task();
watch_display_string("st39235959", 0);
return;
}
@@ -72,12 +79,21 @@ static void _stopwatch_face_update_display(stopwatch_state_t *stopwatch_state, b
void stopwatch_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
if (watch_tick_animation_is_running()) watch_stop_tick_animation();
stopwatch_state_t *stopwatch_state = (stopwatch_state_t *)context;
if (stopwatch_state->running) {
// because the low power update happens on the minute mark, and the wearer could start
// the stopwatch anytime, the low power update could fire up to 59 seconds later than
// we need it to, causing the stopwatch to display stale data.
// So let's schedule a background task that will never fire. This will keep the watch
// from entering low energy mode while the stopwatch is on screen. This background task
// will remain scheduled until the stopwatch stops OR this watch face resigns.
movement_schedule_background_task(distant_future);
}
}
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;
switch (event.event_type) {
@@ -103,6 +119,9 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
}
break;
case EVENT_ALARM_BUTTON_DOWN:
if (settings->bit.button_should_sound) {
watch_buzzer_play_note(BUZZER_NOTE_C8, 50);
}
stopwatch_state->running = !stopwatch_state->running;
if (stopwatch_state->running) {
// we're running now, so we need to set the start_time.
@@ -118,15 +137,28 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
// and resume from the "virtual" start time that's that many seconds ago.
stopwatch_state->start_time = watch_utility_date_time_from_unix_time(timestamp, 0);
}
// schedule our keepalive task when running...
movement_schedule_background_task(distant_future);
} else {
// and cancel it when stopped.
movement_cancel_background_task();
}
break;
case EVENT_TIMEOUT:
// explicitly ignore the timeout event so we stay on screen
break;
case EVENT_LOW_ENERGY_UPDATE:
if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
_stopwatch_face_update_display(stopwatch_state, false);
watch_set_indicator(WATCH_INDICATOR_BELL);
if (!watch_tick_animation_is_running()) watch_start_tick_animation(1000);
if (!stopwatch_state->running) {
// since the tick animation is running, displaying the stopped time could be misleading,
// as it could imply that the stopwatch is running. instead, show a blank display to
// indicate that we are in sleep mode.
watch_display_string("st ---- ", 0);
} else {
// this OTOH shouldn't happen anymore; if we're running, we shouldn't enter low energy mode
_stopwatch_face_update_display(stopwatch_state, false);
watch_set_indicator(WATCH_INDICATOR_BELL);
}
break;
default:
break;
@@ -138,4 +170,8 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
void stopwatch_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
}
// regardless of whether we're running or stopped, cancel the task
// that was keeping us awake while on screen.
movement_cancel_background_task();
}

View File

@@ -96,6 +96,11 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (seconds < 30) scratch_time.unit.minute = floor(minutes);
else scratch_time.unit.minute = ceil(minutes);
if (scratch_time.unit.minute == 60) {
scratch_time.unit.minute = 0;
scratch_time.unit.hour = (scratch_time.unit.hour + 1) % 24;
}
if (date_time.reg < scratch_time.reg) _sunrise_sunset_set_expiration(state, scratch_time);
if (date_time.reg < scratch_time.reg || show_next_match) {
@@ -118,6 +123,11 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (seconds < 30) scratch_time.unit.minute = floor(minutes);
else scratch_time.unit.minute = ceil(minutes);
if (scratch_time.unit.minute == 60) {
scratch_time.unit.minute = 0;
scratch_time.unit.hour = (scratch_time.unit.hour + 1) % 24;
}
if (date_time.reg < scratch_time.reg) _sunrise_sunset_set_expiration(state, scratch_time);
if (date_time.reg < scratch_time.reg || show_next_match) {
@@ -371,8 +381,11 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
}
break;
case EVENT_TIMEOUT:
if (state->page || state->rise_index) {
// on timeout, exit settings mode and return to the next sunrise or sunset
if (watch_get_backup_data(1) == 0) {
// if no location set, return home
movement_move_to_face(0);
} else if (state->page || state->rise_index) {
// otherwise on timeout, exit settings mode and return to the next sunrise or sunset
state->page = 0;
state->rise_index = 0;
movement_request_tick_frequency(1);

View File

@@ -66,8 +66,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
date_time.unit.second = 0;
break;
case 3: // year
// only allow 2021-2030. fix this sometime next decade
date_time.unit.year = ((date_time.unit.year % 10) + 1);
// only allow 2021-2050. fix this if we make it that far.
date_time.unit.year = ((date_time.unit.year % 30) + 1);
break;
case 4: // month
date_time.unit.month = (date_time.unit.month % 12) + 1;