diff options
author | Michael Nolan <C-Elegans@users.noreply.github.com> | 2020-06-15 03:09:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 09:09:06 +0200 |
commit | e19539e5f6a70b2acb1b8a2cf979c80f4d63a91d (patch) | |
tree | 3ad1aec115c602338bd7be43acdc0e0c9e470c0d | |
parent | 09358d26982431702c3652e8f07ebff7166a1181 (diff) |
Add support for batteries outputting Time to empty on linux (#378)
* Add support for batteries outputting Time to empty on linux
The battery in the pinebook pro does not output the remaining charge
in Wh or mAh, so i3 cannot calculate the time remaining. However, it
does directly output the number of minutes remaining on in
POWER_SUPPLY_TIME_TO_EMPTY. This adds support for reading this field
and converting it to seconds_remaining.
* Add testcase for POWER_SUPPLY_TIME_TO_EMTY_NOW
-rw-r--r-- | src/print_battery_info.c | 2 | ||||
-rw-r--r-- | testcases/026-battery-time-to-empty/BAT0_uevent | 4 | ||||
-rw-r--r-- | testcases/026-battery-time-to-empty/expected_output.txt | 1 | ||||
-rw-r--r-- | testcases/026-battery-time-to-empty/i3status.conf | 10 |
4 files changed, 17 insertions, 0 deletions
diff --git a/src/print_battery_info.c b/src/print_battery_info.c index dd3211a..0f480b2 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -175,6 +175,8 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen batt_info->present_rate = abs(atoi(walk + 1)); else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW=")) voltage = abs(atoi(walk + 1)); + else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_NOW=")) + 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 diff --git a/testcases/026-battery-time-to-empty/BAT0_uevent b/testcases/026-battery-time-to-empty/BAT0_uevent new file mode 100644 index 0000000..5657217 --- /dev/null +++ b/testcases/026-battery-time-to-empty/BAT0_uevent @@ -0,0 +1,4 @@ +POWER_SUPPLY_STATUS=Discharging +POWER_SUPPLY_TIME_TO_EMPTY_NOW=655 +POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000 +POWER_SUPPLY_CHARGE_NOW=2390000 diff --git a/testcases/026-battery-time-to-empty/expected_output.txt b/testcases/026-battery-time-to-empty/expected_output.txt new file mode 100644 index 0000000..92926bb --- /dev/null +++ b/testcases/026-battery-time-to-empty/expected_output.txt @@ -0,0 +1 @@ +BAT 30.64% 10:55 diff --git a/testcases/026-battery-time-to-empty/i3status.conf b/testcases/026-battery-time-to-empty/i3status.conf new file mode 100644 index 0000000..038ca5e --- /dev/null +++ b/testcases/026-battery-time-to-empty/i3status.conf @@ -0,0 +1,10 @@ +general { + output_format = "none" +} + +order += "battery 0" + +battery 0 { + format = "%status %percentage %remaining" + path = "testcases/026-battery-time-to-empty/BAT0_uevent" +} |