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 <slavek.banko@axis.cz>
pull/5/head
Slávek Banko 5 years ago
parent 80c12d8a76
commit fa0e4e246c
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -273,12 +273,17 @@ void detaileddialog::setPowerConsumption() {
// refresh battery collection // refresh battery collection
primaryBatteries = hwinfo->getPrimaryBatteries(); 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; 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'); _val += " " + primaryBatteries->getChargeLevelUnit().remove('h');
tl_powerConsValue->setText(_val); tl_powerConsValue->setText(_val);

@ -94,7 +94,7 @@ void Battery::initDefault() {
state = BAT_NORM; state = BAT_NORM;
capacity_state = "ok"; capacity_state = "ok";
charging_state = UNKNOWN_STATE; charging_state = UNKNOWN_STATE;
charge_level_unit = "mWh"; charge_level_unit = "Ah";
charge_level_current = 0; charge_level_current = 0;
charge_level_lastfull = 0; charge_level_lastfull = 0;
charge_level_percentage = 0; charge_level_percentage = 0;
@ -461,16 +461,18 @@ bool Battery::checkChargeLevelRate () {
return false; return false;
} }
int _rate = present_rate; double _rate = present_rate;
// FIXME VERIFY CORRECTNESS // Note that the units used for charge_level_unit and present_rate_unit
// what does tdepowersave expect to see in present_rate (battery.charge_level.rate)? // are different. This is intentionally because the battery charge
present_rate = bdevice->dischargeRate(); // values are in Ah while the power consumption is displayed in W.
present_rate = bdevice->dischargeRate()*bdevice->voltage();
if (present_rate < 0 ) if (present_rate < 0 )
present_rate = 0; present_rate = 0;
if (present_rate != _rate) if (present_rate != _rate) {
emit changedBattery(); emit changedBattery();
}
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
return true; return true;
@ -839,7 +841,7 @@ int Battery::getRemainingMinutes() const {
} }
//! current charging/discharging rate //! current charging/discharging rate
int Battery::getPresentRate() const { double Battery::getPresentRate() const {
return present_rate; return present_rate;
} }

@ -162,7 +162,7 @@ private:
* second) the currently reported charging/discharging rate. * second) the currently reported charging/discharging rate.
* \li a value >= 0 * \li a value >= 0
*/ */
int present_rate; double present_rate;
//! Expected minutes unitl fully discharged/charged //! Expected minutes unitl fully discharged/charged
/*! /*!
* This int tells the current estimate until the battery is fully * This int tells the current estimate until the battery is fully
@ -262,8 +262,8 @@ public:
int getState() const; int getState() const;
//! estimates the remaining minutes until fully charged/discharged //! estimates the remaining minutes until fully charged/discharged
int getRemainingMinutes() const; int getRemainingMinutes() const;
//! current charging/discharging rate //! current charging/discharging rate
int getPresentRate() const; double getPresentRate() const;
//! maximum capacity of this battery by design //! maximum capacity of this battery by design
int getDesignCapacity() const; int getDesignCapacity() const;
//! current charging state as enum BAT_CHARG_STATE //! current charging state as enum BAT_CHARG_STATE

@ -50,7 +50,7 @@ void BatteryCollection::initDefault() {
udis.clear(); udis.clear();
present_rate_unit = "mWh"; present_rate_unit = "W";
charging_state = UNKNOWN_STATE; charging_state = UNKNOWN_STATE;
state = BAT_NORM; state = BAT_NORM;
@ -79,7 +79,7 @@ bool BatteryCollection::refreshInfo(TQPtrList<Battery> BatteryList, bool force_l
int _percent = 0; int _percent = 0;
int _minutes = 0; int _minutes = 0;
int _present_batteries = 0; int _present_batteries = 0;
int _present_rate = 0; double _present_rate = 0;
// for now: clean list before run update process! // for now: clean list before run update process!
udis.clear(); udis.clear();
@ -214,7 +214,7 @@ TQString BatteryCollection::getChargeLevelUnit() const {
} }
//! get the current reported battery rate //! get the current reported battery rate
int BatteryCollection::getCurrentRate() const { double BatteryCollection::getCurrentRate() const {
return present_rate; return present_rate;
} }

@ -117,7 +117,7 @@ private:
* This int tells the current rate of the batteries * This int tells the current rate of the batteries
* \li a value >= 0 * \li a value >= 0
*/ */
int present_rate; double present_rate;
//! charge_level in percent that will put battery into warning state //! charge_level in percent that will put battery into warning state
int warn_level; int warn_level;
@ -184,7 +184,7 @@ public:
//! get the battery Type from enum \ref BAT_TYPE //! get the battery Type from enum \ref BAT_TYPE
int getBatteryType() const; int getBatteryType() const;
//! get the current battery rate //! get the current battery rate
int getCurrentRate() const; double getCurrentRate() const;
//! reports the chargelevel in percent when battery goes to state warning //! reports the chargelevel in percent when battery goes to state warning
int getWarnLevel() const; int getWarnLevel() const;

Loading…
Cancel
Save