diff options
author | Sam Delmerico <svdelmerico@gmail.com> | 2018-11-26 16:12:15 -0500 |
---|---|---|
committer | Sam Delmerico <svdelmerico@gmail.com> | 2018-11-26 16:19:29 -0500 |
commit | f369e1cb28a308f6967d7bc31375c637755b1e3f (patch) | |
tree | 7f0e5f918028ddbd3dcf0fe73045da832056acbe /battery-widget | |
parent | 3d38cdb866bc6360b1d00d6b8ebdc695fa41bb0d (diff) |
battery is biased on capacities instead of a naive average
Diffstat (limited to 'battery-widget')
-rw-r--r-- | battery-widget/battery.lua | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/battery-widget/battery.lua b/battery-widget/battery.lua index 4cbc314..9adc7ea 100644 --- a/battery-widget/battery.lua +++ b/battery-widget/battery.lua @@ -69,14 +69,25 @@ end local last_battery_check = os.time() -watch("acpi", 10, +watch("acpi -i", 10, function(widget, stdout, stderr, exitreason, exitcode) local batteryType local battery_info = {} + local capacities = {} for s in stdout:gmatch("[^\r\n]+") do - local _, status, charge_str, time = string.match(s, '(.+): (%a+), (%d?%d?%d)%%,? ?.*') - table.insert(battery_info, {status = status, charge = tonumber(charge_str)}) + local status, charge_str, time = string.match(s, '.+: (%a+), (%d?%d?%d)%%,?.*') + if status ~= nil then + table.insert(battery_info, {status = status, charge = tonumber(charge_str)}) + else + local cap_str = string.match(s, '.+:.+last full capacity (%d+)') + table.insert(capacities, tonumber(cap_str)) + end + end + + local capacity = 0 + for i, cap in ipairs(capacities) do + capacity = capacity + cap end local charge = 0 @@ -87,9 +98,9 @@ watch("acpi", 10, -- this is arbitrary, and maybe another metric should be used end - charge = charge + batt.charge + charge = charge + batt.charge * capacities[i] end - charge = charge // #battery_info -- use average charge for battery icon + charge = charge // capacity if (charge >= 0 and charge < 15) then batteryType = "battery-empty%s-symbolic" |