@@ -220,28 +220,27 @@ void DisplayApp::Refresh() {
220220 TickType_t queueTimeout;
221221 switch (state) {
222222 case States::Idle:
223- if (settingsController.GetAlwaysOnDisplay ()) {
224- if (!currentScreen->IsRunning ()) {
225- LoadPreviousScreen ();
226- }
227- // Check we've slept long enough
228- // Might not be true if the loop received an event
229- // If not true, then wait that amount of time
230- queueTimeout = CalculateSleepTime ();
231- if (queueTimeout == 0 ) {
232- // Only advance the tick count when LVGL is done
233- // Otherwise keep running the task handler while it still has things to draw
234- // Note: under high graphics load, LVGL will always have more work to do
235- if (lv_task_handler () > 0 ) {
236- // Drop frames that we've missed if drawing/event handling took way longer than expected
237- while (queueTimeout == 0 ) {
238- alwaysOnTickCount += 1 ;
239- queueTimeout = CalculateSleepTime ();
240- }
241- };
223+ queueTimeout = portMAX_DELAY;
224+ break ;
225+ case States::AOD:
226+ if (!currentScreen->IsRunning ()) {
227+ LoadPreviousScreen ();
228+ }
229+ // Check we've slept long enough
230+ // Might not be true if the loop received an event
231+ // If not true, then wait that amount of time
232+ queueTimeout = CalculateSleepTime ();
233+ if (queueTimeout == 0 ) {
234+ // Only advance the tick count when LVGL is done
235+ // Otherwise keep running the task handler while it still has things to draw
236+ // Note: under high graphics load, LVGL will always have more work to do
237+ if (lv_task_handler () > 0 ) {
238+ // Drop frames that we've missed if drawing/event handling took way longer than expected
239+ while (queueTimeout == 0 ) {
240+ alwaysOnTickCount += 1 ;
241+ queueTimeout = CalculateSleepTime ();
242+ }
242243 }
243- } else {
244- queueTimeout = portMAX_DELAY;
245244 }
246245 break ;
247246 case States::Running:
@@ -284,6 +283,7 @@ void DisplayApp::Refresh() {
284283 if (xQueueReceive (msgQueue, &msg, queueTimeout) == pdTRUE) {
285284 switch (msg) {
286285 case Messages::GoToSleep:
286+ case Messages::GoToAOD:
287287 if (state != States::Running) {
288288 break ;
289289 }
@@ -292,7 +292,7 @@ void DisplayApp::Refresh() {
292292 vTaskDelay (100 );
293293 }
294294 // Turn brightness down (or set to AlwaysOn mode)
295- if (settingsController. GetAlwaysOnDisplay () ) {
295+ if (msg == Messages::GoToAOD ) {
296296 brightnessController.Set (Controllers::BrightnessController::Levels::AlwaysOn);
297297 } else {
298298 brightnessController.Set (Controllers::BrightnessController::Levels::Off);
@@ -305,17 +305,18 @@ void DisplayApp::Refresh() {
305305 while (!lv_task_handler ()) {
306306 };
307307 }
308- // Turn LCD display off (or set to low power for AlwaysOn mode)
309- if (settingsController.GetAlwaysOnDisplay ()) {
308+ if (msg == Messages::GoToAOD) {
310309 lcd.LowPowerOn ();
311310 // Record idle entry time
312311 alwaysOnTickCount = 0 ;
313312 alwaysOnStartTime = xTaskGetTickCount ();
313+ PushMessageToSystemTask (Pinetime::System::Messages::OnDisplayTaskAOD);
314+ state = States::AOD;
314315 } else {
315316 lcd.Sleep ();
317+ PushMessageToSystemTask (Pinetime::System::Messages::OnDisplayTaskSleeping);
318+ state = States::Idle;
316319 }
317- PushMessageToSystemTask (Pinetime::System::Messages::OnDisplayTaskSleeping);
318- state = States::Idle;
319320 break ;
320321 case Messages::NotifyDeviceActivity:
321322 lv_disp_trig_activity (nullptr );
@@ -324,7 +325,7 @@ void DisplayApp::Refresh() {
324325 if (state == States::Running) {
325326 break ;
326327 }
327- if (settingsController. GetAlwaysOnDisplay () ) {
328+ if (state == States::AOD ) {
328329 lcd.LowPowerOff ();
329330 } else {
330331 lcd.Wakeup ();
0 commit comments