]> git.earman.xyz Git - sensor-watch.git/commitdiff
add timeout event to give faces a chance to resign
authorJoey Castillo <jose.castillo@gmail.com>
Mon, 18 Oct 2021 16:15:57 +0000 (12:15 -0400)
committerJoey Castillo <jose.castillo@gmail.com>
Mon, 18 Oct 2021 17:55:22 +0000 (13:55 -0400)
movement/movement.c
movement/movement.h
movement/watch_faces/clock/simple_clock_face.c
movement/watch_faces/complications/pulsometer_face.c
movement/watch_faces/settings/preferences_face.c
movement/watch_faces/settings/set_time_face.c

index d43285e18bc739ff60360b98bd9353398e72256b..6576bd75f27113859d80d6fa7739e6eecd345834 100644 (file)
@@ -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;
index 3f3f0365a4e2ab2177a7f9654de9050c78226c6e..d116a6e02eb62a3bce5da553e1e19816bd168ce9 100644 (file)
@@ -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;
index 351c7ebc1c687f1d75e87f0e0f8ddd1919bb10b4..95db3901e2203cebf319fdc5c188c6695a1ce3a4 100644 (file)
@@ -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);
index db5c5d0e1135b0f886626e4e401856904f0f6567..e54b45517f38d269af1f87d9eb31702328f43da4 100644 (file)
@@ -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;
     }
index c3b7663c8ba4664a9086374a32cede0bccb93a43..98a2372da27b224e30b3fee1440916dee2c204d6 100644 (file)
@@ -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;
     }
index 7bb63d0b8f3595d1e53ddaf175b32759318d602d..6b82c68b05c902e2771594a8b2dc02d470078a86 100644 (file)
@@ -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;
     }