Various fixes and improvements (#435)
- Fix for `sdkconfig` generation: the keys that contained the MCU type in its name weren't properly upper-cased. - Moved WiFi configuration property files to the user data path of the app instead of a fixed location. - Moved more properties from `device.py` to `sdkconfig/default.properties` - Fix for `device.cmake` device id parsing: separate basic property parsing from device id validation - Created internal `tt::service::wifi::findServiceContext()` - Changed Wi-Fi service id to lowercase (will change it for other services later)
This commit is contained in:
committed by
GitHub
parent
261796068e
commit
f48654d3dc
@@ -1,13 +1,14 @@
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/service/ServicePaths.h>
|
||||
#include <Tactility/service/wifi/WifiPrivate.h>
|
||||
|
||||
namespace tt::service::wifi::settings {
|
||||
|
||||
constexpr auto* TAG = "WifiSettings";
|
||||
constexpr auto* SETTINGS_FILE = "/data/settings/wifi.properties";
|
||||
constexpr auto* SETTINGS_KEY_ENABLE_ON_BOOT = "enableOnBoot";
|
||||
|
||||
struct WifiSettings {
|
||||
@@ -21,8 +22,14 @@ static WifiSettings cachedSettings {
|
||||
static bool cached = false;
|
||||
|
||||
static bool load(WifiSettings& settings) {
|
||||
auto service_context = findServiceContext();
|
||||
if (service_context == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
std::string settings_path = service_context->getPaths()->getUserDataPath("settings.properties");
|
||||
if (!file::loadPropertiesFile(settings_path, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,15 +43,20 @@ static bool load(WifiSettings& settings) {
|
||||
}
|
||||
|
||||
static bool save(const WifiSettings& settings) {
|
||||
auto service_context = findServiceContext();
|
||||
if (service_context == nullptr) {
|
||||
return false;
|
||||
}
|
||||
std::map<std::string, std::string> map;
|
||||
map[SETTINGS_KEY_ENABLE_ON_BOOT] = settings.enableOnBoot ? "true" : "false";
|
||||
return file::savePropertiesFile(SETTINGS_FILE, map);
|
||||
std::string settings_path = service_context->getPaths()->getUserDataPath("settings.properties");
|
||||
return file::savePropertiesFile(settings_path, map);
|
||||
}
|
||||
|
||||
WifiSettings getCachedOrLoad() {
|
||||
if (!cached) {
|
||||
if (!load(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to load %s", SETTINGS_FILE);
|
||||
TT_LOG_E(TAG, "Failed to load");
|
||||
} else {
|
||||
cached = true;
|
||||
}
|
||||
@@ -56,7 +68,7 @@ WifiSettings getCachedOrLoad() {
|
||||
void setEnableOnBoot(bool enable) {
|
||||
cachedSettings.enableOnBoot = enable;
|
||||
if (!save(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
|
||||
TT_LOG_E(TAG, "Failed to save");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user