f620255c41
- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>` - Changed default timezone to Europe/Amsterdam - Fix for logic bug in unPhone hardware - Fix for init/deinit in DRV2605 driver - Other fixes - Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#ifdef ESP_PLATFORM
|
|
#include <Tactility/file/PropertiesFile.h>
|
|
#include <Tactility/Logger.h>
|
|
#include <Tactility/service/development/DevelopmentSettings.h>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
namespace tt::service::development {
|
|
|
|
static const auto LOGGER = Logger("DevSettings");
|
|
|
|
constexpr auto* SETTINGS_FILE = "/data/settings/development.properties";
|
|
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
|
|
|
struct DevelopmentSettings {
|
|
bool enableOnBoot;
|
|
};
|
|
|
|
static bool load(DevelopmentSettings& settings) {
|
|
std::map<std::string, std::string> map;
|
|
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
|
return false;
|
|
}
|
|
|
|
if (!map.contains(SETTINGS_KEY_ENABLE_ON_BOOT)) {
|
|
return false;
|
|
}
|
|
|
|
auto enable_on_boot_string = map[SETTINGS_KEY_ENABLE_ON_BOOT];
|
|
settings.enableOnBoot = (enable_on_boot_string == "true");
|
|
return true;
|
|
}
|
|
|
|
static bool save(const DevelopmentSettings& settings) {
|
|
std::map<std::string, std::string> map;
|
|
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
|
|
return file::savePropertiesFile(SETTINGS_FILE, map);
|
|
}
|
|
|
|
void setEnableOnBoot(bool enable) {
|
|
DevelopmentSettings properties { .enableOnBoot = enable };
|
|
if (!save(properties)) {
|
|
LOGGER.error("Failed to save {}", SETTINGS_FILE);
|
|
}
|
|
}
|
|
|
|
bool shouldEnableOnBoot() {
|
|
DevelopmentSettings settings;
|
|
if (!load(settings)) {
|
|
return false;
|
|
}
|
|
return settings.enableOnBoot;
|
|
}
|
|
}
|
|
|
|
#endif // ESP_PLATFORM
|