diff options
Diffstat (limited to 'src/systemtask')
-rw-r--r-- | src/systemtask/Messages.h | 5 | ||||
-rw-r--r-- | src/systemtask/SystemTask.cpp | 112 | ||||
-rw-r--r-- | src/systemtask/SystemTask.h | 5 |
3 files changed, 97 insertions, 25 deletions
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index b7142704..4d5ab4ce 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -21,11 +21,16 @@ namespace Pinetime { EnableSleeping, DisableSleeping, OnNewDay, + OnNewHour, + OnNewHalfHour, OnChargingEvent, + OnPairing, SetOffAlarm, StopRinging, MeasureBatteryTimerExpired, BatteryPercentageUpdated, + StartFileTransfer, + StopFileTransfer, }; } } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 4b03f9ac..e71ebc17 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -1,4 +1,4 @@ -#include "SystemTask.h" +#include "systemtask/SystemTask.h" #define min // workaround: nimble's min/max macros conflict with libstdc++ #define max #include <host/ble_gap.h> @@ -109,13 +109,15 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, batteryController, spiNorFlash, heartRateController, - motionController) { + motionController, + fs) { } void SystemTask::Start() { systemTasksMsgQueue = xQueueCreate(10, 1); - if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 350, this, 0, &taskHandle)) + if (pdPASS != xTaskCreate(SystemTask::Process, "MAIN", 350, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); + } } void SystemTask::Process(void* instance) { @@ -186,20 +188,22 @@ void SystemTask::Work() { pinConfig.skip_gpio_setup = false; pinConfig.hi_accuracy = false; pinConfig.is_watcher = false; - pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_TOGGLE; - pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown; + pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_TOGGLE); + pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pulldown); nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_event_enable(PinMap::Button, true); // Touchscreen - nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low); + nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, + static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup), + static_cast<nrf_gpio_pin_sense_t>(GPIO_PIN_CNF_SENSE_Low)); pinConfig.skip_gpio_setup = true; pinConfig.hi_accuracy = false; pinConfig.is_watcher = false; - pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; - pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup; + pinConfig.sense = static_cast<nrf_gpiote_polarity_t>(NRF_GPIOTE_POLARITY_HITOLO); + pinConfig.pull = static_cast<nrf_gpio_pin_pull_t>(GPIO_PIN_CNF_PULL_Pullup); nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); @@ -220,7 +224,6 @@ void SystemTask::Work() { xTimerStart(dimTimer, 0); xTimerStart(measureBatteryTimer, portMAX_DELAY); -// Suppress endless loop diagnostic #pragma clang diagnostic push #pragma ide diagnostic ignored "EndlessLoop" while (true) { @@ -236,6 +239,7 @@ void SystemTask::Work() { if (!bleController.IsFirmwareUpdating()) { doNotGoToSleep = false; } + ReloadIdleTimer(); break; case Messages::DisableSleeping: doNotGoToSleep = true; @@ -258,8 +262,9 @@ void SystemTask::Work() { displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning); heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp); - if (!bleController.IsConnected()) + if (!bleController.IsConnected()) { nimbleController.RestartFastAdv(); + } isSleeping = false; isWakingUp = false; @@ -278,6 +283,9 @@ void SystemTask::Work() { } } break; case Messages::GoToSleep: + if (doNotGoToSleep) { + break; + } isGoingToSleep = true; NRF_LOG_INFO("[systemtask] Going to sleep"); xTimerStop(idleTimer, 0); @@ -288,6 +296,9 @@ void SystemTask::Work() { case Messages::OnNewTime: ReloadIdleTimer(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime); + if (alarmController.State() == Controllers::AlarmController::AlarmState::Set) { + alarmController.ScheduleAlarm(); + } break; case Messages::OnNewNotification: if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) { @@ -323,8 +334,9 @@ void SystemTask::Work() { break; case Messages::BleFirmwareUpdateStarted: doNotGoToSleep = true; - if (isSleeping && !isWakingUp) + if (isSleeping && !isWakingUp) { GoToRunning(); + } displayApp.PushMessage(Pinetime::Applications::Display::Messages::BleFirmwareUpdateStarted); break; case Messages::BleFirmwareUpdateFinished: @@ -334,6 +346,19 @@ void SystemTask::Work() { doNotGoToSleep = false; xTimerStart(dimTimer, 0); break; + case Messages::StartFileTransfer: + NRF_LOG_INFO("[systemtask] FS Started"); + doNotGoToSleep = true; + if (isSleeping && !isWakingUp) + GoToRunning(); + // TODO add intent of fs access icon or something + break; + case Messages::StopFileTransfer: + NRF_LOG_INFO("[systemtask] FS Stopped"); + doNotGoToSleep = false; + xTimerStart(dimTimer, 0); + // TODO add intent of fs access icon or something + break; case Messages::OnTouchEvent: if (touchHandler.GetNewTouchInfo()) { touchHandler.UpdateLvglTouchPoint(); @@ -382,6 +407,26 @@ void SystemTask::Work() { // Remember we'll have to reset the counter next time we're awake stepCounterMustBeReset = true; break; + case Messages::OnNewHour: + using Pinetime::Controllers::AlarmController; + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours && alarmController.State() != AlarmController::AlarmState::Alerting) { + if (isSleeping && !isWakingUp) { + GoToRunning(); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + } + motorController.RunForDuration(35); + } + break; + case Messages::OnNewHalfHour: + using Pinetime::Controllers::AlarmController; + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours && alarmController.State() != AlarmController::AlarmState::Alerting) { + if (isSleeping && !isWakingUp) { + GoToRunning(); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + } + motorController.RunForDuration(35); + } + break; case Messages::OnChargingEvent: batteryController.ReadPowerState(); motorController.RunForDuration(15); @@ -396,6 +441,13 @@ void SystemTask::Work() { case Messages::BatteryPercentageUpdated: nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; + case Messages::OnPairing: + if (isSleeping && !isWakingUp) { + GoToRunning(); + } + motorController.RunForDuration(35); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowPairingKey); + break; default: break; @@ -417,19 +469,22 @@ void SystemTask::Work() { uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); dateTimeController.UpdateTime(systick_counter); NoInit_BackUpTime = dateTimeController.CurrentDateTime(); - if (!nrf_gpio_pin_read(PinMap::Button)) + if (!nrf_gpio_pin_read(PinMap::Button)) { watchdog.Kick(); + } } -// Clear diagnostic suppression #pragma clang diagnostic pop } + void SystemTask::UpdateMotion() { - if (isGoingToSleep or isWakingUp) + if (isGoingToSleep or isWakingUp) { return; + } - if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) + if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) { return; - + } if (stepCounterMustBeReset) { motionSensor.ResetStepCounter(); stepCounterMustBeReset = false; @@ -439,7 +494,13 @@ void SystemTask::UpdateMotion() { motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); - if (motionController.ShouldWakeUp(isSleeping)) { + + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && + motionController.Should_RaiseWake(isSleeping)) { + GoToRunning(); + } + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && + motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { GoToRunning(); } } @@ -477,15 +538,17 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) { } void SystemTask::GoToRunning() { - if (isGoingToSleep or (not isSleeping) or isWakingUp) + if (isGoingToSleep or (not isSleeping) or isWakingUp) { return; + } isWakingUp = true; PushMessage(Messages::GoToRunning); } void SystemTask::OnTouchEvent() { - if (isGoingToSleep) + if (isGoingToSleep) { return; + } if (!isSleeping) { PushMessage(Messages::OnTouchEvent); } else if (!isWakingUp) { @@ -497,7 +560,7 @@ void SystemTask::OnTouchEvent() { } void SystemTask::PushMessage(System::Messages msg) { - if (msg == Messages::GoToSleep) { + if (msg == Messages::GoToSleep && !doNotGoToSleep) { isGoingToSleep = true; } @@ -515,8 +578,9 @@ void SystemTask::PushMessage(System::Messages msg) { } void SystemTask::OnDim() { - if (doNotGoToSleep) + if (doNotGoToSleep) { return; + } NRF_LOG_INFO("Dim timeout -> Dim screen") displayApp.PushMessage(Pinetime::Applications::Display::Messages::DimScreen); xTimerStart(idleTimer, 0); @@ -524,15 +588,17 @@ void SystemTask::OnDim() { } void SystemTask::OnIdle() { - if (doNotGoToSleep) + if (doNotGoToSleep) { return; + } NRF_LOG_INFO("Idle timeout -> Going to sleep") PushMessage(Messages::GoToSleep); } void SystemTask::ReloadIdleTimer() { - if (isSleeping || isGoingToSleep) + if (isSleeping || isGoingToSleep) { return; + } if (isDimmed) { displayApp.PushMessage(Pinetime::Applications::Display::Messages::RestoreBrightness); isDimmed = false; diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 412878b1..abeffd2f 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -3,6 +3,7 @@ #include <memory> #include <FreeRTOS.h> +#include <queue.h> #include <task.h> #include <timers.h> #include <heartratetask/HeartRateTask.h> @@ -11,7 +12,7 @@ #include <drivers/PinMap.h> #include <components/motion/MotionController.h> -#include "SystemMonitor.h" +#include "systemtask/SystemMonitor.h" #include "components/battery/BatteryController.h" #include "components/ble/NimbleController.h" #include "components/ble/NotificationManager.h" @@ -33,7 +34,7 @@ #endif #include "drivers/Watchdog.h" -#include "Messages.h" +#include "systemtask/Messages.h" extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime; namespace Pinetime { |