summaryrefslogtreecommitdiffstats
path: root/app/Sensor.hs
diff options
context:
space:
mode:
authorLibravatar Fabian Kirchner <kirchner@posteo.de>2024-08-13 12:54:27 +0200
committerLibravatar Fabian Kirchner <kirchner@posteo.de>2024-08-13 12:54:33 +0200
commit62049f094ac0b270aa4464127a6a3ebb405b6c0c (patch)
treec0183c61a7799b4bffc47892f815471c3c90b6b5 /app/Sensor.hs
parent0b52b4fba669e334099dc306d0dd68e3c54de121 (diff)
feat: add thermal info
Diffstat (limited to 'app/Sensor.hs')
-rw-r--r--app/Sensor.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/Sensor.hs b/app/Sensor.hs
index 612b2bc..b6cfba5 100644
--- a/app/Sensor.hs
+++ b/app/Sensor.hs
@@ -26,6 +26,7 @@ module Sensor
Sensor.snd,
disk,
date,
+ thermal,
time,
wmName,
weatherForecast,
@@ -116,6 +117,25 @@ diagram n sf = S.feedbackS [] $ proc ((), xs) -> do
x <- sf -< ()
returnA -< (P.diagram n (reverse (x : xs)), take (2 * (n - 1) + 1) (x : xs))
+data Thermal = Thermal deriving (Show)
+
+instance (S.MonadSensor m) => S.Aggregate m Thermal Int where
+ aggregate _ = forever do S.yield =<< parse <* sleep
+ where
+ parse = liftIO do
+ is <- listDirectory "/sys/class/thermal"
+ maximum <$> mapM (parse1 . ("/sys/class/thermal" </>)) is
+ parse1 fp = do
+ (choice 0 [readFile (fp </> "temp") (pure . read . strip)])
+
+thermal :: (S.MonadSensor m) => S.Sensor m () String
+thermal = do
+ temp <- S.sensor Thermal
+ pure (printf "%.1f" (value temp))
+ where
+ value :: Int -> Float
+ value temp = fromIntegral temp / 1000.0
+
data IoStat = IoStat deriving (Show)
instance (S.MonadSensor m) => S.Aggregate m IoStat Int where