Skip to content

Commit

Permalink
Code improvements by HLint.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Nov 22, 2010
1 parent 8128123 commit 3c5fd76
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions NXT.cabal
@@ -1,5 +1,5 @@
Name: NXT Name: NXT
Version: 0.1.2 Version: 0.1.3
Synopsis: A Haskell interface to Lego Mindstorms NXT Synopsis: A Haskell interface to Lego Mindstorms NXT
Description: A Haskell interface to Lego Mindstorms NXT over Bluetoooth. It supports direct commands, messages and Description: A Haskell interface to Lego Mindstorms NXT over Bluetoooth. It supports direct commands, messages and
many sensors (also unofficial). It has also support for a simple message-based control of a NXT brick many sensors (also unofficial). It has also support for a simple message-based control of a NXT brick
Expand Down Expand Up @@ -59,7 +59,7 @@ Executable nxt-shutdown
HS-source-dirs: src HS-source-dirs: src
Build-depends: base >= 4 && < 5, Build-depends: base >= 4 && < 5,
mtl >= 1.1 && < 2, mtl >= 1.1 && < 2,
NXT == 0.1.2 NXT == 0.1.3
GHC-options: -Wall GHC-options: -Wall


Executable nxt-upload Executable nxt-upload
Expand All @@ -69,7 +69,7 @@ Executable nxt-upload
mtl >= 1.1 && < 2, mtl >= 1.1 && < 2,
bytestring >= 0.9 && < 1, bytestring >= 0.9 && < 1,
filepath >= 1.1 && < 2, filepath >= 1.1 && < 2,
NXT == 0.1.2 NXT == 0.1.3
GHC-options: -Wall GHC-options: -Wall
GHC-prof-options: -Wall GHC-prof-options: -Wall
GHC-shared-options: -Wall GHC-shared-options: -Wall
4 changes: 2 additions & 2 deletions lib/Robotics/NXT/Internals.hs
Expand Up @@ -28,13 +28,13 @@ data NXTInternals = NXTInternals {
Runs a computation in a context of a given 'NXTInternals' token, returning a value and a new token. Runs a computation in a context of a given 'NXTInternals' token, returning a value and a new token.
-} -}
runNXT :: NXT a -> NXTInternals -> IO (a, NXTInternals) runNXT :: NXT a -> NXTInternals -> IO (a, NXTInternals)
runNXT (NXT action) internals = runStateT action internals runNXT (NXT action) = runStateT action


{-| {-|
Runs a computation in a context of a given 'NXTInternals' token, returning just a new token. Runs a computation in a context of a given 'NXTInternals' token, returning just a new token.
-} -}
execNXT :: NXT a -> NXTInternals -> IO NXTInternals execNXT :: NXT a -> NXTInternals -> IO NXTInternals
execNXT (NXT action) internals = execStateT action internals execNXT (NXT action) = execStateT action


modifyNXT :: (NXTInternals -> NXTInternals) -> NXT () modifyNXT :: (NXTInternals -> NXTInternals) -> NXT ()
modifyNXT f = NXT (modify f) modifyNXT f = NXT (modify f)
Expand Down
10 changes: 5 additions & 5 deletions lib/Robotics/NXT/MotorControl.hs
Expand Up @@ -51,7 +51,7 @@ Requires dynamic\/minimal pauses.
-} -}
controlledMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> [MotorControlMode] -> NXT () controlledMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> [MotorControlMode] -> NXT ()
controlledMotorCmd ports power limit modes = motorControlSend message controlledMotorCmd ports power limit modes = motorControlSend message
where message = "1" ++ (fromPorts ports) ++ (fromPower power) ++ (fromLimit limit) ++ modes' where message = "1" ++ fromPorts ports ++ fromPower power ++ fromLimit limit ++ modes'
modes' = show . sum . zipWith (*) [1, 2, 4] . map (fromEnum . flip elem modes) $ [HoldBrake ..] modes' = show . sum . zipWith (*) [1, 2, 4] . map (fromEnum . flip elem modes) $ [HoldBrake ..]


{-| {-|
Expand All @@ -62,7 +62,7 @@ The same thing can be achieved by using 'resetMotorPosition' with 'InternalPosit
-} -}
resetErrorCorrection :: [OutputPort] -> NXT () resetErrorCorrection :: [OutputPort] -> NXT ()
resetErrorCorrection ports = motorControlSend message resetErrorCorrection ports = motorControlSend message
where message = "2" ++ ports' where message = '2' : ports'
ports' = fromPorts ports ports' = fromPorts ports


{-| {-|
Expand All @@ -73,7 +73,7 @@ Implements static pauses.
-} -}
isMotorReady :: [OutputPort] -> NXT [Bool] isMotorReady :: [OutputPort] -> NXT [Bool]
isMotorReady ports = do isMotorReady ports = do
mapM_ (\port -> motorControlSend $ "3" ++ port) ports'' mapM_ (\port -> motorControlSend $ '3' : port) ports''
liftIO $ threadDelay (10 * 1000) -- 10 ms liftIO $ threadDelay (10 * 1000) -- 10 ms
replies <- mapM (\_ -> motorControlReceive) ports'' replies <- mapM (\_ -> motorControlReceive) ports''
liftIO $ threadDelay (10 * 1000) -- 10 ms liftIO $ threadDelay (10 * 1000) -- 10 ms
Expand All @@ -89,7 +89,7 @@ Requires dynamic\/minimal pauses.
-} -}
classicMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> SpeedRegulation -> NXT () classicMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> SpeedRegulation -> NXT ()
classicMotorCmd ports power limit regulation = motorControlSend message classicMotorCmd ports power limit regulation = motorControlSend message
where message = "4" ++ (fromPorts ports) ++ (fromPower power) ++ (fromLimit limit) ++ regulation' where message = "4" ++ fromPorts ports ++ fromPower power ++ fromLimit limit ++ regulation'
regulation' | regulation = "1" regulation' | regulation = "1"
| otherwise = "0" | otherwise = "0"


Expand Down Expand Up @@ -131,7 +131,7 @@ fromPorts ports | length ports' == 1 = show . fromEnum . head $ ports'
where ports' = sort . nub $ ports where ports' = sort . nub $ ports


fromPower :: OutputPower -> String fromPower :: OutputPower -> String
fromPower power | (-100) <= power && power <= 100 = printf "%03d" $ if power < 0 then 100 + (abs power) else power fromPower power | (-100) <= power && power <= 100 = printf "%03d" $ if power < 0 then 100 + abs power else power
| otherwise = throw $ PatternMatchFail "fromPower" | otherwise = throw $ PatternMatchFail "fromPower"


fromLimit :: TachoLimit -> String fromLimit :: TachoLimit -> String
Expand Down
2 changes: 1 addition & 1 deletion lib/Robotics/NXT/Sensor/Ultrasonic.hs
Expand Up @@ -235,4 +235,4 @@ Helper function which gets all measurements available in order (closer first).
-} -}
usGetAllMeasurements :: InputPort -> NXT [Measurement] usGetAllMeasurements :: InputPort -> NXT [Measurement]
usGetAllMeasurements input = mapMaybeM (usGetMeasurement input) [0..7] usGetAllMeasurements input = mapMaybeM (usGetMeasurement input) [0..7]
where mapMaybeM f as = catMaybes <$> (mapM f as) where mapMaybeM f as = catMaybes <$> mapM f as

0 comments on commit 3c5fd76

Please sign in to comment.