Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call set_time_face on long press of alarm. Move alert toggle to light. #456

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion movement/movement_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const watch_face_t watch_faces[] = {
moon_phase_face,
stopwatch_face,
preferences_face,
set_time_face,
thermistor_readout_face,
voltage_face
};
Expand Down
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 @@ -50,6 +51,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 @@ -221,6 +224,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 @@ -237,12 +241,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 @@ -260,6 +279,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 @@ -276,13 +299,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 @@ -68,13 +70,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 @@ -135,6 +152,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 @@ -153,13 +174,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