Revert bat_openbsd since the change is unnecessary
This commit is contained in:
parent
83efd26802
commit
d533a1d190
|
@ -34,49 +34,52 @@ local STATES = { [0] = "↯", -- not charging
|
||||||
|
|
||||||
return helpers.setasyncall{
|
return helpers.setasyncall{
|
||||||
async = function (format, warg, callback)
|
async = function (format, warg, callback)
|
||||||
if warg == nil then warg = 'bat0' end
|
local filter = "hw.sensors.acpi" .. (warg or "bat0")
|
||||||
local pattern = ("hw.sensors.acpi%s.(%S+)=(%S+)"):format(warg)
|
local pattern = filter .. ".(%S+)=(%S+)"
|
||||||
|
local bat_info = {}
|
||||||
|
|
||||||
spawn.async(
|
spawn.with_line_callback_with_shell(
|
||||||
"sysctl -a",
|
("sysctl -a | grep '^%s'"):format(filter),
|
||||||
function (stdout, stderr, exitreason, exitcode)
|
{ stdout = function (line)
|
||||||
local bat_info = {}
|
for key, value in line:gmatch(pattern) do
|
||||||
for key, value in stdout:gmatch(pattern) do
|
bat_info[key] = value
|
||||||
bat_info[key] = value
|
end
|
||||||
end
|
end,
|
||||||
|
output_done = function ()
|
||||||
|
-- current state
|
||||||
|
local state = STATES[tonumber(bat_info.raw0)]
|
||||||
|
|
||||||
-- current state
|
-- battery capacity in percent
|
||||||
local state = STATES[tonumber(bat_info.raw0)]
|
local percent = tonumber(
|
||||||
|
bat_info.watthour3 / bat_info.watthour0 * 100)
|
||||||
|
|
||||||
-- battery capacity in percent
|
local time
|
||||||
local percent = tonumber(
|
if tonumber(bat_info.power0) < 1 then
|
||||||
bat_info.watthour3 / bat_info.watthour0 * 100)
|
time = "∞"
|
||||||
|
else
|
||||||
|
local raw_time = bat_info.watthour3 / bat_info.power0
|
||||||
|
local hours, hour_fraction = math.modf(raw_time)
|
||||||
|
local minutes = math.floor(60 * hour_fraction)
|
||||||
|
time = ("%d:%0.2d"):format(hours, minutes)
|
||||||
|
end
|
||||||
|
|
||||||
local time = "∞"
|
-- calculate wear level from (last full / design) capacity
|
||||||
if tonumber(bat_info.power0) >= 1 then
|
local wear = "N/A"
|
||||||
local raw_time = bat_info.watthour3 / bat_info.power0
|
if bat_info.watthour0 and bat_info.watthour4 then
|
||||||
local hours, hour_fraction = math.modf(raw_time)
|
local l_full = tonumber(bat_info.watthour0)
|
||||||
local minutes = math.floor(60 * hour_fraction)
|
local design = tonumber(bat_info.watthour4)
|
||||||
time = ("%d:%0.2d"):format(hours, minutes)
|
wear = math.floor(l_full / design * 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- calculate wear level from (last full / design) capacity
|
-- dis-/charging rate as presented by battery
|
||||||
local wear = "N/A"
|
local rate = bat_info.power0
|
||||||
if bat_info.watthour0 and bat_info.watthour4 then
|
|
||||||
local l_full = tonumber(bat_info.watthour0)
|
|
||||||
local design = tonumber(bat_info.watthour4)
|
|
||||||
wear = math.floor(l_full / design * 100)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- dis-/charging rate as presented by battery
|
-- Pass the following arguments to callback function:
|
||||||
local rate = bat_info.power0
|
-- * battery state symbol (↯, -, !, + or N/A)
|
||||||
|
-- * remaining_capacity (in percent)
|
||||||
-- Pass the following arguments to callback function:
|
-- * remaining_time, by battery
|
||||||
-- * battery state symbol (↯, -, !, + or N/A)
|
-- * wear level (in percent)
|
||||||
-- * remaining_capacity (in percent)
|
-- * present_rate (in Watts)
|
||||||
-- * remaining_time, by battery
|
callback{state, percent, time, wear, rate}
|
||||||
-- * wear level (in percent)
|
end })
|
||||||
-- * present_rate (in Watts)
|
|
||||||
callback{state, percent, time, wear, rate}
|
|
||||||
end)
|
|
||||||
end }
|
end }
|
||||||
|
|
Loading…
Reference in New Issue