summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoeycastillo <joeycastillo@utexas.edu>2023-01-10 16:14:20 -0500
committerGitHub <noreply@github.com>2023-01-10 16:14:20 -0500
commit0aa77e27e4149fac6def8c8d86b00d9b47cf857a (patch)
tree1dfe40d7b6e1d00a047cdde68af6ff5e5128bc2c
parent6ee84e7d6bc5ca00e9ef081f0c7892dca0c9fd88 (diff)
parentc576f5332dabe09a1a84e38a085a310b28404199 (diff)
downloadSensor-Watch-0aa77e27e4149fac6def8c8d86b00d9b47cf857a.tar.gz
Sensor-Watch-0aa77e27e4149fac6def8c8d86b00d9b47cf857a.tar.bz2
Sensor-Watch-0aa77e27e4149fac6def8c8d86b00d9b47cf857a.zip
Merge pull request #119 from neutralinsomniac/add_hours_to_countdown_face
Add hours support to the countdown face
-rw-r--r--movement/watch_faces/complication/countdown_face.c30
-rw-r--r--movement/watch_faces/complication/countdown_face.h7
2 files changed, 25 insertions, 12 deletions
diff --git a/movement/watch_faces/complication/countdown_face.c b/movement/watch_faces/complication/countdown_face.c
index 92400e66..b2206b8f 100644
--- a/movement/watch_faces/complication/countdown_face.c
+++ b/movement/watch_faces/complication/countdown_face.c
@@ -31,7 +31,7 @@
#include "watch_utility.h"
-#define CD_SELECTIONS 2
+#define CD_SELECTIONS 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->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));
movement_schedule_background_task(target_dt);
watch_set_indicator(WATCH_INDICATOR_BELL);
@@ -55,28 +55,33 @@ static void draw(countdown_state_t *state, uint8_t subsecond) {
uint32_t delta;
div_t result;
- uint8_t min, sec;
+ uint8_t hour, min, sec;
switch (state->mode) {
case cd_running:
delta = state->target_ts - state->now_ts;
result = div(delta, 60);
- min = result.quot;
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;
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;
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) {
switch(state->selection) {
case 0:
- buf[6] = buf[7] = ' ';
+ buf[4] = buf[5] = ' ';
break;
case 1:
+ buf[6] = buf[7] = ' ';
+ break;
+ case 2:
buf[8] = buf[9] = ' ';
break;
default:
@@ -102,9 +107,12 @@ static void ring(countdown_state_t *state) {
static void settings_increment(countdown_state_t *state) {
switch(state->selection) {
case 0:
- state->minutes = (state->minutes + 1) % 100;
+ state->hours = (state->hours + 1) % 24;
break;
case 1:
+ state->minutes = (state->minutes + 1) % 60;
+ break;
+ case 2:
state->seconds = (state->seconds + 1) % 60;
break;
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));
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);
break;
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.
start(state, settings);
}
@@ -196,6 +205,7 @@ bool countdown_face_loop(movement_event_t event, movement_settings_t *settings,
break;
case EVENT_ALARM_LONG_PRESS:
if (state->mode == cd_setting) {
+ state->hours = 0;
state->minutes = 0;
state->seconds = 0;
draw(state, event.subsecond);
diff --git a/movement/watch_faces/complication/countdown_face.h b/movement/watch_faces/complication/countdown_face.h
index 657c6377..f6c845d6 100644
--- a/movement/watch_faces/complication/countdown_face.h
+++ b/movement/watch_faces/complication/countdown_face.h
@@ -32,8 +32,10 @@
/*
A countdown/timer face
-Max countdown is 99 minutes and 59 seconds since we have to prevent the watch
-from going to deep sleep using movement_schedule_background_task
+Max countdown is 23 hours, 59 minutes and 59 seconds.
+
+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 {
uint32_t target_ts;
uint32_t now_ts;
+ uint8_t hours;
uint8_t minutes;
uint8_t seconds;
uint8_t selection;