mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-12-24 10:13:56 +03:00
Refactor into defined states
This commit is contained in:
parent
97ba39988b
commit
f032847ae1
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -6,6 +6,7 @@ namespace Pinetime {
|
||||
namespace Display {
|
||||
enum class Messages : uint8_t {
|
||||
GoToSleep,
|
||||
GoToAOD,
|
||||
GoToRunning,
|
||||
UpdateBleConnection,
|
||||
TouchEvent,
|
||||
|
@ -17,6 +17,7 @@ namespace Pinetime {
|
||||
HandleButtonEvent,
|
||||
HandleButtonTimerEvent,
|
||||
OnDisplayTaskSleeping,
|
||||
OnDisplayTaskAOD,
|
||||
EnableSleeping,
|
||||
DisableSleeping,
|
||||
OnNewDay,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user