def connect(self):
"""
Connects the sphero with the address given in the constructor
"""
self._device = bluepy.btle.Peripheral(self._addr, addrType=bluepy.btle.ADDR_TYPE_RANDOM)
self._notifier = DelegateObj(self, self._notification_lock)
#set notifier to be notified
self._device.withDelegate(self._notifier)
self._devModeOn()
self._connected = True #Might need to change to be a callback format
#get the command service
cmd_service = self._device.getServiceByUUID(RobotControlService)
self._cmd_characteristics = {}
characteristic_list = cmd_service.getCharacteristics()
for characteristic in characteristic_list:
uuid_str = binascii.b2a_hex(characteristic.uuid.binVal).decode('utf-8')
self._cmd_characteristics[uuid_str] = characteristic
self._listening_flag = True
self._listening_thread = threading.Thread(target=self._listening_loop)
self._listening_thread.start()
评论列表
文章目录