Simplify systemtask states
This commit is contained in:
parent
beddfc346d
commit
ae2b9d30d6
|
@ -258,8 +258,7 @@ void SystemTask::Work() {
|
||||||
nimbleController.RestartFastAdv();
|
nimbleController.RestartFastAdv();
|
||||||
}
|
}
|
||||||
|
|
||||||
isSleeping = false;
|
state = Running;
|
||||||
isWakingUp = false;
|
|
||||||
isDimmed = false;
|
isDimmed = false;
|
||||||
break;
|
break;
|
||||||
case Messages::TouchWakeUp: {
|
case Messages::TouchWakeUp: {
|
||||||
|
@ -278,7 +277,7 @@ void SystemTask::Work() {
|
||||||
if (doNotGoToSleep) {
|
if (doNotGoToSleep) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
isGoingToSleep = true;
|
state = GoingToSleep; // Already set in PushMessage()
|
||||||
NRF_LOG_INFO("[systemtask] Going to sleep");
|
NRF_LOG_INFO("[systemtask] Going to sleep");
|
||||||
xTimerStop(idleTimer, 0);
|
xTimerStop(idleTimer, 0);
|
||||||
xTimerStop(dimTimer, 0);
|
xTimerStop(dimTimer, 0);
|
||||||
|
@ -294,7 +293,7 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewNotification:
|
case Messages::OnNewNotification:
|
||||||
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) {
|
if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) {
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
} else {
|
} else {
|
||||||
ReloadIdleTimer();
|
ReloadIdleTimer();
|
||||||
|
@ -303,14 +302,14 @@ void SystemTask::Work() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Messages::OnTimerDone:
|
case Messages::OnTimerDone:
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
motorController.RunForDuration(35);
|
motorController.RunForDuration(35);
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
||||||
break;
|
break;
|
||||||
case Messages::SetOffAlarm:
|
case Messages::SetOffAlarm:
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
motorController.StartRinging();
|
motorController.StartRinging();
|
||||||
|
@ -326,7 +325,7 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::BleFirmwareUpdateStarted:
|
case Messages::BleFirmwareUpdateStarted:
|
||||||
doNotGoToSleep = true;
|
doNotGoToSleep = true;
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
|
||||||
|
@ -341,8 +340,9 @@ void SystemTask::Work() {
|
||||||
case Messages::StartFileTransfer:
|
case Messages::StartFileTransfer:
|
||||||
NRF_LOG_INFO("[systemtask] FS Started");
|
NRF_LOG_INFO("[systemtask] FS Started");
|
||||||
doNotGoToSleep = true;
|
doNotGoToSleep = true;
|
||||||
if (isSleeping && !isWakingUp)
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
|
}
|
||||||
// TODO add intent of fs access icon or something
|
// TODO add intent of fs access icon or something
|
||||||
break;
|
break;
|
||||||
case Messages::StopFileTransfer:
|
case Messages::StopFileTransfer:
|
||||||
|
@ -391,8 +391,7 @@ void SystemTask::Work() {
|
||||||
touchPanel.Sleep();
|
touchPanel.Sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
isSleeping = true;
|
state = Sleeping;
|
||||||
isGoingToSleep = false;
|
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewDay:
|
case Messages::OnNewDay:
|
||||||
// We might be sleeping (with TWI device disabled.
|
// We might be sleeping (with TWI device disabled.
|
||||||
|
@ -401,8 +400,9 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewHour:
|
case Messages::OnNewHour:
|
||||||
using Pinetime::Controllers::AlarmController;
|
using Pinetime::Controllers::AlarmController;
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours && alarmController.State() != AlarmController::AlarmState::Alerting) {
|
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours &&
|
||||||
if (isSleeping && !isWakingUp) {
|
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
||||||
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
|
||||||
}
|
}
|
||||||
|
@ -411,8 +411,9 @@ void SystemTask::Work() {
|
||||||
break;
|
break;
|
||||||
case Messages::OnNewHalfHour:
|
case Messages::OnNewHalfHour:
|
||||||
using Pinetime::Controllers::AlarmController;
|
using Pinetime::Controllers::AlarmController;
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours && alarmController.State() != AlarmController::AlarmState::Alerting) {
|
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours &&
|
||||||
if (isSleeping && !isWakingUp) {
|
alarmController.State() != AlarmController::AlarmState::Alerting) {
|
||||||
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
|
||||||
}
|
}
|
||||||
|
@ -423,7 +424,7 @@ void SystemTask::Work() {
|
||||||
batteryController.ReadPowerState();
|
batteryController.ReadPowerState();
|
||||||
motorController.RunForDuration(15);
|
motorController.RunForDuration(15);
|
||||||
ReloadIdleTimer();
|
ReloadIdleTimer();
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -434,7 +435,7 @@ void SystemTask::Work() {
|
||||||
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
|
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
|
||||||
break;
|
break;
|
||||||
case Messages::OnPairing:
|
case Messages::OnPairing:
|
||||||
if (isSleeping && !isWakingUp) {
|
if (state == Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
motorController.RunForDuration(35);
|
motorController.RunForDuration(35);
|
||||||
|
@ -475,14 +476,15 @@ void SystemTask::Work() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTask::UpdateMotion() {
|
void SystemTask::UpdateMotion() {
|
||||||
if (isGoingToSleep or isWakingUp) {
|
if (state == GoingToSleep || state == WakingUp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
|
if (state == Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
|
||||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
|
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stepCounterMustBeReset) {
|
if (stepCounterMustBeReset) {
|
||||||
motionSensor.ResetStepCounter();
|
motionSensor.ResetStepCounter();
|
||||||
stepCounterMustBeReset = false;
|
stepCounterMustBeReset = false;
|
||||||
|
@ -494,7 +496,7 @@ void SystemTask::UpdateMotion() {
|
||||||
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
|
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
|
||||||
|
|
||||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
|
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
|
||||||
motionController.Should_RaiseWake(isSleeping)) {
|
motionController.Should_RaiseWake(state == Sleeping)) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
}
|
}
|
||||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
|
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
|
||||||
|
@ -515,7 +517,7 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case Actions::Click:
|
case Actions::Click:
|
||||||
// If the first action after fast wakeup is a click, it should be ignored.
|
// If the first action after fast wakeup is a click, it should be ignored.
|
||||||
if (!fastWakeUpDone && !isGoingToSleep) {
|
if (!fastWakeUpDone && state != GoingToSleep) {
|
||||||
displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
|
displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -536,20 +538,16 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTask::GoToRunning() {
|
void SystemTask::GoToRunning() {
|
||||||
if (isGoingToSleep or (not isSleeping) or isWakingUp) {
|
if (state == Sleeping) {
|
||||||
return;
|
state = WakingUp;
|
||||||
}
|
|
||||||
isWakingUp = true;
|
|
||||||
PushMessage(Messages::GoToRunning);
|
PushMessage(Messages::GoToRunning);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SystemTask::OnTouchEvent() {
|
void SystemTask::OnTouchEvent() {
|
||||||
if (isGoingToSleep) {
|
if (state == Running) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!isSleeping) {
|
|
||||||
PushMessage(Messages::OnTouchEvent);
|
PushMessage(Messages::OnTouchEvent);
|
||||||
} else if (!isWakingUp) {
|
} else if (state == Sleeping) {
|
||||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
|
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap) or
|
||||||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||||
PushMessage(Messages::TouchWakeUp);
|
PushMessage(Messages::TouchWakeUp);
|
||||||
|
@ -559,7 +557,7 @@ void SystemTask::OnTouchEvent() {
|
||||||
|
|
||||||
void SystemTask::PushMessage(System::Messages msg) {
|
void SystemTask::PushMessage(System::Messages msg) {
|
||||||
if (msg == Messages::GoToSleep && !doNotGoToSleep) {
|
if (msg == Messages::GoToSleep && !doNotGoToSleep) {
|
||||||
isGoingToSleep = true;
|
state = GoingToSleep;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_isr()) {
|
if (in_isr()) {
|
||||||
|
@ -594,7 +592,7 @@ void SystemTask::OnIdle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemTask::ReloadIdleTimer() {
|
void SystemTask::ReloadIdleTimer() {
|
||||||
if (isSleeping || isGoingToSleep) {
|
if (state != Running) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isDimmed) {
|
if (isDimmed) {
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace Pinetime {
|
||||||
namespace System {
|
namespace System {
|
||||||
class SystemTask {
|
class SystemTask {
|
||||||
public:
|
public:
|
||||||
|
enum SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
|
||||||
SystemTask(Drivers::SpiMaster& spi,
|
SystemTask(Drivers::SpiMaster& spi,
|
||||||
Drivers::St7789& lcd,
|
Drivers::St7789& lcd,
|
||||||
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
||||||
|
@ -91,7 +92,7 @@ namespace Pinetime {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool IsSleeping() const {
|
bool IsSleeping() const {
|
||||||
return isSleeping;
|
return state == Sleeping || state == WakingUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -110,10 +111,6 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::TimerController& timerController;
|
Pinetime::Controllers::TimerController& timerController;
|
||||||
Pinetime::Controllers::AlarmController& alarmController;
|
Pinetime::Controllers::AlarmController& alarmController;
|
||||||
QueueHandle_t systemTasksMsgQueue;
|
QueueHandle_t systemTasksMsgQueue;
|
||||||
std::atomic<bool> isSleeping {false};
|
|
||||||
std::atomic<bool> isGoingToSleep {false};
|
|
||||||
std::atomic<bool> isWakingUp {false};
|
|
||||||
std::atomic<bool> isDimmed {false};
|
|
||||||
Pinetime::Drivers::Watchdog& watchdog;
|
Pinetime::Drivers::Watchdog& watchdog;
|
||||||
Pinetime::Controllers::NotificationManager& notificationManager;
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
||||||
Pinetime::Controllers::MotorController& motorController;
|
Pinetime::Controllers::MotorController& motorController;
|
||||||
|
@ -139,6 +136,8 @@ namespace Pinetime {
|
||||||
TimerHandle_t idleTimer;
|
TimerHandle_t idleTimer;
|
||||||
TimerHandle_t measureBatteryTimer;
|
TimerHandle_t measureBatteryTimer;
|
||||||
bool doNotGoToSleep = false;
|
bool doNotGoToSleep = false;
|
||||||
|
bool isDimmed = false;
|
||||||
|
SystemTaskState state = Running;
|
||||||
|
|
||||||
void HandleButtonAction(Controllers::ButtonActions action);
|
void HandleButtonAction(Controllers::ButtonActions action);
|
||||||
bool fastWakeUpDone = false;
|
bool fastWakeUpDone = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user