]> git.earman.xyz Git - sensor-watch.git/commitdiff
movement: store settings in BKUP to persist across resets
authorJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:38:17 +0000 (10:38 -0500)
committerJoey Castillo <joeycastillo@utexas.edu>
Thu, 25 Nov 2021 15:39:09 +0000 (10:39 -0500)
movement/movement.c
movement/movement.h
movement/watch_faces/settings/preferences_face.c
movement/watch_faces/settings/set_time_face.c

index 1a31175a677ba16886b632c540cd7a68a467ad94..128011b98afbb72b02e8a3b7b727df4b294cb71b 100644 (file)
@@ -114,10 +114,12 @@ void app_init() {
 }
 
 void app_wake_from_backup() {
-    // This app does not support BACKUP mode.
+    movement_state.settings.reg = watch_get_backup_data(0);
 }
 
 void app_setup() {
+    watch_store_backup_data(movement_state.settings.reg, 0);
+
     static bool is_first_launch = true;
 
     if (is_first_launch) {
index 4e791fca93fa3b59ab7cdae4d0ca296dacfb1303..0379fe7b6fedd5370cd3d8e9ce027ac4a8844af7 100644 (file)
 //   stored in BKUP[1] and BKUP[2], respectively.
 // * The movement_reserved_t type is here as a placeholder, because I sense there's some other generally useful
 //   stuff we'll want to make available to all watch faces and stash in the BKUP[3] register.
-// Anyway: Eventually, if Movement supports the BACKUP sleep mode, this will allow these preferences to be stored
-// before entering BACKUP mode and and restored after waking from reset.
+// This allows these preferences to be stored before entering BACKUP mode and and restored after waking from reset.
 
 // movement_settings_t contains global settings that cover watch behavior, including preferences around clock and unit
-// display, time zones, buzzer behavior, LED color and low energy mode timeouts.
-// Eventually it will be stored in BKUP[0] when Movement enters BACKUP mode.
+// display, time zones, buzzer behavior, LED color and low energy mode timeouts. These settings are stored in BKUP[0].
+// If your watch face changes one of these settings, you should store your changes in either your loop or resign
+// function by calling `watch_store_backup_data(settings->reg, 0)`. Otherwise it may not persist after a reset event.
 typedef union {
     struct {
         bool button_should_sound : 1;       // if true, pressing a button emits a sound.
index afe71034ab1ee3ef1e795f644d3172bb643f4091..03a58834adfb481af5b531d4155035c8da5d323d 100644 (file)
@@ -165,4 +165,5 @@ void preferences_face_resign(movement_settings_t *settings, void *context) {
     (void) context;
     watch_set_led_off();
     movement_request_tick_frequency(1);
+    watch_store_backup_data(settings->reg, 0);
 }
index fd4142793ed6232001a81e090c1998efd1fa8fd4..0f5af31278159ba995073d0092e4cec281726abc 100644 (file)
@@ -123,4 +123,5 @@ void set_time_face_resign(movement_settings_t *settings, void *context) {
     (void) context;
     watch_set_led_off();
     movement_request_tick_frequency(1);
+    watch_store_backup_data(settings->reg, 0);
 }