summaryrefslogtreecommitdiff
path: root/src/systemtask/SystemTask.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemtask/SystemTask.cpp')
-rw-r--r--src/systemtask/SystemTask.cpp193
1 files changed, 2 insertions, 191 deletions
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index c121808..c333aad 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -28,20 +28,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) {
auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
@@ -185,10 +171,7 @@ void SystemTask::Work() {
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);
- xTimerStart(dimTimer, 0);
xTimerStart(measureBatteryTimer, portMAX_DELAY);
#pragma clang diagnostic push
@@ -200,75 +183,13 @@ void SystemTask::Work() {
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
Messages message = static_cast<Messages>(msg);
switch (message) {
- case Messages::EnableSleeping:
- // Make sure that exiting an app doesn't enable sleeping,
- // if the exiting was caused by a firmware update
- if (!bleController.IsFirmwareUpdating()) {
- doNotGoToSleep = false;
- }
- ReloadIdleTimer();
- break;
- case Messages::DisableSleeping:
- doNotGoToSleep = true;
- break;
case Messages::UpdateTimeOut:
- xTimerChangePeriod(dimTimer, pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), 0);
- break;
- case Messages::GoToRunning:
- spi.Wakeup();
-
- // Double Tap needs the touch screen to be in normal mode
- if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
- touchPanel.Wakeup();
- }
-
- xTimerStart(dimTimer, 0);
- spiNorFlash.Wakeup();
- lcd.Wakeup();
-
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
-
- if (!bleController.IsConnected()) {
- nimbleController.RestartFastAdv();
- }
-
- isSleeping = false;
- isWakingUp = false;
- isDimmed = false;
- break;
- case Messages::TouchWakeUp: {
- if (touchHandler.GetNewTouchInfo()) {
- auto gesture = touchHandler.GestureGet();
- if (gesture != Pinetime::Drivers::Cst816S::Gestures::None and
- ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
- settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or
- (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
- settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
- GoToRunning();
- }
- }
- } break;
- case Messages::GoToSleep:
- if (doNotGoToSleep) {
- break;
- }
- isGoingToSleep = true;
- NRF_LOG_INFO("[systemtask] Going to sleep");
- xTimerStop(idleTimer, 0);
- xTimerStop(dimTimer, 0);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToSleep);
break;
case Messages::OnNewTime:
- ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
break;
case Messages::OnNewNotification:
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) {
- if (isSleeping && !isWakingUp) {
- GoToRunning();
- } else {
- ReloadIdleTimer();
- }
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
}
break;
@@ -276,29 +197,21 @@ void SystemTask::Work() {
motorController.StopRinging();
break;
case Messages::BleConnected:
- ReloadIdleTimer();
isBleDiscoveryTimerRunning = true;
bleDiscoveryTimer = 5;
break;
case Messages::BleFirmwareUpdateStarted:
- doNotGoToSleep = true;
- if (isSleeping && !isWakingUp) {
- GoToRunning();
- }
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
break;
case Messages::BleFirmwareUpdateFinished:
if (bleController.State() == Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated) {
NVIC_SystemReset();
}
- doNotGoToSleep = false;
- xTimerStart(dimTimer, 0);
break;
case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) {
touchHandler.UpdateLvglTouchPoint();
}
- ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::HandleButtonEvent: {
@@ -307,12 +220,6 @@ void SystemTask::Work() {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
} else {
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
- // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
- if (IsSleeping()) {
- fastWakeUpDone = true;
- GoToRunning();
- break;
- }
}
HandleButtonAction(action);
} break;
@@ -320,23 +227,6 @@ void SystemTask::Work() {
auto action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Timer);
HandleButtonAction(action);
} break;
- case Messages::OnDisplayTaskSleeping:
- if (BootloaderVersion::IsValid()) {
- // First versions of the bootloader do not expose their version and cannot initialize the SPI NOR FLASH
- // if it's in sleep mode. Avoid bricked device by disabling sleep mode on these versions.
- spiNorFlash.Sleep();
- }
- lcd.Sleep();
- spi.Sleep();
-
- // Double Tap needs the touch screen to be in normal mode
- if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
- touchPanel.Sleep();
- }
-
- isSleeping = true;
- isGoingToSleep = false;
- break;
case Messages::OnNewDay:
// We might be sleeping (with TWI device disabled.
// Remember we'll have to reset the counter next time we're awake
@@ -345,10 +235,6 @@ void SystemTask::Work() {
case Messages::OnChargingEvent:
batteryController.ReadPowerState();
motorController.RunForDuration(15);
- ReloadIdleTimer();
- if (isSleeping && !isWakingUp) {
- GoToRunning();
- }
break;
case Messages::MeasureBatteryTimerExpired:
batteryController.MeasureVoltage();
@@ -383,14 +269,6 @@ void SystemTask::Work() {
}
void SystemTask::UpdateMotion() {
- if (isGoingToSleep or isWakingUp) {
- return;
- }
-
- if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) {
- // Could we use here the accelerometer's low energy tilt-to-wake function?
- return;
- }
if (stepCounterMustBeReset) {
motionSensor.ResetStepCounter();
stepCounterMustBeReset = false;
@@ -401,27 +279,14 @@ void SystemTask::UpdateMotion() {
motionController.IsSensorOk(motionSensor.IsOk());
motionController.Update(motionValues.x, motionValues.y, motionValues.z);
- if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
- motionController.Should_RaiseWake(isSleeping)) {
- GoToRunning();
- }
}
void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
- if (IsSleeping()) {
- return;
- }
-
- ReloadIdleTimer();
-
using Actions = Controllers::ButtonActions;
switch (action) {
case Actions::Click:
- // If the first action after fast wakeup is a click, it should be ignored.
- if (!fastWakeUpDone && !isGoingToSleep) {
- displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
- }
+ displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
break;
case Actions::DoubleClick:
displayApp.PushMessage(Applications::Display::Messages::ButtonDoubleClicked);
@@ -435,37 +300,13 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
default:
return;
}
-
- fastWakeUpDone = false;
-}
-
-void SystemTask::GoToRunning() {
- if (isGoingToSleep or (not isSleeping) or isWakingUp) {
- return;
- }
- isWakingUp = true;
- PushMessage(Messages::GoToRunning);
}
void SystemTask::OnTouchEvent() {
- if (isGoingToSleep) {
- return;
- }
- if (!isSleeping) {
- PushMessage(Messages::OnTouchEvent);
- } else if (!isWakingUp) {
- if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
- settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
- PushMessage(Messages::TouchWakeUp);
- }
- }
+ PushMessage(Messages::OnTouchEvent);
}
void SystemTask::PushMessage(System::Messages msg) {
- if (msg == Messages::GoToSleep && !doNotGoToSleep) {
- isGoingToSleep = true;
- }
-
if (in_isr()) {
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
@@ -478,33 +319,3 @@ void SystemTask::PushMessage(System::Messages msg) {
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 (isSleeping || isGoingToSleep) {
- return;
- }
- if (isDimmed) {
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness);
- isDimmed = false;
- }
- xTimerReset(dimTimer, 0);
- xTimerStop(idleTimer, 0);
-}