summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-10-18 12:15:57 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-10-18 13:55:22 -0400
commit93624f0b692648eac415a3df5689de6dee06c2db (patch)
treee9f052d71ceed7e2a8a20c42a286e97968c7015e
parent8dbbe92a9bad950219c4bc1a46871f44dda5fef3 (diff)
downloadSensor-Watch-93624f0b692648eac415a3df5689de6dee06c2db.tar.gz
Sensor-Watch-93624f0b692648eac415a3df5689de6dee06c2db.tar.bz2
Sensor-Watch-93624f0b692648eac415a3df5689de6dee06c2db.zip
add timeout event to give faces a chance to resign
-rw-r--r--movement/movement.c15
-rw-r--r--movement/movement.h7
-rw-r--r--movement/watch_faces/clock/simple_clock_face.c2
-rw-r--r--movement/watch_faces/complications/pulsometer_face.c4
-rw-r--r--movement/watch_faces/settings/preferences_face.c4
-rw-r--r--movement/watch_faces/settings/set_time_face.c3
6 files changed, 28 insertions, 7 deletions
diff --git a/movement/movement.c b/movement/movement.c
index d43285e1..6576bd75 100644
--- a/movement/movement.c
+++ b/movement/movement.c
@@ -7,7 +7,8 @@
movement_state_t movement_state;
void * watch_face_contexts[MOVEMENT_NUM_FACES];
-const int32_t movement_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
+const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
+const int32_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800};
movement_event_t event;
void cb_mode_btn_interrupt();
@@ -18,8 +19,10 @@ void cb_alarm_fired();
void cb_tick();
static inline void _movement_reset_inactivity_countdown() {
- // for testing, make the timeout happen 60x faster.
- movement_state.le_mode_ticks = movement_inactivity_deadlines[movement_state.settings.bit.le_inactivity_interval] / 60;
+ // for testing, make the low energy timeout happen 60x faster.
+ movement_state.le_mode_ticks = movement_le_inactivity_deadlines[movement_state.settings.bit.le_inactivity_interval] / 60;
+ // for testing, make the inactivity timeout happen 4x faster.
+ movement_state.timeout_ticks = movement_timeout_inactivity_deadlines[movement_state.settings.bit.to_inactivity_interval] / 4;
}
void movement_request_tick_frequency(uint8_t freq) {
@@ -130,6 +133,11 @@ bool app_loop() {
}
}
+ // if we have timed out of our timeout countdown, give the app a hint that they can resign.
+ if (movement_state.timeout_ticks == 0) {
+ event.event_type = EVENT_TIMEOUT;
+ }
+
// if we have timed out of our low energy mode countdown, enter low energy mode.
if (movement_state.le_mode_ticks == 0) {
movement_state.le_mode_ticks = -1;
@@ -210,6 +218,7 @@ void cb_tick() {
if (date_time.unit.second != movement_state.last_second) {
if (movement_state.light_ticks) movement_state.light_ticks--;
if (movement_state.settings.bit.le_inactivity_interval && movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--;
+ if (movement_state.timeout_ticks > 0) movement_state.timeout_ticks--;
movement_state.last_second = date_time.unit.second;
movement_state.subsecond = 0;
diff --git a/movement/movement.h b/movement/movement.h
index 3f3f0365..d116a6e0 100644
--- a/movement/movement.h
+++ b/movement/movement.h
@@ -6,9 +6,10 @@
// TODO: none of this is implemented
typedef union {
struct {
- uint32_t reserved : 16;
+ uint32_t reserved : 14;
uint32_t clock_mode_24h : 1; // determines whether clock should use 12 or 24 hour mode.
uint32_t button_should_sound : 1; // if true, pressing a button emits a sound.
+ uint32_t to_inactivity_interval : 2;// an inactivity interval for asking the active face to resign.
uint32_t le_inactivity_interval : 3;// 0 to disable low energy mode, or an inactivity interval for going into low energy mode.
uint32_t led_duration : 3; // how many seconds to shine the LED for, or 0 to disable it.
uint32_t led_red_color : 4; // for general purpose illumination, the red LED value (0-15)
@@ -23,6 +24,7 @@ typedef enum {
EVENT_TICK, // Most common event type. Your watch face is being called from the tick callback.
EVENT_LOW_ENERGY_UPDATE, // If the watch is in low energy mode and you are in the foreground, you will get a chance to update the display once per minute.
EVENT_BACKGROUND_TASK, // Your watch face is being invoked to perform a background task. Don't update the display here; you may not be in the foreground.
+ EVENT_TIMEOUT, // Your watch face has been inactive for a while. You may want to resign, depending on your watch face's intended use case.
EVENT_LIGHT_BUTTON_DOWN, // The light button has been pressed, but not yet released.
EVENT_LIGHT_BUTTON_UP, // The light button was pressed and released.
EVENT_LIGHT_LONG_PRESS, // The light button was held for >2 seconds, and released.
@@ -162,6 +164,9 @@ typedef struct {
// low energy mode countdown
int32_t le_mode_ticks;
+ // app resignation countdown (TODO: consolidate with LE countdown?)
+ int16_t timeout_ticks;
+
// stuff for subsecond tracking
uint8_t tick_frequency;
uint8_t last_second;
diff --git a/movement/watch_faces/clock/simple_clock_face.c b/movement/watch_faces/clock/simple_clock_face.c
index 351c7ebc..95db3901 100644
--- a/movement/watch_faces/clock/simple_clock_face.c
+++ b/movement/watch_faces/clock/simple_clock_face.c
@@ -18,7 +18,6 @@ void simple_clock_face_activate(movement_settings_t *settings, void *context) {
}
bool simple_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
- printf("simple_clock_face_loop\n");
const char weekdays[7][3] = {"SA", "SU", "MO", "TU", "WE", "TH", "FR"};
char buf[11];
uint8_t pos;
@@ -28,6 +27,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
switch (event.event_type) {
case EVENT_ACTIVATE:
case EVENT_TICK:
+ case EVENT_TIMEOUT:
case EVENT_LOW_ENERGY_UPDATE:
date_time = watch_rtc_get_date_time();
previous_date_time = *((uint32_t *)context);
diff --git a/movement/watch_faces/complications/pulsometer_face.c b/movement/watch_faces/complications/pulsometer_face.c
index db5c5d0e..e54b4551 100644
--- a/movement/watch_faces/complications/pulsometer_face.c
+++ b/movement/watch_faces/complications/pulsometer_face.c
@@ -17,7 +17,6 @@ void pulsometer_face_activate(movement_settings_t *settings, void *context) {
}
bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
- printf("pulsometer_face_loop\n");
(void) settings;
pulsometer_state_t *pulsometer_state = (pulsometer_state_t *)context;
char buf[14];
@@ -74,6 +73,9 @@ bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings,
pulsometer_state->measuring = false;
movement_request_tick_frequency(1);
break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
default:
break;
}
diff --git a/movement/watch_faces/settings/preferences_face.c b/movement/watch_faces/settings/preferences_face.c
index c3b7663c..98a2372d 100644
--- a/movement/watch_faces/settings/preferences_face.c
+++ b/movement/watch_faces/settings/preferences_face.c
@@ -17,7 +17,6 @@ void preferences_face_activate(movement_settings_t *settings, void *context) {
}
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
- printf("preferences_face_loop\n");
uint8_t current_page = *((uint8_t *)context);
switch (event.event_type) {
case EVENT_MODE_BUTTON_UP:
@@ -47,6 +46,9 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
break;
}
break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
default:
break;
}
diff --git a/movement/watch_faces/settings/set_time_face.c b/movement/watch_faces/settings/set_time_face.c
index 7bb63d0b..6b82c68b 100644
--- a/movement/watch_faces/settings/set_time_face.c
+++ b/movement/watch_faces/settings/set_time_face.c
@@ -58,6 +58,9 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
}
watch_rtc_set_date_time(date_time);
break;
+ case EVENT_TIMEOUT:
+ movement_move_to_face(0);
+ break;
default:
break;
}