summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-11-29 14:04:22 +0000
committerRichard Hughes <richard@hughsie.com>2011-11-29 14:04:22 +0000
commitd4ea1cb566377399c6aecdcbe003bd1313905ff3 (patch)
treed8558b372f5ad0bd1c9f92c5f9a08cde46ff4a59
parent46f1c7f0283b3e72c05c2514352a2a11ba7c8761 (diff)
If a power-supply device doesn't report charge or energy, try to read the percentage
-rw-r--r--src/linux/up-device-supply.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index d272e36..0c17f94 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -40,7 +40,7 @@
#define UP_DEVICE_SUPPLY_REFRESH_TIMEOUT 30 /* seconds */
#define UP_DEVICE_SUPPLY_UNKNOWN_TIMEOUT 2 /* seconds */
#define UP_DEVICE_SUPPLY_UNKNOWN_RETRIES 30
-#define UP_DEVICE_SUPPLY_CHARGED_THRESHOLD 90.0f /* % */
+#define UP_DEVICE_SUPPLY_CHARGED_THRESHOLD 90.0f /* % */
#define UP_DEVICE_SUPPLY_COLDPLUG_UNITS_CHARGE TRUE
#define UP_DEVICE_SUPPLY_COLDPLUG_UNITS_ENERGY FALSE
@@ -703,6 +703,13 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply)
percentage = 100.0f;
}
+ /* device is a peripheral and not providing power to the computer */
+ if (energy < 0.01f &&
+ energy_rate < 0.01f &&
+ energy_full < 0.01f) {
+ percentage = sysfs_get_double (native_path, "CAPACITY");
+ }
+
/* the battery isn't charging or discharging, it's just
* sitting there half full doing nothing: try to guess a state */
if (state == UP_DEVICE_STATE_UNKNOWN) {