summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEmeric Planet <emeric.planet@gmail.com>2017-04-13 21:46:21 +0200
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2017-04-13 21:46:21 +0200
commitc7dea747519f99584002084df3dce546f37df8b5 (patch)
tree4315dd2be5fde515a6c590c903b43efd557a1de8 /src
parent94651257cea4ff419f9cf2143d93193d5a5ccb96 (diff)
Add battery capacity parsing (#216)
The Linux power supply class defines three entries to provide battery status. One of them wasn't used: POWER_SUPPLY_CAPACITY. https://www.kernel.org/doc/Documentation/power/power_supply_class.txt
Diffstat (limited to 'src')
-rw-r--r--src/print_battery_info.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c
index 7883a11..f15cbfa 100644
--- a/src/print_battery_info.c
+++ b/src/print_battery_info.c
@@ -138,9 +138,13 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen
if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW=")) {
watt_as_unit = true;
batt_info->remaining = atoi(walk + 1);
+ batt_info->percentage_remaining = -1;
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW=")) {
watt_as_unit = false;
batt_info->remaining = atoi(walk + 1);
+ batt_info->percentage_remaining = -1;
+ } else if (BEGINS_WITH(last, "POWER_SUPPLY_CAPACITY=") && batt_info->remaining == -1) {
+ batt_info->percentage_remaining = atoi(walk + 1);
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW="))
batt_info->present_rate = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW="))