summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-12-18 00:08:10 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-12-18 00:08:10 +0100
commit1e43372a6112a8f07ab47be470ba68633f96741b (patch)
tree811fda4a0aeaec8d1bd5610b9183046b4fa6759d /src/Plugins/Monitors
parent216009575ce3a3aec405727f92c53cd75697abd2 (diff)
downloadxmobar-1e43372a6112a8f07ab47be470ba68633f96741b.tar.gz
xmobar-1e43372a6112a8f07ab47be470ba68633f96741b.tar.bz2
Battery: correct computation of watts
Diffstat (limited to 'src/Plugins/Monitors')
-rw-r--r--src/Plugins/Monitors/Batt.hs19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index f0aaa4a..24f5263 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -86,8 +86,7 @@ data Files = Files
data Battery = Battery
{ full :: !Float
, now :: !Float
- , voltage :: !Float
- , current :: !Float
+ , power :: !Float
}
safeFileExist :: String -> String -> IO Bool
@@ -119,16 +118,14 @@ haveAc f =
where onError = const (return False) :: SomeException -> IO Bool
readBattery :: Files -> IO Battery
-readBattery NoFiles = return $ Battery 0 0 0 0
+readBattery NoFiles = return $ Battery 0 0 0
readBattery files =
- do a <- grab $ fFull files -- microwatthours
+ do a <- grab $ fFull files
b <- grab $ fNow files
- c <- grab $ fVoltage files -- microvolts
- d <- grab $ fCurrent files -- microwatts (huh!)
- return $ Battery (3600 * a / 1000000) -- wattseconds
- (3600 * b / 1000000) -- wattseconds
- (c / 1000000) -- volts
- (if c > 0 then d / c else -1) -- amperes
+ d <- grab $ fCurrent files
+ return $ Battery (3600 * a / 1e5) -- wattseconds
+ (3600 * b / 1e5) -- wattseconds
+ (d / 1e5) -- watts
where grab f = handle onError $ withFile f ReadMode (fmap read . hGetLine)
onError = const (return (-1)) :: SomeException -> IO Float
@@ -139,7 +136,7 @@ readBatteries opts bfs =
let sign = if ac then 1 else -1
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)
+ watts = sign * sum (map power bats)
time = if watts == 0 then 0 else sum $ map time' bats
mwatts = if watts == 0 then 1 else sign * watts
time' b = (if ac then full b - now b else now b) / mwatts