diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index dc15612e..95a30792 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -88,10 +88,16 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) { firstMeasurement = false; + lastPercentRemaining = percentRemaining; percentRemaining = newPercent; systemTask->PushMessage(System::Messages::BatteryPercentageUpdated); } + constexpr uint8_t lowBatteryThreshold {50}; + if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) { + systemTask->PushMessage(System::Messages::LowBattery); + } + nrfx_saadc_uninit(); isReading = false; } diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 5a7394c4..53eb7d19 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -39,6 +39,7 @@ namespace Pinetime { static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7; uint16_t voltage = 0; uint8_t percentRemaining = 0; + uint8_t lastPercentRemaining = 0; bool isFull = false; bool isCharging = false; diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index d730d74f..1883c396 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -29,6 +29,7 @@ namespace Pinetime { StopRinging, MeasureBatteryTimerExpired, BatteryPercentageUpdated, + LowBattery, StartFileTransfer, StopFileTransfer, BleRadioEnableToggle diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 01056a9a..169eaa05 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -424,6 +424,17 @@ void SystemTask::Work() { case Messages::BatteryPercentageUpdated: nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; + case Messages::LowBattery: + { + Pinetime::Controllers::NotificationManager::Notification notif; + std::array message {"Low Battery\0Low Battery\0"}; + notif.message = message; + notif.size = 25; + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; + notificationManager.Push(std::move(notif)); + PushMessage(Messages::OnNewNotification); + } + break; case Messages::OnPairing: if (state == SystemTaskState::Sleeping) { GoToRunning();