summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFelix Springer <felixspringer149@gmail.com>2019-07-12 00:58:40 +0200
committerFelix Springer <felixspringer149@gmail.com>2019-07-12 00:58:40 +0200
commit06b117fda0fc2412ef6e9cf95037d13ed81ab7e7 (patch)
treebc05c759f7036502ccd635b1fec6c965d173deff
parentc8a2d1881b724d4faa6dbc8eee80885f4a1e025a (diff)
downloadxmobar-06b117fda0fc2412ef6e9cf95037d13ed81ab7e7.tar.gz
xmobar-06b117fda0fc2412ef6e9cf95037d13ed81ab7e7.tar.bz2
added comments
-rw-r--r--src/Xmobar/Plugins/Monitors/CoreTemp.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/CoreTemp.hs b/src/Xmobar/Plugins/Monitors/CoreTemp.hs
index 18efa98..abe3fb8 100644
--- a/src/Xmobar/Plugins/Monitors/CoreTemp.hs
+++ b/src/Xmobar/Plugins/Monitors/CoreTemp.hs
@@ -68,31 +68,38 @@ cTConfig = mkMConfig cTTemplate cTOptions
, "avg" , "avgpc" , "avgbar" , "avgvbar" , "avgipat"
] ++ (map (("core" ++) . show) [0 :: Int ..])
+-- | Returns the first coretemp.N path found.
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] ]
+-- | Returns the first hwmonN path found.
hwmonPath :: IO String
hwmonPath = do p <- coretempPath
xs <- filterM doesDirectoryExist [ p ++ "hwmon/hwmon" ++ show (x :: Int) ++ "/" | x <- [0..9] ]
let x = head xs
return x
+-- | Checks Labels, if they refer to a core and returns Strings of core-
+-- temperatures.
corePaths :: IO [String]
corePaths = do p <- hwmonPath
ls <- filterM doesFileExist [ p ++ "temp" ++ show (x :: Int) ++ "_label" | x <- [0..9] ]
cls <- filterM isLabelFromCore ls
return $ map labelToCore cls
+-- | Checks if Label refers to a core.
isLabelFromCore :: FilePath -> IO Bool
isLabelFromCore p = do a <- readFile p
return $ take 4 a == "Core"
+-- | Transform a path to Label to a path to core-temperature.
labelToCore :: FilePath -> FilePath
labelToCore = (++ "input") . reverse . drop 5 . reverse
+-- | Reads core-temperatures as data from the system.
cTData :: IO [Float]
cTData = do fps <- corePaths
fs <- traverse readSingleFile fps
@@ -103,11 +110,14 @@ cTData = do fps <- corePaths
where parseContent :: String -> Float
parseContent = read . head . lines
+-- | Transforms data of temperatures into temperatures of degree Celsius.
parseCT :: IO [Float]
parseCT = do rawCTs <- cTData
let normalizedCTs = map (/ 1000) rawCTs :: [Float]
return normalizedCTs
+-- | Performs calculation for maximum and average.
+-- Sets up Bars and Values to be printed.
formatCT :: CTOpts -> [Float] -> Monitor [String]
formatCT opts cTs = do let CTOpts { mintemp = minT
, maxtemp = maxT } = opts