save prefs directly after timeout is changed
This commit is contained in:
parent
eef110f733
commit
6dbf80c09a
4 changed files with 22 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
#include "preferences_storage.h"
|
||||||
#include "hardware/tft.h"
|
#include "hardware/tft.h"
|
||||||
#include "hardware/sleep.h"
|
#include "hardware/sleep.h"
|
||||||
#include "gui_general_and_keys/guiBase.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);
|
// Serial.printf("New timeout: %lu ms\r\n", actualSleepTimeout);
|
||||||
resetStandbyTimer();
|
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) {
|
void init_gui_tab_settings(lv_obj_t* tabview) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "gui_general_and_keys/keys.h"
|
#include "gui_general_and_keys/keys.h"
|
||||||
#include "preferences_storage.h"
|
#include "preferences_storage.h"
|
||||||
#include "commandHandler.h"
|
#include "commandHandler.h"
|
||||||
|
#include "scenes/sceneHandler.h"
|
||||||
|
|
||||||
int motion = 0;
|
int motion = 0;
|
||||||
uint32_t actualSleepTimeout;
|
uint32_t actualSleepTimeout;
|
||||||
|
@ -99,14 +100,7 @@ void configIMUInterrupts()
|
||||||
// Enter Sleep Mode
|
// Enter Sleep Mode
|
||||||
void enterSleep(){
|
void enterSleep(){
|
||||||
// Save settings to internal flash memory
|
// Save settings to internal flash memory
|
||||||
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
|
save_preferences();
|
||||||
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();
|
|
||||||
|
|
||||||
// Configure IMU
|
// Configure IMU
|
||||||
uint8_t intDataRead;
|
uint8_t intDataRead;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "hardware/tft.h"
|
#include "hardware/tft.h"
|
||||||
#include "gui_general_and_keys/guiBase.h"
|
#include "gui_general_and_keys/guiBase.h"
|
||||||
#include "commandHandler.h"
|
#include "commandHandler.h"
|
||||||
|
#include "scenes/sceneHandler.h"
|
||||||
|
|
||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
|
|
||||||
|
@ -14,11 +15,23 @@ void init_preferences(void) {
|
||||||
actualSleepTimeout = preferences.getUInt("slpTimeout");
|
actualSleepTimeout = preferences.getUInt("slpTimeout");
|
||||||
backlight_brightness = preferences.getUChar("blBrightness");
|
backlight_brightness = preferences.getUChar("blBrightness");
|
||||||
currentScreen = preferences.getUChar("currentScreen");
|
currentScreen = preferences.getUChar("currentScreen");
|
||||||
allDevsPowered = preferences.getUChar("allDevsPowered");
|
currentScene = std::string(preferences.getString("currentScene").c_str());
|
||||||
currentScene = preferences.getString("currentScene");
|
|
||||||
|
|
||||||
// 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 {
|
} else {
|
||||||
// Serial.printf("No preferences to restore\r\n");
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,6 @@
|
||||||
extern Preferences preferences;
|
extern Preferences preferences;
|
||||||
|
|
||||||
void init_preferences(void);
|
void init_preferences(void);
|
||||||
|
void save_preferences(void);
|
||||||
|
|
||||||
#endif /*__PREFERENCES_STORAGE_H__*/
|
#endif /*__PREFERENCES_STORAGE_H__*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue