diff options
author | Felix Springer <felixspringer149@gmail.com> | 2019-07-12 00:52:26 +0200 |
---|---|---|
committer | Felix Springer <felixspringer149@gmail.com> | 2019-07-12 00:52:26 +0200 |
commit | c8a2d1881b724d4faa6dbc8eee80885f4a1e025a (patch) | |
tree | 35dfb3a0983a4f2cb6874b681a5821298244909c /src/Xmobar/Plugins/Monitors | |
parent | 9564b4d611f93d1f074af2c7a48840bb0d9d6fdb (diff) | |
download | xmobar-c8a2d1881b724d4faa6dbc8eee80885f4a1e025a.tar.gz xmobar-c8a2d1881b724d4faa6dbc8eee80885f4a1e025a.tar.bz2 |
plugin complete, might need better comments
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/CoreTemp.hs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/Xmobar/Plugins/Monitors/CoreTemp.hs b/src/Xmobar/Plugins/Monitors/CoreTemp.hs index 65eabe0..18efa98 100644 --- a/src/Xmobar/Plugins/Monitors/CoreTemp.hs +++ b/src/Xmobar/Plugins/Monitors/CoreTemp.hs @@ -18,7 +18,9 @@ module Xmobar.Plugins.Monitors.CoreTemp (startCoreTemp) where import Xmobar.Plugins.Monitors.Common import Control.Monad (filterM) import System.Console.GetOpt -import System.Directory (doesDirectoryExist) +import System.Directory ( doesDirectoryExist + , doesFileExist + ) -- | Declare Options. data CTOpts = CTOpts { loadIconPattern :: Maybe IconPattern @@ -70,26 +72,31 @@ coretempPath :: IO String coretempPath = do xs <- filterM doesDirectoryExist ps let x = head xs return x - where ps = [ "/sys/bus/platform/devices/coretemp." ++ (show (x :: Int)) | x <- [0..9] ] + where ps = [ "/sys/bus/platform/devices/coretemp." ++ (show (x :: Int)) ++ "/" | x <- [0..9] ] hwmonPath :: IO String hwmonPath = do p <- coretempPath - xs <- filterM doesDirectoryExist [ p ++ "/hwmon/hwmon" ++ show (x :: Int) | x <- [0..9] ] + xs <- filterM doesDirectoryExist [ p ++ "hwmon/hwmon" ++ show (x :: Int) ++ "/" | x <- [0..9] ] let x = head xs return x corePaths :: IO [String] corePaths = do p <- hwmonPath - return [ p ] + ls <- filterM doesFileExist [ p ++ "temp" ++ show (x :: Int) ++ "_label" | x <- [0..9] ] + cls <- filterM isLabelFromCore ls + return $ map labelToCore cls -cTFilePaths = [ "/sys/bus/platform/devices/coretemp.0/hwmon/hwmon1/temp2_input" - , "/sys/bus/platform/devices/coretemp.0/hwmon/hwmon1/temp3_input" - , "/sys/bus/platform/devices/coretemp.0/hwmon/hwmon1/temp4_input" - , "/sys/bus/platform/devices/coretemp.0/hwmon/hwmon1/temp5_input" - ] +isLabelFromCore :: FilePath -> IO Bool +isLabelFromCore p = do a <- readFile p + return $ take 4 a == "Core" + +labelToCore :: FilePath -> FilePath +labelToCore = (++ "input") . reverse . drop 5 . reverse cTData :: IO [Float] -cTData = traverse readSingleFile cTFilePaths +cTData = do fps <- corePaths + fs <- traverse readSingleFile fps + return fs where readSingleFile :: FilePath -> IO Float readSingleFile s = do a <- readFile s return $ parseContent a @@ -137,8 +144,3 @@ runCT argv = do cTs <- io $ parseCT startCoreTemp :: [String] -> Int -> (String -> IO ()) -> IO () startCoreTemp a = runM a cTConfig runCT - ---- - ---showTemps :: [Float] -> Monitor [String] ---showTemps fs = do fstrs <- mapM |