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) {
|
if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) {
|
||||||
firstMeasurement = false;
|
firstMeasurement = false;
|
||||||
|
lastPercentRemaining = percentRemaining;
|
||||||
percentRemaining = newPercent;
|
percentRemaining = newPercent;
|
||||||
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
|
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t lowBatteryThreshold {50};
|
||||||
|
if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) {
|
||||||
|
systemTask->PushMessage(System::Messages::LowBattery);
|
||||||
|
}
|
||||||
|
|
||||||
nrfx_saadc_uninit();
|
nrfx_saadc_uninit();
|
||||||
isReading = false;
|
isReading = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace Pinetime {
|
||||||
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
|
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
|
||||||
uint16_t voltage = 0;
|
uint16_t voltage = 0;
|
||||||
uint8_t percentRemaining = 0;
|
uint8_t percentRemaining = 0;
|
||||||
|
uint8_t lastPercentRemaining = 0;
|
||||||
|
|
||||||
bool isFull = false;
|
bool isFull = false;
|
||||||
bool isCharging = false;
|
bool isCharging = false;
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Pinetime {
|
||||||
StopRinging,
|
StopRinging,
|
||||||
MeasureBatteryTimerExpired,
|
MeasureBatteryTimerExpired,
|
||||||
BatteryPercentageUpdated,
|
BatteryPercentageUpdated,
|
||||||
|
LowBattery,
|
||||||
StartFileTransfer,
|
StartFileTransfer,
|
||||||
StopFileTransfer,
|
StopFileTransfer,
|
||||||
BleRadioEnableToggle
|
BleRadioEnableToggle
|
||||||
|
|
|
@ -424,6 +424,17 @@ void SystemTask::Work() {
|
||||||
case Messages::BatteryPercentageUpdated:
|
case Messages::BatteryPercentageUpdated:
|
||||||
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
|
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
|
||||||
break;
|
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:
|
case Messages::OnPairing:
|
||||||
if (state == SystemTaskState::Sleeping) {
|
if (state == SystemTaskState::Sleeping) {
|
||||||
GoToRunning();
|
GoToRunning();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user