Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code cleaning.

  • Loading branch information...
commit 35413962edf8014e6beb75aa468bc4309064d2b2 1 parent 1a3749d
@mitar authored
View
2  NXT.cabal
@@ -54,9 +54,9 @@ Library
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
View
12 ffi/blue.c
@@ -6,18 +6,15 @@
// 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;
@@ -49,10 +46,8 @@ int findConn(int s, int dev_id, long arg) {
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;
@@ -103,13 +98,9 @@ int rssi(char *address) {
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;
@@ -159,7 +150,4 @@ int lq(char *address) {
hci_close_dev(dd);
return lq;
-#else
- return BLUE_NOT_SUPPORTED;
-#endif
}
View
1  ffi/blue.h
@@ -3,7 +3,6 @@
#define BLUE_ERROR 1000
#define BLUE_NOT_CONNECTED 1001
-#define BLUE_NOT_SUPPORTED 1002
int rssi(char *address);
int lq(char *address);
View
11 lib/Robotics/NXT/BluetoothUtils.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ForeignFunctionInterface,CPP #-}
+{-# LANGUAGE ForeignFunctionInterface, CPP #-}
{-# CFILES ffi/blue.c #-}
module Robotics.NXT.BluetoothUtils (
@@ -32,8 +32,6 @@ blueError :: Int
blueError = 1000
blueNotConnected :: Int
blueNotConnected = 1001
-blueNotSupported :: Int
-blueNotSupported = 1002
{-|
Gets received signal strength indicator (RSSI) of the Bluetooth connection to the NXT brick.
@@ -53,12 +51,10 @@ bluetoothRSSIAddr addr = do
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.
@@ -78,10 +74,9 @@ bluetoothLinkQualityAddr addr = do
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
View
22 tests/Main.hs
@@ -1,20 +1,17 @@
module Main where
-import Robotics.NXT
-import Robotics.NXT.Basic
-
import Control.Exception
-import Control.Monad.State.Class
+import Control.Monad.Trans ()
+import Data.IORef
+import System.Environment
-import Test.Framework (defaultMainWithArgs, testGroup,Test)
+import Test.Framework
import Test.Framework.Providers.HUnit
+import Robotics.NXT
+import Robotics.NXT.Basic
-import System.Environment ( getArgs)
-import Data.IORef
-import Control.Monad.IO.Class (liftIO)
-
-main :: IO()
+main :: IO ()
main = do
(device:args) <- getArgs
bracket (do
@@ -34,5 +31,6 @@ main = do
-- )
tests :: IORef (NXTInternals) -> [Test]
-tests ref= [testGroup "Basic Tests" (concatMap hUnitTestToTests (basicTests ref))
- ]
+tests ref = [
+ testGroup "Basic Tests" (concatMap hUnitTestToTests (basicTests ref)),
+ ]
Please sign in to comment.
Something went wrong with that request. Please try again.