1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Fix run away game

This commit is contained in:
Andrey Pohilko 2017-09-21 13:55:29 +03:00
parent a6047b3279
commit 369da2ce6a
2 changed files with 8 additions and 2 deletions

View File

@ -397,7 +397,10 @@ class Button(Peripheral):
def subscribe(self, callback, mode=None, granularity=1, async=False):
cmd = pack("<B", PACKET_VER) + pack("<B", MSG_DEVICE_INFO) + b'\x02\x02'
self.started()
self.parent.connection.write(MOVE_HUB_HARDWARE_HANDLE, pack("<B", len(cmd) + 1) + cmd)
self._wait_sync(async)
if callback:
self._subscribers.add(callback)
@ -410,4 +413,7 @@ class Button(Peripheral):
self.parent.connection.write(MOVE_HUB_HARDWARE_HANDLE, pack("<B", len(cmd) + 1) + cmd)
def handle_port_data(self, data):
self._notify_subscribers(bool(unpack("<B", data[5:6])[0]))
param = unpack("<B", data[5:6])[0]
if self.in_progress():
self.finished()
self._notify_subscribers(bool(param))

View File

@ -26,8 +26,8 @@ def on_btn(pressed):
robot.led.set_color(COLOR_GREEN)
robot.button.subscribe(on_btn)
robot.say("Place your hand in front of sensor")
robot.color_distance_sensor.subscribe(callback)
robot.say("Place your hand in front of sensor")
while running:
time.sleep(1)