Skip to content

Commit f753872

Browse files
committed
push code
1 parent b097530 commit f753872

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pymycobot/bluet.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import sys
44

55
class BluetoothConnection:
6-
def __init__(self):
6+
def __init__(self, bd_address=None, port=None):
77
self.device = []
88
self.target_name = "mybuddy"
99
self.nearby_devices = None
10+
self.bd_address = bd_address
11+
self.port = port
1012

1113
def find_target_device(self):
1214
available_addr = []
@@ -19,6 +21,10 @@ def find_target_device(self):
1921
return None
2022

2123
def connect_target_device(self):
24+
if self.bd_address:
25+
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
26+
sock.connect((self.bd_address, self.port))
27+
return sock
2228
target_address = self.find_target_device()
2329
if target_address:
2430
if len(target_address) > 1:

pymycobot/mybuddybluetooth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
class MyBuddyBlueTooth(MyBuddyCommandGenerator):
1111
"""MyBuddy bluetooth API"""
12-
def __init__(self):
12+
def __init__(self, bt_address=None, port = 10):
1313
"""There is a default Bluetooth search time of 5 seconds"""
1414
super(MyBuddyBlueTooth).__init__()
15-
self.ble = BluetoothConnection()
15+
self.ble = BluetoothConnection(bt_address, port)
1616
self.ble_obj = self.ble.connect_target_device()
1717

1818
def __read(self):

0 commit comments

Comments
 (0)