Permalink
Browse files

Ported to GHC 7.0.

  • Loading branch information...
mitar committed Nov 25, 2010
1 parent cb6e348 commit cdcba4bca4151945e14b5174f90da270c755df5c
Showing with 15 additions and 14 deletions.
  1. +9 −9 NXT.cabal
  2. +3 −1 lib/Robotics/NXT/MotorControl.hs
  3. +3 −4 lib/Robotics/NXT/Protocol.hs
View
@@ -1,5 +1,5 @@
Name: NXT
-Version: 0.1.4
+Version: 0.1.5
Synopsis: A Haskell interface to Lego Mindstorms NXT
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
@@ -33,8 +33,8 @@ Library
Robotics.NXT.Remote,
Robotics.NXT.Sensor.Compass,
Robotics.NXT.Sensor.Ultrasonic
- Build-depends: base >= 4 && < 5,
- mtl >= 1.1 && < 2,
+ Build-depends: base >= 4.3 && < 5,
+ mtl >= 1.1 && < 3,
bytestring >= 0.9 && < 1,
unix >= 2.4 && < 3,
time >= 1.1 && < 2
@@ -57,19 +57,19 @@ Library
Executable nxt-shutdown
Main-is: Shutdown.hs
HS-source-dirs: src
- Build-depends: base >= 4 && < 5,
- mtl >= 1.1 && < 2,
- NXT == 0.1.4
+ Build-depends: base >= 4.3 && < 5,
+ mtl >= 1.1 && < 3,
+ NXT == 0.1.5
GHC-options: -Wall
Executable nxt-upload
Main-is: UploadFiles.hs
HS-source-dirs: src
- Build-depends: base >= 4 && < 5,
- mtl >= 1.1 && < 2,
+ Build-depends: base >= 4.3 && < 5,
+ mtl >= 1.1 && < 3,
bytestring >= 0.9 && < 1,
filepath >= 1.1 && < 2,
- NXT == 0.1.4
+ NXT == 0.1.5
GHC-options: -Wall
GHC-prof-options: -Wall
GHC-shared-options: -Wall
@@ -77,10 +77,12 @@ isMotorReady ports = do
liftIO $ threadDelay (10 * 1000) -- 10 ms
replies <- mapM (\_ -> motorControlReceive) ports''
liftIO $ threadDelay (10 * 1000) -- 10 ms
- let replies' = map (\[p, r] -> ([p], r == '1')) replies
+ let replies' = map ready replies
return $ map (fromJust . (`lookup` replies')) ports'
where ports' = map (show . fromEnum) ports
ports'' = nub ports'
+ ready [p, r] = ([p], r == '1')
+ ready _ = undefined
{-|
Interface to @CLASSIC_MOTORCMD@ command which is very similar to 'setOutputState' but better interacts with @MotorControl@.
@@ -131,7 +131,7 @@ import Robotics.NXT.Internals
-- TODO: All functions which requests ModuleInfo could populate module ID cache along the way
-- TODO: Add an optional warning if direction of communication changes
--- TODO: Implement all missing "confirm" versions
+-- TODO: Implement all missing "confirm" versions of functions
-- Foreign function call for C function which initialize serial port device on POSIX systems
foreign import ccall unsafe "initSerialPort" initSerialPort' :: Fd -> IO CInt
@@ -175,15 +175,14 @@ terminate i = do
hClose h
when debug $ hPutStrLn stderr "terminated"
--- TODO: Change to mask/restore in GHC 7.0
{-|
Function which initializes and terminates Bluetooth connection to the NXT brick (using 'initialize' and 'terminate') and in-between
runs given computation. It terminates Bluetooth connection on an exception, too, rethrowing it afterwards.
-}
withNXT :: FilePath -> NXT a -> IO a
-withNXT device action = block $ do
+withNXT device action = mask $ \restore -> do
i <- initialize device
- (r, i') <- unblock (runNXT action i) `onException` terminate i
+ (r, i') <- restore (runNXT action i) `onException` terminate i
terminate i'
return r

0 comments on commit cdcba4b

Please sign in to comment.