caa4235c75
Sliders only support ranges from min to max but the slider visual and the setting to the IMU are reversed. At the IMU we therefore store 0x7F, which is the maximum possible value, minus the slider value: 0x7F-0x3A = 0x45. So if the minimum IMU value is practically 0x40, the maximum slider value shuld be 0x3F. We use a non signed variable so we only need to do a sanitycheck on the maximum slider value of 0x3F.
60 lines
2 KiB
C++
60 lines
2 KiB
C++
#include <Preferences.h>
|
|
#include "sleep_hal_esp32.h"
|
|
#include "tft_hal_esp32.h"
|
|
|
|
Preferences preferences;
|
|
|
|
std::string currentScene;
|
|
std::string currentGUIname;
|
|
|
|
void init_preferences_HAL(void) {
|
|
// Restore settings from internal flash memory
|
|
preferences.begin("settings", false);
|
|
if (preferences.getBool("alreadySetUp")) {
|
|
// from sleep.h
|
|
set_wakeupByIMUEnabled_HAL(preferences.getBool("wkpByIMU"));
|
|
set_sleepTimeout_HAL(preferences.getUInt("slpTimeout"));
|
|
// from tft.h
|
|
set_backlightBrightness_HAL(preferences.getUChar("blBrightness"));
|
|
// from here
|
|
currentScene = std::string(preferences.getString("currentScene").c_str());
|
|
currentGUIname = std::string(preferences.getString("currentGUIname").c_str());
|
|
set_wakeupByIMUthreshold_HAL(preferences.getUChar("threshold", 0x3A));
|
|
|
|
// Serial.printf("Preferences restored: brightness %d, GUI %s, scene %s\r\n", get_backlightBrightness_HAL(), get_currentGUIname().c_str(), get_currentScene().c_str());
|
|
} else {
|
|
// Serial.printf("No preferences to restore\r\n");
|
|
}
|
|
preferences.end();
|
|
}
|
|
|
|
void save_preferences_HAL(void) {
|
|
preferences.begin("settings", false);
|
|
// from sleep.h
|
|
preferences.putBool("wkpByIMU", get_wakeupByIMUEnabled_HAL());
|
|
// from tft.h
|
|
preferences.putUInt("slpTimeout", get_sleepTimeout_HAL());
|
|
preferences.putUChar("blBrightness", get_backlightBrightness_HAL());
|
|
// from here
|
|
preferences.putString("currentScene", currentScene.c_str());
|
|
preferences.putString("currentGUIname", currentGUIname.c_str());
|
|
preferences.putUChar("threshold", get_wakeupByIMUthreshold_HAL());
|
|
|
|
if (!preferences.getBool("alreadySetUp")) {
|
|
preferences.putBool("alreadySetUp", true);
|
|
}
|
|
preferences.end();
|
|
}
|
|
|
|
std::string get_currentScene_HAL() {
|
|
return currentScene;
|
|
}
|
|
void set_currentScene_HAL(std::string aCurrentScene) {
|
|
currentScene = aCurrentScene;
|
|
}
|
|
std::string get_currentGUIname_HAL(){
|
|
return currentGUIname;
|
|
}
|
|
void set_currentGUIname_HAL(std::string aCurrentGUIname) {
|
|
currentGUIname = aCurrentGUIname;
|
|
}
|