diff options
author | Fabian Kirchner <kirchner@posteo.de> | 2024-08-13 12:54:27 +0200 |
---|---|---|
committer | Fabian Kirchner <kirchner@posteo.de> | 2024-08-13 12:54:33 +0200 |
commit | 62049f094ac0b270aa4464127a6a3ebb405b6c0c (patch) | |
tree | c0183c61a7799b4bffc47892f815471c3c90b6b5 | |
parent | 0b52b4fba669e334099dc306d0dd68e3c54de121 (diff) |
feat: add thermal info
-rw-r--r-- | app/Main.hs | 3 | ||||
-rw-r--r-- | app/Sensor.hs | 20 |
2 files changed, 22 insertions, 1 deletions
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 |