Merge pull request #119 from neutralinsomniac/add_hours_to_countdown_face

Add hours support to the countdown face
This commit is contained in:
joeycastillo 2023-01-10 16:14:20 -05:00 committed by GitHub
commit 0aa77e27e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 12 deletions

View File

@ -31,7 +31,7 @@
#include "watch_utility.h" #include "watch_utility.h"
#define CD_SELECTIONS 2 #define CD_SELECTIONS 3
#define DEFAULT_MINUTES 3 #define DEFAULT_MINUTES 3
@ -44,7 +44,7 @@ static void start(countdown_state_t *state, movement_settings_t *settings) {
state->mode = cd_running; state->mode = cd_running;
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
state->target_ts = watch_utility_offset_timestamp(state->now_ts, 0, state->minutes, state->seconds); state->target_ts = watch_utility_offset_timestamp(state->now_ts, state->hours, state->minutes, state->seconds);
watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings)); watch_date_time target_dt = watch_utility_date_time_from_unix_time(state->target_ts, get_tz_offset(settings));
movement_schedule_background_task(target_dt); movement_schedule_background_task(target_dt);
watch_set_indicator(WATCH_INDICATOR_BELL); watch_set_indicator(WATCH_INDICATOR_BELL);
@ -55,28 +55,33 @@ static void draw(countdown_state_t *state, uint8_t subsecond) {
uint32_t delta; uint32_t delta;
div_t result; div_t result;
uint8_t min, sec; uint8_t hour, min, sec;
switch (state->mode) { switch (state->mode) {
case cd_running: case cd_running:
delta = state->target_ts - state->now_ts; delta = state->target_ts - state->now_ts;
result = div(delta, 60); result = div(delta, 60);
min = result.quot;
sec = result.rem; sec = result.rem;
result = div(result.quot, 60);
hour = result.quot;
min = result.rem;
sprintf(buf, "CD %2d%02d", min, sec); sprintf(buf, "CD %2d%02d%02d", hour, min, sec);
break; break;
case cd_waiting: case cd_waiting:
sprintf(buf, "CD %2d%02d", state->minutes, state->seconds); sprintf(buf, "CD %2d%02d%02d", state->hours, state->minutes, state->seconds);
break; break;
case cd_setting: case cd_setting:
sprintf(buf, "CD %2d%02d", state->minutes, state->seconds); sprintf(buf, "CD %2d%02d%02d", state->hours, state->minutes, state->seconds);
if (subsecond % 2) { if (subsecond % 2) {
switch(state->selection) { switch(state->selection) {
case 0: case 0:
buf[6] = buf[7] = ' '; buf[4] = buf[5] = ' ';
break; break;
case 1: case 1:
buf[6] = buf[7] = ' ';
break;
case 2:
buf[8] = buf[9] = ' '; buf[8] = buf[9] = ' ';
break; break;
default: default:
@ -102,9 +107,12 @@ static void ring(countdown_state_t *state) {
static void settings_increment(countdown_state_t *state) { static void settings_increment(countdown_state_t *state) {
switch(state->selection) { switch(state->selection) {
case 0: case 0:
state->minutes = (state->minutes + 1) % 100; state->hours = (state->hours + 1) % 24;
break; break;
case 1: case 1:
state->minutes = (state->minutes + 1) % 60;
break;
case 2:
state->seconds = (state->seconds + 1) % 60; state->seconds = (state->seconds + 1) % 60;
break; break;
default: default:
@ -134,6 +142,7 @@ void countdown_face_activate(movement_settings_t *settings, void *context) {
state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings)); state->now_ts = watch_utility_date_time_to_unix_time(now, get_tz_offset(settings));
watch_set_indicator(WATCH_INDICATOR_BELL); watch_set_indicator(WATCH_INDICATOR_BELL);
} }
watch_set_colon();
} }
@ -180,7 +189,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings,
reset(state); reset(state);
break; break;
case cd_waiting: case cd_waiting:
if (!(state->minutes == 0 && state->seconds == 0)) { if (!(state->hours == 0 && state->minutes == 0 && state->seconds == 0)) {
// Only start the timer if we have a valid time. // Only start the timer if we have a valid time.
start(state, settings); start(state, settings);
} }
@ -196,6 +205,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings,
break; break;
case EVENT_ALARM_LONG_PRESS: case EVENT_ALARM_LONG_PRESS:
if (state->mode == cd_setting) { if (state->mode == cd_setting) {
state->hours = 0;
state->minutes = 0; state->minutes = 0;
state->seconds = 0; state->seconds = 0;
draw(state, event.subsecond); draw(state, event.subsecond);

View File

@ -32,8 +32,10 @@
/* /*
A countdown/timer face A countdown/timer face
Max countdown is 99 minutes and 59 seconds since we have to prevent the watch Max countdown is 23 hours, 59 minutes and 59 seconds.
from going to deep sleep using movement_schedule_background_task
Note: we have to prevent the watch from going to deep sleep using
movement_schedule_background_task() while the timer is running.
*/ */
@ -46,6 +48,7 @@ typedef enum {
typedef struct { typedef struct {
uint32_t target_ts; uint32_t target_ts;
uint32_t now_ts; uint32_t now_ts;
uint8_t hours;
uint8_t minutes; uint8_t minutes;
uint8_t seconds; uint8_t seconds;
uint8_t selection; uint8_t selection;