summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Plugins/Monitors.hs57
-rw-r--r--Plugins/Monitors/Batt.hs41
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"