From 1a1c2c92caee4b67e10d0f13bd3a370f3d0b4e15 Mon Sep 17 00:00:00 2001 From: Fredrik Orderud Date: Tue, 15 Oct 2024 14:00:26 +0200 Subject: [PATCH] Generalize iRemaining & iRunTimeToEmpty calculations to also support iFullChargeCapacity other than 100. --- examples/UPS/UPS.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/UPS/UPS.ino b/examples/UPS/UPS.ino index 3961337..e908b1b 100644 --- a/examples/UPS/UPS.ino +++ b/examples/UPS/UPS.ino @@ -106,9 +106,9 @@ void loop() { bool bDischarging = !bCharging; // TODO - replace with sensor int iBattSoc = analogRead(BATTSOCPIN); // TODO - this is for debug only. Replace with charge estimation - iRemaining = (byte)(round((float)100*iBattSoc/1024)); - iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/100); - + iRemaining = (byte)(round((float)iFullChargeCapacity*iBattSoc/1024)); + iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/iFullChargeCapacity); + // Charging iPresentStatus.Charging = bCharging; iPresentStatus.ACPresent = bACPresent;