diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2011-02-25 16:27:45 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2011-02-25 16:27:45 +0100 |
commit | 7561fa48cf88603b2f839945902e75a6b6d2ecd4 (patch) | |
tree | 3e42d10f1642ab5dc3d684153e8b2f293a648332 /src/Plugins/Monitors/ThermalZone.hs | |
parent | 34dcc41287af8070ffab2e049016ad7dae39e255 (diff) | |
download | xmobar-7561fa48cf88603b2f839945902e75a6b6d2ecd4.tar.gz xmobar-7561fa48cf88603b2f839945902e75a6b6d2ecd4.tar.bz2 |
New monitor, ThermalZone, addressing issue 44
Diffstat (limited to 'src/Plugins/Monitors/ThermalZone.hs')
-rw-r--r-- | src/Plugins/Monitors/ThermalZone.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Plugins/Monitors/ThermalZone.hs b/src/Plugins/Monitors/ThermalZone.hs new file mode 100644 index 0000000..8ba858a --- /dev/null +++ b/src/Plugins/Monitors/ThermalZone.hs @@ -0,0 +1,43 @@ +------------------------------------------------------------------------------ +-- | +-- Module : Plugins.Monitors.ThermalZone +-- Copyright : (c) 2011 Jose Antonio Ortega Ruiz +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : jao@gnu.org +-- Stability : unstable +-- Portability : portable +-- Created : Fri Feb 25, 2011 03:18 +-- +-- +-- A thermal zone plugin based on the sysfs linux interface. +-- See http://www.mjmwired.net/kernel/Documentation/thermal/sysfs-api.txt +-- +------------------------------------------------------------------------------ + +module Plugins.Monitors.ThermalZone (thermalZoneConfig, runThermalZone) where + +import Plugins.Monitors.Common + +import System.Posix.Files (fileExist) +import qualified Data.ByteString.Char8 as B + +-- | Default thermal configuration. +thermalZoneConfig :: IO MConfig +thermalZoneConfig = mkMConfig "<temp>C" ["temp"] + +-- | Retrieves thermal information. Argument is name of thermal +-- directory in \/sys\/clas\/thermal. Returns the monitor string +-- parsed according to template (either default or user specified). +runThermalZone :: [String] -> Monitor String +runThermalZone args = do + let zone = head args + file = "/sys/class/thermal/thermal_zone" ++ zone ++ "/temp" + parse = return . (read :: String -> Int) . B.unpack + exists <- io $ fileExist file + if exists + then do mdegrees <- io $ B.readFile file >>= parse + temp <- showWithColors show (mdegrees `quot` 1000) + parseTemplate [ temp ] + else return "N/A" + |