mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
Lots of things "ported" over from the "enhanced" fork. With some adjustments here and there. KeyboardBacklight driver (for T-Deck only currently) Trackball driver (for T-Deck only currently) Keyboard backlight sleep/wake (for T-Deck only currently...also requires keyboard firmware update) Display sleep/wake Files - create file/folder Keyboard settings (for T-Deck only currently) Time & Date settings tweaks Locale settings tweaks Systeminfo additions Espnow wifi coexist initI2cDevices - moved to T-deck init.cpp / initBoot KeyboardInitService - removed, moved to T-deck init.cpp / initBoot Adjusted TIMER_UPDATE_INTERVAL to 2 seconds. Added lock to ActionCreateFolder Maybe missed some things in the list. Display wake could do with some kind of block on wake first touch to prevent UI elements being hit when waking device with touch. Same with encoder/trackball/keyboard press i guess. The original code was written by @cscott0108 at https://github.com/cscott0108/tactility-enhanced-t-deck
90 lines
3.2 KiB
C++
90 lines
3.2 KiB
C++
#include <Tactility/service/ServiceRegistration.h>
|
|
#include <Tactility/service/ServiceManifest.h>
|
|
#include <Tactility/service/ServiceContext.h>
|
|
#include <Tactility/Timer.h>
|
|
#include <Tactility/lvgl/LvglSync.h>
|
|
#include <Tactility/settings/DisplaySettings.h>
|
|
#include <Tactility/hal/display/DisplayDevice.h>
|
|
|
|
namespace tt::service::displayidle {
|
|
|
|
constexpr auto* TAG = "DisplayIdle";
|
|
|
|
class DisplayIdleService final : public Service {
|
|
|
|
std::unique_ptr<Timer> timer;
|
|
bool displayDimmed = false;
|
|
settings::display::DisplaySettings cachedDisplaySettings;
|
|
|
|
static std::shared_ptr<hal::display::DisplayDevice> getDisplay() {
|
|
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
|
}
|
|
|
|
void tick() {
|
|
// Settings are now cached and event-driven (no file I/O in timer callback!)
|
|
// This prevents watchdog timeout from blocking the Timer Service task
|
|
|
|
// Query LVGL inactivity once for both checks
|
|
uint32_t inactive_ms = 0;
|
|
if (lvgl::lock(100)) {
|
|
inactive_ms = lv_disp_get_inactive_time(nullptr);
|
|
lvgl::unlock();
|
|
}
|
|
|
|
// Handle display backlight
|
|
auto display = getDisplay();
|
|
if (display != nullptr && display->supportsBacklightDuty()) {
|
|
// If timeout disabled, ensure backlight restored if we had dimmed it
|
|
if (!cachedDisplaySettings.backlightTimeoutEnabled || cachedDisplaySettings.backlightTimeoutMs == 0) {
|
|
if (displayDimmed) {
|
|
display->setBacklightDuty(cachedDisplaySettings.backlightDuty);
|
|
displayDimmed = false;
|
|
}
|
|
} else {
|
|
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
|
display->setBacklightDuty(0);
|
|
displayDimmed = true;
|
|
} else if (displayDimmed && inactive_ms < 100) {
|
|
display->setBacklightDuty(cachedDisplaySettings.backlightDuty);
|
|
displayDimmed = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public:
|
|
bool onStart(TT_UNUSED ServiceContext& service) override {
|
|
// Load settings once at startup and cache them
|
|
// This eliminates file I/O from timer callback (prevents watchdog timeout)
|
|
cachedDisplaySettings = settings::display::loadOrGetDefault();
|
|
|
|
// Note: Settings changes require service restart to take effect
|
|
// TODO: Add DisplaySettingsChanged events for dynamic updates
|
|
|
|
timer = std::make_unique<Timer>(Timer::Type::Periodic, [this]{ this->tick(); });
|
|
timer->setThreadPriority(Thread::Priority::Lower);
|
|
timer->start(250); // check 4x per second for snappy restore
|
|
return true;
|
|
}
|
|
|
|
void onStop(TT_UNUSED ServiceContext& service) override {
|
|
if (timer) {
|
|
timer->stop();
|
|
timer = nullptr;
|
|
}
|
|
// Ensure display restored on stop
|
|
auto display = getDisplay();
|
|
if (display && displayDimmed) {
|
|
display->setBacklightDuty(cachedDisplaySettings.backlightDuty);
|
|
displayDimmed = false;
|
|
}
|
|
}
|
|
};
|
|
|
|
extern const ServiceManifest manifest = {
|
|
.id = "DisplayIdle",
|
|
.createService = create<DisplayIdleService>
|
|
};
|
|
|
|
}
|