diff options
| author | Riku Isokoski <riksu9000@gmail.com> | 2023-02-21 23:30:43 +0200 |
|---|---|---|
| committer | Riku Isokoski <riksu9000@gmail.com> | 2023-03-18 01:15:33 +0200 |
| commit | 310ea81eec3bd35e13718dd85e578048ce20eb47 (patch) | |
| tree | a0eb6526a9606094148172d2c00955d44c150506 /src/displayapp | |
| parent | 11ade64166c8900abb5574dd9d4aa2ae597f69c5 (diff) | |
inactivity: Use LVGL inactivity timers
Replace custom FreeRTOS inactivity timers with LVGL inactivity timers.
DisplayApp: Trigger display activity on timer done.
inactivity: Add additional checks
The backlight could be turned on by RestoreBrightness() on ble connect
event.
inactivity: Trigger activity on screen switch
A notification timing out could put the watch to sleep immediately.
While this could be ideal behaviour, it was caused by delay in
processing the EnableSleeping event and pushing RestoreBrightness to
DisplayApp.
Diffstat (limited to 'src/displayapp')
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 47 | ||||
| -rw-r--r-- | src/displayapp/DisplayApp.h | 2 | ||||
| -rw-r--r-- | src/displayapp/Messages.h | 1 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingDisplay.cpp | 1 |
4 files changed, 43 insertions, 8 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index ccba7ee6..2aa828bb 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -155,6 +155,29 @@ void DisplayApp::Refresh() { LoadScreen(returnAppStack.Pop(), returnDirection); }; + auto DimScreen = [this]() { + if (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) { + isDimmed = true; + brightnessController.Set(Controllers::BrightnessController::Levels::Low); + } + }; + + auto RestoreBrightness = [this]() { + if (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) { + isDimmed = false; + lv_disp_trig_activity(nullptr); + ApplyBrightness(); + } + }; + + auto IsPastDimTime = [this]() -> bool { + return lv_disp_get_inactive_time(nullptr) >= pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000); + }; + + auto IsPastSleepTime = [this]() -> bool { + return lv_disp_get_inactive_time(nullptr) >= pdMS_TO_TICKS(settingsController.GetScreenTimeOut()); + }; + TickType_t queueTimeout; switch (state) { case States::Idle: @@ -165,6 +188,18 @@ void DisplayApp::Refresh() { LoadPreviousScreen(); } queueTimeout = lv_task_handler(); + + if (!systemTask->IsSleepDisabled() && IsPastDimTime()) { + if (!isDimmed) { + DimScreen(); + } + if (IsPastSleepTime()) { + systemTask->PushMessage(System::Messages::GoToSleep); + state = States::Idle; + } + } else if (isDimmed) { + RestoreBrightness(); + } break; default: queueTimeout = portMAX_DELAY; @@ -175,10 +210,10 @@ void DisplayApp::Refresh() { if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) { switch (msg) { case Messages::DimScreen: - brightnessController.Set(Controllers::BrightnessController::Levels::Low); + DimScreen(); break; case Messages::RestoreBrightness: - ApplyBrightness(); + RestoreBrightness(); break; case Messages::GoToSleep: while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) { @@ -191,12 +226,10 @@ void DisplayApp::Refresh() { break; case Messages::GoToRunning: lcd.Wakeup(); + lv_disp_trig_activity(nullptr); ApplyBrightness(); state = States::Running; break; - case Messages::UpdateTimeOut: - PushMessageToSystemTask(System::Messages::UpdateTimeOut); - break; case Messages::UpdateBleConnection: // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : // Screens::Clock::BleConnectionStates::NotConnected); @@ -206,6 +239,7 @@ void DisplayApp::Refresh() { break; case Messages::TimerDone: if (currentApp == Apps::Timer) { + lv_disp_trig_activity(nullptr); auto* timer = static_cast<Screens::Timer*>(currentScreen.get()); timer->Reset(); } else { @@ -319,6 +353,7 @@ void DisplayApp::Refresh() { motorController.RunForDuration(35); break; case Messages::OnChargingEvent: + RestoreBrightness(); motorController.RunForDuration(15); break; } @@ -352,7 +387,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) { lvgl.CancelTap(); - ApplyBrightness(); + lv_disp_trig_activity(nullptr); motorController.StopRinging(); currentScreen.reset(nullptr); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 09111865..58df99c0 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -128,6 +128,8 @@ namespace Pinetime { static constexpr size_t returnAppStackSize = 10; StaticStack<Apps, returnAppStackSize> returnAppStack; StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections; + + bool isDimmed = false; }; } } diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index b670b1aa..dada3088 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -17,7 +17,6 @@ namespace Pinetime { NewNotification, TimerDone, BleFirmwareUpdateStarted, - UpdateTimeOut, DimScreen, RestoreBrightness, ShowPairingKey, diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index a9476432..91f4d590 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -69,7 +69,6 @@ void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); settingsController.SetScreenTimeOut(options[i]); - app->PushMessage(Applications::Display::Messages::UpdateTimeOut); } else { lv_checkbox_set_checked(cbOption[i], false); } |
