diff options
Diffstat (limited to 'hsm-command')
-rw-r--r-- | hsm-command/Hsm/Command/Command.hs | 49 | ||||
-rw-r--r-- | hsm-command/Hsm/Command/Readline.hs | 40 | ||||
-rw-r--r-- | hsm-command/Main.hs | 35 | ||||
-rw-r--r-- | hsm-command/hsm-command.cabal | 49 |
4 files changed, 0 insertions, 173 deletions
diff --git a/hsm-command/Hsm/Command/Command.hs b/hsm-command/Hsm/Command/Command.hs deleted file mode 100644 index 53964c4..0000000 --- a/hsm-command/Hsm/Command/Command.hs +++ /dev/null @@ -1,49 +0,0 @@ -{-# LANGUAGE DeriveAnyClass #-} - -module Hsm.Command.Command - ( Direction(X, Z) - , Angle(CW, CCW) - , Speed(Slow, Mid, Fast) - , Command(Move, Rotate) - , commandStream - ) where - -import Data.Binary (Binary) -import Data.Maybe (fromJust, isJust) -import Data.Text (pack) -import Effectful (Eff, (:>)) -import Effectful.Log (Log, logAttention_) -import GHC.Generics (Generic) -import Hsm.Command.Readline (Readline, readline) -import Streamly.Data.Stream qualified as S -import Text.Read (readEither) - -data Direction - = X - | Z - deriving (Binary, Generic, Read, Show) - -data Angle - = CW - | CCW - deriving (Binary, Generic, Read, Show) - -data Speed - = Slow - | Mid - | Fast - deriving (Binary, Generic, Read, Show) - -data Command - = Move Direction Speed Int - | Rotate Angle Speed Int - deriving (Binary, Generic, Read, Show) - -commandStream :: (Log :> es, Readline :> es) => S.Stream (Eff es) Command -commandStream = - S.mapMaybeM (parse . fromJust) $ S.takeWhile isJust $ S.repeatM readline - where - parse string = - case readEither string of - Left err -> logAttention_ (pack err) >> return Nothing - Right command -> return $ Just command diff --git a/hsm-command/Hsm/Command/Readline.hs b/hsm-command/Hsm/Command/Readline.hs deleted file mode 100644 index 1caa562..0000000 --- a/hsm-command/Hsm/Command/Readline.hs +++ /dev/null @@ -1,40 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeFamilies #-} - -module Hsm.Command.Readline - ( Readline - , readline - , runReadline - ) where - -import Effectful (Dispatch(Static), DispatchOf, Eff, IOE, (:>)) -import Effectful.Dispatch.Static qualified as S -import Effectful.Log (Log) -import Effectful.Resource (Resource, allocate) -import Hsm.Core.Log (flushLogger) -import System.Console.Haskeline qualified as H -import System.Console.Haskeline.IO qualified as H - -data Readline a b - -type instance DispatchOf Readline = Static S.WithSideEffects - -newtype instance S.StaticRep Readline = - Readline H.InputState - -readline :: (Log :> es, Readline :> es) => Eff es (Maybe String) -readline = do - flushLogger - Readline hdl <- S.getStaticRep - S.unsafeEff_ - $ H.queryInput hdl - $ H.handleInterrupt (return Nothing) - $ H.withInterrupt - $ H.getInputLine "% " - -runReadline :: (IOE :> es, Resource :> es) => Eff (Readline : es) a -> Eff es a -runReadline action = do - handle <- snd <$> allocate (H.initializeInput settings) H.cancelInput - S.evalStaticRep (Readline handle) action - where - settings = H.defaultSettings {H.historyFile = Just ".hsm_command_history"} diff --git a/hsm-command/Main.hs b/hsm-command/Main.hs deleted file mode 100644 index efcbc6e..0000000 --- a/hsm-command/Main.hs +++ /dev/null @@ -1,35 +0,0 @@ -{-# LANGUAGE OverloadedRecordDot #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} - -import Data.Function ((&)) -import Data.Text (Text) -import Effectful (runEff) -import Effectful.Log (runLog) -import Effectful.Reader.Static (runReader) -import Effectful.Resource (runResource) -import Hsm.Command.Command (commandStream) -import Hsm.Command.Readline (runReadline) -import Hsm.Core.App (launch) -import Hsm.Core.Env (deriveFromYaml) -import Hsm.Core.Zmq.Server (runServer, send) - -data Env = Env - { name :: Text - , pubEp :: Text - } - -$(deriveFromYaml ''Env) - --- Command Service: --- Reads movement commands from the terminal and publishes them through ZMQ. -main :: IO () -main = - launch @Env "command" id $ \env logger level -> - (commandStream & send @Env) - & runServer @Env - & runLog env.name logger level - & runReader env - & runReadline - & runResource - & runEff diff --git a/hsm-command/hsm-command.cabal b/hsm-command/hsm-command.cabal deleted file mode 100644 index 836bf07..0000000 --- a/hsm-command/hsm-command.cabal +++ /dev/null @@ -1,49 +0,0 @@ -cabal-version: 3.4 -author: Paul Oliver -build-type: Simple -maintainer: contact@pauloliver.dev -name: hsm-command -version: 0.1.0.0 - -library - build-depends: - , base - , binary - , effectful-core - , haskeline - , hsm-core - , log-effectful - , resourcet-effectful - , streamly-core - , text - - exposed-modules: - Hsm.Command.Command - Hsm.Command.Readline - - ghc-options: -Wall -Wunused-packages - default-language: GHC2021 - -executable command - build-depends: - , base - , binary - , effectful-core - , haskeline - , hsm-core - , log-effectful - , resourcet-effectful - , streamly-core - , text - - main-is: Main.hs - other-modules: - Hsm.Command.Command - Hsm.Command.Readline - - ghc-options: -Wall -Wunused-packages - - if !arch(x86_64) - ghc-options: -optl=-mno-fix-cortex-a53-835769 - - default-language: GHC2021 |