]> git.earman.xyz Git - sensor-watch.git/commitdiff
activity logging: try to ignore spurious active minutes
authorJoey Castillo <joeycastillo@utexas.edu>
Tue, 20 May 2025 21:34:45 +0000 (17:34 -0400)
committerJoey Castillo <joeycastillo@utexas.edu>
Tue, 20 May 2025 21:34:45 +0000 (17:34 -0400)
watch-faces/sensor/activity_logging_face.c
watch-faces/sensor/activity_logging_face.h

index d73f3e4626cb5149c3a0f4ef866a32fbc2ca0b3b..1fdfd9b4f1429d30bee3b638a7c95ca303f5ff94 100644 (file)
@@ -135,7 +135,14 @@ movement_watch_face_advisory_t activity_logging_face_advise(void *context) {
     activity_logging_state_t *state = (activity_logging_state_t *)context;
     movement_watch_face_advisory_t retval = { 0 };
 
-    if (!HAL_GPIO_A4_read()) state->active_minutes_today++;
+    if (!HAL_GPIO_A4_read()) {
+        // only count this as an active minute if the previous minute was also active.
+        // otherwise, set the flag and we'll count the next minute if the wearer is still active.
+        if (state->previous_minute_was_active) state->active_minutes_today++;
+        else state->previous_minute_was_active = true;
+    } else {
+        state->previous_minute_was_active = false;
+    }
 
     watch_date_time_t datetime = movement_get_local_date_time();
     // request a background task at midnight to shuffle the data into the log
index 8deea66663ec11c4f19eed09a0bad4b26a5f7426..6c5b74fb328e5cda485ea74e1e6aa07d7ad4b1fc 100644 (file)
@@ -53,6 +53,7 @@ typedef struct {
     uint16_t data_points;                               // the number of days logged
     uint8_t display_index;                              // the index we are displaying on screen
     uint16_t active_minutes_today;                      // the number of active minutes logged today
+    bool previous_minute_was_active;                    // we only want to count two or more consecutive active minutes
 } activity_logging_state_t;
 
 void activity_logging_face_setup(uint8_t watch_face_index, void ** context_ptr);