changed to bool

This commit is contained in:
minacode 2022-11-21 00:03:09 +01:00 committed by JF
parent 51d818b774
commit 557a328409
2 changed files with 8 additions and 3 deletions

View File

@ -86,15 +86,20 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
}
if (isPowerPresent) {
batteryLowNotified = false;
}
if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) {
firstMeasurement = false;
lastPercentRemaining = percentRemaining;
percentRemaining = newPercent;
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
// warn about low battery when not charging and below threshold
if (!isPowerPresent && BatteryIsLow() && lastPercentRemaining > lowBatteryThreshold) {
if (BatteryIsLow() && !isPowerPresent && !batteryLowNotified) {
systemTask->PushMessage(System::Messages::LowBattery);
batteryLowNotified = true;
}
}

View File

@ -42,7 +42,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 batteryLowNotified = false;
bool isFull = false;
bool isCharging = false;