bat_freebsd: adds wear-level between remaining_capacity and present_rate

Signed-off-by: Andreas Geisenhainer <psycorama@datenhalde.de>
This commit is contained in:
Andreas Geisenhainer 2017-01-20 20:19:11 +01:00
parent 163aed7213
commit 8c56196c0c
1 changed files with 16 additions and 4 deletions

View File

@ -3,12 +3,15 @@
-- from the battery
-----------------------------------------------------
local setmetatable = setmetatable
local bat_acpi = {}
local function worker(format)
local battery = "batt"
if warg then
battery = warg
end
local bat_info = {}
local pcall = "acpiconf -i batt"
local pcall = "acpiconf -i " .. battery
local f = io.popen(pcall)
for line in f:lines("*line") do
for key,value in string.gmatch(line, "(.+):%s+(.+)") do
@ -32,12 +35,20 @@ local function worker(format)
-- battery capacity in percent
local percent = tonumber(string.gsub(bat_info["Remaining capacity"], "[^%d]", ""), 10)
-- Calculate remaining (charging or discharging) time
-- use remaining (charging or discharging) time calculated by acpiconf
local time = bat_info["Remaining time"]
if time == "unknown" then
time = ""
end
-- calculate wear level from (last full / design) capacity
local wear = "N/A"
if bat_info["Last full capacity"] and bat_info["Design capacity"] then
local l_full = tonumber(string.gsub(bat_info["Last full capacity"], "[^%d]", ""), 10)
local design = tonumber(string.gsub(bat_info["Design capacity"], "[^%d]", ""), 10)
wear = math.floor( 100 - (l_full / design * 100))
end
-- dis-/charging rate as presented by battery
local rate = string.gsub( string.gsub(bat_info["Present rate"], ".*mA[^%d]+", ""), "[%s]+mW.*", "")
rate = string.format( "% 2.1f", tonumber(rate / 1000))
@ -46,8 +57,9 @@ local function worker(format)
-- * state (high "↯", discharging "-", charging "+", N/A "⌁" }
-- * remaining_capacity (percent)
-- * remaining_time, by battery
-- * wear level (percent)
-- * present_rate (mW)
return {state, percent, time, rate}
return {state, percent, time, wear, rate}
end
return setmetatable(bat_acpi, { __call = function(_, ...) return worker(...) end })