added low battery message
This commit is contained in:
parent
29673892c2
commit
ccc8cee07a
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Pinetime {
|
|||
StopRinging,
|
||||
MeasureBatteryTimerExpired,
|
||||
BatteryPercentageUpdated,
|
||||
LowBattery,
|
||||
StartFileTransfer,
|
||||
StopFileTransfer,
|
||||
BleRadioEnableToggle
|
||||
|
|
|
@ -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<char, 101> 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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user