summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-12-10 16:48:11 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-12-10 16:48:11 +0100
commitecb3f46642e19b79d38c5dbc1ce2269040b13ec4 (patch)
tree806ba6f1b7b26bce28038748aad76922b8e72f5d
parentf9a303f5f1b33a2196343aca8d5a79fabcd7302b (diff)
downloadxmobar-ecb3f46642e19b79d38c5dbc1ce2269040b13ec4.tar.gz
xmobar-ecb3f46642e19b79d38c5dbc1ce2269040b13ec4.tar.bz2
Fix for issue #62 (battery monitor on olpc hardware)
-rw-r--r--src/Plugins/Monitors/Batt.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index 77b2d62..662ff43 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -34,6 +34,7 @@ data BattOpts = BattOpts
, lowThreshold :: Float
, highThreshold :: Float
, onlineFile :: FilePath
+ , chargeFile :: FilePath
}
defaultOpts :: BattOpts
@@ -47,6 +48,7 @@ defaultOpts = BattOpts
, lowThreshold = -12
, highThreshold = -10
, onlineFile = "AC/online"
+ , chargeFile = "charge_full"
}
options :: [OptDescr (BattOpts -> BattOpts)]
@@ -60,6 +62,7 @@ options =
, Option "L" ["lowt"] (ReqArg (\x o -> o { lowThreshold = read x }) "") ""
, Option "H" ["hight"] (ReqArg (\x o -> o { highThreshold = read x }) "") ""
, Option "f" ["online"] (ReqArg (\x o -> o { onlineFile = x }) "") ""
+ , Option "c" ["charge"] (ReqArg (\x o -> o { chargeFile = x }) "") ""
]
parseOpts :: [String] -> IO BattOpts
@@ -96,8 +99,8 @@ safeFileExist :: String -> IO Bool
safeFileExist f = handle noErrors $ fileExist f
where noErrors = const (return False) :: SomeException -> IO Bool
-batteryFiles :: String -> IO Files
-batteryFiles bat =
+batteryFiles :: String -> String -> IO Files
+batteryFiles charge_file bat =
do is_charge <- safeFileExist $ prefix </> "charge_now"
is_energy <- safeFileExist $ prefix </> "energy_now"
is_current <- safeFileExist $ prefix </> "current_now"
@@ -107,7 +110,7 @@ batteryFiles bat =
(_, True) -> files "energy" cf
_ -> NoFiles
where prefix = sysDir </> bat
- files ch cf = Files { fFull = prefix </> ch ++ "_full"
+ files ch cf = Files { fFull = prefix </> charge_file
, fNow = prefix </> ch ++ "_now"
, fCurrent = prefix </> cf
, fVoltage = prefix </> "voltage_now" }
@@ -151,7 +154,7 @@ runBatt = runBatt' ["BAT0","BAT1","BAT2"]
runBatt' :: [String] -> [String] -> Monitor String
runBatt' bfs args = do
opts <- io $ parseOpts args
- c <- io $ readBatteries opts =<< mapM batteryFiles bfs
+ c <- io $ readBatteries opts =<< mapM (batteryFiles (chargeFile opts)) bfs
case c of
Result x w t s ->
do l <- fmtPercent x