summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose A. Ortega Ruiz <jao@gnu.org>2010-01-19 20:19:55 +0100
committerJose A. Ortega Ruiz <jao@gnu.org>2010-01-19 20:19:55 +0100
commit14b05b90ee5ba5e1baa4c5333341431b306e4e95 (patch)
tree2609cc6366f72604c95def46bbbc044511e8707f
parent3d100946bc6f900fb5a4035213f4c8c1fd81f062 (diff)
downloadxmobar-14b05b90ee5ba5e1baa4c5333341431b306e4e95.tar.gz
xmobar-14b05b90ee5ba5e1baa4c5333341431b306e4e95.tar.bz2
CoreTemp: return temperatures as integer values
Ignore-this: ce917bed99a2d812238d4581fbbff3d6 darcs-hash:20100119191955-40885-21098d264f191a572a0e30f83296d26405d38cba.gz
-rw-r--r--Plugins/Monitors/CoreCommon.hs22
-rw-r--r--Plugins/Monitors/CoreTemp.hs2
-rw-r--r--Plugins/Monitors/CpuFreq.hs2
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)