save prefs directly after timeout is changed

This commit is contained in:
KlausMu 2024-01-29 10:32:54 +01:00
parent eef110f733
commit 6dbf80c09a
4 changed files with 22 additions and 11 deletions

View file

@ -1,4 +1,5 @@
#include <lvgl.h>
#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) {

View file

@ -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;

View file

@ -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();
}

View file

@ -6,5 +6,6 @@
extern Preferences preferences;
void init_preferences(void);
void save_preferences(void);
#endif /*__PREFERENCES_STORAGE_H__*/