summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@ing.unitn.it>2010-02-10 12:45:05 +0100
committerAndrea Rossato <andrea.rossato@ing.unitn.it>2010-02-10 12:45:05 +0100
commitc9ca8953c6f4099e5c0504ce0e31b016d878989c (patch)
treeed5a89de634902511a0932ef155092c8c03d7e54 /Plugins/Monitors
parent72c9d18dee96f299fa96bf820a835d766a1be4d6 (diff)
downloadxmobar-c9ca8953c6f4099e5c0504ce0e31b016d878989c.tar.gz
xmobar-c9ca8953c6f4099e5c0504ce0e31b016d878989c.tar.bz2
Batt: read energy_ if charge_ is not present
Ignore-this: 76a24d0c8d89c239a2c9d8136f77f409ccb34f1a darcs-hash:20100210114505-d6583-ffe623e21b431c2d4d88b79dfb92a1f3af8ed9d8.gz
Diffstat (limited to 'Plugins/Monitors')
-rw-r--r--Plugins/Monitors/Batt.hs37
1 files changed, 24 insertions, 13 deletions
diff --git a/Plugins/Monitors/Batt.hs b/Plugins/Monitors/Batt.hs
index 93fddf9..03becaa 100644
--- a/Plugins/Monitors/Batt.hs
+++ b/Plugins/Monitors/Batt.hs
@@ -26,25 +26,36 @@ battConfig = mkMConfig
"Batt: <left>" -- template
["left","status"] -- available replacements
-file2batfile :: String -> (String, String, String)
-file2batfile s = ( s' ++ "/charge_full"
- , s' ++ "/charge_now"
- , s' ++ "/status")
+type File = (String, String)
+
+file2batfile :: String -> (File, File)
+file2batfile s = ( (s' ++ "/charge_full", s' ++ "/energy_full")
+ , (s' ++ "/charge_now" , s' ++ "/energy_now" )
+ )
where s' = "/sys/class/power_supply/" ++ s
-readFileBatt :: (String, String, String) -> IO (String, String, String)
-readFileBatt (f,n,s) =
- do a <- rf f
- b <- rf n
- c <- rf s
+readFileBatt :: (File, File) -> IO (String, String, String)
+readFileBatt (f,n) =
+ do a <- rf f
+ b <- rf n
+ ac <- fileExist "/sys/class/power_supply/AC0/online"
+ c <- if not ac
+ then return []
+ else do s <- B.unpack `fmap` catRead "/sys/class/power_supply/AC0/online"
+ return $ if s == "1\n" then "<fc=green>On</fc>" else"<fc=red>Off</fc>"
return (a,b,c)
where rf file = do
- fe <- fileExist file
- if fe then B.unpack `fmap` catRead file else return []
+ fe <- fileExist (fst file)
+ if fe
+ then B.unpack `fmap` catRead (fst file)
+ else do fe' <- fileExist (snd file)
+ if fe'
+ then B.unpack `fmap` catRead (snd file)
+ else return []
-parseBATT :: [(String, String, String)] -> IO Batt
+parseBATT :: [(File,File)] -> IO Batt
parseBATT bfs =
- do [(a0,b0,c0),(a1,b1,_),(a2,b2,_)] <- mapM readFileBatt (take 3 $ bfs ++ repeat ("","",""))
+ do [(a0,b0,c0),(a1,b1,_),(a2,b2,_)] <- mapM readFileBatt (take 3 $ bfs ++ repeat (("",""),("","")))
let read' s = if s == [] then 0 else read s
left = (read' b0 + read' b1 + read' b2) / (read' a0 + read' a1 + read' a2) --present / full
return $ if isNaN left then NA else Batt left c0