diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index ff43bb81..14047571 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -220,28 +220,27 @@ void DisplayApp::Refresh() { TickType_t queueTimeout; switch (state) { case States::Idle: - if (settingsController.GetAlwaysOnDisplay()) { - if (!currentScreen->IsRunning()) { - LoadPreviousScreen(); + queueTimeout = portMAX_DELAY; + break; + case States::AOD: + if (!currentScreen->IsRunning()) { + LoadPreviousScreen(); + } + // Check we've slept long enough + // Might not be true if the loop received an event + // If not true, then wait that amount of time + queueTimeout = CalculateSleepTime(); + if (queueTimeout == 0) { + // Only advance the tick count when LVGL is done + // Otherwise keep running the task handler while it still has things to draw + // Note: under high graphics load, LVGL will always have more work to do + if (lv_task_handler() > 0) { + // Drop frames that we've missed if drawing/event handling took way longer than expected + while (queueTimeout == 0) { + alwaysOnTickCount += 1; + queueTimeout = CalculateSleepTime(); + } } - // Check we've slept long enough - // Might not be true if the loop received an event - // If not true, then wait that amount of time - queueTimeout = CalculateSleepTime(); - if (queueTimeout == 0) { - // Only advance the tick count when LVGL is done - // Otherwise keep running the task handler while it still has things to draw - // Note: under high graphics load, LVGL will always have more work to do - if (lv_task_handler() > 0) { - // Drop frames that we've missed if drawing/event handling took way longer than expected - while (queueTimeout == 0) { - alwaysOnTickCount += 1; - queueTimeout = CalculateSleepTime(); - } - }; - } - } else { - queueTimeout = portMAX_DELAY; } break; case States::Running: @@ -284,6 +283,7 @@ void DisplayApp::Refresh() { if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) { switch (msg) { case Messages::GoToSleep: + case Messages::GoToAOD: if (state != States::Running) { break; } @@ -292,7 +292,7 @@ void DisplayApp::Refresh() { vTaskDelay(100); } // Turn brightness down (or set to AlwaysOn mode) - if (settingsController.GetAlwaysOnDisplay()) { + if (msg == Messages::GoToAOD) { brightnessController.Set(Controllers::BrightnessController::Levels::AlwaysOn); } else { brightnessController.Set(Controllers::BrightnessController::Levels::Off); @@ -305,17 +305,18 @@ void DisplayApp::Refresh() { while (!lv_task_handler()) { }; } - // Turn LCD display off (or set to low power for AlwaysOn mode) - if (settingsController.GetAlwaysOnDisplay()) { + if (msg == Messages::GoToAOD) { lcd.LowPowerOn(); // Record idle entry time alwaysOnTickCount = 0; alwaysOnStartTime = xTaskGetTickCount(); + PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskAOD); + state = States::AOD; } else { lcd.Sleep(); + PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping); + state = States::Idle; } - PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping); - state = States::Idle; break; case Messages::NotifyDeviceActivity: lv_disp_trig_activity(nullptr); @@ -324,7 +325,7 @@ void DisplayApp::Refresh() { if (state == States::Running) { break; } - if (settingsController.GetAlwaysOnDisplay()) { + if (state == States::AOD) { lcd.LowPowerOff(); } else { lcd.Wakeup(); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index d443b8b2..73492808 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -49,7 +49,7 @@ namespace Pinetime { namespace Applications { class DisplayApp { public: - enum class States { Idle, Running }; + enum class States { Idle, Running, AOD }; enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim }; DisplayApp(Drivers::St7789& lcd, diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index dcfff4c2..d2abc8e5 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -6,6 +6,7 @@ namespace Pinetime { namespace Display { enum class Messages : uint8_t { GoToSleep, + GoToAOD, GoToRunning, UpdateBleConnection, TouchEvent, diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index 81be9151..39fb4114 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -17,6 +17,7 @@ namespace Pinetime { HandleButtonEvent, HandleButtonTimerEvent, OnDisplayTaskSleeping, + OnDisplayTaskAOD, EnableSleeping, DisableSleeping, OnNewDay, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index fc4e8f7e..ba12535c 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -284,9 +284,10 @@ void SystemTask::Work() { HandleButtonAction(action); } break; case Messages::OnDisplayTaskSleeping: + case Messages::OnDisplayTaskAOD: // The state was set to GoingToSleep when GoToSleep() was called // If the state is no longer GoingToSleep, we have since transitioned back to Running - // In this case absorb the OnDisplayTaskSleeping + // In this case absorb the OnDisplayTaskSleeping/AOD // as DisplayApp is about to receive GoToRunning if (state != SystemTaskState::GoingToSleep) { break; @@ -298,7 +299,7 @@ void SystemTask::Work() { } // Must keep SPI awake when still updating the display for always on - if (!settingsController.GetAlwaysOnDisplay()) { + if (msg == Messages::OnDisplayTaskSleeping) { spi.Sleep(); } @@ -307,7 +308,11 @@ void SystemTask::Work() { touchPanel.Sleep(); } - state = SystemTaskState::Sleeping; + if (msg == Messages::OnDisplayTaskSleeping) { + state = SystemTaskState::Sleeping; + } else { + state = SystemTaskState::AODSleeping; + } break; case Messages::OnNewDay: // We might be sleeping (with TWI device disabled. @@ -381,8 +386,8 @@ void SystemTask::GoToRunning() { if (state == SystemTaskState::Running) { return; } - // SPI doesn't go to sleep for always on mode - if (!settingsController.GetAlwaysOnDisplay()) { + // SPI only switched off when entering Sleeping, not AOD or GoingToSleep + if (state == SystemTaskState::Sleeping) { spi.Wakeup(); } @@ -411,16 +416,22 @@ void SystemTask::GoToSleep() { return; } NRF_LOG_INFO("[systemtask] Going to sleep"); - displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep); + if (settingsController.GetAlwaysOnDisplay()) { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToAOD); + } else { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep); + } heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep); state = SystemTaskState::GoingToSleep; }; void SystemTask::UpdateMotion() { - if (IsSleeping() && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) || - motionController.GetService()->IsMotionNotificationSubscribed())) { + // Only consider disabling motion updates specifically in the Sleeping state + // AOD needs motion on to show up to date step counts + if (state == SystemTaskState::Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) || + motionController.GetService()->IsMotionNotificationSubscribed())) { return; } diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 8a4e5954..752c5611 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -52,7 +52,7 @@ namespace Pinetime { namespace System { class SystemTask { public: - enum class SystemTaskState { Sleeping, Running, GoingToSleep }; + enum class SystemTaskState { Sleeping, Running, GoingToSleep, AODSleeping }; SystemTask(Drivers::SpiMaster& spi, Pinetime::Drivers::SpiNorFlash& spiNorFlash, Drivers::TwiMaster& twiMaster,