summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2020-02-16 14:34:08 +0100
committerSlávek Banko <[email protected]>2020-02-16 16:32:51 +0100
commit7a52a4c33fb633a6bf227daf31e4ab65a444032e (patch)
treeaef907589ed987f98a54784872a6880c122e003e
parent6609acc640521ae6d1d381c1d411c56d9be8cee3 (diff)
downloadtdepowersave-7a52a4c33fb633a6bf227daf31e4ab65a444032e.tar.gz
tdepowersave-7a52a4c33fb633a6bf227daf31e4ab65a444032e.zip
Fix units of current consumption value.
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 <[email protected]> (cherry picked from commit fa0e4e246ccb8f436598db4deee1777decfbc702)
-rw-r--r--src/detaileddialog.cpp11
-rw-r--r--src/hardware_battery.cpp16
-rw-r--r--src/hardware_battery.h6
-rw-r--r--src/hardware_batteryCollection.cpp6
-rw-r--r--src/hardware_batteryCollection.h4
5 files changed, 25 insertions, 18 deletions
diff --git a/src/detaileddialog.cpp b/src/detaileddialog.cpp
index 76340b5..851d844 100644
--- a/src/detaileddialog.cpp
+++ b/src/detaileddialog.cpp
@@ -273,12 +273,17 @@ void detaileddialog::setPowerConsumption() {
// refresh battery collection
primaryBatteries = hwinfo->getPrimaryBatteries();
- int rate = primaryBatteries->getCurrentRate();
+ double rate = primaryBatteries->getCurrentRate();
- if (rate > 0 && !primaryBatteries->getChargeLevelUnit().isEmpty()) {
+ if (rate > 0 && !primaryBatteries->getChargeLevelUnit().isEmpty()) {
TQString _val;
- _val.setNum(rate);
+ if (rate > 100) {
+ _val = TQString("%L1").arg((int)rate);
+ }
+ else {
+ _val = TQString("%L1").arg(rate, 0, 'g', 3);
+ }
_val += " " + primaryBatteries->getChargeLevelUnit().remove('h');
tl_powerConsValue->setText(_val);
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;
}
diff --git a/src/hardware_battery.h b/src/hardware_battery.h
index 8f9a268..36bf68c 100644
--- a/src/hardware_battery.h
+++ b/src/hardware_battery.h
@@ -162,7 +162,7 @@ private:
* second) the currently reported charging/discharging rate.
* \li a value >= 0
*/
- int present_rate;
+ double present_rate;
//! Expected minutes unitl fully discharged/charged
/*!
* This int tells the current estimate until the battery is fully
@@ -262,8 +262,8 @@ public:
int getState() const;
//! estimates the remaining minutes until fully charged/discharged
int getRemainingMinutes() const;
- //! current charging/discharging rate
- int getPresentRate() const;
+ //! current charging/discharging rate
+ double getPresentRate() const;
//! maximum capacity of this battery by design
int getDesignCapacity() const;
//! current charging state as enum BAT_CHARG_STATE
diff --git a/src/hardware_batteryCollection.cpp b/src/hardware_batteryCollection.cpp
index 523ca6f..e331492 100644
--- a/src/hardware_batteryCollection.cpp
+++ b/src/hardware_batteryCollection.cpp
@@ -50,7 +50,7 @@ void BatteryCollection::initDefault() {
udis.clear();
- present_rate_unit = "mWh";
+ present_rate_unit = "W";
charging_state = UNKNOWN_STATE;
state = BAT_NORM;
@@ -79,7 +79,7 @@ bool BatteryCollection::refreshInfo(TQPtrList<Battery> BatteryList, bool force_l
int _percent = 0;
int _minutes = 0;
int _present_batteries = 0;
- int _present_rate = 0;
+ double _present_rate = 0;
// for now: clean list before run update process!
udis.clear();
@@ -214,7 +214,7 @@ TQString BatteryCollection::getChargeLevelUnit() const {
}
//! get the current reported battery rate
-int BatteryCollection::getCurrentRate() const {
+double BatteryCollection::getCurrentRate() const {
return present_rate;
}
diff --git a/src/hardware_batteryCollection.h b/src/hardware_batteryCollection.h
index c659c3a..c30717d 100644
--- a/src/hardware_batteryCollection.h
+++ b/src/hardware_batteryCollection.h
@@ -117,7 +117,7 @@ private:
* This int tells the current rate of the batteries
* \li a value >= 0
*/
- int present_rate;
+ double present_rate;
//! charge_level in percent that will put battery into warning state
int warn_level;
@@ -184,7 +184,7 @@ public:
//! get the battery Type from enum \ref BAT_TYPE
int getBatteryType() const;
//! get the current battery rate
- int getCurrentRate() const;
+ double getCurrentRate() const;
//! reports the chargelevel in percent when battery goes to state warning
int getWarnLevel() const;