Systemtask : replace enum SystemTaskState by an enum class.

This commit is contained in:
Jean-François Milants 2022-05-08 13:29:02 +02:00
parent ae2b9d30d6
commit dedb397ae0
2 changed files with 25 additions and 25 deletions

View file

@ -258,7 +258,7 @@ void SystemTask::Work() {
nimbleController.RestartFastAdv(); nimbleController.RestartFastAdv();
} }
state = Running; state = SystemTaskState::Running;
isDimmed = false; isDimmed = false;
break; break;
case Messages::TouchWakeUp: { case Messages::TouchWakeUp: {
@ -277,7 +277,7 @@ void SystemTask::Work() {
if (doNotGoToSleep) { if (doNotGoToSleep) {
break; break;
} }
state = 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(idleTimer, 0);
xTimerStop(dimTimer, 0); xTimerStop(dimTimer, 0);
@ -293,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 (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} else { } else {
ReloadIdleTimer(); ReloadIdleTimer();
@ -302,14 +302,14 @@ void SystemTask::Work() {
} }
break; break;
case Messages::OnTimerDone: case Messages::OnTimerDone:
if (state == Sleeping) { if (state == SystemTaskState::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 (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
motorController.StartRinging(); motorController.StartRinging();
@ -325,7 +325,7 @@ void SystemTask::Work() {
break; break;
case Messages::BleFirmwareUpdateStarted: case Messages::BleFirmwareUpdateStarted:
doNotGoToSleep = true; doNotGoToSleep = true;
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted); displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted);
@ -340,7 +340,7 @@ 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 (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
// TODO add intent of fs access icon or something // TODO add intent of fs access icon or something
@ -391,7 +391,7 @@ void SystemTask::Work() {
touchPanel.Sleep(); touchPanel.Sleep();
} }
state = Sleeping; state = SystemTaskState::Sleeping;
break; break;
case Messages::OnNewDay: case Messages::OnNewDay:
// We might be sleeping (with TWI device disabled. // We might be sleeping (with TWI device disabled.
@ -402,7 +402,7 @@ void SystemTask::Work() {
using Pinetime::Controllers::AlarmController; using Pinetime::Controllers::AlarmController;
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours && if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours &&
alarmController.State() != AlarmController::AlarmState::Alerting) { alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
} }
@ -413,7 +413,7 @@ void SystemTask::Work() {
using Pinetime::Controllers::AlarmController; using Pinetime::Controllers::AlarmController;
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours && if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours &&
alarmController.State() != AlarmController::AlarmState::Alerting) { alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock);
} }
@ -424,7 +424,7 @@ void SystemTask::Work() {
batteryController.ReadPowerState(); batteryController.ReadPowerState();
motorController.RunForDuration(15); motorController.RunForDuration(15);
ReloadIdleTimer(); ReloadIdleTimer();
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
break; break;
@ -435,7 +435,7 @@ void SystemTask::Work() {
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
break; break;
case Messages::OnPairing: case Messages::OnPairing:
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
motorController.RunForDuration(35); motorController.RunForDuration(35);
@ -476,11 +476,11 @@ void SystemTask::Work() {
} }
void SystemTask::UpdateMotion() { void SystemTask::UpdateMotion() {
if (state == GoingToSleep || state == WakingUp) { if (state == SystemTaskState::GoingToSleep || state == SystemTaskState::WakingUp) {
return; return;
} }
if (state == Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || if (state == SystemTaskState::Sleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) { settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
return; return;
} }
@ -496,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(state == Sleeping)) { motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) {
GoToRunning(); GoToRunning();
} }
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
@ -517,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 && state != GoingToSleep) { if (!fastWakeUpDone && state != SystemTaskState::GoingToSleep) {
displayApp.PushMessage(Applications::Display::Messages::ButtonPushed); displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
} }
break; break;
@ -538,16 +538,16 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
} }
void SystemTask::GoToRunning() { void SystemTask::GoToRunning() {
if (state == Sleeping) { if (state == SystemTaskState::Sleeping) {
state = WakingUp; state = SystemTaskState::WakingUp;
PushMessage(Messages::GoToRunning); PushMessage(Messages::GoToRunning);
} }
} }
void SystemTask::OnTouchEvent() { void SystemTask::OnTouchEvent() {
if (state == Running) { if (state == SystemTaskState::Running) {
PushMessage(Messages::OnTouchEvent); PushMessage(Messages::OnTouchEvent);
} else if (state == Sleeping) { } else if (state == SystemTaskState::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);
@ -557,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) {
state = GoingToSleep; state = SystemTaskState::GoingToSleep;
} }
if (in_isr()) { if (in_isr()) {
@ -592,7 +592,7 @@ void SystemTask::OnIdle() {
} }
void SystemTask::ReloadIdleTimer() { void SystemTask::ReloadIdleTimer() {
if (state != Running) { if (state != SystemTaskState::Running) {
return; return;
} }
if (isDimmed) { if (isDimmed) {

View file

@ -53,7 +53,7 @@ namespace Pinetime {
namespace System { namespace System {
class SystemTask { class SystemTask {
public: public:
enum SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp }; enum class 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,
@ -92,7 +92,7 @@ namespace Pinetime {
}; };
bool IsSleeping() const { bool IsSleeping() const {
return state == Sleeping || state == WakingUp; return state == SystemTaskState::Sleeping || state == SystemTaskState::WakingUp;
} }
private: private:
@ -137,7 +137,7 @@ namespace Pinetime {
TimerHandle_t measureBatteryTimer; TimerHandle_t measureBatteryTimer;
bool doNotGoToSleep = false; bool doNotGoToSleep = false;
bool isDimmed = false; bool isDimmed = false;
SystemTaskState state = Running; SystemTaskState state = SystemTaskState::Running;
void HandleButtonAction(Controllers::ButtonActions action); void HandleButtonAction(Controllers::ButtonActions action);
bool fastWakeUpDone = false; bool fastWakeUpDone = false;