jpmoresmau avatar jpmoresmau committed 4d431fc

Get to compile under windows

Comments (0)

Files changed (3)

   GHC-prof-options:    -Wall
   GHC-shared-options:  -Wall
   Default-language:    Haskell2010
-  C-sources:           ffi/blue.c
-  Includes:            ffi/blue.h
 
   if !os(windows)
     Build-depends:     unix >= 2.4 && < 3
 
   if os(linux)
     Extra-libraries:   bluetooth
+    C-sources:         ffi/blue.c
+    Includes:          ffi/blue.h
 
 Source-repository head
   type:                mercurial
                        test-framework-quickcheck2 >= 0.2 && < 1,
                        test-framework-hunit >= 0.2 && < 1,
                        mtl >= 1.1 && < 3,
-                       NXT == 0.2.0
+                       NXT == 0.2.0,
+                       transformers
   GHC-options:         -Wall -rtsopts
   Default-language:    Haskell2010
   HS-source-dirs:      tests

lib/Robotics/NXT/BluetoothUtils.hs

-{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE ForeignFunctionInterface,CPP #-}
 {-# CFILES ffi/blue.c #-}
 
 module Robotics.NXT.BluetoothUtils (
 import Robotics.NXT.Types
 import Robotics.NXT.Internals
 
+#ifdef linux_HOST_OS
 -- Foreign function call for C function which returns RSSI Bluetooth value of a connection to a given Bluetooth address
 foreign import ccall unsafe "rssi" rssi :: CString -> IO CInt
 
 -- Foreign function call for C function which returns link quality Bluetooth value of a connection to a given Bluetooth address
 foreign import ccall unsafe "lq" lq :: CString -> IO CInt
+#endif
 
 -- As defined in blue.h
 blueError :: Int
 
 bluetoothRSSIAddr :: BTAddress -> NXT Int
 bluetoothRSSIAddr addr = do
+#ifdef linux_HOST_OS
   ret <- liftIO $ withCString addr rssi
   let ret' = fromIntegral ret
   case ret' of
       | ret' == blueNotConnected -> liftIO $ throwIO $ NXTException "Connection not established"
       | ret' == blueNotSupported -> liftIO $ throwIO $ NXTException "Not supported on this system"
       | otherwise                -> return ret'
+#else
+    liftIO $ throwIO $ NXTException "bluetoothRSSIAddr: only supported on Linux"        
+#endif
+    
 
 {-|
 Gets link quality of the Bluetooth connection to the NXT brick.
 
 bluetoothLinkQualityAddr :: BTAddress -> NXT Int
 bluetoothLinkQualityAddr addr = do
+#ifdef linux_HOST_OS
   ret <- liftIO $ withCString addr lq
   let ret' = fromIntegral ret
   case ret' of
       | ret' == blueNotConnected -> liftIO $ throwIO $ NXTException "Connection not established"
       | ret' == blueNotSupported -> liftIO $ throwIO $ NXTException "Not supported on this system"
       | otherwise                -> return ret'
+#else
+    liftIO $ throwIO $ NXTException "bluetoothLinkQualityAddr: only supported on Linux"        
+#endif
 
 bluetoothAddress :: NXT BTAddress
 bluetoothAddress = do

lib/Robotics/NXT/Protocol.hs

 import Data.Word
 import System.IO
 import System.Hardware.Serialport hiding (One)
-#ifndef windows_HOST_OS
+#if (!defined(mingw32_HOST_OS) && !defined(windows_HOST_OS))
 import System.Posix.Signals
 #endif
 import Text.Printf
 -}
 initialize :: FilePath -> IO NXTInternals
 initialize device = do
-#ifndef windows_HOST_OS
+#if (!defined(mingw32_HOST_OS) && !defined(windows_HOST_OS))
   -- we have to block signals from interrupting openFd system call (fixed in GHC versions after 6.12.1)
   let signals = foldl (flip addSignal) emptySignalSet [virtualTimerExpired]
   blockSignals signals
 #endif
   h <- openSerial device defaultSerialSettings { commSpeed = CS115200, timeout = 1000 }
-#ifndef windows_HOST_OS
+#if (!defined(mingw32_HOST_OS) && !defined(windows_HOST_OS))
   unblockSignals signals
 #endif
   when debug $ hPutStrLn stderr "initialized"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.