aboutsummaryrefslogtreecommitdiff
path: root/hsm-gpio/Hsm/GPIO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-gpio/Hsm/GPIO.hs')
-rw-r--r--hsm-gpio/Hsm/GPIO.hs31
1 files changed, 10 insertions, 21 deletions
diff --git a/hsm-gpio/Hsm/GPIO.hs b/hsm-gpio/Hsm/GPIO.hs
index e3deabd..bc08ef5 100644
--- a/hsm-gpio/Hsm/GPIO.hs
+++ b/hsm-gpio/Hsm/GPIO.hs
@@ -64,20 +64,12 @@ gpioset state gpios periods = do
localDomain domain $ logTrace_ $ "Calling command: " <> pack command
E.unsafeEff_ $ callCommand command
where
- command :: String
+ lineArg gpio = show gpio <> "=" <> stateStr state <> " "
command =
"gpioset -t"
<> intercalate "," (show <$> periods)
<> " "
<> concatMap lineArg (toList gpios)
- --
- lineArg :: GPIO -> String
- lineArg gpio = show gpio <> "=" <> stateStr state <> " "
-
-getGPIOs :: GPIOEffect key :> es => key -> Eff es (Set GPIO)
-getGPIOs key = do
- GPIOEffect mapper <- E.getStaticRep
- return $ mapper key
logReport ::
(Log :> es, Show key) => Bool -> key -> [Int] -> Set GPIO -> Eff es ()
@@ -85,7 +77,6 @@ logReport state key periods gpios = do
localDomain domain $ logTrace_ report
flushLogger
where
- report :: Text
report =
"Setting pins "
<> pack (show gpios)
@@ -103,29 +94,27 @@ toggle ::
-> [Int]
-> Eff es ()
toggle state key periods = do
- gpios <- getGPIOs key
- logReport state key periods gpios
- gpioset state gpios periods
+ GPIOEffect mapper <- E.getStaticRep
+ set $ mapper key
+ where
+ set gpios = do
+ logReport state key periods gpios
+ gpioset state gpios periods
runGPIO ::
- forall key es a. (IOE :> es, Log :> es, Bounded key, Enum key)
+ (IOE :> es, Log :> es, Bounded key, Enum key)
=> (key -> Set GPIO)
-> Eff (GPIOEffect key : es) a
-> Eff es a
runGPIO mapper action =
- E.evalStaticRep (GPIOEffect mapper) $ finally action releaser
+ E.evalStaticRep (GPIOEffect mapper) $ finally action release
where
- gpios :: Set GPIO
gpios = unions $ mapper <$> [minBound .. maxBound]
- --
- endReport :: Text
endReport =
"Setting all mapped pins "
<> pack (show gpios)
<> " to state "
<> stateStr False
- --
- releaser :: Eff (GPIOEffect key : es) ()
- releaser = do
+ release = do
localDomain domain $ logTrace_ endReport
gpioset False gpios [0]