diff options
Diffstat (limited to 'src/systemtask')
-rw-r--r-- | src/systemtask/Messages.h | 2 | ||||
-rw-r--r-- | src/systemtask/SystemTask.cpp | 35 | ||||
-rw-r--r-- | src/systemtask/SystemTask.h | 2 |
3 files changed, 18 insertions, 21 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 38e48c8f..f79fd8e5 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -141,7 +141,6 @@ void SystemTask::Work() { } dateTimeController.Register(this); batteryController.Register(this); - batteryController.Update(); motorController.Init(); motionSensor.SoftReset(); timerController.Register(this); @@ -163,19 +162,21 @@ void SystemTask::Work() { 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; @@ -186,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); @@ -350,18 +349,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; |