summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2013-12-30 16:52:10 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2013-12-30 16:52:10 +0100
commit79fcef645f2448a4ba920c8ccfede43ef17e873b (patch)
tree83857c59ec7f889b232e4bb96563b3dc6cb6cc3d
parent9a9f660998857dba72a13a7376c32ae6c41c1a64 (diff)
downloadxmobar-79fcef645f2448a4ba920c8ccfede43ef17e873b.tar.gz
xmobar-79fcef645f2448a4ba920c8ccfede43ef17e873b.tar.bz2
Battery: workaround for obsolete current_now
-rw-r--r--src/Plugins/Monitors/Batt.hs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index 4976b61..1d168af 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -87,6 +87,7 @@ data Files = Files
, fNow :: String
, fVoltage :: String
, fCurrent :: String
+ , isCurrent :: Bool
} | NoFiles
data Battery = Battery
@@ -103,20 +104,21 @@ batteryFiles :: String -> IO Files
batteryFiles bat =
do is_charge <- exists "charge_now"
is_energy <- if is_charge then return False else exists "energy_now"
- is_current <- exists "current_now"
+ is_power <- exists "power_now"
plain <- if is_charge then exists "charge_full" else exists "energy_full"
- let cf = if is_current then "current_now" else "power_now"
+ let cf = if is_power then "power_now" else "current_now"
sf = if plain then "" else "_design"
return $ case (is_charge, is_energy) of
- (True, _) -> files "charge" cf sf
- (_, True) -> files "energy" cf sf
+ (True, _) -> files "charge" cf sf is_power
+ (_, True) -> files "energy" cf sf is_power
_ -> NoFiles
where prefix = sysDir </> bat
exists = safeFileExist prefix
- files ch cf sf = Files { fFull = prefix </> ch ++ "_full" ++ sf
- , fNow = prefix </> ch ++ "_now"
- , fCurrent = prefix </> cf
- , fVoltage = prefix </> "voltage_now" }
+ files ch cf sf ip = Files { fFull = prefix </> ch ++ "_full" ++ sf
+ , fNow = prefix </> ch ++ "_now"
+ , fCurrent = prefix </> cf
+ , fVoltage = prefix </> "voltage_now"
+ , isCurrent = not ip}
haveAc :: FilePath -> IO Bool
haveAc f =
@@ -129,9 +131,10 @@ readBattery sc files =
do a <- grab $ fFull files
b <- grab $ fNow files
d <- grab $ fCurrent files
+ let d' = if isCurrent files then d * 10 else d
return $ Battery (3600 * a / sc) -- wattseconds
(3600 * b / sc) -- wattseconds
- (d / sc) -- watts
+ (d' / sc) -- watts
where grab f = handle onError $ withFile f ReadMode (fmap read . hGetLine)
onError = const (return (-1)) :: SomeException -> IO Float