From b28555a116278861ffbbfc43199a470e438d45f4 Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Mon, 12 Aug 2024 13:59:50 +0200 Subject: feat: adjust bat icon depending on value --- app/Main.hs | 2 +- app/Sensor.hs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index 7d499d8..caee3fb 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -193,7 +193,7 @@ 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 (if args.icons then "\xf028 " else "snd ")), lit <$> Sensor.snd], - [pure (lit (if args.icons then "\xf240 " else "bat ")), lit <$> bat], + [lit <$> bat], [pure (lit " "), lit <$> date, pure (lit ", "), lit <$> time], [] ] diff --git a/app/Sensor.hs b/app/Sensor.hs index 55d2554..2dcf6c0 100644 --- a/app/Sensor.hs +++ b/app/Sensor.hs @@ -4,6 +4,7 @@ {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE QuasiQuotes #-} @@ -206,8 +207,17 @@ instance (S.MonadSensor m) => S.Aggregate m BatStat Float where <*> (readFile (fp "energy_full") (pure . read)) ] -bat :: (S.MonadSensor m) => S.Sensor m () Float -bat = S.sensor BatStat +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" + ) choice :: a -> [IO a] -> IO a choice def [] = pure def -- cgit v1.2.3