From 6825519e24ff168273fa3aaa47a537cdf61b6121 Mon Sep 17 00:00:00 2001 From: Tony Hoyle Date: Sat, 31 Aug 2024 16:47:47 +0100 Subject: [PATCH] Call set_time_face on long press of alarm. Move alert toggle to light. --- movement/watch_faces/clock/clock_face.c | 27 ++++++++++++++++++- .../watch_faces/clock/simple_clock_face.c | 25 ++++++++++++++++- .../watch_faces/clock/simple_clock_face.h | 2 ++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/movement/watch_faces/clock/clock_face.c b/movement/watch_faces/clock/clock_face.c index eab5cd8d3..170d66e34 100644 --- a/movement/watch_faces/clock/clock_face.c +++ b/movement/watch_faces/clock/clock_face.c @@ -35,6 +35,7 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "../settings/set_time_face.h" // 2.2 volts will happen when the battery has maybe 5-10% remaining? // we can refine this later. @@ -54,6 +55,8 @@ typedef struct { uint8_t watch_face_index; bool time_signal_enabled; bool battery_low; + void *set_time_context; + bool setting_mode; } clock_state_t; static bool clock_is_in_24h_mode(movement_settings_t *settings) { @@ -222,6 +225,7 @@ void clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v clock_state_t *state = (clock_state_t *) *context_ptr; state->time_signal_enabled = false; state->watch_face_index = watch_face_index; + set_time_face.setup(settings, -1, &state->set_time_context); } } @@ -238,12 +242,27 @@ void clock_face_activate(movement_settings_t *settings, void *context) { // this ensures that none of the timestamp fields will match, so we can re-render them all. clock->date_time.previous.reg = 0xFFFFFFFF; + + clock->setting_mode = false; } bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { clock_state_t *state = (clock_state_t *) context; watch_date_time current; + if(state->setting_mode) { + if(event.event_type != EVENT_MODE_BUTTON_UP) { + return set_time_face.loop(event, settings, state->set_time_context); + } else { + // We have to trigger an end to fastticks first.. bit hacky + event.event_type = EVENT_ALARM_LONG_UP; + set_time_face.loop(event, settings, state->set_time_context); + + state->setting_mode = false; + event.event_type = EVENT_ACTIVATE; + } + } + switch (event.event_type) { case EVENT_LOW_ENERGY_UPDATE: clock_start_tick_tock_animation(); @@ -261,6 +280,10 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void break; case EVENT_ALARM_LONG_PRESS: + state->setting_mode = true; + set_time_face.activate(settings, state->set_time_context); + break; + case EVENT_LIGHT_LONG_PRESS: clock_toggle_time_signal(state); break; case EVENT_BACKGROUND_TASK: @@ -277,13 +300,15 @@ bool clock_face_loop(movement_event_t event, movement_settings_t *settings, void void clock_face_resign(movement_settings_t *settings, void *context) { (void) settings; - (void) context; + clock_state_t *state = (clock_state_t *) context; + set_time_face.resign(settings, state->set_time_context); } bool clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; clock_state_t *state = (clock_state_t *) context; if (!state->time_signal_enabled) return false; + if (state->setting_mode) return true; watch_date_time date_time = watch_rtc_get_date_time(); diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c index fbc2c4b3e..15033973f 100644 --- a/movement/watch_faces/clock/simple_clock_face.c +++ b/movement/watch_faces/clock/simple_clock_face.c @@ -27,6 +27,7 @@ #include "watch.h" #include "watch_utility.h" #include "watch_private_display.h" +#include "../settings/set_time_face.h" static void _update_alarm_indicator(bool settings_alarm_enabled, simple_clock_state_t *state) { state->alarm_enabled = settings_alarm_enabled; @@ -43,6 +44,7 @@ void simple_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_i simple_clock_state_t *state = (simple_clock_state_t *)*context_ptr; state->signal_enabled = false; state->watch_face_index = watch_face_index; + set_time_face.setup(settings, -1, &state->set_time_context); } } @@ -64,6 +66,8 @@ void simple_clock_face_activate(movement_settings_t *settings, void *context) { // this ensures that none of the timestamp fields will match, so we can re-render them all. state->previous_date_time = 0xFFFFFFFF; + + state->setting_mode = false; } bool simple_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { @@ -71,6 +75,19 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting char buf[11]; uint8_t pos; + if(state->setting_mode) { + if(event.event_type != EVENT_MODE_BUTTON_UP) { + return set_time_face.loop(event, settings, state->set_time_context); + } else { + // We have to trigger an end to fastticks first.. bit hacky + event.event_type = EVENT_ALARM_LONG_UP; + set_time_face.loop(event, settings, state->set_time_context); + + state->setting_mode = false; + event.event_type = EVENT_LOW_ENERGY_UPDATE; // This forces a full refresh + } + } + watch_date_time date_time; uint32_t previous_date_time; switch (event.event_type) { @@ -129,6 +146,10 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state); break; case EVENT_ALARM_LONG_PRESS: + state->setting_mode = true; + set_time_face.activate(settings, state->set_time_context); + break; + case EVENT_LIGHT_LONG_PRESS: state->signal_enabled = !state->signal_enabled; if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL); else watch_clear_indicator(WATCH_INDICATOR_BELL); @@ -147,13 +168,15 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting void simple_clock_face_resign(movement_settings_t *settings, void *context) { (void) settings; - (void) context; + simple_clock_state_t *state = (simple_clock_state_t *) context; + set_time_face.resign(settings, state->set_time_context); } bool simple_clock_face_wants_background_task(movement_settings_t *settings, void *context) { (void) settings; simple_clock_state_t *state = (simple_clock_state_t *)context; if (!state->signal_enabled) return false; + if (state->setting_mode) return true; watch_date_time date_time = watch_rtc_get_date_time(); diff --git a/movement/watch_faces/clock/simple_clock_face.h b/movement/watch_faces/clock/simple_clock_face.h index e74a6e864..a769fd33f 100644 --- a/movement/watch_faces/clock/simple_clock_face.h +++ b/movement/watch_faces/clock/simple_clock_face.h @@ -43,6 +43,8 @@ typedef struct { bool signal_enabled; bool battery_low; bool alarm_enabled; + void *set_time_context; + bool setting_mode; } simple_clock_state_t; void simple_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);