From a9a0386634c047a2bc5e996b48aa01ea456523b7 Mon Sep 17 00:00:00 2001 From: Andrey Pohilko Date: Tue, 19 Sep 2017 18:08:29 +0300 Subject: [PATCH] Fix tests --- tests.py | 13 ++++++++++++- vernie/android_remote.py | 2 ++ vernie/go_towards_light.py | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 03983fb..7ea19c6 100644 --- a/tests.py +++ b/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() diff --git a/vernie/android_remote.py b/vernie/android_remote.py index b8a346f..53a8d1c 100644 --- a/vernie/android_remote.py +++ b/vernie/android_remote.py @@ -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) diff --git a/vernie/go_towards_light.py b/vernie/go_towards_light.py index 4f0d77c..cd23976 100644 --- a/vernie/go_towards_light.py +++ b/vernie/go_towards_light.py @@ -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 = {}