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:
parent
5b2472c4bc
commit
9342d62a44
|
@ -15,7 +15,6 @@ Battery::Battery() {
|
||||||
|
|
||||||
void Battery::Init() {
|
void Battery::Init() {
|
||||||
nrf_gpio_cfg_input(chargingPin, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup);
|
nrf_gpio_cfg_input(chargingPin, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup);
|
||||||
nrf_gpio_cfg_input(powerPresentPin, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Battery::Update() {
|
void Battery::Update() {
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -101,11 +101,13 @@ Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress};
|
||||||
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
|
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
|
||||||
|
|
||||||
TimerHandle_t debounceTimer;
|
TimerHandle_t debounceTimer;
|
||||||
|
TimerHandle_t debounceChargeTimer;
|
||||||
Pinetime::Controllers::Battery batteryController;
|
Pinetime::Controllers::Battery batteryController;
|
||||||
Pinetime::Controllers::Ble bleController;
|
Pinetime::Controllers::Ble bleController;
|
||||||
void ble_manager_set_ble_connection_callback(void (*connection)());
|
void ble_manager_set_ble_connection_callback(void (*connection)());
|
||||||
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
|
||||||
static constexpr uint8_t pinTouchIrq = 28;
|
static constexpr uint8_t pinTouchIrq = 28;
|
||||||
|
static constexpr uint8_t pinPowerPresentIrq = 19;
|
||||||
std::unique_ptr<Pinetime::System::SystemTask> systemTask;
|
std::unique_ptr<Pinetime::System::SystemTask> systemTask;
|
||||||
|
|
||||||
Pinetime::Controllers::Settings settingsController {spiNorFlash};
|
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;
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||||
|
|
||||||
|
if (pin == pinPowerPresentIrq and action == NRF_GPIOTE_POLARITY_TOGGLE) {
|
||||||
|
xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken);
|
||||||
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken);
|
xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken);
|
||||||
portYIELD_FROM_ISR(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) {
|
void DebounceTimerCallback(TimerHandle_t xTimer) {
|
||||||
xTimerStop(xTimer, 0);
|
xTimerStop(xTimer, 0);
|
||||||
systemTask->OnButtonPushed();
|
systemTask->OnButtonPushed();
|
||||||
|
@ -248,6 +262,7 @@ int main(void) {
|
||||||
nrf_drv_clock_init();
|
nrf_drv_clock_init();
|
||||||
|
|
||||||
debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback);
|
debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback);
|
||||||
|
debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback);
|
||||||
|
|
||||||
systemTask = std::make_unique<Pinetime::System::SystemTask>(spi,
|
systemTask = std::make_unique<Pinetime::System::SystemTask>(spi,
|
||||||
lcd,
|
lcd,
|
||||||
|
|
|
@ -149,6 +149,16 @@ void SystemTask::Work() {
|
||||||
|
|
||||||
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||||
|
|
||||||
|
nrf_gpio_cfg_sense_input(pinPowerPresentIrq, (nrf_gpio_pin_pull_t) NRF_GPIO_PIN_NOPULL, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
nrfx_gpiote_in_init(pinPowerPresentIrq, &pinConfig, nrfx_gpiote_evt_handler);
|
||||||
|
|
||||||
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), pdFALSE, this, IdleTimerCallback);
|
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut()), pdFALSE, this, IdleTimerCallback);
|
||||||
xTimerStart(idleTimer, 0);
|
xTimerStart(idleTimer, 0);
|
||||||
|
|
||||||
|
@ -161,12 +171,9 @@ void SystemTask::Work() {
|
||||||
uint8_t msg;
|
uint8_t msg;
|
||||||
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
|
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
|
||||||
|
|
||||||
// call the battery controller or use the MSG in DisplayApp to get the battery status ???
|
|
||||||
// it is necessary to validate which is the most efficient
|
|
||||||
batteryController.Update();
|
batteryController.Update();
|
||||||
// displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
|
// the battery does not emit events when changing charge levels, so we piggyback
|
||||||
// analyze a more efficient way to do this refreshment
|
// on any system event to read and update the current values
|
||||||
// this and the UpdateMotion(); can be called on a timer to be independent of the main process ???
|
|
||||||
|
|
||||||
Messages message = static_cast<Messages>(msg);
|
Messages message = static_cast<Messages>(msg);
|
||||||
switch (message) {
|
switch (message) {
|
||||||
|
@ -274,6 +281,11 @@ void SystemTask::Work() {
|
||||||
// Remember we'll have to reset the counter next time we're awake
|
// Remember we'll have to reset the counter next time we're awake
|
||||||
stepCounterMustBeReset = true;
|
stepCounterMustBeReset = true;
|
||||||
break;
|
break;
|
||||||
|
case Messages::OnChargingEvent:
|
||||||
|
motorController.SetDuration(15);
|
||||||
|
// Battery level is updated on every message - there's no need to do anything
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,8 @@ namespace Pinetime {
|
||||||
OnDisplayTaskSleeping,
|
OnDisplayTaskSleeping,
|
||||||
EnableSleeping,
|
EnableSleeping,
|
||||||
DisableSleeping,
|
DisableSleeping,
|
||||||
OnNewDay
|
OnNewDay,
|
||||||
|
OnChargingEvent
|
||||||
};
|
};
|
||||||
|
|
||||||
SystemTask(Drivers::SpiMaster& spi,
|
SystemTask(Drivers::SpiMaster& spi,
|
||||||
|
@ -121,6 +122,7 @@ namespace Pinetime {
|
||||||
static constexpr uint8_t pinLcdDataCommand = 18;
|
static constexpr uint8_t pinLcdDataCommand = 18;
|
||||||
static constexpr uint8_t pinButton = 13;
|
static constexpr uint8_t pinButton = 13;
|
||||||
static constexpr uint8_t pinTouchIrq = 28;
|
static constexpr uint8_t pinTouchIrq = 28;
|
||||||
|
static constexpr uint8_t pinPowerPresentIrq = 19;
|
||||||
|
|
||||||
static void Process(void* instance);
|
static void Process(void* instance);
|
||||||
void Work();
|
void Work();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user