From 56dc8741dc03e59ddbf362d35e54fe70f75524f5 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 19 Jan 2018 17:30:34 +0100 Subject: [PATCH] defer the creation of the wacom device object If bluez is restarted, the services are not resolved. If the data has not been connected, the manufacturerData might be correctly set, but the services are still not resolved, meaning that we can not start listening on the various GATT characteristics. Defer the creation of the wacom device object after connect, when we are sure the services are resolved. --- tuhi.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tuhi.py b/tuhi.py index 1e03657..090fbe5 100755 --- a/tuhi.py +++ b/tuhi.py @@ -81,15 +81,12 @@ class TuhiDevice(GObject.Object): GObject.Object.__init__(self) self.config = config self._tuhi_dbus_device = tuhi_dbus_device - self._wacom_device = WacomDevice(bluez_device, uuid) - 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) - self._wacom_device.connect('notify::uuid', self._on_uuid_updated, bluez_device) + self._wacom_device = None self.drawings = [] # We need either uuid or paired as false assert uuid is not None or paired is False self.paired = paired + self._uuid = uuid bluez_device.connect('connected', self._on_bluez_device_connected) bluez_device.connect('disconnected', self._on_bluez_device_disconnected) @@ -102,6 +99,13 @@ class TuhiDevice(GObject.Object): def _on_bluez_device_connected(self, bluez_device): logger.debug('{}: connected'.format(bluez_device.address)) + if self._wacom_device is None: + self._wacom_device = WacomDevice(bluez_device, self._uuid) + 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) + self._wacom_device.connect('notify::uuid', self._on_uuid_updated, bluez_device) + self._wacom_device.start(not self.paired) self.pairing_mode = False