summaryrefslogtreecommitdiff
path: root/src/components/battery
diff options
context:
space:
mode:
authorminacode <minamoto9@web.de>2022-10-03 14:22:18 +0200
committerJF <JF002@users.noreply.github.com>2022-12-27 12:13:52 +0100
commit59ee0ad1aae99476c69c908dc9bce8626e695c94 (patch)
tree4b6f4589975c7f43c97c2fffb7656e77d399c08c /src/components/battery
parent5f5c771752a80dcd64e684b1f10b45f297763d1f (diff)
add percentage rescaling
Diffstat (limited to 'src/components/battery')
-rw-r--r--src/components/battery/BatteryController.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 95a30792..ca0db79f 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -85,6 +85,11 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
if (!isFull) {
newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
}
+ // quick hack for better values
+ // rescale the percentages between 35 and 100
+ constexpr uint8_t realMin = 35;
+ newPercent = std::max(newPercent, realMin);
+ newPercent = (newPercent - realMin) * 100 / (100 - realMin);
if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) {
firstMeasurement = false;
@@ -93,7 +98,8 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
}
- constexpr uint8_t lowBatteryThreshold {50};
+ // warn at 20% battery (wrt. rescaling above)
+ constexpr uint8_t lowBatteryThreshold {20};
if (!isPowerPresent && lastPercentRemaining >= lowBatteryThreshold && percentRemaining < lowBatteryThreshold) {
systemTask->PushMessage(System::Messages::LowBattery);
}