Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3180bff80f | |||
| 09bf9d7f0b | |||
| 9d380cdaaa | |||
| 8970143f72 | |||
| 2aa8e7a839 | |||
| 9993bccdd3 | |||
| 3b9cb8a607 | |||
| e02c8ccb76 | |||
| eaa248b0f4 |
@@ -1,46 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <src/display/lv_display.h>
|
||||
|
||||
namespace tt::settings::display {
|
||||
|
||||
enum class Orientation {
|
||||
// In order of rotation (to make it easier to convert to LVGL rotation)
|
||||
Landscape,
|
||||
Portrait,
|
||||
LandscapeFlipped,
|
||||
PortraitFlipped,
|
||||
};
|
||||
|
||||
enum class ScreensaverType {
|
||||
None, // Just black screen
|
||||
None,
|
||||
BouncingBalls,
|
||||
Mystify,
|
||||
MatrixRain,
|
||||
StackChan,
|
||||
McpScreen,
|
||||
Count // Sentinel for bounds checking - must be last
|
||||
Count
|
||||
};
|
||||
|
||||
struct DisplaySettings {
|
||||
Orientation orientation;
|
||||
uint8_t gammaCurve;
|
||||
uint8_t backlightDuty;
|
||||
bool backlightTimeoutEnabled;
|
||||
uint32_t backlightTimeoutMs; // 0 = Never
|
||||
uint32_t backlightTimeoutMs;
|
||||
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
||||
bool disableScreensaverWhenCharging = false;
|
||||
};
|
||||
|
||||
/** Compares default settings with the function parameter to return the difference */
|
||||
lv_display_rotation_t toLvglDisplayRotation(Orientation orientation);
|
||||
|
||||
bool load(DisplaySettings& settings);
|
||||
|
||||
DisplaySettings loadOrGetDefault();
|
||||
|
||||
DisplaySettings getDefault();
|
||||
|
||||
bool save(const DisplaySettings& settings);
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
@@ -152,7 +152,6 @@ namespace app {
|
||||
namespace crashdiagnostics { extern const AppManifest manifest; }
|
||||
namespace webserversettings { extern const AppManifest manifest; }
|
||||
namespace mcpsettings { extern const AppManifest manifest; }
|
||||
namespace mcpoverride { extern const AppManifest manifest; }
|
||||
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
||||
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
|
||||
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan\nMcpScreen");
|
||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
||||
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
||||
@@ -295,16 +295,13 @@ public:
|
||||
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
// Disable screensaver when charging toggle
|
||||
disableWhenChargingWrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(disableWhenChargingWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* charging_label = lv_label_create(disableWhenChargingWrapper);
|
||||
lv_label_set_text(charging_label, "Disable on charging");
|
||||
lv_obj_align(charging_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
disableWhenChargingSwitch = lv_switch_create(disableWhenChargingWrapper);
|
||||
if (displaySettings.disableScreensaverWhenCharging) {
|
||||
lv_obj_add_state(disableWhenChargingSwitch, LV_STATE_CHECKED);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||
|
||||
@@ -13,10 +14,10 @@
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/service/ServiceContext.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
@@ -34,12 +35,12 @@ static bool isDeviceCharging() {
|
||||
bool charging = false;
|
||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&charging](const auto& power) {
|
||||
if (!power->supportsMetric(hal::power::PowerDevice::MetricType::IsCharging)) {
|
||||
return true;
|
||||
return true; // continue
|
||||
}
|
||||
hal::power::PowerDevice::MetricData data;
|
||||
if (power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, data) && data.valueAsBool) {
|
||||
charging = true;
|
||||
return false;
|
||||
return false; // stop iter
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -48,17 +49,10 @@ static bool isDeviceCharging() {
|
||||
|
||||
void DisplayIdleService::stopScreensaverCb(lv_event_t* e) {
|
||||
auto* self = static_cast<DisplayIdleService*>(lv_event_get_user_data(e));
|
||||
lv_event_stop_bubbling(e);
|
||||
self->stopScreensaverRequested.store(true, std::memory_order_release);
|
||||
lv_display_trigger_activity(nullptr);
|
||||
self->stopScreensaverLocked();
|
||||
}
|
||||
|
||||
void DisplayIdleService::stopScreensaver() {
|
||||
if (!lvgl::lock(100)) {
|
||||
// Lock failed - keep flag set to retry on next tick
|
||||
return;
|
||||
}
|
||||
|
||||
void DisplayIdleService::stopScreensaverLocked() {
|
||||
const auto restoreDuty = cachedDisplaySettings.backlightDuty;
|
||||
const bool wasDimmed = displayDimmed;
|
||||
|
||||
@@ -70,7 +64,6 @@ void DisplayIdleService::stopScreensaver() {
|
||||
lv_obj_delete(screensaverOverlay);
|
||||
screensaverOverlay = nullptr;
|
||||
}
|
||||
lvgl::unlock();
|
||||
stopScreensaverRequested.store(false, std::memory_order_relaxed);
|
||||
|
||||
// Reset auto-off state
|
||||
@@ -85,6 +78,15 @@ void DisplayIdleService::stopScreensaver() {
|
||||
displayDimmed = wasDimmed ? false : displayDimmed;
|
||||
}
|
||||
|
||||
void DisplayIdleService::stopScreensaver() {
|
||||
if (!lvgl::lock(100)) {
|
||||
// Lock failed - keep flag set to retry on next tick
|
||||
return;
|
||||
}
|
||||
stopScreensaverLocked();
|
||||
lvgl::unlock();
|
||||
}
|
||||
|
||||
void DisplayIdleService::activateScreensaver() {
|
||||
lv_obj_t* top = lv_layer_top();
|
||||
|
||||
@@ -145,6 +147,16 @@ void DisplayIdleService::updateScreensaver() {
|
||||
}
|
||||
|
||||
void DisplayIdleService::tick() {
|
||||
// Check if MCP override is active — must not be auto-stopped by idle logic
|
||||
// READ OUTSIDE LVGL lock to avoid lock inversion:
|
||||
// MCP video task locks mutex -> LVGL, we must NOT do LVGL -> mutex
|
||||
bool isMcpActive = false;
|
||||
{
|
||||
auto& st = mcp::getState();
|
||||
std::lock_guard<std::mutex> lk(st.mutex);
|
||||
isMcpActive = (st.drawArea != nullptr) || st.overrideActive;
|
||||
}
|
||||
|
||||
if (!lvgl::lock(100)) {
|
||||
return;
|
||||
}
|
||||
@@ -159,11 +171,10 @@ void DisplayIdleService::tick() {
|
||||
}
|
||||
|
||||
uint32_t inactive_ms = 0;
|
||||
|
||||
inactive_ms = lv_display_get_inactive_time(nullptr);
|
||||
|
||||
// Only update if not stopping (prevents lag on touch)
|
||||
if (displayDimmed && screensaverOverlay && !stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
// Only update if not stopping (prevents lag on touch) — skip for MCP (no animation)
|
||||
if (displayDimmed && screensaverOverlay && !stopScreensaverRequested.load(std::memory_order_acquire) && !isMcpActive) {
|
||||
// Check if screensaver should auto-off after 5 minutes
|
||||
if (!backlightOff) {
|
||||
screensaverActiveCounter++;
|
||||
@@ -193,35 +204,49 @@ void DisplayIdleService::tick() {
|
||||
}
|
||||
|
||||
auto display = getDisplay();
|
||||
if (display != nullptr && display->supportsBacklightDuty()) {
|
||||
if (!cachedDisplaySettings.backlightTimeoutEnabled || cachedDisplaySettings.backlightTimeoutMs == 0) {
|
||||
if (displayDimmed) {
|
||||
bool supportsBacklight = display != nullptr && display->supportsBacklightDuty();
|
||||
|
||||
if (!cachedDisplaySettings.backlightTimeoutEnabled || cachedDisplaySettings.backlightTimeoutMs == 0) {
|
||||
// Timeout disabled (Never): ensure we restore if we were dimmed, regardless of display type
|
||||
if (displayDimmed && !isMcpActive) {
|
||||
if (supportsBacklight && display != nullptr) {
|
||||
display->setBacklightDuty(cachedDisplaySettings.backlightDuty);
|
||||
displayDimmed = false;
|
||||
}
|
||||
} else {
|
||||
bool charging_blocks = cachedDisplaySettings.disableScreensaverWhenCharging && isDeviceCharging();
|
||||
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
||||
if (charging_blocks) {
|
||||
// Skip screensaver while charging
|
||||
} else {
|
||||
if (!lvgl::lock(100)) {
|
||||
return; // Retry on next tick
|
||||
}
|
||||
activateScreensaver();
|
||||
lvgl::unlock();
|
||||
// Turn off backlight for "None" screensaver (just black screen)
|
||||
if (cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::None) {
|
||||
displayDimmed = false;
|
||||
}
|
||||
} else if (supportsBacklight) {
|
||||
// For backlight-capable displays: full idle handling
|
||||
bool charging_blocks = cachedDisplaySettings.disableScreensaverWhenCharging && isDeviceCharging();
|
||||
|
||||
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
||||
if (charging_blocks) {
|
||||
// Skip screensaver while charging
|
||||
} else {
|
||||
if (!lvgl::lock(100)) {
|
||||
return; // Retry on next tick
|
||||
}
|
||||
activateScreensaver();
|
||||
lvgl::unlock();
|
||||
if (cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::None) {
|
||||
if (display != nullptr) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
displayDimmed = true;
|
||||
}
|
||||
} else if (displayDimmed) {
|
||||
if (inactive_ms < kWakeActivityThresholdMs) {
|
||||
stopScreensaver();
|
||||
} else if (charging_blocks) {
|
||||
stopScreensaver();
|
||||
}
|
||||
displayDimmed = true;
|
||||
}
|
||||
} else if (displayDimmed && !isMcpActive) {
|
||||
if (inactive_ms < kWakeActivityThresholdMs) {
|
||||
stopScreensaver();
|
||||
} else if (charging_blocks) {
|
||||
stopScreensaver();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// For monochrome/RLCD (no backlight): don't auto-enter screensaver (heavy full_refresh SPI causes freeze)
|
||||
// Only handle wake if we are somehow dimmed (e.g. MCP left it)
|
||||
if (displayDimmed && !isMcpActive) {
|
||||
if (inactive_ms < kWakeActivityThresholdMs) {
|
||||
stopScreensaver();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,6 +258,11 @@ bool DisplayIdleService::onStart(ServiceContext& service) {
|
||||
|
||||
cachedDisplaySettings = settings::display::loadOrGetDefault();
|
||||
|
||||
auto display = getDisplay();
|
||||
if (display != nullptr && !display->supportsBacklightDuty()) {
|
||||
LOG_I(TAG, "Monochrome/RLCD display detected (no backlight control): idle timer will run but auto-backlight off is disabled");
|
||||
}
|
||||
|
||||
timer = std::make_unique<Timer>(Timer::Type::Periodic, kernel::millisToTicks(TICK_INTERVAL_MS), [this]{ this->tick(); });
|
||||
timer->setCallbackPriority(Thread::Priority::Lower);
|
||||
timer->start();
|
||||
@@ -284,6 +314,11 @@ bool DisplayIdleService::isScreensaverActive() const {
|
||||
return screensaverOverlay != nullptr;
|
||||
}
|
||||
|
||||
void DisplayIdleService::reloadSettings() {
|
||||
// Set flag for thread-safe reload - actual reload happens in tick()
|
||||
settingsReloadRequested.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
void DisplayIdleService::startMcpScreensaver() {
|
||||
if (!lvgl::lock(200)) {
|
||||
LOG_W(TAG, "startMcpScreensaver: failed to acquire LVGL lock");
|
||||
@@ -319,6 +354,7 @@ void DisplayIdleService::startMcpScreensaver() {
|
||||
}
|
||||
|
||||
lv_coord_t screenW = lv_display_get_horizontal_resolution(nullptr);
|
||||
|
||||
lv_coord_t screenH = lv_display_get_vertical_resolution(nullptr);
|
||||
|
||||
lv_obj_t* top = lv_layer_top();
|
||||
@@ -339,11 +375,6 @@ void DisplayIdleService::startMcpScreensaver() {
|
||||
LOG_I(TAG, "MCP screensaver activated");
|
||||
}
|
||||
|
||||
void DisplayIdleService::reloadSettings() {
|
||||
// Set flag for thread-safe reload - actual reload happens in tick()
|
||||
settingsReloadRequested.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
std::shared_ptr<DisplayIdleService> findService() {
|
||||
return std::static_pointer_cast<DisplayIdleService>(
|
||||
findServiceById("DisplayIdle")
|
||||
|
||||
@@ -29,7 +29,6 @@ static Orientation getDefaultOrientation() {
|
||||
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 {
|
||||
@@ -40,91 +39,51 @@ static Orientation getDefaultOrientation() {
|
||||
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();
|
||||
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;
|
||||
}
|
||||
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; }
|
||||
}
|
||||
|
||||
static std::string toString(ScreensaverType type) {
|
||||
switch (type) {
|
||||
using enum ScreensaverType;
|
||||
case None:
|
||||
return "None";
|
||||
case BouncingBalls:
|
||||
return "BouncingBalls";
|
||||
case Mystify:
|
||||
return "Mystify";
|
||||
case MatrixRain:
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
case McpScreen:
|
||||
return "McpScreen";
|
||||
default:
|
||||
std::unreachable();
|
||||
case None: return "None";
|
||||
case BouncingBalls: return "BouncingBalls";
|
||||
case Mystify: return "Mystify";
|
||||
case MatrixRain: return "MatrixRain";
|
||||
case StackChan: return "StackChan";
|
||||
case McpScreen: return "McpScreen";
|
||||
case Count: return "None";
|
||||
default: std::unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static bool fromString(const std::string& str, ScreensaverType& type) {
|
||||
if (str == "None") {
|
||||
type = ScreensaverType::None;
|
||||
return true;
|
||||
} else if (str == "BouncingBalls") {
|
||||
type = ScreensaverType::BouncingBalls;
|
||||
return true;
|
||||
} else if (str == "Mystify") {
|
||||
type = ScreensaverType::Mystify;
|
||||
return true;
|
||||
} else if (str == "MatrixRain") {
|
||||
type = ScreensaverType::MatrixRain;
|
||||
return true;
|
||||
} else if (str == "StackChan") {
|
||||
type = ScreensaverType::StackChan;
|
||||
return true;
|
||||
} else if (str == "McpScreen") {
|
||||
type = ScreensaverType::McpScreen;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (str == "None") { type = ScreensaverType::None; return true; }
|
||||
else if (str == "BouncingBalls") { type = ScreensaverType::BouncingBalls; return true; }
|
||||
else if (str == "Mystify") { type = ScreensaverType::Mystify; return true; }
|
||||
else if (str == "MatrixRain") { type = ScreensaverType::MatrixRain; return true; }
|
||||
else if (str == "StackChan") { type = ScreensaverType::StackChan; return true; }
|
||||
else if (str == "McpScreen") { type = ScreensaverType::McpScreen; return true; }
|
||||
else { return false; }
|
||||
}
|
||||
|
||||
bool load(DisplaySettings& settings) {
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::isFile(settings_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file::isFile(settings_path)) { return false; }
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(settings_path, map)) {
|
||||
return false;
|
||||
}
|
||||
if (!file::loadPropertiesFile(settings_path, map)) { return false; }
|
||||
|
||||
auto orientation_entry = map.find(SETTINGS_KEY_ORIENTATION);
|
||||
Orientation orientation;
|
||||
@@ -134,17 +93,13 @@ bool load(DisplaySettings& settings) {
|
||||
|
||||
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());
|
||||
}
|
||||
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
|
||||
int backlight_duty = 200;
|
||||
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;
|
||||
}
|
||||
if (backlight_duty_entry->second != "0" && backlight_duty == 0) backlight_duty = 200;
|
||||
}
|
||||
|
||||
bool timeout_enabled = false;
|
||||
@@ -153,7 +108,7 @@ bool load(DisplaySettings& settings) {
|
||||
timeout_enabled = (timeout_enabled_entry->second == "1" || timeout_enabled_entry->second == "true" || timeout_enabled_entry->second == "True");
|
||||
}
|
||||
|
||||
uint32_t timeout_ms = 60000; // default 60s
|
||||
uint32_t timeout_ms = 60000;
|
||||
auto timeout_ms_entry = map.find(SETTINGS_KEY_TIMEOUT_MS);
|
||||
if (timeout_ms_entry != map.end()) {
|
||||
timeout_ms = static_cast<uint32_t>(std::strtoul(timeout_ms_entry->second.c_str(), nullptr, 10));
|
||||
@@ -161,14 +116,12 @@ bool load(DisplaySettings& settings) {
|
||||
|
||||
auto screensaver_entry = map.find(SETTINGS_KEY_SCREENSAVER_TYPE);
|
||||
ScreensaverType screensaver_type = ScreensaverType::BouncingBalls;
|
||||
if (screensaver_entry != map.end()) {
|
||||
fromString(screensaver_entry->second, screensaver_type);
|
||||
}
|
||||
if (screensaver_entry != map.end()) { fromString(screensaver_entry->second, screensaver_type); }
|
||||
|
||||
bool disable_when_charging = false;
|
||||
auto charging_entry = map.find(SETTINGS_KEY_DISABLE_WHEN_CHARGING);
|
||||
if (charging_entry != map.end()) {
|
||||
disable_when_charging = (charging_entry->second == "1" || charging_entry->second == "true" || charging_entry->second == "True");
|
||||
disable_when_charging = (charging_entry->second == "1" || charging_entry->second == "true");
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
@@ -178,7 +131,6 @@ bool load(DisplaySettings& settings) {
|
||||
settings.backlightTimeoutMs = timeout_ms;
|
||||
settings.screensaverType = screensaver_type;
|
||||
settings.disableScreensaverWhenCharging = disable_when_charging;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -196,9 +148,7 @@ DisplaySettings getDefault() {
|
||||
|
||||
DisplaySettings loadOrGetDefault() {
|
||||
DisplaySettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
}
|
||||
if (!load(settings)) { settings = getDefault(); }
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -212,9 +162,7 @@ bool save(const DisplaySettings& settings) {
|
||||
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
||||
map[SETTINGS_KEY_DISABLE_WHEN_CHARGING] = settings.disableScreensaverWhenCharging ? "1" : "0";
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
return false;
|
||||
}
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) { return false; }
|
||||
return file::savePropertiesFile(settings_path, map);
|
||||
}
|
||||
|
||||
@@ -222,40 +170,26 @@ 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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user