diff options
Diffstat (limited to 'src/systemtask')
-rw-r--r-- | src/systemtask/Messages.h | 2 | ||||
-rw-r--r-- | src/systemtask/SystemTask.cpp | 57 | ||||
-rw-r--r-- | src/systemtask/SystemTask.h | 2 |
3 files changed, 33 insertions, 28 deletions
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index bd1de234..5aa218d2 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -24,7 +24,7 @@ namespace Pinetime { SetOffAlarm, StopRinging, MeasureBatteryTimerExpired, - BatteryMeasurementDone, + BatteryPercentageUpdated, }; } } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c162..f1c5165a 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -23,6 +23,7 @@ #include "drivers/Hrs3300.h" #include "drivers/PinMap.h" #include "main.h" +#include "BootErrors.h" #include <memory> @@ -116,6 +117,8 @@ void SystemTask::Process(void* instance) { } void SystemTask::Work() { + BootErrors bootError = BootErrors::None; + watchdog.Setup(7); watchdog.Start(); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); @@ -133,10 +136,11 @@ void SystemTask::Work() { lcd.Init(); twiMaster.Init(); - touchPanel.Init(); + if (!touchPanel.Init()) { + bootError = BootErrors::TouchController; + } dateTimeController.Register(this); batteryController.Register(this); - batteryController.Update(); motorController.Init(); motionSensor.SoftReset(); timerController.Register(this); @@ -152,25 +156,27 @@ void SystemTask::Work() { settingsController.Init(); displayApp.Register(this); - displayApp.Start(); + displayApp.Start(bootError); heartRateSensor.Init(); heartRateSensor.Disable(); heartRateApp.Start(); - nrf_gpio_cfg_sense_input(PinMap::Button, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High); + // Button nrf_gpio_cfg_output(15); nrf_gpio_pin_set(15); nrfx_gpiote_in_config_t pinConfig; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; pinConfig.hi_accuracy = false; pinConfig.is_watcher = false; - pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; + pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = (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); pinConfig.skip_gpio_setup = true; @@ -181,18 +187,16 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); + // Power present pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = NRF_GPIO_PIN_NOPULL; pinConfig.is_watcher = false; pinConfig.hi_accuracy = false; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); + nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - if (nrf_gpio_pin_read(PinMap::PowerPresent)) { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); - } else { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); - } + batteryController.MeasureVoltage(); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); @@ -246,12 +250,13 @@ void SystemTask::Work() { isDimmed = false; break; case Messages::TouchWakeUp: { - if(touchHandler.GetNewTouchInfo()) { + 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)))) { + 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(); } } @@ -272,6 +277,8 @@ void SystemTask::Work() { if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) { if (isSleeping && !isWakingUp) { GoToRunning(); + } else { + ReloadIdleTimer(); } displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification); } @@ -345,18 +352,18 @@ void SystemTask::Work() { stepCounterMustBeReset = true; break; case Messages::OnChargingEvent: - batteryController.Update(); + batteryController.ReadPowerState(); motorController.RunForDuration(15); + ReloadIdleTimer(); + if (isSleeping && !isWakingUp) { + GoToRunning(); + } break; case Messages::MeasureBatteryTimerExpired: - sendBatteryNotification = true; - batteryController.Update(); + batteryController.MeasureVoltage(); break; - case Messages::BatteryMeasurementDone: - if (sendBatteryNotification) { - sendBatteryNotification = false; - nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); - } + case Messages::BatteryPercentageUpdated: + nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; default: diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 1fcfeb8a..879c1be8 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -133,14 +133,12 @@ namespace Pinetime { TimerHandle_t dimTimer; TimerHandle_t idleTimer; TimerHandle_t measureBatteryTimer; - bool sendBatteryNotification = false; bool doNotGoToSleep = false; void GoToRunning(); void UpdateMotion(); bool stepCounterMustBeReset = false; static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000); - TickType_t lastBatteryNotificationTime = 0; #if configUSE_TRACE_FACILITY == 1 SystemMonitor<FreeRtosMonitor> monitor; |