[bat] division by zero, if battery is full charged
If the battery state change from charging to full, power_now is reseted to zero for a little time. This cause division by zero, which was visible as a very big negative number because of the behaviour of string.format.
This commit is contained in:
parent
7fd6234fa0
commit
29f809e819
|
@ -10,7 +10,6 @@ local string = { format = string.format }
|
||||||
local helpers = require("vicious.helpers")
|
local helpers = require("vicious.helpers")
|
||||||
local math = {
|
local math = {
|
||||||
min = math.min,
|
min = math.min,
|
||||||
max = math.max,
|
|
||||||
floor = math.floor
|
floor = math.floor
|
||||||
}
|
}
|
||||||
-- }}}
|
-- }}}
|
||||||
|
@ -57,9 +56,9 @@ local function worker(format, warg)
|
||||||
|
|
||||||
-- Get charge information
|
-- Get charge information
|
||||||
if battery.current_now then
|
if battery.current_now then
|
||||||
rate = battery.current_now
|
rate = tonumber(battery.current_now)
|
||||||
elseif battery.power_now then
|
elseif battery.power_now then
|
||||||
rate = battery.power_now
|
rate = tonumber(battery.power_now)
|
||||||
else
|
else
|
||||||
return {state, percent, "N/A"}
|
return {state, percent, "N/A"}
|
||||||
end
|
end
|
||||||
|
@ -67,7 +66,7 @@ local function worker(format, warg)
|
||||||
-- Calculate remaining (charging or discharging) time
|
-- Calculate remaining (charging or discharging) time
|
||||||
local time = "N/A"
|
local time = "N/A"
|
||||||
|
|
||||||
if tonumber(rate) then
|
if rate ~= nil and rate ~= 0 then
|
||||||
if state == "+" then
|
if state == "+" then
|
||||||
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
||||||
elseif state == "-" then
|
elseif state == "-" then
|
||||||
|
@ -76,9 +75,9 @@ local function worker(format, warg)
|
||||||
return {state, percent, time}
|
return {state, percent, time}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate time (but work around broken BAT/ACPI implementations)
|
-- Calculate time
|
||||||
local hoursleft = math.max(math.floor(timeleft), 0)
|
local hoursleft = math.floor(timeleft)
|
||||||
local minutesleft = math.max(math.floor((timeleft - hoursleft) * 60 ), 0)
|
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
||||||
|
|
||||||
time = string.format("%02d:%02d", hoursleft, minutesleft)
|
time = string.format("%02d:%02d", hoursleft, minutesleft)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue