diff --git a/Platformio/src/gui_general_and_keys/gui_settings.cpp b/Platformio/src/gui_general_and_keys/gui_settings.cpp index cdbace1..cd2f50d 100644 --- a/Platformio/src/gui_general_and_keys/gui_settings.cpp +++ b/Platformio/src/gui_general_and_keys/gui_settings.cpp @@ -1,4 +1,5 @@ #include +#include "preferences_storage.h" #include "hardware/tft.h" #include "hardware/sleep.h" #include "gui_general_and_keys/guiBase.h" @@ -34,6 +35,8 @@ static void timout_event_cb(lv_event_t * e){ } // Serial.printf("New timeout: %lu ms\r\n", actualSleepTimeout); resetStandbyTimer(); + // save preferences now, otherwise if you set a very big timeout and upload your firmware again, it never got saved + save_preferences(); } void init_gui_tab_settings(lv_obj_t* tabview) { diff --git a/Platformio/src/hardware/sleep.cpp b/Platformio/src/hardware/sleep.cpp index b68c428..32335ac 100644 --- a/Platformio/src/hardware/sleep.cpp +++ b/Platformio/src/hardware/sleep.cpp @@ -10,6 +10,7 @@ #include "gui_general_and_keys/keys.h" #include "preferences_storage.h" #include "commandHandler.h" +#include "scenes/sceneHandler.h" int motion = 0; uint32_t actualSleepTimeout; @@ -99,14 +100,7 @@ void configIMUInterrupts() // Enter Sleep Mode void enterSleep(){ // Save settings to internal flash memory - preferences.putBool("wkpByIMU", wakeupByIMUEnabled); - preferences.putUInt("slpTimeout", actualSleepTimeout); - preferences.putUChar("blBrightness", backlight_brightness); - preferences.putUChar("currentScreen", currentScreen); - preferences.putUChar("allDevsPowered", allDevsPowered); - preferences.putString("currentScene", currentScene); - if(!preferences.getBool("alreadySetUp")) preferences.putBool("alreadySetUp", true); - preferences.end(); + save_preferences(); // Configure IMU uint8_t intDataRead; diff --git a/Platformio/src/preferences_storage.cpp b/Platformio/src/preferences_storage.cpp index 74c6313..38f8b32 100644 --- a/Platformio/src/preferences_storage.cpp +++ b/Platformio/src/preferences_storage.cpp @@ -3,6 +3,7 @@ #include "hardware/tft.h" #include "gui_general_and_keys/guiBase.h" #include "commandHandler.h" +#include "scenes/sceneHandler.h" Preferences preferences; @@ -14,11 +15,23 @@ void init_preferences(void) { actualSleepTimeout = preferences.getUInt("slpTimeout"); backlight_brightness = preferences.getUChar("blBrightness"); currentScreen = preferences.getUChar("currentScreen"); - allDevsPowered = preferences.getUChar("allDevsPowered"); - currentScene = preferences.getString("currentScene"); + currentScene = std::string(preferences.getString("currentScene").c_str()); - // Serial.printf("Preferences restored: brightness %d, screen %d, allDevPowered %d, scene %s\r\n", backlight_brightness, currentScreen, allDevsPowered, currentScene.c_str()); + // Serial.printf("Preferences restored: brightness %d, screen %d, scene %s\r\n", backlight_brightness, currentScreen, currentScene.c_str()); } else { // Serial.printf("No preferences to restore\r\n"); } + preferences.end(); } + +void save_preferences(void) { + preferences.begin("settings", false); + preferences.putBool("wkpByIMU", wakeupByIMUEnabled); + preferences.putUInt("slpTimeout", actualSleepTimeout); + preferences.putUChar("blBrightness", backlight_brightness); + preferences.putUChar("currentScreen", currentScreen); + preferences.putString("currentScene", currentScene.c_str()); + if(!preferences.getBool("alreadySetUp")) preferences.putBool("alreadySetUp", true); + preferences.end(); +} + diff --git a/Platformio/src/preferences_storage.h b/Platformio/src/preferences_storage.h index a499666..d4fd8fb 100644 --- a/Platformio/src/preferences_storage.h +++ b/Platformio/src/preferences_storage.h @@ -6,5 +6,6 @@ extern Preferences preferences; void init_preferences(void); +void save_preferences(void); #endif /*__PREFERENCES_STORAGE_H__*/