summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-01-06 00:57:21 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-01-06 00:57:21 +0100
commita3872b05d344c70bf2d7d7064fde507b31643821 (patch)
treec4642d714441ce464cbe57137dd11d6ca6f45070 /src
parent4578f0f05de2ad73dffc15b998420b0351693b2b (diff)
downloadxmobar-a3872b05d344c70bf2d7d7064fde507b31643821.tar.gz
xmobar-a3872b05d344c70bf2d7d7064fde507b31643821.tar.bz2
Nits
Diffstat (limited to 'src')
-rw-r--r--src/Plugins/Monitors/Batt.hs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index e42049f..0bb64d5 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -67,8 +67,8 @@ parseOpts argv =
data Result = Result Float Float Float String | NA
-base :: String
-base = "/sys/class/power_supply"
+sysDir :: FilePath
+sysDir = "/sys/class/power_supply"
battConfig :: IO MConfig
battConfig = mkMConfig
@@ -91,25 +91,25 @@ data Battery = Battery
batteryFiles :: String -> IO Files
batteryFiles bat =
- do is_charge <- fileExist $ prefix ++ "/charge_now"
- is_energy <- fileExist $ prefix ++ "/energy_now"
+ do is_charge <- fileExist $ prefix </> "charge_now"
+ is_energy <- fileExist $ prefix </> "energy_now"
return $ case (is_charge, is_energy) of
- (True, _) -> files "/charge"
- (_, True) -> files "/energy"
+ (True, _) -> files "charge"
+ (_, True) -> files "energy"
_ -> NoFiles
- where prefix = base ++ "/" ++ bat
- files ch = Files { fFull = prefix ++ ch ++ "_full"
- , fNow = prefix ++ ch ++ "_now"
- , fCurrent = prefix ++ "/current_now"
- , fVoltage = prefix ++ "/voltage_now" }
+ where prefix = sysDir </> bat
+ files ch = Files { fFull = prefix </> ch ++ "_full"
+ , fNow = prefix </> ch ++ "_now"
+ , fCurrent = prefix </> "current_now"
+ , fVoltage = prefix </> "voltage_now" }
haveAc :: FilePath -> IO Bool
haveAc f = do
- know <- fileExist ofile
- if know
+ exists <- fileExist ofile
+ if exists
then fmap ((== "1\n") . B.unpack) (catRead ofile)
else return False
- where ofile = base </> f
+ where ofile = sysDir </> f
readBattery :: Files -> IO Battery
readBattery NoFiles = return $ Battery 0 0 0 0
@@ -131,7 +131,7 @@ readBatteries opts bfs =
let sign = if ac then 1 else -1
left = sum (map now bats) / sum (map full bats)
watts = sign * sum (map voltage bats) * sum (map current bats)
- time = if watts == 0 then 0 else sum $ map time' bats -- negate sign
+ 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)
acstr = if ac then onString opts else offString opts
return $ if isNaN left then NA else Result left watts time acstr