mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Fix tests
This commit is contained in:
parent
bb602dae98
commit
a9a0386634
13
tests.py
13
tests.py
@ -78,15 +78,18 @@ class GeneralTest(unittest.TestCase):
|
||||
else:
|
||||
log.debug("Tilt: %s %s %s", param1, param2, param3)
|
||||
|
||||
self._inject_notification(hub, '1b0e000a00 47 3a 090100000001', 1)
|
||||
hub.tilt_sensor.subscribe(callback)
|
||||
hub.connection.notifications.append((HANDLE, "1b0e000500453a05"))
|
||||
hub.connection.notifications.append((HANDLE, "1b0e000a00473a010100000001"))
|
||||
time.sleep(1)
|
||||
self._inject_notification(hub, '1b0e000a00 47 3a 090100000001', 1)
|
||||
hub.tilt_sensor.subscribe(callback, TILT_MODE_2AXIS_SIMPLE)
|
||||
|
||||
hub.connection.notifications.append((HANDLE, "1b0e000500453a09"))
|
||||
time.sleep(1)
|
||||
|
||||
self._inject_notification(hub, '1b0e000a00 47 3a 090100000001', 1)
|
||||
hub.tilt_sensor.subscribe(callback, TILT_MODE_2AXIS_FULL)
|
||||
hub.connection.notifications.append((HANDLE, "1b0e000600453a04fe"))
|
||||
time.sleep(1)
|
||||
@ -130,13 +133,14 @@ class GeneralTest(unittest.TestCase):
|
||||
def test_color_sensor(self):
|
||||
#
|
||||
hub = HubMock()
|
||||
hub.connection.notifications.append((HANDLE, '1b0e000f0004010125000000001000000010'))
|
||||
hub.connection.notifications.append((HANDLE, '1b0e000f00 04010125000000001000000010'))
|
||||
time.sleep(1)
|
||||
|
||||
def callback(color, unk1, unk2=None):
|
||||
name = COLORS[color] if color is not None else 'NONE'
|
||||
log.info("Color: %s %s %s", name, unk1, unk2)
|
||||
|
||||
self._inject_notification(hub, '1b0e000a00 4701090100000001', 1)
|
||||
hub.color_distance_sensor.subscribe(callback)
|
||||
|
||||
hub.connection.notifications.append((HANDLE, "1b0e0008004501ff0aff00"))
|
||||
@ -160,3 +164,10 @@ class GeneralTest(unittest.TestCase):
|
||||
# TODO: assert
|
||||
self._wait_notifications_handled(hub)
|
||||
hub.button.unsubscribe(callback)
|
||||
|
||||
def _inject_notification(self, hub, notify, pause):
|
||||
def inject():
|
||||
time.sleep(pause)
|
||||
hub.connection.notifications.append((HANDLE, notify))
|
||||
|
||||
Thread(target=inject).start()
|
||||
|
@ -44,6 +44,8 @@ robot = Vernie()
|
||||
robot.button.subscribe(on_btn)
|
||||
robot.motor_AB.stop()
|
||||
|
||||
# TODO: use distance sensor to stop movement forward
|
||||
|
||||
try:
|
||||
udp_sock.bind((host, port))
|
||||
time.sleep(1)
|
||||
|
@ -30,6 +30,7 @@ def on_turn(angle):
|
||||
robot.button.subscribe(on_btn)
|
||||
robot.color_distance_sensor.subscribe(on_change_lum, CDS_MODE_LUMINOSITY, granularity=1)
|
||||
robot.motor_A.subscribe(on_turn, granularity=30)
|
||||
# TODO: add bump detect to go back?
|
||||
while running:
|
||||
# turn around, measuring luminosity
|
||||
lum_values = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user