From 62049f094ac0b270aa4464127a6a3ebb405b6c0c Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Tue, 13 Aug 2024 12:54:27 +0200 Subject: feat: add thermal info --- app/Sensor.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/Sensor.hs') 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 -- cgit v1.2.3