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:
parent
a6047b3279
commit
369da2ce6a
@ -397,7 +397,10 @@ class Button(Peripheral):
|
|||||||
|
|
||||||
def subscribe(self, callback, mode=None, granularity=1, async=False):
|
def subscribe(self, callback, mode=None, granularity=1, async=False):
|
||||||
cmd = pack("<B", PACKET_VER) + pack("<B", MSG_DEVICE_INFO) + b'\x02\x02'
|
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.parent.connection.write(MOVE_HUB_HARDWARE_HANDLE, pack("<B", len(cmd) + 1) + cmd)
|
||||||
|
self._wait_sync(async)
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
self._subscribers.add(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)
|
self.parent.connection.write(MOVE_HUB_HARDWARE_HANDLE, pack("<B", len(cmd) + 1) + cmd)
|
||||||
|
|
||||||
def handle_port_data(self, data):
|
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))
|
||||||
|
@ -26,8 +26,8 @@ def on_btn(pressed):
|
|||||||
|
|
||||||
robot.led.set_color(COLOR_GREEN)
|
robot.led.set_color(COLOR_GREEN)
|
||||||
robot.button.subscribe(on_btn)
|
robot.button.subscribe(on_btn)
|
||||||
robot.say("Place your hand in front of sensor")
|
|
||||||
robot.color_distance_sensor.subscribe(callback)
|
robot.color_distance_sensor.subscribe(callback)
|
||||||
|
robot.say("Place your hand in front of sensor")
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user