From db29fcb24521c4ab1c2bab3e7ffb512afdb74978 Mon Sep 17 00:00:00 2001 From: Dmitry Moiseev Date: Fri, 13 Dec 2013 15:38:02 +0600 Subject: Added lightblue support in mac os x --- ParrotZik.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'ParrotZik.py') diff --git a/ParrotZik.py b/ParrotZik.py index 73df83b..4510e27 100644 --- a/ParrotZik.py +++ b/ParrotZik.py @@ -1,6 +1,11 @@ #!/usr/bin/env python -import bluetooth +import sys +if sys.platform == "darwin": + import lightblue +else: + import bluetooth + import ParrotProtocol import struct from BeautifulSoup import BeautifulSoup @@ -9,7 +14,11 @@ class ParrotZik(object): def __init__(self,addr=None): uuid = "0ef0f502-f0ee-46c9-986c-54ed027807fb" - service_matches = bluetooth.find_service( uuid = uuid, address = addr ) + + if sys.platform == "darwin": + service_matches = lightblue.findservices( name = "RFCOMM", addr = addr ) + else: + service_matches = bluetooth.find_service( uuid = uuid, address = addr ) if len(service_matches) == 0: print "Failed to find Parrot Zik RFCOMM service" @@ -23,7 +32,11 @@ class ParrotZik(object): print "Connecting to \"%s\" on %s" % (name, host) - self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) + if sys.platform == "darwin": + self.sock=lightblue.lightblueSocket( lightblue.RFCOMM ) + else: + self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) + self.sock.connect((host, port)) self.sock.send('\x00\x03\x00') @@ -115,10 +128,9 @@ class ParrotZik(object): self.sock ="" return data = self.sock.recv(7) - len = struct.unpack('B', data[1])[0] data = self.sock.recv(1024) data=BeautifulSoup(data) return data def Close(self): - self.sock.close() + self.sock.close() \ No newline at end of file -- cgit v1.2.1