If a power-supply device doesn't report charge or energy, try to read the percentage

This commit is contained in:
Richard Hughes 2011-11-29 14:04:22 +00:00
parent 46f1c7f028
commit d4ea1cb566

View file

@ -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) {