]> git.earman.xyz Git - sensor-watch.git/commitdiff
use accelerometer to enter and exit low energy mode
authorjoeycastillo <joeycastillo@utexas.edu>
Tue, 19 Nov 2024 02:45:18 +0000 (21:45 -0500)
committerjoeycastillo <joeycastillo@utexas.edu>
Tue, 19 Nov 2024 02:48:10 +0000 (21:48 -0500)
movement.c
watch-faces/sensor/activity_logging_face.c

index 0d5f82fc42acdf444d518235aded6c0ce597b93c..6639e35985e131818ab4022f8cf6e8aa29c91f89 100644 (file)
@@ -159,8 +159,18 @@ static void _movement_handle_top_of_minute(void) {
     watch_date_time_t date_time = watch_rtc_get_date_time();
 
 #ifdef HAS_ACCELEROMETER
-    // every minute, we want to log whether the accelerometer is asleep or awake.
-    if (HAL_GPIO_A4_read()) stationary_minutes++;
+    if (stationary_minutes < 5) {
+        // if the watch has been stationary for fewer than 5 minutes, find out if it's still stationary.
+        if (HAL_GPIO_A4_read()) stationary_minutes++;
+        printf("Stationary minutes: %d\n", stationary_minutes);
+
+        // does this mark five stationary minutes? and are we not already asleep?
+        if (stationary_minutes == 5 && movement_state.le_mode_ticks != -1) {
+            // if so, enter low energy mode.
+            printf("Entering low energy mode due to inactivity.\n");
+            movement_request_sleep();
+        }
+    }
 #endif
 
     // update the DST offset cache every 30 minutes, since someplace in the world could change.
@@ -958,6 +968,8 @@ void cb_accelerometer_sleep_change(void) {
         event.event_type = EVENT_ACCELEROMETER_WAKE;
         // reset the stationary minutes counter; we're counting consecutive stationary minutes.
         stationary_minutes = 0;
+        // also: wake up!
+        _movement_reset_inactivity_countdown();
         printf("Wake on INT2\n");
     }
 }
index 812d6a677b580dade0453fb164511363b6df7d7f..b0a75a6ca16180c5a694def77e564d5379c885ca 100644 (file)
@@ -57,7 +57,6 @@ static void _activity_logging_face_log_data(activity_logging_state_t *state) {
     state->data[pos].reg = data_point.reg;
     state->data_points++;
 
-    stationary_minutes = 0;
     orientation_changes = 0;
 }