Revert bat_openbsd since the change is unnecessary

This commit is contained in:
Nguyễn Gia Phong 2019-08-24 13:49:42 +07:00
parent 83efd26802
commit d533a1d190
1 changed files with 42 additions and 39 deletions

View File

@ -34,17 +34,18 @@ local STATES = { [0] = "↯", -- not charging
return helpers.setasyncall{
async = function (format, warg, callback)
if warg == nil then warg = 'bat0' end
local pattern = ("hw.sensors.acpi%s.(%S+)=(%S+)"):format(warg)
spawn.async(
"sysctl -a",
function (stdout, stderr, exitreason, exitcode)
local filter = "hw.sensors.acpi" .. (warg or "bat0")
local pattern = filter .. ".(%S+)=(%S+)"
local bat_info = {}
for key, value in stdout:gmatch(pattern) do
spawn.with_line_callback_with_shell(
("sysctl -a | grep '^%s'"):format(filter),
{ stdout = function (line)
for key, value in line:gmatch(pattern) do
bat_info[key] = value
end
end,
output_done = function ()
-- current state
local state = STATES[tonumber(bat_info.raw0)]
@ -52,8 +53,10 @@ return helpers.setasyncall{
local percent = tonumber(
bat_info.watthour3 / bat_info.watthour0 * 100)
local time = ""
if tonumber(bat_info.power0) >= 1 then
local time
if tonumber(bat_info.power0) < 1 then
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)
@ -78,5 +81,5 @@ return helpers.setasyncall{
-- * wear level (in percent)
-- * present_rate (in Watts)
callback{state, percent, time, wear, rate}
end)
end })
end }