Merge develop into main (#313)
- Add app path get() functions to `TactilityC` - Improved `Dispatcher` and `DispatcherThread` - Improved `PubSub` (type safety) - Created test for `DispatcherThread` and `PubSub` - Save properties files on app exit (various apps) by posting it to the main dispatcher (fixes UI hanging briefly on app exit) - Fixed bug with `SystemSettings` being read from the wrong file path. - `loadPropertiesFile()` now uses `file::readLines()` instead of doing that manually - Increased timer task stack size (required due to issues when reading a properties file for the very first time) - General cleanup - Created `EstimatedPower` driver that uses an ADC pin to measure voltage and estimate the battery charge that is left. - Cleanup of T-Deck board (updated to new style)
This commit is contained in:
committed by
GitHub
parent
5cc5b50694
commit
0f8380e8fe
@@ -1,9 +1,8 @@
|
||||
#include "Tactility/service/wifi/WifiSettings.h"
|
||||
#include "Tactility/Preferences.h"
|
||||
#include "Tactility/file/PropertiesFile.h"
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
namespace tt::service::wifi::settings {
|
||||
|
||||
@@ -15,6 +14,12 @@ struct WifiSettings {
|
||||
bool enableOnBoot;
|
||||
};
|
||||
|
||||
static WifiSettings cachedSettings {
|
||||
.enableOnBoot = false
|
||||
};
|
||||
|
||||
static bool cached = false;
|
||||
|
||||
static bool load(WifiSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
@@ -36,19 +41,27 @@ static bool save(const WifiSettings& settings) {
|
||||
return file::savePropertiesFile(SETTINGS_FILE, map);
|
||||
}
|
||||
|
||||
WifiSettings getCachedOrLoad() {
|
||||
if (!cached) {
|
||||
if (!load(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to load %s", SETTINGS_FILE);
|
||||
} else {
|
||||
cached = true;
|
||||
}
|
||||
}
|
||||
|
||||
return cachedSettings;
|
||||
}
|
||||
|
||||
void setEnableOnBoot(bool enable) {
|
||||
WifiSettings settings { .enableOnBoot = enable };
|
||||
if (!save(settings)) {
|
||||
cachedSettings.enableOnBoot = enable;
|
||||
if (!save(cachedSettings)) {
|
||||
TT_LOG_E(TAG, "Failed to save %s", SETTINGS_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
bool shouldEnableOnBoot() {
|
||||
WifiSettings settings;
|
||||
if (!load(settings)) {
|
||||
return false;
|
||||
}
|
||||
return settings.enableOnBoot;
|
||||
return getCachedOrLoad().enableOnBoot;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user