diff options
Diffstat (limited to 'src/Plugins/Monitors/Batt.hs')
-rw-r--r-- | src/Plugins/Monitors/Batt.hs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index 7d4242a..c276e6b 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -123,18 +123,20 @@ readBattery files = return $ Battery (3600 * a / 1000000) -- wattseconds (3600 * b / 1000000) -- wattseconds (c / 1000000) -- volts - (d / c) -- amperes - where grab = fmap (read . B.unpack) . B.readFile + (if c > 0 then (d / c) else -1) -- amperes + where grab f = catch (fmap (read . B.unpack) $ B.readFile f) (\_ -> return 0) readBatteries :: BattOpts -> [Files] -> IO Result readBatteries opts bfs = do bats <- mapM readBattery (take 3 bfs) ac <- haveAc (onlineFile opts) let sign = if ac then 1 else -1 - left = sum (map now bats) / sum (map full bats) + ft = sum (map full bats) + left = if ft > 0 then sum (map now bats) / ft else 0 watts = sign * sum (map voltage bats) * sum (map current bats) time = if watts == 0 then 0 else sum $ map time' bats - time' b = (if ac then full b - now b else now b) / (sign * watts) + mwatts = if watts == 0 then 1 else sign * watts + time' b = (if ac then full b - now b else now b) / mwatts acstr = if ac then onString opts else offString opts return $ if isNaN left then NA else Result left watts time acstr |