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
This commit is contained in:
David Ventura
2021-05-16 21:13:22 +02:00
committed by GitHub
parent 5b2472c4bc
commit 9342d62a44
4 changed files with 35 additions and 7 deletions

View File

@@ -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,