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.
This commit is contained in:
parent
11ade64166
commit
310ea81eec
|
@ -155,6 +155,29 @@ void DisplayApp::Refresh() {
|
||||||
LoadScreen(returnAppStack.Pop(), returnDirection);
|
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;
|
TickType_t queueTimeout;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case States::Idle:
|
case States::Idle:
|
||||||
|
@ -165,6 +188,18 @@ void DisplayApp::Refresh() {
|
||||||
LoadPreviousScreen();
|
LoadPreviousScreen();
|
||||||
}
|
}
|
||||||
queueTimeout = lv_task_handler();
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
queueTimeout = portMAX_DELAY;
|
queueTimeout = portMAX_DELAY;
|
||||||
|
@ -175,10 +210,10 @@ void DisplayApp::Refresh() {
|
||||||
if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
|
if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case Messages::DimScreen:
|
case Messages::DimScreen:
|
||||||
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
|
DimScreen();
|
||||||
break;
|
break;
|
||||||
case Messages::RestoreBrightness:
|
case Messages::RestoreBrightness:
|
||||||
ApplyBrightness();
|
RestoreBrightness();
|
||||||
break;
|
break;
|
||||||
case Messages::GoToSleep:
|
case Messages::GoToSleep:
|
||||||
while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) {
|
while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) {
|
||||||
|
@ -191,12 +226,10 @@ void DisplayApp::Refresh() {
|
||||||
break;
|
break;
|
||||||
case Messages::GoToRunning:
|
case Messages::GoToRunning:
|
||||||
lcd.Wakeup();
|
lcd.Wakeup();
|
||||||
|
lv_disp_trig_activity(nullptr);
|
||||||
ApplyBrightness();
|
ApplyBrightness();
|
||||||
state = States::Running;
|
state = States::Running;
|
||||||
break;
|
break;
|
||||||
case Messages::UpdateTimeOut:
|
|
||||||
PushMessageToSystemTask(System::Messages::UpdateTimeOut);
|
|
||||||
break;
|
|
||||||
case Messages::UpdateBleConnection:
|
case Messages::UpdateBleConnection:
|
||||||
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
|
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
|
||||||
// Screens::Clock::BleConnectionStates::NotConnected);
|
// Screens::Clock::BleConnectionStates::NotConnected);
|
||||||
|
@ -206,6 +239,7 @@ void DisplayApp::Refresh() {
|
||||||
break;
|
break;
|
||||||
case Messages::TimerDone:
|
case Messages::TimerDone:
|
||||||
if (currentApp == Apps::Timer) {
|
if (currentApp == Apps::Timer) {
|
||||||
|
lv_disp_trig_activity(nullptr);
|
||||||
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
|
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
|
||||||
timer->Reset();
|
timer->Reset();
|
||||||
} else {
|
} else {
|
||||||
|
@ -319,6 +353,7 @@ void DisplayApp::Refresh() {
|
||||||
motorController.RunForDuration(35);
|
motorController.RunForDuration(35);
|
||||||
break;
|
break;
|
||||||
case Messages::OnChargingEvent:
|
case Messages::OnChargingEvent:
|
||||||
|
RestoreBrightness();
|
||||||
motorController.RunForDuration(15);
|
motorController.RunForDuration(15);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -352,7 +387,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc
|
||||||
|
|
||||||
void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
|
void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
|
||||||
lvgl.CancelTap();
|
lvgl.CancelTap();
|
||||||
ApplyBrightness();
|
lv_disp_trig_activity(nullptr);
|
||||||
motorController.StopRinging();
|
motorController.StopRinging();
|
||||||
|
|
||||||
currentScreen.reset(nullptr);
|
currentScreen.reset(nullptr);
|
||||||
|
|
|
@ -128,6 +128,8 @@ namespace Pinetime {
|
||||||
static constexpr size_t returnAppStackSize = 10;
|
static constexpr size_t returnAppStackSize = 10;
|
||||||
StaticStack<Apps, returnAppStackSize> returnAppStack;
|
StaticStack<Apps, returnAppStackSize> returnAppStack;
|
||||||
StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections;
|
StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections;
|
||||||
|
|
||||||
|
bool isDimmed = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ namespace Pinetime {
|
||||||
NewNotification,
|
NewNotification,
|
||||||
TimerDone,
|
TimerDone,
|
||||||
BleFirmwareUpdateStarted,
|
BleFirmwareUpdateStarted,
|
||||||
UpdateTimeOut,
|
|
||||||
DimScreen,
|
DimScreen,
|
||||||
RestoreBrightness,
|
RestoreBrightness,
|
||||||
ShowPairingKey,
|
ShowPairingKey,
|
||||||
|
|
|
@ -69,7 +69,6 @@ void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (object == cbOption[i]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
settingsController.SetScreenTimeOut(options[i]);
|
settingsController.SetScreenTimeOut(options[i]);
|
||||||
app->PushMessage(Applications::Display::Messages::UpdateTimeOut);
|
|
||||||
} else {
|
} else {
|
||||||
lv_checkbox_set_checked(cbOption[i], false);
|
lv_checkbox_set_checked(cbOption[i], false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace Pinetime {
|
||||||
OnTimerDone,
|
OnTimerDone,
|
||||||
OnNewCall,
|
OnNewCall,
|
||||||
BleConnected,
|
BleConnected,
|
||||||
UpdateTimeOut,
|
|
||||||
BleFirmwareUpdateStarted,
|
BleFirmwareUpdateStarted,
|
||||||
BleFirmwareUpdateFinished,
|
BleFirmwareUpdateFinished,
|
||||||
OnTouchEvent,
|
OnTouchEvent,
|
||||||
|
|
|
@ -27,20 +27,6 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DimTimerCallback(TimerHandle_t xTimer) {
|
|
||||||
|
|
||||||
NRF_LOG_INFO("DimTimerCallback");
|
|
||||||
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
|
|
||||||
sysTask->OnDim();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IdleTimerCallback(TimerHandle_t xTimer) {
|
|
||||||
|
|
||||||
NRF_LOG_INFO("IdleTimerCallback");
|
|
||||||
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
|
|
||||||
sysTask->OnIdle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
|
void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
|
||||||
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
|
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
|
||||||
sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
|
sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
|
||||||
|
@ -189,10 +175,7 @@ void SystemTask::Work() {
|
||||||
|
|
||||||
batteryController.MeasureVoltage();
|
batteryController.MeasureVoltage();
|
||||||
|
|
||||||
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
|
|
||||||
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
|
|
||||||
measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
|
measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
|
||||||
xTimerStart(dimTimer, 0);
|
|
||||||
xTimerStart(measureBatteryTimer, portMAX_DELAY);
|
xTimerStart(measureBatteryTimer, portMAX_DELAY);
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
|
@ -209,14 +192,11 @@ void SystemTask::Work() {
|
||||||
if (!bleController.IsFirmwareUpdating()) {
|
if (!bleController.IsFirmwareUpdating()) {
|
||||||
doNotGoToSleep = false;
|
doNotGoToSleep = false;
|
||||||
}
|
}
|
||||||
ReloadIdleTimer();
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||||
break;
|
break;
|
||||||
case Messages::DisableSleeping:
|
case Messages::DisableSleeping:
|
||||||
doNotGoToSleep = true;
|
doNotGoToSleep = true;
|
||||||
break;
|
break;
|
||||||
case Messages::UpdateTimeOut:
|
|
||||||
xTimerChangePeriod(dimTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), 0);
|
|
||||||
break;
|
|
||||||
case Messages::GoToRunning:
|
case Messages::GoToRunning:
|
||||||
spi.Wakeup();
|
spi.Wakeup();
|
||||||
|
|
||||||
|
@ -225,7 +205,6 @@ void SystemTask::Work() {
|
||||||
touchPanel.Wakeup();
|
touchPanel.Wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
xTimerStart(dimTimer, 0);
|
|
||||||
spiNorFlash.Wakeup();
|
spiNorFlash.Wakeup();
|
||||||
|
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
|
||||||
|
@ -236,7 +215,6 @@ void SystemTask::Work() {
|
||||||
}
|
}
|
||||||
|
|
||||||
state = SystemTaskState::Running;
|
state = SystemTaskState::Running;
|
||||||
isDimmed = false;
|
|
||||||
break;
|
break;
|
||||||
case Messages::TouchWakeUp: {
|
case Messages::TouchWakeUp: {
|
||||||
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
|
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
|
||||||
|
@ -258,13 +236,11 @@ void SystemTask::Work() {
|
||||||
}
|
}
|
||||||
state = SystemTaskState::GoingToSleep; // Already set in PushMessage()
|
state = SystemTaskState::GoingToSleep; // Already set in PushMessage()
|
||||||
NRF_LOG_INFO("[systemtask] Going to sleep");
|
NRF_LOG_INFO("[systemtask] Going to sleep");
|
||||||
xTimerStop(idleTimer, 0);
|
|
||||||
xTimerStop(dimTimer, 0);
|
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
|
||||||
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
|
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::GoToSleep);
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewTime:
|
case Messages::OnNewTime:
|
||||||
ReloadIdleTimer();
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
|
||||||
if (alarmController.State() == Controllers::AlarmController::AlarmState::Set) {
|
if (alarmController.State() == Controllers::AlarmController::AlarmState::Set) {
|
||||||
alarmController.ScheduleAlarm();
|
alarmController.ScheduleAlarm();
|
||||||
|
@ -275,7 +251,7 @@ void SystemTask::Work() {
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
} else {
|
} else {
|
||||||
ReloadIdleTimer();
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||||
}
|
}
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
|
||||||
}
|
}
|
||||||
|
@ -293,7 +269,7 @@ void SystemTask::Work() {
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
|
||||||
break;
|
break;
|
||||||
case Messages::BleConnected:
|
case Messages::BleConnected:
|
||||||
ReloadIdleTimer();
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||||
isBleDiscoveryTimerRunning = true;
|
isBleDiscoveryTimerRunning = true;
|
||||||
bleDiscoveryTimer = 5;
|
bleDiscoveryTimer = 5;
|
||||||
break;
|
break;
|
||||||
|
@ -309,7 +285,6 @@ void SystemTask::Work() {
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
doNotGoToSleep = false;
|
doNotGoToSleep = false;
|
||||||
xTimerStart(dimTimer, 0);
|
|
||||||
break;
|
break;
|
||||||
case Messages::StartFileTransfer:
|
case Messages::StartFileTransfer:
|
||||||
NRF_LOG_INFO("[systemtask] FS Started");
|
NRF_LOG_INFO("[systemtask] FS Started");
|
||||||
|
@ -322,12 +297,10 @@ void SystemTask::Work() {
|
||||||
case Messages::StopFileTransfer:
|
case Messages::StopFileTransfer:
|
||||||
NRF_LOG_INFO("[systemtask] FS Stopped");
|
NRF_LOG_INFO("[systemtask] FS Stopped");
|
||||||
doNotGoToSleep = false;
|
doNotGoToSleep = false;
|
||||||
xTimerStart(dimTimer, 0);
|
|
||||||
// TODO add intent of fs access icon or something
|
// TODO add intent of fs access icon or something
|
||||||
break;
|
break;
|
||||||
case Messages::OnTouchEvent:
|
case Messages::OnTouchEvent:
|
||||||
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
|
if (touchHandler.ProcessTouchInfo(touchPanel.GetTouchInfo())) {
|
||||||
ReloadIdleTimer();
|
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -395,7 +368,6 @@ void SystemTask::Work() {
|
||||||
case Messages::OnChargingEvent:
|
case Messages::OnChargingEvent:
|
||||||
batteryController.ReadPowerState();
|
batteryController.ReadPowerState();
|
||||||
displayApp.PushMessage(Applications::Display::Messages::OnChargingEvent);
|
displayApp.PushMessage(Applications::Display::Messages::OnChargingEvent);
|
||||||
ReloadIdleTimer();
|
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
|
@ -481,7 +453,7 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReloadIdleTimer();
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
||||||
|
|
||||||
using Actions = Controllers::ButtonActions;
|
using Actions = Controllers::ButtonActions;
|
||||||
|
|
||||||
|
@ -542,33 +514,3 @@ void SystemTask::PushMessage(System::Messages msg) {
|
||||||
xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY);
|
xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTask::OnDim() {
|
|
||||||
if (doNotGoToSleep) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NRF_LOG_INFO("Dim timeout -> Dim screen")
|
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::DimScreen);
|
|
||||||
xTimerStart(idleTimer, 0);
|
|
||||||
isDimmed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemTask::OnIdle() {
|
|
||||||
if (doNotGoToSleep) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
NRF_LOG_INFO("Idle timeout -> Going to sleep")
|
|
||||||
PushMessage(Messages::GoToSleep);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SystemTask::ReloadIdleTimer() {
|
|
||||||
if (state != SystemTaskState::Running) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isDimmed) {
|
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
|
|
||||||
isDimmed = false;
|
|
||||||
}
|
|
||||||
xTimerReset(dimTimer, 0);
|
|
||||||
xTimerStop(idleTimer, 0);
|
|
||||||
}
|
|
||||||
|
|
|
@ -84,6 +84,10 @@ namespace Pinetime {
|
||||||
void OnIdle();
|
void OnIdle();
|
||||||
void OnDim();
|
void OnDim();
|
||||||
|
|
||||||
|
bool IsSleepDisabled() {
|
||||||
|
return doNotGoToSleep;
|
||||||
|
}
|
||||||
|
|
||||||
Pinetime::Controllers::NimbleController& nimble() {
|
Pinetime::Controllers::NimbleController& nimble() {
|
||||||
return nimbleController;
|
return nimbleController;
|
||||||
};
|
};
|
||||||
|
@ -123,14 +127,10 @@ namespace Pinetime {
|
||||||
|
|
||||||
static void Process(void* instance);
|
static void Process(void* instance);
|
||||||
void Work();
|
void Work();
|
||||||
void ReloadIdleTimer();
|
|
||||||
bool isBleDiscoveryTimerRunning = false;
|
bool isBleDiscoveryTimerRunning = false;
|
||||||
uint8_t bleDiscoveryTimer = 0;
|
uint8_t bleDiscoveryTimer = 0;
|
||||||
TimerHandle_t dimTimer;
|
|
||||||
TimerHandle_t idleTimer;
|
|
||||||
TimerHandle_t measureBatteryTimer;
|
TimerHandle_t measureBatteryTimer;
|
||||||
bool doNotGoToSleep = false;
|
bool doNotGoToSleep = false;
|
||||||
bool isDimmed = false;
|
|
||||||
SystemTaskState state = SystemTaskState::Running;
|
SystemTaskState state = SystemTaskState::Running;
|
||||||
|
|
||||||
void HandleButtonAction(Controllers::ButtonActions action);
|
void HandleButtonAction(Controllers::ButtonActions action);
|
||||||
|
|
Loading…
Reference in a new issue