From fa0e4e246ccb8f436598db4deee1777decfbc702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Sun, 16 Feb 2020 14:34:08 +0100 Subject: Fix units of current consumption value. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously it was not clear whether the units in tdehwlib are in Wh and W or Ah and A. Now the units are always Ah and A. Because power consumption is usually given in W, the value is converted from A to W. If it is less than 100 W, it is displayed as a decimal number. This is related to issue TDE/tdelibs#68. Signed-off-by: Slávek Banko --- src/hardware_battery.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/hardware_battery.cpp') diff --git a/src/hardware_battery.cpp b/src/hardware_battery.cpp index ac18b52..2e60fb7 100644 --- a/src/hardware_battery.cpp +++ b/src/hardware_battery.cpp @@ -94,7 +94,7 @@ void Battery::initDefault() { state = BAT_NORM; capacity_state = "ok"; charging_state = UNKNOWN_STATE; - charge_level_unit = "mWh"; + charge_level_unit = "Ah"; charge_level_current = 0; charge_level_lastfull = 0; charge_level_percentage = 0; @@ -461,16 +461,18 @@ bool Battery::checkChargeLevelRate () { return false; } - int _rate = present_rate; + double _rate = present_rate; - // FIXME VERIFY CORRECTNESS - // what does tdepowersave expect to see in present_rate (battery.charge_level.rate)? - present_rate = bdevice->dischargeRate(); + // Note that the units used for charge_level_unit and present_rate_unit + // are different. This is intentionally because the battery charge + // values are in Ah while the power consumption is displayed in W. + present_rate = bdevice->dischargeRate()*bdevice->voltage(); if (present_rate < 0 ) present_rate = 0; - if (present_rate != _rate) + if (present_rate != _rate) { emit changedBattery(); + } kdDebugFuncOut(trace); return true; @@ -839,7 +841,7 @@ int Battery::getRemainingMinutes() const { } //! current charging/discharging rate -int Battery::getPresentRate() const { +double Battery::getPresentRate() const { return present_rate; } -- cgit v1.2.3