diff options
author | Jörg Thalheim <jthalheim@gmail.com> | 2012-02-09 12:43:22 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2012-03-04 20:24:22 +0100 |
commit | 7a3699cf4c1102cddb7ace1c089364634c25a227 (patch) | |
tree | 94d3b1eb7992b8b7535fac6036c63dbf952e5b2f /widgets | |
parent | b11bb78e04b1efa1cd7b352f0522c88280647ad4 (diff) | |
download | vicious-legacy-7a3699cf4c1102cddb7ace1c089364634c25a227.tar.xz |
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.
Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/bat.lua | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/widgets/bat.lua b/widgets/bat.lua index cf953a9..25a3aac 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -10,7 +10,6 @@ local string = { format = string.format } local helpers = require("vicious.helpers") local math = { min = math.min, - max = math.max, floor = math.floor } -- }}} @@ -57,9 +56,9 @@ local function worker(format, warg) -- Get charge information if battery.current_now then - rate = battery.current_now + rate = tonumber(battery.current_now) elseif battery.power_now then - rate = battery.power_now + rate = tonumber(battery.power_now) else return {state, percent, "N/A"} end @@ -67,7 +66,7 @@ local function worker(format, warg) -- Calculate remaining (charging or discharging) time local time = "N/A" - if tonumber(rate) then + if rate ~= nil and rate ~= 0 then if state == "+" then timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate) elseif state == "-" then @@ -76,9 +75,9 @@ local function worker(format, warg) return {state, percent, time} end - -- Calculate time (but work around broken BAT/ACPI implementations) - local hoursleft = math.max(math.floor(timeleft), 0) - local minutesleft = math.max(math.floor((timeleft - hoursleft) * 60 ), 0) + -- Calculate time + local hoursleft = math.floor(timeleft) + local minutesleft = math.floor((timeleft - hoursleft) * 60 ) time = string.format("%02d:%02d", hoursleft, minutesleft) end |