summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-02-12 23:01:49 +0100
committerSlávek Banko <slavek.banko@axis.cz>2020-02-16 10:22:59 +0100
commitc088fbf55bde4faa68a6d51ba44085bd97c1e4e2 (patch)
treeb9ad8377d7472e5e7672ac6a717b26f9e23dc83e /tdecore
parent8b8f5064f7094a713a16ade3bf37d8efec601949 (diff)
downloadtdelibs-c088fbf55bde4faa68a6d51ba44085bd97c1e4e2.tar.gz
tdelibs-c088fbf55bde4faa68a6d51ba44085bd97c1e4e2.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>
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp50
1 files changed, 42 insertions, 8 deletions
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 0d1207e0a..cde5e3bcb 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -3073,6 +3073,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;
@@ -3082,9 +3083,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;
@@ -3095,25 +3107,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());
}
@@ -3139,9 +3176,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;