aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyfantom.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyfantom.py')
-rw-r--r--pyfantom.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/pyfantom.py b/pyfantom.py
index 75d6e3a..3570479 100644
--- a/pyfantom.py
+++ b/pyfantom.py
@@ -3,7 +3,7 @@
# License version 2 or any later version, or the Mozilla Public License
# version 2.0.
#
-# Copyright (C) 2011 Tat-Chee Wan
+# Copyright (C) 2011-2013 Tat-Chee Wan
# Copyright (C) 2011 Nicolas Schodet
#
# --------------
@@ -36,17 +36,20 @@ import collections
kMaxFileNameLength = 101
BT_PIN = "1234"
VI_ERROR_IO = -0x4000ffc2 # Equivalent to 0xBFFF003E
-
+MACOSX_BTMODVER = "12.0.0"
+MACOSX_BTENABLE = True
DEBUG = True
libpath = None
# Check platform.
platform_type = platform.system()
+platform_rel = platform.release()
if DEBUG:
- print "Running on %s Platform" % platform_type
+ print "Running on %s Platform (Rel. %s)" % (platform_type, platform_rel)
if platform_type == 'Darwin':
import sys
+
if sys.maxsize > 2**32:
raise RuntimeError("fantom drivers not available in 64 bit mode.\n"
"You can run python in 32 bit mode (Bash shell syntax) using:\n"
@@ -55,6 +58,13 @@ if platform_type == 'Darwin':
"\n\tNote: This approach will work for for both Apple's Python >= 2.6\n\t\tand MacPorts' Python >= 2.7 installation\n")
#libpath = '/Library/Frameworks/Fantom.framework/Fantom'
libpath = ctypes.util.find_library('fantom')
+
+ if platform_rel >= MACOSX_BTMODVER:
+ print " Bluetooth Stack not supported (Rel >= %s)" % MACOSX_BTMODVER
+ MACOSX_BTENABLE = False
+ compatlibpath = './IOBluetooth-Compat.dylib'
+
+
from AppKit import NSAutoreleasePool, NSApplication
elif platform_type == 'Linux':
libpath = ctypes.util.find_library('fantom')
@@ -70,7 +80,15 @@ else:
raise RuntimeError("Fantom Driver not found")
# Load library.
+if not MACOSX_BTENABLE:
+ print "Loading IOBluetooth-Compat Library (", compatlibpath, ")"
+ # Need to set DYLD_FORCE_FLAT_NAMESPACE in env
+ compatdll = ctypes.cdll.LoadLibrary(compatlibpath)
+
+# RTLD_NOW is set by ctypes and can't be overridden
+# http://hg.python.org/cpython/file/2.7/Modules/_ctypes/callproc.c#l1432
dll = ctypes.cdll.LoadLibrary(libpath)
+
dll.nFANTOM100_createNXTIterator.argtypes = [c_ushort, c_uint, POINTER(c_int)]
dll.nFANTOM100_createNXTIterator.restype = c_uint
dll.nFANTOM100_destroyNXTIterator.argtypes = [c_int, POINTER(c_int)]
@@ -110,12 +128,15 @@ dll.nFANTOM100_iNXT_getResourceString.argtypes = [c_uint, c_char_p,
POINTER(c_int)]
dll.nFANTOM100_iNXT_getResourceString.restype = None
-dll.nFANTOM100_pairBluetooth.argtypes = [c_char_p, c_char_p, c_char_p, POINTER(c_int)]
-dll.nFANTOM100_pairBluetooth.restype = None
-dll.nFANTOM100_unpairBluetooth.argtypes = [c_char_p, POINTER(c_int)]
-dll.nFANTOM100_unpairBluetooth.restype = None
-dll.nFANTOM100_isPaired.argtypes = [c_char_p, POINTER(c_int)]
-dll.nFANTOM100_isPaired.restype = c_ushort
+if MACOSX_BTENABLE:
+ print "Binding Buletooth routines"
+ dll.nFANTOM100_pairBluetooth.argtypes = [c_char_p, c_char_p, c_char_p, POINTER(c_int)]
+ dll.nFANTOM100_pairBluetooth.restype = None
+ dll.nFANTOM100_unpairBluetooth.argtypes = [c_char_p, POINTER(c_int)]
+ dll.nFANTOM100_unpairBluetooth.restype = None
+ dll.nFANTOM100_isPaired.argtypes = [c_char_p, POINTER(c_int)]
+ dll.nFANTOM100_isPaired.restype = c_ushort
+
if DEBUG:
print "Load Library Done"
@@ -251,7 +272,7 @@ class StatusVar(Structure):
class NXTIterator:
"""Interface to an iterator, to find connected NXT."""
- def __init__(self, search_bluetooth, bluetooth_search_timeout_s=5):
+ def __init__(self, search_bluetooth=False, bluetooth_search_timeout_s=5):
"""Initialize iterator."""
self.debug = DEBUG
self.search_bluetooth = search_bluetooth
@@ -260,7 +281,7 @@ class NXTIterator:
self.stop = False
self.nsapp = None
self.pool = None
- if platform.system() == 'Darwin':
+ if platform_type == 'Darwin':
self.nsapp = NSApplication.sharedApplication()
self.pool = NSAutoreleasePool.alloc().init()
def destroy():