diff options
| author | David Ventura <davidventura27@gmail.com> | 2021-05-16 19:13:22 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-16 19:13:22 (GMT) |
| commit | 9342d62a44830113241f0fdbc2951db93e474e26 (patch) | |
| tree | 20094e33a7eb84060af9976433f54cb58fb1b1cb /src/main.cpp | |
| parent | 5b2472c4bc84bbdd5e8326ea7562f6bc133cf00e (diff) | |
Emit event on power-present toggle (#320)
* Emit event on power-present toggle
* clang-format on changes
* also update battery status on any event
* update comments; remove double battery update
* Fix formatting
* Vibrate shortly on charging event
* debounce charge event
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 04cef6b..61194b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,11 +101,13 @@ Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress}; Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress}; TimerHandle_t debounceTimer; +TimerHandle_t debounceChargeTimer; Pinetime::Controllers::Battery batteryController; Pinetime::Controllers::Ble bleController; void ble_manager_set_ble_connection_callback(void (*connection)()); void ble_manager_set_ble_disconnection_callback(void (*disconnection)()); static constexpr uint8_t pinTouchIrq = 28; +static constexpr uint8_t pinPowerPresentIrq = 19; std::unique_ptr<Pinetime::System::SystemTask> systemTask; Pinetime::Controllers::Settings settingsController {spiNorFlash}; @@ -119,6 +121,13 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action } BaseType_t xHigherPriorityTaskWoken = pdFALSE; + + if (pin == pinPowerPresentIrq and action == NRF_GPIOTE_POLARITY_TOGGLE) { + xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + return; + } + xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } @@ -130,6 +139,11 @@ void vApplicationIdleHook(void) { } } +void DebounceTimerChargeCallback(TimerHandle_t xTimer) { + xTimerStop(xTimer, 0); + systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnChargingEvent); +} + void DebounceTimerCallback(TimerHandle_t xTimer) { xTimerStop(xTimer, 0); systemTask->OnButtonPushed(); @@ -248,6 +262,7 @@ int main(void) { nrf_drv_clock_init(); debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); + debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); systemTask = std::make_unique<Pinetime::System::SystemTask>(spi, lcd, |
