diff --git a/examples/plotter/__init__.py b/examples/plotter/__init__.py index b783176..6fb13c6 100644 --- a/examples/plotter/__init__.py +++ b/examples/plotter/__init__.py @@ -84,7 +84,7 @@ class Plotter(object): def finalize(self): if self.is_tool_down: self._tool_up() - self.both.stop(async=True) + self.both.stop(is_async=True) def _tool_down(self): self.is_tool_down = True diff --git a/examples/plotter/try.py b/examples/plotter/try.py index f0cd4f3..7b69ca8 100644 --- a/examples/plotter/try.py +++ b/examples/plotter/try.py @@ -182,7 +182,7 @@ def angles_experiment(): class MotorMock(EncodedMotor): - def _wait_sync(self, async): + def _wait_sync(self, is_async): super(MotorMock, self)._wait_sync(True) diff --git a/examples/sorter/__init__.py b/examples/sorter/__init__.py index 27ea73a..c7ce597 100644 --- a/examples/sorter/__init__.py +++ b/examples/sorter/__init__.py @@ -53,7 +53,7 @@ class ColorSorter(MoveHub): self.color_distance_sensor.unsubscribe(self.on_color) if not self.motor_B.in_progress(): self.move_to_bucket(COLOR_BLACK) - self.motor_AB.stop(async=True) + self.motor_AB.stop(is_async=True) def tick(self): res = False diff --git a/examples/vernie/run_away_game.py b/examples/vernie/run_away_game.py index 3ec0a7c..f5b5eb2 100644 --- a/examples/vernie/run_away_game.py +++ b/examples/vernie/run_away_game.py @@ -11,7 +11,7 @@ def callback(color, distance): secs = (10 - distance + 1) / 10.0 print("Distance is %.1f inches, I'm running back with %s%% speed!" % (distance, int(speed * 100))) if speed <= 1: - robot.motor_AB.timed(secs / 1, -speed, async=True) + robot.motor_AB.timed(secs / 1, -speed, is_async=True) robot.say("Ouch") diff --git a/pylgbst/comms/__init__.py b/pylgbst/comms/__init__.py index bb53315..6d51fff 100644 --- a/pylgbst/comms/__init__.py +++ b/pylgbst/comms/__init__.py @@ -118,7 +118,7 @@ class DebugServer(object): buf = buf[buf.index("\n") + 1:] if line: - log.info("Cmd line: %s", line) + log.debug("Cmd line: %s", line) try: self._handle_cmd(json.loads(line)) except KeyboardInterrupt: diff --git a/pylgbst/comms/cgatt.py b/pylgbst/comms/cgatt.py index 23fe267..4ac47bb 100644 --- a/pylgbst/comms/cgatt.py +++ b/pylgbst/comms/cgatt.py @@ -85,7 +85,7 @@ class GattConnection(Connection): raise NotImplementedError("Gatt is not implemented for this platform") self._manager_thread = threading.Thread(target=self._manager.run) - self._manager_thread.setDaemon(False) + self._manager_thread.setDaemon(True) log.debug('Starting DeviceManager...') def connect(self, hub_mac=None): diff --git a/pylgbst/peripherals.py b/pylgbst/peripherals.py index 23b50d7..db6222e 100644 --- a/pylgbst/peripherals.py +++ b/pylgbst/peripherals.py @@ -61,17 +61,17 @@ class Peripheral(object): def in_progress(self): return bool(self._working) - def subscribe(self, callback, mode, granularity=1, async=False): + def subscribe(self, callback, mode, granularity=1, is_async=False): self._port_subscription_mode = mode self.started() self._port_subscribe(self._port_subscription_mode, granularity, True) - self._wait_sync(async) # having async=True leads to stuck notifications + self._wait_sync(is_async) # having async=True leads to stuck notifications if callback: self._subscribers.add(callback) - def unsubscribe(self, callback=None, async=False): + def unsubscribe(self, callback=None, is_async=False): if callback in self._subscribers: self._subscribers.remove(callback) @@ -80,7 +80,7 @@ class Peripheral(object): elif not self._subscribers: self.started() self._port_subscribe(self._port_subscription_mode, 0, False) - self._wait_sync(async) + self._wait_sync(is_async) self._port_subscription_mode = None def _notify_subscribers(self, *args, **kwargs): @@ -106,8 +106,8 @@ class Peripheral(object): log.warning("%s", traceback.format_exc()) log.warning("Failed to handle port data by %s: %s", self, str2hex(data)) - def _wait_sync(self, async): - if not async: + def _wait_sync(self, is_async): + if not is_async: log.debug("Waiting for sync command work to finish...") while self.in_progress(): if not self.parent.connection.is_alive(): @@ -142,10 +142,10 @@ class LED(Peripheral): log.debug("LED has changed color to %s", COLORS[self.last_color_set]) self._notify_subscribers(self.last_color_set) - def subscribe(self, callback, mode=None, granularity=None, async=False): + def subscribe(self, callback, mode=None, granularity=None, is_async=False): self._subscribers.add(callback) - def unsubscribe(self, callback=None, async=False): + def unsubscribe(self, callback=None, is_async=False): if callback in self._subscribers: self._subscribers.remove(callback) @@ -202,7 +202,7 @@ class EncodedMotor(Peripheral): self._write_to_hub(MSG_SET_PORT_VAL, params) - def timed(self, seconds, speed_primary=1, speed_secondary=None, async=False): + def timed(self, seconds, speed_primary=1, speed_secondary=None, is_async=False): if speed_secondary is None: speed_secondary = speed_primary @@ -210,9 +210,9 @@ class EncodedMotor(Peripheral): self.started() self._wrap_and_write(self.TIMED_SINGLE, params, speed_primary, speed_secondary) - self._wait_sync(async) + self._wait_sync(is_async) - def angled(self, angle, speed_primary=1, speed_secondary=None, async=False): + def angled(self, angle, speed_primary=1, speed_secondary=None, is_async=False): if speed_secondary is None: speed_secondary = speed_primary @@ -226,26 +226,26 @@ class EncodedMotor(Peripheral): self.started() self._wrap_and_write(self.ANGLED_SINGLE, params, speed_primary, speed_secondary) - self._wait_sync(async) + self._wait_sync(is_async) - def constant(self, speed_primary=1, speed_secondary=None, async=False): + def constant(self, speed_primary=1, speed_secondary=None, is_async=False): if speed_secondary is None: speed_secondary = speed_primary self.started() self._wrap_and_write(self.CONSTANT_SINGLE, b"", speed_primary, speed_secondary) - self._wait_sync(async) + self._wait_sync(is_async) - def __some(self, speed_primary=1, speed_secondary=None, async=False): + def __some(self, speed_primary=1, speed_secondary=None, is_async=False): if speed_secondary is None: speed_secondary = speed_primary self.started() self._wrap_and_write(self.SOME_SINGLE, b"", speed_primary, speed_secondary) - self._wait_sync(async) + self._wait_sync(is_async) - def stop(self, async=False): - self.constant(0, async=async) + def stop(self, is_async=False): + self.constant(0, is_async=is_async) def handle_port_data(self, data): if self._port_subscription_mode == self.SENSOR_ANGLE: @@ -261,7 +261,7 @@ class EncodedMotor(Peripheral): else: log.debug("Got motor sensor data while in unexpected mode: %s", self._port_subscription_mode) - def subscribe(self, callback, mode=SENSOR_ANGLE, granularity=1, async=False): + def subscribe(self, callback, mode=SENSOR_ANGLE, granularity=1, is_async=False): super(EncodedMotor, self).subscribe(callback, mode, granularity) @@ -302,7 +302,7 @@ class TiltSensor(Peripheral): TRI_FRONT: "FRONT", } - def subscribe(self, callback, mode=MODE_3AXIS_SIMPLE, granularity=1, async=False): + def subscribe(self, callback, mode=MODE_3AXIS_SIMPLE, granularity=1, is_async=False): super(TiltSensor, self).subscribe(callback, mode, granularity) def handle_port_data(self, data): @@ -350,7 +350,7 @@ class ColorDistanceSensor(Peripheral): def __init__(self, parent, port): super(ColorDistanceSensor, self).__init__(parent, port) - def subscribe(self, callback, mode=COLOR_DISTANCE_FLOAT, granularity=1, async=False): + def subscribe(self, callback, mode=COLOR_DISTANCE_FLOAT, granularity=1, is_async=False): super(ColorDistanceSensor, self).subscribe(callback, mode, granularity) def handle_port_data(self, data): @@ -399,7 +399,7 @@ class Voltage(Peripheral): super(Voltage, self).__init__(parent, port) self.last_value = None - def subscribe(self, callback, mode=MODE1, granularity=1, async=False): + def subscribe(self, callback, mode=MODE1, granularity=1, is_async=False): super(Voltage, self).subscribe(callback, mode, granularity) # we know only voltage subscription from it. is it really battery or just onboard voltage? @@ -423,7 +423,7 @@ class Amperage(Peripheral): super(Amperage, self).__init__(parent, port) self.last_value = None - def subscribe(self, callback, mode=MODE1, granularity=1, async=False): + def subscribe(self, callback, mode=MODE1, granularity=1, is_async=False): super(Amperage, self).subscribe(callback, mode, granularity) def handle_port_data(self, data): @@ -440,15 +440,15 @@ class Button(Peripheral): def __init__(self, parent): super(Button, self).__init__(parent, 0) # fake port 0 - def subscribe(self, callback, mode=None, granularity=1, async=False): + def subscribe(self, callback, mode=None, granularity=1, is_async=False): self.started() self.parent.send(MSG_DEVICE_INFO, pack('