Skip to content

Commit

Permalink
Call set_time_face on long press of alarm. Move alert toggle to light.
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyHoyle committed Aug 31, 2024
1 parent 0194044 commit 6825519
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion movement/watch_faces/clock/clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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();
Expand All @@ -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:
Expand All @@ -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();

Expand Down
25 changes: 24 additions & 1 deletion movement/watch_faces/clock/simple_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -64,13 +66,28 @@ 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) {
simple_clock_state_t *state = (simple_clock_state_t *)context;
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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions movement/watch_faces/clock/simple_clock_face.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6825519

Please sign in to comment.