diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2008-03-16 17:01:15 +0100 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2008-03-16 17:01:15 +0100 |
commit | 7a7e4aa53317e8bba1c6781e65ec8274c1e58524 (patch) | |
tree | 0343eaadb69617e56099546dc397162b6d7d2460 /Plugins/Monitors | |
parent | d777ba363bd49f6c2839979b2a49921632039e50 (diff) | |
download | xmobar-7a7e4aa53317e8bba1c6781e65ec8274c1e58524.tar.gz xmobar-7a7e4aa53317e8bba1c6781e65ec8274c1e58524.tar.bz2 |
Add BatteryP a monitor for batteries
With this monitor is possible to set specific location where to
retrieve battery information.
For example:
Run BatteryP ["BAT0","BAT1","BAT2"] [] 10
this will read the following files:
/proc/acpi/battery/BAT0/info and /proc/acpi/battery/BAT0/state
/proc/acpi/battery/BAT1/info and /proc/acpi/battery/BAT1/state
/proc/acpi/battery/BAT1/info and /proc/acpi/battery/BAT2/state
darcs-hash:20080316160115-d6583-efd35abf7a6a1a40fcb5f97ec430783f40b3221d.gz
Diffstat (limited to 'Plugins/Monitors')
-rw-r--r-- | Plugins/Monitors/Batt.hs | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/Plugins/Monitors/Batt.hs b/Plugins/Monitors/Batt.hs index 6a7a858..af5a48c 100644 --- a/Plugins/Monitors/Batt.hs +++ b/Plugins/Monitors/Batt.hs @@ -3,7 +3,7 @@ -- Module : Plugins.Monitors.Batt -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) --- +-- -- Maintainer : Andrea Rossato <andrea.rossato@unibz.it> -- Stability : unstable -- Portability : unportable @@ -18,7 +18,7 @@ import qualified Data.ByteString.Lazy.Char8 as B import Plugins.Monitors.Common import System.Posix.Files (fileExist) -data Batt = Batt Float +data Batt = Batt Float | NA battConfig :: IO MConfig @@ -26,17 +26,11 @@ battConfig = mkMConfig "Batt: <left>" -- template ["left"] -- available replacements -fileB0 :: (String, String) -fileB0 = ("/proc/acpi/battery/BAT0/info", "/proc/acpi/battery/BAT0/state") - -fileB1 :: (String, String) -fileB1 = ("/proc/acpi/battery/BAT1/info", "/proc/acpi/battery/BAT1/state") - -fileB2 :: (String, String) -fileB2 = ("/proc/acpi/battery/BAT2/info", "/proc/acpi/battery/BAT2/state") +file2batfile :: String -> (String, String) +file2batfile s = ("/proc/acpi/battery/"++ s ++ "/info", "/proc/acpi/battery/"++ s ++ "/state") readFileBatt :: (String, String) -> IO (B.ByteString, B.ByteString) -readFileBatt (i,s) = +readFileBatt (i,s) = do a <- rf i b <- rf s return (a,b) @@ -44,11 +38,9 @@ readFileBatt (i,s) = f <- fileExist file if f then B.readFile file else return B.empty -parseBATT :: IO Batt -parseBATT = - do (a0,b0) <- readFileBatt fileB0 - (a1,b1) <- readFileBatt fileB1 - (a2,b2) <- readFileBatt fileB2 +parseBATT :: [(String, String)] -> IO Batt +parseBATT bfs = + do [(a0,b0),(a1,b1),(a2,b2)] <- mapM readFileBatt (take 3 $ bfs ++ repeat ("","")) let sp p s = case stringParser p s of [] -> 0 x -> read x @@ -58,16 +50,19 @@ parseBATT = left = (p0 + p1 + p2) / (f0 + f1 + f2) --present / full return $ if isNaN left then NA else Batt left -formatBatt :: Float -> Monitor [String] +formatBatt :: Float -> Monitor [String] formatBatt x = do let f s = floatToPercent (s / 100) l <- showWithColors f (x * 100) return [l] runBatt :: [String] -> Monitor String -runBatt _ = - do c <- io $ parseBATT - case c of - Batt x -> do l <- formatBatt x - parseTemplate l - NA -> return "N/A" +runBatt = runBatt' ["BAT0","BAT1","BAT2"] + +runBatt' :: [String] -> [String] -> Monitor String +runBatt' bfs _ = do + c <- io $ parseBATT (map file2batfile bfs) + case c of + Batt x -> do l <- formatBatt x + parseTemplate l + NA -> return "N/A" |