diff options
Diffstat (limited to 'Plugins')
-rw-r--r-- | Plugins/Monitors/CoreCommon.hs | 22 | ||||
-rw-r--r-- | Plugins/Monitors/CoreTemp.hs | 2 | ||||
-rw-r--r-- | Plugins/Monitors/CpuFreq.hs | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/Plugins/Monitors/CoreCommon.hs b/Plugins/Monitors/CoreCommon.hs index 5dceb33..95d8613 100644 --- a/Plugins/Monitors/CoreCommon.hs +++ b/Plugins/Monitors/CoreCommon.hs @@ -25,19 +25,23 @@ import Data.List (isPrefixOf) -- Function checks the existence of first file specified by pattern and if the -- file doesn't exists failure message is shown, otherwise the data retrieval -- is performed. -checkedDataRetrieval :: String -> String -> String -> String -> Double -> Monitor String -checkedDataRetrieval failureMessage dir file pattern divisor = do +checkedDataRetrieval :: (Num a, Ord a, Show a) => + String -> String -> String -> String -> (Double -> a) + -> Monitor String +checkedDataRetrieval failureMessage dir file pattern trans = do exists <- io $ fileExist $ concat [dir, "/", pattern, "0/", file] case exists of False -> return failureMessage - True -> retrieveData dir file pattern divisor + True -> retrieveData dir file pattern trans -- | --- Function retrieves data from files in directory dir specified by pattern. --- String values are converted to double and adjusted with divisor. Final array --- is processed by template parser function and returned as monitor string. -retrieveData :: String -> String -> String -> Double -> Monitor String -retrieveData dir file pattern divisor = do +-- Function retrieves data from files in directory dir specified by +-- pattern. String values are converted to double and 'trans' applied +-- to each one. Final array is processed by template parser function +-- and returned as monitor string. +retrieveData :: (Num a, Ord a, Show a) => + String -> String -> String -> (Double -> a) -> Monitor String +retrieveData dir file pattern trans = do count <- io $ dirCount dir pattern contents <- io $ mapM getGuts $ files count values <- mapM (showWithColors show) $ map conversion contents @@ -50,5 +54,5 @@ retrieveData dir file pattern divisor = do && isDigit (last s)) files count = map (\i -> concat [dir, "/", pattern, show i, "/", file]) [0 .. count - 1] - conversion = (/divisor) . (read :: String -> Double) + conversion = trans . (read :: String -> Double) diff --git a/Plugins/Monitors/CoreTemp.hs b/Plugins/Monitors/CoreTemp.hs index f014335..2bb220c 100644 --- a/Plugins/Monitors/CoreTemp.hs +++ b/Plugins/Monitors/CoreTemp.hs @@ -35,7 +35,7 @@ runCoreTemp _ = do let dir = "/sys/bus/platform/devices" file = "temp1_input" pattern = "coretemp." - divisor = 1e3 :: Double + divisor = (floor . (/1000.0)) :: Double -> Integer failureMessage = "CoreTemp: N/A" checkedDataRetrieval failureMessage dir file pattern divisor diff --git a/Plugins/Monitors/CpuFreq.hs b/Plugins/Monitors/CpuFreq.hs index 0cf37fb..70482f5 100644 --- a/Plugins/Monitors/CpuFreq.hs +++ b/Plugins/Monitors/CpuFreq.hs @@ -36,5 +36,5 @@ runCpuFreq _ = do pattern = "cpu" divisor = 1e6 :: Double failureMessage = "CpuFreq: N/A" - checkedDataRetrieval failureMessage dir file pattern divisor + checkedDataRetrieval failureMessage dir file pattern (/divisor) |