From c7dea747519f99584002084df3dce546f37df8b5 Mon Sep 17 00:00:00 2001 From: Emeric Planet Date: Thu, 13 Apr 2017 21:46:21 +0200 Subject: 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 --- src/print_battery_info.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') 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=")) -- cgit v1.2.3