module Robotics.NXT.Internals where
import Control.Monad.State
import Data.Time.Clock.POSIX
import Data.Typeable
import System.Hardware.Serialport
import Robotics.NXT.Externals
newtype NXT a = NXT (StateT NXTInternals IO a) deriving (Monad, MonadIO, Functor, MonadFix)
data NXTInternals = NXTInternals {
nxthandle :: SerialPort,
address :: Maybe BTAddress,
modules :: [(ModuleName, ModuleInfo)],
sleeptime :: Maybe Duration,
lastkeepalive :: Maybe POSIXTime
} deriving (Typeable)
instance Show NXTInternals where
show = show . typeOf
runNXT :: NXT a -> NXTInternals -> IO (a, NXTInternals)
runNXT (NXT action) = runStateT action
execNXT :: NXT a -> NXTInternals -> IO NXTInternals
execNXT (NXT action) = execStateT action
modifyNXT :: (NXTInternals -> NXTInternals) -> NXT ()
modifyNXT f = NXT (modify f)
getsNXT :: (NXTInternals -> a) -> NXT a
getsNXT f = NXT (gets f)