Fixed bugs and improved watchface
- A background task is only scheduled if the alarm option is activated. If the option is enabled, an alarm sounds when the next deadline is reached. If the option is disabled, no alarm sounds and the watch can enter low energy sleep. - Fixed tick frequency error. During running mode, the clock ticks at 1Hz. This is set in the init function `_running_init` and thus ensures that we do not run too fast when returning from the setting mode. - Minor corrections to comments and indentations.
This commit is contained in:
parent
c89316b3ec
commit
27ab799e85
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Konrad Rieck
|
* Copyright (c) 2023-2024 Konrad Rieck
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the
|
* copy of this software and associated documentation files (the
|
||||||
@ -66,6 +66,12 @@
|
|||||||
* - A *long press* on the *alarm button* activates settings mode and
|
* - A *long press* on the *alarm button* activates settings mode and
|
||||||
* enables configuring the currently selected deadline.
|
* enables configuring the currently selected deadline.
|
||||||
*
|
*
|
||||||
|
* - A *long press* on the *light button* activates a deadline alarm. The
|
||||||
|
* bell icon is displayed, and the alarm will ring upon reaching any of
|
||||||
|
* the deadlines set. It is important to note that the watch will not
|
||||||
|
* enter low-energy sleep mode while the alarm is enabled.
|
||||||
|
*
|
||||||
|
*
|
||||||
* ## Settings Mode
|
* ## Settings Mode
|
||||||
*
|
*
|
||||||
* In settings mode, the currently selected slot for a deadline can be
|
* In settings mode, the currently selected slot for a deadline can be
|
||||||
@ -147,7 +153,7 @@ static inline int _days_in_month(int16_t month, int16_t year)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate time zone offset */
|
/* Return time zone offset */
|
||||||
static inline int32_t _get_tz_offset(movement_settings_t *settings)
|
static inline int32_t _get_tz_offset(movement_settings_t *settings)
|
||||||
{
|
{
|
||||||
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
return movement_timezone_offsets[settings->bit.time_zone] * 60;
|
||||||
@ -156,7 +162,7 @@ static inline int32_t _get_tz_offset(movement_settings_t *settings)
|
|||||||
/* Beep for a button press*/
|
/* Beep for a button press*/
|
||||||
static inline void _beep_button(movement_settings_t *settings)
|
static inline void _beep_button(movement_settings_t *settings)
|
||||||
{
|
{
|
||||||
// play a beep as confirmation for a button press (if applicable)
|
// Play a beep as confirmation for a button press (if applicable)
|
||||||
if (!settings->bit.button_should_sound)
|
if (!settings->bit.button_should_sound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -289,7 +295,7 @@ static void _running_display(movement_event_t event, movement_settings_t *settin
|
|||||||
(void) event;
|
(void) event;
|
||||||
(void) settings;
|
(void) settings;
|
||||||
|
|
||||||
/* seconds, minutes, hours, days, months, years */
|
/* Seconds, minutes, hours, days, months, years */
|
||||||
int16_t unit[] = { 0, 0, 0, 0, 0, 0 };
|
int16_t unit[] = { 0, 0, 0, 0, 0, 0 };
|
||||||
uint8_t i, range[] = { 60, 60, 24, 30, 12, 0 };
|
uint8_t i, range[] = { 60, 60, 24, 30, 12, 0 };
|
||||||
char buf[16];
|
char buf[16];
|
||||||
@ -370,6 +376,9 @@ static void _running_init(movement_settings_t *settings, deadline_state_t *state
|
|||||||
watch_clear_indicator(WATCH_INDICATOR_24H);
|
watch_clear_indicator(WATCH_INDICATOR_24H);
|
||||||
watch_clear_indicator(WATCH_INDICATOR_PM);
|
watch_clear_indicator(WATCH_INDICATOR_PM);
|
||||||
watch_set_colon();
|
watch_set_colon();
|
||||||
|
|
||||||
|
/* Ensure 1Hz updates only */
|
||||||
|
_change_tick_freq(1, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop of running mode */
|
/* Loop of running mode */
|
||||||
@ -397,15 +406,21 @@ static bool _running_loop(movement_event_t event, movement_settings_t *settings,
|
|||||||
case EVENT_LIGHT_LONG_PRESS:
|
case EVENT_LIGHT_LONG_PRESS:
|
||||||
_beep_button(settings);
|
_beep_button(settings);
|
||||||
state->alarm_enabled = !state->alarm_enabled;
|
state->alarm_enabled = !state->alarm_enabled;
|
||||||
|
if (state->alarm_enabled) {
|
||||||
|
_schedule_alarm(settings, state);
|
||||||
|
} else {
|
||||||
|
movement_cancel_background_task();
|
||||||
|
}
|
||||||
_running_display(event, settings, state);
|
_running_display(event, settings, state);
|
||||||
break;
|
break;
|
||||||
case EVENT_TIMEOUT:
|
case EVENT_TIMEOUT:
|
||||||
movement_move_to_face(0);
|
movement_move_to_face(0);
|
||||||
break;
|
break;
|
||||||
case EVENT_BACKGROUND_TASK:
|
case EVENT_BACKGROUND_TASK:
|
||||||
if (state->alarm_enabled)
|
if (state->alarm_enabled) {
|
||||||
movement_play_alarm();
|
movement_play_alarm();
|
||||||
_schedule_alarm(settings, state);
|
_schedule_alarm(settings, state);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_LOW_ENERGY_UPDATE:
|
case EVENT_LOW_ENERGY_UPDATE:
|
||||||
break;
|
break;
|
||||||
@ -465,13 +480,15 @@ static void _setting_display(movement_event_t event, movement_settings_t *settin
|
|||||||
/* Init setting mode */
|
/* Init setting mode */
|
||||||
static void _setting_init(movement_settings_t *settings, deadline_state_t *state)
|
static void _setting_init(movement_settings_t *settings, deadline_state_t *state)
|
||||||
{
|
{
|
||||||
_change_tick_freq(1, state);
|
|
||||||
state->current_page = 0;
|
state->current_page = 0;
|
||||||
|
|
||||||
/* Init fresh deadline to next day */
|
/* Init fresh deadline to next day */
|
||||||
if (state->deadlines[state->current_index] == 0) {
|
if (state->deadlines[state->current_index] == 0) {
|
||||||
_reset_deadline(settings, state);
|
_reset_deadline(settings, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ensure 1Hz updates only */
|
||||||
|
_change_tick_freq(1, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop of setting mode */
|
/* Loop of setting mode */
|
||||||
@ -517,20 +534,30 @@ static bool _setting_loop(movement_event_t event, movement_settings_t *settings,
|
|||||||
break;
|
break;
|
||||||
case EVENT_TIMEOUT:
|
case EVENT_TIMEOUT:
|
||||||
_beep_button(settings);
|
_beep_button(settings);
|
||||||
_schedule_alarm(settings, state);
|
|
||||||
_change_tick_freq(1, state);
|
_change_tick_freq(1, state);
|
||||||
|
|
||||||
|
/* Update alarm as deadlines may have changed */
|
||||||
|
if (state->alarm_enabled) {
|
||||||
|
_schedule_alarm(settings, state);
|
||||||
|
}
|
||||||
movement_move_to_face(0);
|
movement_move_to_face(0);
|
||||||
break;
|
break;
|
||||||
case EVENT_MODE_BUTTON_UP:
|
case EVENT_MODE_BUTTON_UP:
|
||||||
_beep_disable(settings);
|
_beep_disable(settings);
|
||||||
_schedule_alarm(settings, state);
|
|
||||||
_running_init(settings, state);
|
_running_init(settings, state);
|
||||||
|
_running_display(event, settings, state);
|
||||||
|
|
||||||
|
/* Update alarm as deadlines may have changed */
|
||||||
|
if (state->alarm_enabled) {
|
||||||
|
_schedule_alarm(settings, state);
|
||||||
|
}
|
||||||
state->mode = DEADLINE_FACE_RUNNING;
|
state->mode = DEADLINE_FACE_RUNNING;
|
||||||
break;
|
break;
|
||||||
case EVENT_BACKGROUND_TASK:
|
case EVENT_BACKGROUND_TASK:
|
||||||
if (state->alarm_enabled)
|
if (state->alarm_enabled) {
|
||||||
movement_play_alarm();
|
movement_play_alarm();
|
||||||
_schedule_alarm(settings, state);
|
_schedule_alarm(settings, state);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return movement_default_loop_handler(event, settings);
|
return movement_default_loop_handler(event, settings);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 Konrad Rieck
|
* Copyright (c) 2023-2024 Konrad Rieck
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the
|
* copy of this software and associated documentation files (the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user