Skip to content

Commit 0b69e75

Browse files
committed
Generalize iRemaining & iRunTimeToEmpty calculations to also support iFullChargeCapacity other than 100.
1 parent 414fedc commit 0b69e75

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

examples/UPS/UPS.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ void loop() {
106106
bool bDischarging = !bCharging; // TODO - replace with sensor
107107
int iBattSoc = analogRead(BATTSOCPIN); // potensiometer value in [0,1024)
108108

109-
iRemaining = (byte)(round((float)100*iBattSoc/1024));
110-
iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/100);
111-
109+
iRemaining = (byte)(round((float)iFullChargeCapacity*iBattSoc/1024));
110+
iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/iFullChargeCapacity);
111+
112112
// Charging
113113
iPresentStatus.Charging = bCharging;
114114
iPresentStatus.ACPresent = bACPresent;

0 commit comments

Comments
 (0)