summaryrefslogtreecommitdiffstats
path: root/app/Sensor.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-08-12 14:11:40 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-08-12 14:56:02 +0200
commitc27c55fad9cd1fbf0d27ebcd919b78f59c4cbbb0 (patch)
tree40941f3df361a33cea0b0dbdfcbe561e4854e7f9 /app/Sensor.hs
parentbb8fc0abf3d55f292601d04517818f74f79c6e30 (diff)
feat: critical battery blinks
Diffstat (limited to 'app/Sensor.hs')
-rw-r--r--app/Sensor.hs32
1 files changed, 21 insertions, 11 deletions
diff --git a/app/Sensor.hs b/app/Sensor.hs
index 0c05519..9ef38d0 100644
--- a/app/Sensor.hs
+++ b/app/Sensor.hs
@@ -207,17 +207,27 @@ instance (S.MonadSensor m) => S.Aggregate m BatStat Float where
<*> (readFile (fp </> "energy_full") (pure . read))
]
-bat :: (S.MonadSensor m) => S.Sensor m () String
-bat = do
- value <- S.sensor BatStat
- return
- ( if
- | 0.8 < value -> "\xf240"
- | 0.6 < value -> "\xf241"
- | 0.4 < value -> "\xf242"
- | 0.2 < value -> "\xf243"
- | otherwise -> "\xf244"
- )
+bat :: (S.MonadSensor m) => S.Sensor m () P.Doc
+bat =
+ S.sensor BatStat >>= \value ->
+ if
+ | value >= 0.8 -> pure (P.pretty "\xf240 ")
+ | value >= 0.6 -> pure (P.pretty "\xf241 ")
+ | value >= 0.4 -> pure (P.pretty "\xf242 ")
+ | value >= 0.2 -> pure (P.pretty "\xf243 ")
+ | otherwise ->
+ (\b -> (if b then id else (P.color P.Red)) (P.pretty "\xf244 "))
+ <$> blink
+
+data Blink = Blink deriving (Show)
+
+blink :: (S.MonadSensor m) => S.Sensor m () Bool
+blink = S.sensor Blink
+
+instance (S.MonadSensor m) => S.Aggregate m Blink Bool where
+ aggregate _ = loop True
+ where
+ loop b = S.yield b >> sleep >> loop (not b)
choice :: a -> [IO a] -> IO a
choice def [] = pure def