Commits

mitar committed cd151d0

Code cleaning.

Comments (0)

Files changed (5)

     Build-depends:     unix >= 2.4 && < 3
 
   if os(linux)
-    Extra-libraries:   bluetooth
     C-sources:         ffi/blue.c
     Includes:          ffi/blue.h
+    Extra-libraries:   bluetooth
 
 Source-repository head
   type:                mercurial
 
 // TODO: This works currently only on Linux
 
-#if defined(LINUX) || defined(__linux__)
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/hci.h>
 #include <bluetooth/hci_lib.h>
-#endif
 
 #include "blue.h"
 
 // This is not really thread-safe
 bool error;
 
-#if defined(LINUX) || defined(__linux__)
 int findConn(int s, int dev_id, long arg) {
 	struct hci_conn_list_req *cl;
 	struct hci_conn_info *ci;
 	free(cl);
 	return 0;
 }
-#endif
 
 int rssi(char *address) {
-#if defined(LINUX) || defined(__linux__)
 	struct hci_conn_info_req *cr;
 	int8_t rssi;
 	int dd, dev_id;
 	hci_close_dev(dd);
 	
 	return rssi;
-#else
-    return BLUE_NOT_SUPPORTED;
-#endif
 }
 
 int lq(char *address) {
-#if defined(LINUX) || defined(__linux__)
 	struct hci_conn_info_req *cr;
 	uint8_t lq;
 	int dd, dev_id;
 	hci_close_dev(dd);
 	
 	return lq;
-#else
-	return BLUE_NOT_SUPPORTED;
-#endif
 }
 
 #define BLUE_ERROR 1000
 #define BLUE_NOT_CONNECTED 1001
-#define BLUE_NOT_SUPPORTED 1002
 
 int rssi(char *address);
 int lq(char *address);

lib/Robotics/NXT/BluetoothUtils.hs

-{-# LANGUAGE ForeignFunctionInterface,CPP #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP #-}
 {-# CFILES ffi/blue.c #-}
 
 module Robotics.NXT.BluetoothUtils (
 blueError = 1000
 blueNotConnected :: Int
 blueNotConnected = 1001
-blueNotSupported :: Int
-blueNotSupported = 1002
 
 {-|
 Gets received signal strength indicator (RSSI) of the Bluetooth connection to the NXT brick.
   case ret' of
     _ | ret' == blueError        -> liftIO $ throwIO $ NXTException "Could not get connection's RSSI"
       | 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"        
+    liftIO $ throwIO $ NXTException "Not supported on this system"
 #endif
-    
 
 {-|
 Gets link quality of the Bluetooth connection to the NXT brick.
   case ret' of
     _ | ret' == blueError        -> liftIO $ throwIO $ NXTException "Could not get connection's link quality"
       | 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"        
+  liftIO $ throwIO $ NXTException "Not supported on this system"
 #endif
 
 bluetoothAddress :: NXT BTAddress
 module Main where
 
+import Control.Exception
+import Control.Monad.Trans ()
+import Data.IORef
+import System.Environment
+
+import Test.Framework
+import Test.Framework.Providers.HUnit
+
 import Robotics.NXT
 import Robotics.NXT.Basic
 
-import Control.Exception
-import Control.Monad.State.Class
-
-import Test.Framework (defaultMainWithArgs, testGroup,Test)
-import Test.Framework.Providers.HUnit
-
-
-import System.Environment ( getArgs)
-import Data.IORef
-import Control.Monad.IO.Class (liftIO)
-
-main :: IO()
+main :: IO ()
 main = do
   (device:args) <- getArgs
   bracket (do
 --        )
 
 tests :: IORef (NXTInternals) -> [Test]
-tests ref= [testGroup "Basic Tests" (concatMap hUnitTestToTests (basicTests ref))
-         ]
+tests ref = [
+    testGroup "Basic Tests" (concatMap hUnitTestToTests (basicTests ref)),
+  ]