diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2020-02-12 23:01:49 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2020-02-16 10:28:35 +0100 |
commit | 6350327928dc6961e0710a0ff6dc4cdcfa5d466e (patch) | |
tree | d84ec2dc77370686769782464c042584f9cfa8f6 | |
parent | ef4c56c613fab1124f9ddfdeab48fcbcc5f836e4 (diff) | |
download | tdelibs-6350327928dc6961e0710a0ff6dc4cdcfa5d466e.tar.gz tdelibs-6350327928dc6961e0710a0ff6dc4cdcfa5d466e.zip |
tdehwlib: Unify units of battery values.
The values from energy_* and power_now are converted
from mWh and mW to Ah and A, so that the units are
equal to values from charge_* and current_now.
This resolves issue #68.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit c088fbf55bde4faa68a6d51ba44085bd97c1e4e2)
-rw-r--r-- | tdecore/tdehw/tdehardwaredevices.cpp | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp index 81c9e1fae..697048dbf 100644 --- a/tdecore/tdehw/tdehardwaredevices.cpp +++ b/tdecore/tdehw/tdehardwaredevices.cpp @@ -3024,6 +3024,7 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist valuesdir.setFilter(TQDir::All); TQString nodename; double bdevice_capacity = 0; + double bdevice_voltage = 0; int bdevice_time_to_empty = 0; int bdevice_time_to_full = 0; bool bdevice_has_energy = false; @@ -3033,9 +3034,20 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist if (dirlist) { TQFileInfoListIterator valuesdirit(*dirlist); TQFileInfo *dirfi; + // Get the voltage as first... + TQFile file( valuesnodename + "voltage_now" ); + if ( file.open( IO_ReadOnly ) ) { + TQTextStream stream( &file ); + TQString line; + line = stream.readLine(); + bdevice_voltage = line.toDouble()/1000000.0; + bdevice->internalSetVoltage(bdevice_voltage); + file.close(); + } + // ...and then the other values while ( (dirfi = valuesdirit.current()) != 0 ) { nodename = dirfi->fileName(); - TQFile file( valuesnodename + nodename ); + file.setName( valuesnodename + nodename ); if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); TQString line; @@ -3046,25 +3058,50 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist else if (nodename == "capacity") { bdevice_capacity = line.toDouble(); } - else if (nodename == "charge_full" || nodename == "energy_full") { + else if (nodename == "charge_full") { bdevice->internalSetMaximumEnergy(line.toDouble()/1000000.0); } - else if (nodename == "charge_full_design" || nodename == "energy_full_design") { + else if (nodename == "energy_full") { + if (bdevice_voltage > 0) { + // Convert from mWh do Ah + bdevice->internalSetMaximumEnergy(line.toDouble()/1000000.0/bdevice_voltage); + } + } + else if (nodename == "charge_full_design") { bdevice->internalSetMaximumDesignEnergy(line.toDouble()/1000000.0); } - else if (nodename == "charge_now" || nodename == "energy_now") { + else if (nodename == "energy_full_design") { + if (bdevice_voltage > 0) { + // Convert from mWh do Ah + bdevice->internalSetMaximumDesignEnergy(line.toDouble()/1000000.0/bdevice_voltage); + } + } + else if (nodename == "charge_now") { bdevice->internalSetEnergy(line.toDouble()/1000000.0); bdevice_has_energy = true; } + else if (nodename == "energy_now") { + if (bdevice_voltage > 0) { + // Convert from mWh do Ah + bdevice->internalSetEnergy(line.toDouble()/1000000.0/bdevice_voltage); + bdevice_has_energy = true; + } + } else if (nodename == "manufacturer") { bdevice->internalSetVendorName(line.stripWhiteSpace()); } else if (nodename == "model_name") { bdevice->internalSetVendorModel(line.stripWhiteSpace()); } - else if (nodename == "power_now" || nodename == "current_now") { + else if (nodename == "current_now") { bdevice->internalSetDischargeRate(line.toDouble()/1000000.0); } + else if (nodename == "power_now") { + if (bdevice_voltage > 0) { + // Convert from mW do A + bdevice->internalSetDischargeRate(line.toDouble()/1000000.0/bdevice_voltage); + } + } else if (nodename == "present") { bdevice->internalSetInstalled(line.toInt()); } @@ -3090,9 +3127,6 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist else if (nodename == "voltage_min_design") { bdevice->internalSetMinimumVoltage(line.toDouble()/1000000.0); } - else if (nodename == "voltage_now") { - bdevice->internalSetVoltage(line.toDouble()/1000000.0); - } file.close(); } ++valuesdirit; |