diff --git a/pylgbst/comms.py b/pylgbst/comms.py index a5a5c8b..b7686ee 100644 --- a/pylgbst/comms.py +++ b/pylgbst/comms.py @@ -8,7 +8,7 @@ import socket import sys import time import traceback -from Queue import Queue +from six.moves import queue from abc import abstractmethod from binascii import unhexlify from gattlib import DiscoveryService, GATTRequester @@ -42,7 +42,8 @@ class Requester(GATTRequester): super(Requester, self).__init__(p_object, *args, **kwargs) self.notification_sink = None - self._notify_queue = Queue() + # noinspection PyUnresolvedReferences + self._notify_queue = queue.Queue() self._notifier_thread = Thread(target=self._dispatch_notifications) self._notifier_thread.setDaemon(True) self._notifier_thread.setName("Notify queue dispatcher") @@ -170,7 +171,7 @@ class DebugServer(object): self.sock.close() def _notify_dummy(self, handle, data): - log.debug("Notification from handle %s: %s", handle, hexlify(data.strip())) + log.debug("Notification from handle %s: %s", handle, binascii.hexlify(data.strip())) self._check_shutdown(data) def _notify(self, conn, handle, data): diff --git a/pylgbst/constants.py b/pylgbst/constants.py index ed7fd73..2f48c38 100644 --- a/pylgbst/constants.py +++ b/pylgbst/constants.py @@ -34,7 +34,7 @@ PORTS = { # PACKET TYPES MSG_DEVICE_INFO = 0x01 -MSG_DEVICE_SHUTDOWN = 0x02 +MSG_DEVICE_SHUTDOWN = 0x02 # sent when hub shuts down by button hold MSG_PING_RESPONSE = 0x03 MSG_PORT_INFO = 0x04 MSG_PORT_CMD_ERROR = 0x05 diff --git a/pylgbst/peripherals.py b/pylgbst/peripherals.py index a682975..cd003c1 100644 --- a/pylgbst/peripherals.py +++ b/pylgbst/peripherals.py @@ -21,7 +21,7 @@ class Peripheral(object): super(Peripheral, self).__init__() self.parent = parent self.port = port - self._working = 0 # 3-state, -1 means command sent, 1 means notified on command, 0 means notified on finish + self._working = False self._subscribers = set() self._port_subscription_mode = None @@ -41,10 +41,12 @@ class Peripheral(object): self._write_to_hub(MSG_SENSOR_SUBSCRIBE, params) def started(self): - self._working = 1 + log.debug("Started: %s", self) + self._working = True def finished(self): - self._working = 0 + log.debug("Finished: %s", self) + self._working = False def is_working(self): return bool(self._working) @@ -79,7 +81,7 @@ class LED(Peripheral): raise ValueError("Color %s is not in list of available colors" % color) cmd = pack("