Merge develop into main (#312)
- Move various settings to `/data/settings` and `/sdcard/settings` - Fix for `Gui` and `Statusbar` errors on startup (LVGL start) - Implement Development service settings as properties file - Rename `service::findManifestId()` to `service::findManifestById()` - Renamed various classes like `BootProperties` to `BootSettings` - Renamed `settings.properties` to `system.properties`. Code was moved to `settings` namespace/folder - `DevelopmentSettings` is now in `settings` namespace/folder (moved from service)
This commit is contained in:
committed by
GitHub
parent
5dfc6d70da
commit
5cc5b50694
@@ -0,0 +1,46 @@
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/hal/sdcard/SdCardDevice.h>
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/settings/BootSettings.h>
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tt::settings {
|
||||
|
||||
constexpr auto* TAG = "BootProperties";
|
||||
constexpr auto* PROPERTIES_FILE_FORMAT = "{}/settings/boot.properties";
|
||||
constexpr auto* PROPERTIES_KEY_LAUNCHER_APP_ID = "launcherAppId";
|
||||
constexpr auto* PROPERTIES_KEY_AUTO_START_APP_ID = "autoStartAppId";
|
||||
|
||||
static std::string getPropertiesFilePath() {
|
||||
const auto sdcards = hal::findDevices<hal::sdcard::SdCardDevice>(hal::Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
std::string path = std::format(PROPERTIES_FILE_FORMAT, sdcard->getMountPath());
|
||||
if (file::isFile(path)) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
return std::format(PROPERTIES_FILE_FORMAT, file::MOUNT_POINT_DATA);
|
||||
}
|
||||
|
||||
bool loadBootSettings(BootSettings& properties) {
|
||||
const std::string path = getPropertiesFilePath();
|
||||
if (!file::loadPropertiesFile(path, [&properties](auto& key, auto& value) {
|
||||
if (key == PROPERTIES_KEY_AUTO_START_APP_ID) {
|
||||
properties.autoStartAppId = value;
|
||||
} else if (key == PROPERTIES_KEY_LAUNCHER_APP_ID) {
|
||||
properties.launcherAppId = value;
|
||||
}
|
||||
})) {
|
||||
TT_LOG_E(TAG, "Failed to load %s", path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return !properties.launcherAppId.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/hal/Device.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace tt::settings::display {
|
||||
|
||||
constexpr auto* TAG = "DisplaySettings";
|
||||
constexpr auto* SETTINGS_FILE = "/data/settings/display.properties";
|
||||
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
|
||||
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
|
||||
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
||||
|
||||
static Orientation getDefaultOrientation() {
|
||||
auto* display = lv_display_get_default();
|
||||
if (display == nullptr) {
|
||||
return Orientation::Landscape;
|
||||
}
|
||||
|
||||
if (lv_display_get_physical_horizontal_resolution(display) > lv_display_get_physical_vertical_resolution(display)) {
|
||||
return Orientation::Landscape;
|
||||
} else {
|
||||
return Orientation::Portrait;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string toString(Orientation orientation) {
|
||||
switch (orientation) {
|
||||
using enum Orientation;
|
||||
case Portrait:
|
||||
return "Portrait";
|
||||
case Landscape:
|
||||
return "Landscape";
|
||||
case PortraitFlipped:
|
||||
return "PortraitFlipped";
|
||||
case LandscapeFlipped:
|
||||
return "LandscapeFlipped";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static bool fromString(const std::string& str, Orientation& orientation) {
|
||||
if (str == "Portrait") {
|
||||
orientation = Orientation::Portrait;
|
||||
return true;
|
||||
} else if (str == "Landscape") {
|
||||
orientation = Orientation::Landscape;
|
||||
return true;
|
||||
} else if (str == "PortraitFlipped") {
|
||||
orientation = Orientation::PortraitFlipped;
|
||||
return true;
|
||||
} else if (str == "LandscapeFlipped") {
|
||||
orientation = Orientation::LandscapeFlipped;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool load(DisplaySettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(SETTINGS_FILE, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto orientation_entry = map.find(SETTINGS_KEY_ORIENTATION);
|
||||
Orientation orientation;
|
||||
if (orientation_entry == map.end() || !fromString(orientation_entry->second, orientation)) {
|
||||
orientation = getDefaultOrientation();
|
||||
}
|
||||
|
||||
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
|
||||
int gamma_curve = 0;
|
||||
if (gamma_entry != map.end()) {
|
||||
gamma_curve = atoi(gamma_entry->second.c_str());
|
||||
}
|
||||
|
||||
auto backlight_duty_entry = map.find(SETTINGS_KEY_BACKLIGHT_DUTY);
|
||||
int backlight_duty = 200; // default
|
||||
if (backlight_duty_entry != map.end()) {
|
||||
backlight_duty = atoi(backlight_duty_entry->second.c_str());
|
||||
if (backlight_duty_entry->second != "0" && backlight_duty == 0) {
|
||||
backlight_duty = 200;
|
||||
}
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
settings.gammaCurve = gamma_curve;
|
||||
settings.backlightDuty = backlight_duty;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DisplaySettings getDefault() {
|
||||
return DisplaySettings {
|
||||
.orientation = getDefaultOrientation(),
|
||||
.gammaCurve = 1,
|
||||
.backlightDuty = 200
|
||||
};
|
||||
}
|
||||
|
||||
DisplaySettings loadOrGetDefault() {
|
||||
DisplaySettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool save(const DisplaySettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
|
||||
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
|
||||
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
|
||||
return file::savePropertiesFile(SETTINGS_FILE, map);
|
||||
}
|
||||
|
||||
lv_display_rotation_t toLvglDisplayRotation(Orientation orientation) {
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
auto rotation = lv_display_get_rotation(lvgl_display);
|
||||
bool is_originally_landscape;
|
||||
// The lvgl resolution code compensates for rotation. We have to revert the compensation to get the real display resolution
|
||||
// TODO: Use info from display driver
|
||||
if (rotation == LV_DISPLAY_ROTATION_0 || rotation == LV_DISPLAY_ROTATION_180) {
|
||||
is_originally_landscape = lv_display_get_physical_horizontal_resolution(lvgl_display) > lv_display_get_physical_vertical_resolution(lvgl_display);
|
||||
} else {
|
||||
is_originally_landscape = lv_display_get_physical_horizontal_resolution(lvgl_display) < lv_display_get_physical_vertical_resolution(lvgl_display);
|
||||
}
|
||||
if (is_originally_landscape) {
|
||||
// Landscape display
|
||||
switch (orientation) {
|
||||
case Orientation::Landscape:
|
||||
return LV_DISPLAY_ROTATION_0;
|
||||
case Orientation::Portrait:
|
||||
return LV_DISPLAY_ROTATION_90;
|
||||
case Orientation::LandscapeFlipped:
|
||||
return LV_DISPLAY_ROTATION_180;
|
||||
case Orientation::PortraitFlipped:
|
||||
return LV_DISPLAY_ROTATION_270;
|
||||
default:
|
||||
return LV_DISPLAY_ROTATION_0;
|
||||
}
|
||||
} else {
|
||||
// Portrait display
|
||||
switch (orientation) {
|
||||
case Orientation::Landscape:
|
||||
return LV_DISPLAY_ROTATION_90;
|
||||
case Orientation::Portrait:
|
||||
return LV_DISPLAY_ROTATION_0;
|
||||
case Orientation::LandscapeFlipped:
|
||||
return LV_DISPLAY_ROTATION_270;
|
||||
case Orientation::PortraitFlipped:
|
||||
return LV_DISPLAY_ROTATION_180;
|
||||
default:
|
||||
return LV_DISPLAY_ROTATION_0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -1,25 +1,25 @@
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/settings/Language.h>
|
||||
#include <utility>
|
||||
#include <Tactility/settings/SettingsProperties.h>
|
||||
#include <Tactility/settings/SystemSettings.h>
|
||||
|
||||
namespace tt::settings {
|
||||
|
||||
constexpr auto* TAG = "Language";
|
||||
|
||||
void setLanguage(Language newLanguage) {
|
||||
SettingsProperties properties;
|
||||
if (!loadSettingsProperties(properties)) {
|
||||
SystemSettings properties;
|
||||
if (!loadSystemSettings(properties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
properties.language = newLanguage;
|
||||
saveSettingsProperties(properties);
|
||||
saveSystemSettings(properties);
|
||||
}
|
||||
|
||||
Language getLanguage() {
|
||||
SettingsProperties properties;
|
||||
if (!loadSettingsProperties(properties)) {
|
||||
SystemSettings properties;
|
||||
if (!loadSystemSettings(properties)) {
|
||||
return Language::en_US;
|
||||
} else {
|
||||
return properties.language;
|
||||
|
||||
+8
-8
@@ -2,18 +2,18 @@
|
||||
#include <Tactility/file/FileLock.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/settings/Language.h>
|
||||
#include <Tactility/settings/SettingsProperties.h>
|
||||
#include <Tactility/settings/SystemSettings.h>
|
||||
|
||||
namespace tt::settings {
|
||||
|
||||
constexpr auto* TAG = "SettingsProperties";
|
||||
constexpr auto* FILE_PATH = "/data/settings.properties";
|
||||
constexpr auto* TAG = "SystemSettings";
|
||||
constexpr auto* FILE_PATH = "/data/system.properties";
|
||||
|
||||
static Mutex mutex = Mutex();
|
||||
static bool cached = false;
|
||||
static SettingsProperties cachedProperties;
|
||||
static SystemSettings cachedProperties;
|
||||
|
||||
static bool loadSettingsPropertiesFromFile(SettingsProperties& properties) {
|
||||
static bool loadSystemSettingsFromFile(SystemSettings& properties) {
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::withLock<bool>(FILE_PATH, [&map] {
|
||||
return file::loadPropertiesFile(FILE_PATH, map);
|
||||
@@ -39,12 +39,12 @@ static bool loadSettingsPropertiesFromFile(SettingsProperties& properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadSettingsProperties(SettingsProperties& properties) {
|
||||
bool loadSystemSettings(SystemSettings& properties) {
|
||||
auto scoped_lock = mutex.asScopedLock();
|
||||
scoped_lock.lock();
|
||||
|
||||
if (!cached) {
|
||||
if (!loadSettingsPropertiesFromFile(cachedProperties)) {
|
||||
if (!loadSystemSettingsFromFile(cachedProperties)) {
|
||||
return false;
|
||||
}
|
||||
cached = true;
|
||||
@@ -54,7 +54,7 @@ bool loadSettingsProperties(SettingsProperties& properties) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool saveSettingsProperties(const SettingsProperties& properties) {
|
||||
bool saveSystemSettings(const SystemSettings& properties) {
|
||||
auto scoped_lock = mutex.asScopedLock();
|
||||
scoped_lock.lock();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/Preferences.h>
|
||||
#include <Tactility/settings/SettingsProperties.h>
|
||||
#include <Tactility/settings/SystemSettings.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <ctime>
|
||||
@@ -60,8 +60,8 @@ std::string getTimeZoneCode() {
|
||||
}
|
||||
|
||||
bool isTimeFormat24Hour() {
|
||||
SettingsProperties properties;
|
||||
if (!loadSettingsProperties(properties)) {
|
||||
SystemSettings properties;
|
||||
if (!loadSystemSettings(properties)) {
|
||||
return true;
|
||||
} else {
|
||||
return properties.timeFormat24h;
|
||||
@@ -69,13 +69,13 @@ bool isTimeFormat24Hour() {
|
||||
}
|
||||
|
||||
void setTimeFormat24Hour(bool show24Hour) {
|
||||
SettingsProperties properties;
|
||||
if (!loadSettingsProperties(properties)) {
|
||||
SystemSettings properties;
|
||||
if (!loadSystemSettings(properties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
properties.timeFormat24h = show24Hour;
|
||||
saveSettingsProperties(properties);
|
||||
saveSystemSettings(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user