Skip to content

Commit

Permalink
BTSession: Additional change to pretend LEGO EV3 with LEGO Hub
Browse files Browse the repository at this point in the history
The previous commit tweaked the class IDs returned from the LEGO Hub as
that of LEGO EV3. On top of that, it is required to tweak the class ID
to search and discover for bluetooth.DeviceDiscoverer API.

Also, add some more debug prints to track BT device discovery.

Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
kawasaki committed Nov 21, 2021
1 parent 3ffbde3 commit 3cf61a1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pyscrlink/scratch_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ def __init__(self, session, major_device_class, minor_device_class):
self.ping_time = None

def discover(self):
discoverer = self.BTDiscoverer(self.major_device_class, self.minor_device_class)
major = self.major_device_class
minor = self.minor_device_class
if major == 8 and minor == 1:
logger.info(f"Search LEGO Hub instead of LEGO EV3")
minor = 4
logger.debug(f"BT discover: class={major}/{minor}")
discoverer = self.BTDiscoverer(major, minor)
discoverer.find_devices(lookup_names=True)
while self.session.status == self.session.DISCOVERY and not discoverer.done and not self.cancel_discovery:
readable = select.select([discoverer], [], [], 0.5)[0]
Expand All @@ -206,7 +212,7 @@ def discover(self):
def run(self):
while self.session.status != self.session.DONE:

logger.debug("loop in BT thread")
logger.debug(f"loop in BT thread: session status={self.session.status}")
current_time = int(round(time.time()))

if self.session.status == self.session.DISCOVERY and not self.cancel_discovery:
Expand Down

0 comments on commit 3cf61a1

Please sign in to comment.