summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tdecore/tdehw/tdebatterydevice.cpp9
-rw-r--r--tdecore/tdehw/tdehardwaredevices.cpp37
2 files changed, 36 insertions, 10 deletions
diff --git a/tdecore/tdehw/tdebatterydevice.cpp b/tdecore/tdehw/tdebatterydevice.cpp
index 781fb994b..e220fa5a6 100644
--- a/tdecore/tdehw/tdebatterydevice.cpp
+++ b/tdecore/tdehw/tdebatterydevice.cpp
@@ -21,7 +21,14 @@
#include "config.h"
-TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
+TDEBatteryDevice::TDEBatteryDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) :
+ m_currentVoltage(0), m_minimumVoltage(0), m_maximumVoltage(0), m_maximumDesignVoltage(0),
+ m_alarmEnergy(0), m_currentEnergy(0), m_maximumEnergy(0), m_maximumDesignEnergy(0),
+ m_dischargeRate(0), m_timeRemaining(0),
+ m_technology(TQString::null),
+ m_status(TDEBatteryStatus::Unknown),
+ m_installed(0),
+ TDEGenericDevice(dt, dn) {
}
TDEBatteryDevice::~TDEBatteryDevice() {
diff --git a/tdecore/tdehw/tdehardwaredevices.cpp b/tdecore/tdehw/tdehardwaredevices.cpp
index 45633bd9e..04ace0f07 100644
--- a/tdecore/tdehw/tdehardwaredevices.cpp
+++ b/tdecore/tdehw/tdehardwaredevices.cpp
@@ -3023,6 +3023,9 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
TQDir valuesdir(valuesnodename);
valuesdir.setFilter(TQDir::All);
TQString nodename;
+ double bdevice_capacity = 0;
+ bool bdevice_has_energy = false;
+ bool bdevice_has_time_to_empty = false;
const TQFileInfoList *dirlist = valuesdir.entryInfoList();
if (dirlist) {
TQFileInfoListIterator valuesdirit(*dirlist);
@@ -3092,6 +3095,9 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
if (nodename == "alarm") {
bdevice->internalSetAlarmEnergy(line.toDouble()/1000000.0);
}
+ else if (nodename == "capacity") {
+ bdevice_capacity = line.toDouble();
+ }
else if (nodename == "charge_full" || nodename == "energy_full") {
bdevice->internalSetMaximumEnergy(line.toDouble()/1000000.0);
}
@@ -3100,6 +3106,7 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
}
else if (nodename == "charge_now" || nodename == "energy_now") {
bdevice->internalSetEnergy(line.toDouble()/1000000.0);
+ bdevice_has_energy = true;
}
else if (nodename == "manufacturer") {
bdevice->internalSetVendorName(line.stripWhiteSpace());
@@ -3122,6 +3129,11 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
else if (nodename == "technology") {
bdevice->internalSetTechnology(line);
}
+ else if (nodename == "time_to_empty_now") {
+ // Convert from minutes to seconds
+ bdevice->internalSetTimeRemaining(line.toDouble()*60);
+ bdevice_has_time_to_empty = true;
+ }
else if (nodename == "voltage_min_design") {
bdevice->internalSetMinimumVoltage(line.toDouble()/1000000.0);
}
@@ -3134,16 +3146,23 @@ void TDEHardwareDevices::updateExistingDeviceInformation(TDEGenericDevice* exist
}
}
- // Calculate time remaining
- // Discharge/charge rate is in watt-hours
- // Energy is in watt-hours
- // Therefore, energy/rate = time in hours
- // Convert to seconds...
- if (bdevice->status() == TDEBatteryStatus::Charging) {
- bdevice->internalSetTimeRemaining(((bdevice->maximumEnergy()-bdevice->energy())/bdevice->dischargeRate())*60*60);
+ // Calculate current energy if missing
+ if (!bdevice_has_energy) {
+ bdevice->internalSetEnergy(bdevice_capacity*bdevice->maximumEnergy()/100);
}
- else {
- bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
+
+ // Calculate time remaining
+ if (bdevice->dischargeRate() > 0) {
+ // Discharge/charge rate is in watt-hours
+ // Energy is in watt-hours
+ // Therefore, energy/rate = time in hours
+ // Convert to seconds...
+ if (bdevice->status() == TDEBatteryStatus::Charging) {
+ bdevice->internalSetTimeRemaining(((bdevice->maximumEnergy()-bdevice->energy())/bdevice->dischargeRate())*60*60);
+ }
+ else if (!bdevice_has_time_to_empty) {
+ bdevice->internalSetTimeRemaining((bdevice->energy()/bdevice->dischargeRate())*60*60);
+ }
}
}