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/Main.hs | 3 ++- app/Sensor.hs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index aadae2d..216b3ce 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -193,7 +193,8 @@ createWindow args = do [pure (lit (if args.icons then "\xf1638 " else "io ")), lit <$> io], [pure (lit (if args.icons then "\xf0200 " else "net ")), lit <$> net], [pure (lit " "), lit <$> Sensor.snd], - [pure (lit " "), lit <$> bat], + [pure (lit " "), lit <$> thermal], + [pure (lit " "), lit <$> bat], [pure (lit " "), lit <$> weatherForecast], [pure (lit " "), lit <$> date, pure (lit ", "), lit <$> time], [] 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