diff options
Diffstat (limited to 'app/Sensor.hs')
-rw-r--r-- | app/Sensor.hs | 20 |
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 |