summaryrefslogtreecommitdiffstats
path: root/Sensor Watch Starter Project
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2021-08-03 18:00:07 -0400
committerJoey Castillo <jose.castillo@gmail.com>2021-08-03 18:09:58 -0400
commitfc31739eb6fdf230a26930e8d42de7a26558aeae (patch)
treedcd629420799cba11304d0d4184f15c5f12f3e6e /Sensor Watch Starter Project
parent8a06636833e007675c150532035588bc1bf7749a (diff)
downloadSensor-Watch-fc31739eb6fdf230a26930e8d42de7a26558aeae.tar.gz
Sensor-Watch-fc31739eb6fdf230a26930e8d42de7a26558aeae.tar.bz2
Sensor-Watch-fc31739eb6fdf230a26930e8d42de7a26558aeae.zip
WIP deep sleep mode
Diffstat (limited to 'Sensor Watch Starter Project')
-rw-r--r--Sensor Watch Starter Project/app.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/Sensor Watch Starter Project/app.c b/Sensor Watch Starter Project/app.c
index 4e44deb7..c3eddcbc 100644
--- a/Sensor Watch Starter Project/app.c
+++ b/Sensor Watch Starter Project/app.c
@@ -23,6 +23,7 @@ typedef struct ApplicationState {
LightColor color;
uint8_t wake_count;
bool debounce_wait;
+ bool enter_deep_sleep;
} ApplicationState;
ApplicationState application_state;
@@ -58,7 +59,10 @@ void app_init() {
* @see watch_enter_deep_sleep()
*/
void app_wake_from_deep_sleep() {
- // TODO: deep sleep demo
+ // retrieve our application state from the backup registers
+ application_state.mode = (ApplicationMode)watch_get_backup_data(0);
+ application_state.color = (LightColor)watch_get_backup_data(1);
+ application_state.wake_count = (uint8_t)watch_get_backup_data(2) + 1;
}
/**
@@ -141,6 +145,24 @@ bool app_loop() {
// Wait a moment to debounce button input
delay_ms(250);
+ if (application_state.enter_deep_sleep) {
+ application_state.enter_deep_sleep = false;
+
+ // stash our application state in the backup registers
+ watch_store_backup_data((uint32_t)application_state.mode, 0);
+ watch_store_backup_data((uint32_t)application_state.color, 1);
+ watch_store_backup_data((uint32_t)application_state.wake_count, 2);
+
+ // turn off the LED
+ watch_set_led_off();
+
+ // wait a moment for the user's finger to be off the button
+ delay_ms(1000);
+
+ // nap time :)
+ watch_enter_deep_sleep();
+ }
+
return true;
}
@@ -161,5 +183,7 @@ void cb_mode_pressed() {
}
void cb_alarm_pressed() {
- // TODO: deep sleep demo
-} \ No newline at end of file
+ if (application_state.debounce_wait) return;
+ application_state.debounce_wait = true;
+ application_state.enter_deep_sleep = true;
+}