Branch: r14.0.x

43b1218e 2015-12-03 19:27:33 Slávek Banko
Fix calculation of remaining charging time in TDE hardware library

Signed-off-by: Slávek Banko <slavek.banko@...>
(cherry picked from commit 075cf11458a98245a47505b944c5606c1b86afb2)
M tdecore/tdehw/tdehardwaredevices.cpp
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 62fd6a4..3fc8e42 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -3028,11 +3028,16 @@
 		}
 
 		// Calculate time remaining
-		// Discharge rate is in watt-hours
+		// Discharge/charge rate is in watt-hours
 		// Energy is in watt-hours
 		// Therefore, energy/rate = time in hours
 		// Convert to seconds...
-		bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
+		if (bdevice->status() == TDEBatteryStatus::Charging) {
+			bdevice->internalSetTimeRemaining(((bdevice->maximumEnergy()-bdevice->energy())/bdevice->dischargeRate())*60*60);
+		}
+		else {
+			bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
+		}
 	}
 
 	if (device->type() == TDEGenericDeviceType::PowerSupply) {