From acdf631b666e8516223c94cd901c1ce40ccbdb87 Mon Sep 17 00:00:00 2001 From: Andrey Pohilko Date: Sat, 23 Sep 2017 14:09:53 +0300 Subject: [PATCH] getting hub info --- README.md | 3 +-- pylgbst/comms.py | 4 ++-- pylgbst/constants.py | 18 ++++++++++++++++++ pylgbst/movehub.py | 38 +++++++++++++++++++++++++++++++++++--- pylgbst/peripherals.py | 17 +++++++---------- tests.py | 3 +++ 6 files changed, 66 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index cef0864..9e2338f 100644 --- a/README.md +++ b/README.md @@ -287,8 +287,7 @@ Then push green button on MoveHub, so permanent BLE connection will be establish ## Roadmap & TODO -- handle device detach and device attach events on ports C/D -- generalize getting device info + give constants (low priority) +- work out completely synchronous command model - with either command error or confirmation - organize requesting and printing device info on startup - firmware version at least - document all API methods - make sure unit tests cover all important code diff --git a/pylgbst/comms.py b/pylgbst/comms.py index 0a26241..8357d8e 100644 --- a/pylgbst/comms.py +++ b/pylgbst/comms.py @@ -77,7 +77,7 @@ class BLEConnection(Connection): super(BLEConnection, self).__init__() self.requester = None - def connect(self, bt_iface_name='hci0'): + def connect(self, bt_iface_name='hci0', hub_mac=None): service = DiscoveryService(bt_iface_name) while not self.requester: @@ -86,7 +86,7 @@ class BLEConnection(Connection): log.debug("Devices: %s", devices) for address, name in devices.items(): - if name == LEGO_MOVE_HUB: + if name == LEGO_MOVE_HUB or hub_mac == address: logging.info("Found %s at %s", name, address) self.requester = Requester(address, True, bt_iface_name) break diff --git a/pylgbst/constants.py b/pylgbst/constants.py index 1fd5f7d..cdfc538 100644 --- a/pylgbst/constants.py +++ b/pylgbst/constants.py @@ -116,3 +116,21 @@ COLORS = { COLOR_WHITE: "WHITE", COLOR_NONE: "NONE" } + +# DEVICE INFO +INFO_DEVICE_NAME = 0x01 +INFO_BUTTON_STATE = 0x02 +INFO_FIRMWARE_VERSION = 0x03 +INFO_SOME4 = 0x04 +INFO_SOME5_JITTERING = 0x05 +INFO_SOME6 = 0x06 +INFO_SOME7 = 0x07 +INFO_MANUFACTURER = 0x08 +INFO_HW_VERSION = 0x09 +INFO_SOME10 = 0x0a +INFO_SOME11 = 0x0b +INFO_SOME12 = 0x0c + +INFO_ACTION_SUBSCRIBE = 0x02 +INFO_ACTION_UNSUBSCRIBE = 0x03 +INFO_ACTION_GET = 0x05 diff --git a/pylgbst/movehub.py b/pylgbst/movehub.py index f20ac4d..52d865a 100644 --- a/pylgbst/movehub.py +++ b/pylgbst/movehub.py @@ -40,6 +40,7 @@ class MoveHub(object): connection = BLEConnection() self.connection = connection + self.info = {} self.devices = {} # shorthand fields @@ -59,6 +60,11 @@ class MoveHub(object): self.connection.set_notify_handler(self._notify) self._wait_for_devices() + self._report_status() + + def send(self, msg_type, payload): + cmd = pack("