diff options
-rw-r--r-- | hsm-command/Hsm/Command/Command.hs | 4 | ||||
-rw-r--r-- | hsm-dummy-blinker/Main.hs | 2 | ||||
-rw-r--r-- | hsm-dummy-fail/Main.hs | 4 | ||||
-rw-r--r-- | hsm-dummy-poller/Main.hs | 20 | ||||
-rw-r--r-- | hsm-dummy-pulser/Main.hs | 12 | ||||
-rw-r--r-- | hsm-dummy-receiver/Main.hs | 2 | ||||
-rw-r--r-- | hsm-gpio/Hsm/GPIO.hs | 6 | ||||
-rw-r--r-- | hsm-status/Main.hs | 2 |
8 files changed, 27 insertions, 25 deletions
diff --git a/hsm-command/Hsm/Command/Command.hs b/hsm-command/Hsm/Command/Command.hs index 902d637..4b5ccea 100644 --- a/hsm-command/Hsm/Command/Command.hs +++ b/hsm-command/Hsm/Command/Command.hs @@ -43,8 +43,8 @@ data Speed deriving (Binary, Generic, Read, Show) data Command - = Move Direction Speed Int - | Rotate Angle Speed Int + = Move Direction Speed Word + | Rotate Angle Speed Word deriving (Binary, Generic, Read, Show) commandStream :: diff --git a/hsm-dummy-blinker/Main.hs b/hsm-dummy-blinker/Main.hs index 88b7b5f..9405ae3 100644 --- a/hsm-dummy-blinker/Main.hs +++ b/hsm-dummy-blinker/Main.hs @@ -21,7 +21,7 @@ import System.IO.Echo (withoutInputEcho) data Env = Env { name :: Text , gpio :: [GPIO] - , period :: Int + , period :: Word } $(deriveFromYaml ''Env) diff --git a/hsm-dummy-fail/Main.hs b/hsm-dummy-fail/Main.hs index b2b8988..785304c 100644 --- a/hsm-dummy-fail/Main.hs +++ b/hsm-dummy-fail/Main.hs @@ -21,7 +21,7 @@ import System.IO.Echo (withoutInputEcho) data Env = Env { name :: Text , pubEp :: Text - , alive :: Int + , alive :: Word } $(deriveFromYaml ''Env) @@ -33,7 +33,7 @@ singleError = -- Seemingly, the service needs to be alive for a bit for ZMQ comms to -- kick in. env <- ask @Env - threadDelay env.alive + threadDelay $ fromIntegral env.alive return $ message env.name $ Error 0 "Sent from dummy-fail service" -- Dummy fail service: diff --git a/hsm-dummy-poller/Main.hs b/hsm-dummy-poller/Main.hs index bc60c7c..8e6908b 100644 --- a/hsm-dummy-poller/Main.hs +++ b/hsm-dummy-poller/Main.hs @@ -23,7 +23,7 @@ data Env = Env { name :: Text , subEps :: [Text] , topics :: [Text] - , period :: Int + , period :: Word } $(deriveFromYaml ''Env) @@ -32,16 +32,18 @@ handle :: (Concurrent :> es, Log :> es, Reader Env :> es) => S.Stream (Eff es) [ByteString] -> Eff es () -handle = - S.fold S.drain . S.mapM (\ps -> asks period >>= threadDelay >> handler ps) +handle = S.fold S.drain . S.mapM handler where receiverDomain = "receiver" - handler [] = localDomain receiverDomain $ logInfo_ "No pulse received yet" - handler ps = - forM_ ps $ \p -> - localDomain receiverDomain - $ logInfo_ - $ "Received pulse #" <> pack (show $ body @Int p) + delay = asks period >>= threadDelay . fromIntegral + handler [] = do + localDomain receiverDomain $ logInfo_ "No pulse received yet" + delay + handler ps = do + localDomain receiverDomain + $ forM_ ps + $ logInfo_ . mappend "Received pulse #" . pack . show . body @Word + delay -- Dummy poller service: -- Proof of concept. Polls for "pulses" through ZMQ at a set interval and diff --git a/hsm-dummy-pulser/Main.hs b/hsm-dummy-pulser/Main.hs index cc16cd4..3e2a7ae 100644 --- a/hsm-dummy-pulser/Main.hs +++ b/hsm-dummy-pulser/Main.hs @@ -22,16 +22,16 @@ import System.IO.Echo (withoutInputEcho) data Env = Env { name :: Text , pubEp :: Text - , period :: Int - , pulses :: Int + , period :: Word + , pulses :: Word } $(deriveFromYaml ''Env) pulse :: (Concurrent :> es, Reader Env :> es) => Stream (Eff es) () -pulse = repeatM $ asks period >>= threadDelay +pulse = repeatM $ asks period >>= threadDelay . fromIntegral -stateRun :: F.FsmState () ByteString Env Int +stateRun :: F.FsmState () ByteString Env Word stateRun = F.FsmState "run" $ \_ env sta -> if sta < env.pulses @@ -47,9 +47,9 @@ stateRun = main :: IO () main = launch @Env "dummy-pulser" withoutInputEcho $ \env logger level -> - (pulse & F.fsm @_ @_ @Env @Int & send) + (pulse & F.fsm @_ @_ @Env @Word & send) & runServer @Env - & evalState @Int 1 + & evalState @Word 1 & evalState stateRun & runConcurrent & runLog env.name logger level diff --git a/hsm-dummy-receiver/Main.hs b/hsm-dummy-receiver/Main.hs index 6f3db81..6fb78b1 100644 --- a/hsm-dummy-receiver/Main.hs +++ b/hsm-dummy-receiver/Main.hs @@ -34,7 +34,7 @@ handle = S.fold S.drain . S.mapM handler . mappend "Received pulse #" . pack . show - . body @Int + . body @Word -- Dummy receiver service: -- Proof of concept. Listens for "pulses" through ZMQ and logs each time one diff --git a/hsm-gpio/Hsm/GPIO.hs b/hsm-gpio/Hsm/GPIO.hs index bc08ef5..5357167 100644 --- a/hsm-gpio/Hsm/GPIO.hs +++ b/hsm-gpio/Hsm/GPIO.hs @@ -59,7 +59,7 @@ stateStr False = "off" -- To control the pins, I use a subprocess call to `gpioset`. In the future -- I'd prefer wrapping `libgpiod` directly. It looks like no one has created a -- C wrapper yet, I might do it if I get bored. :) -gpioset :: Log :> es => Bool -> Set GPIO -> [Int] -> Eff es () +gpioset :: Log :> es => Bool -> Set GPIO -> [Word] -> Eff es () gpioset state gpios periods = do localDomain domain $ logTrace_ $ "Calling command: " <> pack command E.unsafeEff_ $ callCommand command @@ -72,7 +72,7 @@ gpioset state gpios periods = do <> concatMap lineArg (toList gpios) logReport :: - (Log :> es, Show key) => Bool -> key -> [Int] -> Set GPIO -> Eff es () + (Log :> es, Show key) => Bool -> key -> [Word] -> Set GPIO -> Eff es () logReport state key periods gpios = do localDomain domain $ logTrace_ report flushLogger @@ -91,7 +91,7 @@ toggle :: (GPIOEffect key :> es, Log :> es, Show key) => Bool -> key - -> [Int] + -> [Word] -> Eff es () toggle state key periods = do GPIOEffect mapper <- E.getStaticRep diff --git a/hsm-status/Main.hs b/hsm-status/Main.hs index ec883ff..634d1d1 100644 --- a/hsm-status/Main.hs +++ b/hsm-status/Main.hs @@ -26,7 +26,7 @@ data Env = Env { name :: Text , gpioOk :: GPIO , gpioError :: GPIO - , period :: Int + , period :: Word , subEps :: [Text] , topics :: [Text] } |