Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

battery_info: Check for _AVG postfix parameters when slurping battery info #453

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/print_battery_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,33 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen
if (*walk != '=')
continue;

if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW=")) {
if (BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_ENERGY_AVG=")) {
watt_as_unit = true;
batt_info->remaining = atoi(walk + 1);
batt_info->percentage_remaining = -1;
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW=")) {
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_CHARGE_AVG=")) {
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="))
} else if (BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_CURRENT_AVG="))
batt_info->present_rate = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW="))
else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_AVG="))
voltage = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_NOW="))
else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_AVG="))
batt_info->seconds_remaining = abs(atoi(walk + 1)) * 60;
/* on some systems POWER_SUPPLY_POWER_NOW does not exist, but actually
* it is the same as POWER_SUPPLY_CURRENT_NOW but with μWh as
* unit instead of μAh. We will calculate it as we need it
* later. */
else if (BEGINS_WITH(last, "POWER_SUPPLY_POWER_NOW="))
else if (BEGINS_WITH(last, "POWER_SUPPLY_POWER_NOW=") ||
BEGINS_WITH(last, "POWER_SUPPLY_POWER_AVG="))
batt_info->present_rate = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_STATUS=Charging"))
batt_info->status = CS_CHARGING;
Expand Down