From af5eb0ca07aac94bf4ebf5429e9d5c2c1fb7d4e9 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 30 Mar 2015 18:48:06 +0200 Subject: [PATCH] battery: report current if known The power field is not always available (take my Clevo B7130 laptop for example). The current is reported though via "current_now". According to the ACPI spec v5.0, sect. 10.2.2.6 _BST (Battery Status), the reported field is "battery present rate" which is always positive (its direction depends on the charging state). Contents of /sys/class/power_supply/BAT0/uevent for my laptop: POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Discharging POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000 POWER_SUPPLY_VOLTAGE_NOW=11824000 POWER_SUPPLY_CURRENT_NOW=1498000 POWER_SUPPLY_CHARGE_FULL_DESIGN=5200000 POWER_SUPPLY_CHARGE_FULL=5280000 POWER_SUPPLY_CHARGE_NOW=4797000 POWER_SUPPLY_CAPACITY=90 POWER_SUPPLY_CAPACITY_LEVEL=Normal POWER_SUPPLY_MODEL_NAME=BAT POWER_SUPPLY_MANUFACTURER=NOTEBOOK POWER_SUPPLY_SERIAL_NUMBER=0001 Note for Clevo B7130 owners, the charging rate is not reported when discharging but this can be [patched][1]. [1]: https://github.com/Lekensteyn/acpi-stuff/blob/master/Clevo-B7130/BatteryFix.dsl --- src/battery.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/battery.c b/src/battery.c index 185442c1..f106da09 100644 --- a/src/battery.c +++ b/src/battery.c @@ -513,13 +513,15 @@ static int read_sysfs_callback (char const *dir, /* {{{ */ v *= -1.0; battery_submit (plugin_instance, "power", v * SYSFS_FACTOR); } + if (sysfs_file_to_gauge (dir, power_supply, "current_now", &v) == 0) + { + if (discharging) + v *= -1.0; + battery_submit (plugin_instance, "current", v * SYSFS_FACTOR); + } if (sysfs_file_to_gauge (dir, power_supply, "voltage_now", &v) == 0) battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR); -#if 0 - if (sysfs_file_to_gauge (dir, power_supply, "voltage_min_design", &v) == 0) - battery_submit (plugin_instance, "voltage", v * SYSFS_FACTOR); -#endif return (0); } /* }}} int read_sysfs_callback */ -- 2.30.2