From 4b494917b14054ca4602cb1a8b90dd15776e36ed Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Thu, 8 Feb 2018 11:10:28 +0100 Subject: [PATCH] wacom: load the protocol of the device from the config file We can store this once for all, which will allow to keep the logic of detecting the protocol while registering only --- tuhi/base.py | 2 +- tuhi/wacom.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tuhi/base.py b/tuhi/base.py index 332223f..ab31c18 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -134,7 +134,7 @@ class TuhiDevice(GObject.Object): def _on_bluez_device_connected(self, bluez_device): logger.debug(f'{bluez_device.address}: connected') if self._wacom_device is None: - self._wacom_device = WacomDevice(bluez_device, self._uuid) + self._wacom_device = WacomDevice(bluez_device, self.config) self._wacom_device.connect('drawing', self._on_drawing_received) self._wacom_device.connect('done', self._on_fetching_finished, bluez_device) self._wacom_device.connect('button-press-required', self._on_button_press_required) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 6304220..0e0c2b2 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -118,7 +118,7 @@ class WacomDevice(GObject.Object): (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_INT, GObject.TYPE_BOOLEAN)), } - def __init__(self, device, uuid=None): + def __init__(self, device, config): GObject.Object.__init__(self) self.device = device self.nordic_answer = None @@ -127,10 +127,23 @@ class WacomDevice(GObject.Object): self.width = WACOM_SLATE_WIDTH self.height = WACOM_SLATE_HEIGHT self.name = device.name - self._uuid = uuid + self._config = None self.fw_logger = logging.getLogger('tuhi.fw') self._is_running = False + try: + self._config = config.devices[device.address] + except KeyError: + self._uuid = None + self._wacom_protocol = None + else: + self._uuid = self._config['uuid'] + try: + self._protocol = next(p for p in Protocol if p.value == self._config['Protocol']) + except StopIteration: + logger.error(f'Unknown protocol in configuration: {self._config["Protocol"]}') + raise WacomCorruptDataException(f'Unknown Protocol {self._config["Protocol"]}') + device.connect_gatt_value(WACOM_CHRC_LIVE_PEN_DATA_UUID, self._on_pen_data_changed) device.connect_gatt_value(WACOM_OFFLINE_CHRC_PEN_DATA_UUID,