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 | |
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
-rw-r--r-- | Plugins/Monitors.hs | 57 | ||||
-rw-r--r-- | Plugins/Monitors/Batt.hs | 41 |
2 files changed, 48 insertions, 50 deletions
diff --git a/Plugins/Monitors.hs b/Plugins/Monitors.hs index 5be6057..690e198 100644 --- a/Plugins/Monitors.hs +++ b/Plugins/Monitors.hs @@ -3,7 +3,7 @@ -- Module : Xmobar.Plugins.Monitors -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) --- +-- -- Maintainer : Andrea Rossato <andrea.rossato@unibz.it> -- Stability : unstable -- Portability : unportable @@ -27,15 +27,16 @@ import Plugins.Monitors.Thermal import Plugins.Monitors.CpuFreq import Plugins.Monitors.CoreTemp -data Monitors = Weather Station Args Rate +data Monitors = Weather Station Args Rate | Network Interface Args Rate - | Memory Args Rate - | Swap Args Rate - | Cpu Args Rate - | Battery Args Rate - | Thermal Zone Args Rate - | CpuFreq Args Rate - | CoreTemp Args Rate + | Memory Args Rate + | Swap Args Rate + | Cpu Args Rate + | Battery Args Rate + | BatteryP [String] Args Rate + | Thermal Zone Args Rate + | CpuFreq Args Rate + | CoreTemp Args Rate deriving (Show,Read,Eq) type Args = [String] @@ -47,21 +48,23 @@ type Interface = String type Rate = Int instance Exec Monitors where - alias (Weather s _ _) = s - alias (Network i _ _) = i - alias (Thermal z _ _) = z - alias (Memory _ _) = "memory" - alias (Swap _ _) = "swap" - alias (Cpu _ _) = "cpu" - alias (Battery _ _) = "battery" - alias (CpuFreq _ _) = "cpufreq" - alias (CoreTemp _ _) = "coretemp" - start (Weather s a r) = runM (a ++ [s]) weatherConfig runWeather r - start (Network i a r) = runM (a ++ [i]) netConfig runNet r - start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r - start (Memory a r) = runM a memConfig runMem r - start (Swap a r) = runM a swapConfig runSwap r - start (Cpu a r) = runM a cpuConfig runCpu r - start (Battery a r) = runM a battConfig runBatt r - start (CpuFreq a r) = runM a cpuFreqConfig runCpuFreq r - start (CoreTemp a r) = runM a coreTempConfig runCoreTemp r + alias (Weather s _ _) = s + alias (Network i _ _) = i + alias (Thermal z _ _) = z + alias (Memory _ _) = "memory" + alias (Swap _ _) = "swap" + alias (Cpu _ _) = "cpu" + alias (Battery _ _) = "battery" + alias (BatteryP _ _ _) = "battery" + alias (CpuFreq _ _) = "cpufreq" + alias (CoreTemp _ _) = "coretemp" + start (Weather s a r) = runM (a ++ [s]) weatherConfig runWeather r + start (Network i a r) = runM (a ++ [i]) netConfig runNet r + start (Thermal z a r) = runM (a ++ [z]) thermalConfig runThermal r + start (Memory a r) = runM a memConfig runMem r + start (Swap a r) = runM a swapConfig runSwap r + start (Cpu a r) = runM a cpuConfig runCpu r + start (Battery a r) = runM a battConfig runBatt r + start (BatteryP s a r) = runM a battConfig (runBatt' s) r + start (CpuFreq a r) = runM a cpuFreqConfig runCpuFreq r + start (CoreTemp a r) = runM a coreTempConfig runCoreTemp r 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" |