From d4405cc1ef2c73e16b20f95b54b8bd4b9400f117 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 19 Jan 2018 13:09:26 +1000 Subject: [PATCH] Hook up a ButtonPressRequired signal When the nordic communication requires us to notify the user to press the button, emit a signal and pass that up. --- README.md | 6 ++++++ tuhi.py | 5 +++++ tuhi/dbusserver.py | 7 +++++++ tuhi/wacom.py | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 1a90f39..8140889 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,12 @@ org.freedesktop.tuhi1.Device Returns a string representing the JSON data from the last drawings or the empty string if no data is available or the index is invalid. + + Signal: ButtonPressRequired() + Sent when the user is expected to press the physical button on the + device. A client should display a notification in response, if the + user does not press the button during the (firmware-specific) timeout + the current operation will fail. ``` JSON File Format diff --git a/tuhi.py b/tuhi.py index d8af9ff..d08beff 100755 --- a/tuhi.py +++ b/tuhi.py @@ -75,12 +75,14 @@ class TuhiDevice(GObject.Object): real device) with the frontend DBusServer object that exports the device over Tuhi's DBus interface """ + def __init__(self, bluez_device, tuhi_dbus_device, paired=True): GObject.Object.__init__(self) self._tuhi_dbus_device = tuhi_dbus_device self._wacom_device = WacomDevice(bluez_device) 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.drawings = [] self.paired = paired @@ -139,6 +141,9 @@ class TuhiDevice(GObject.Object): def _on_fetching_finished(self, device, bluez_device): bluez_device.disconnect_device() + def _on_button_press_required(self, device): + self._tuhi_dbus_device.notify_button_press_required() + class Tuhi(GObject.Object): __gsignals__ = { diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index 1747b72..a54406c 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -61,6 +61,8 @@ INTROSPECTION_XML = """ + + @@ -162,6 +164,11 @@ class TuhiDBusDevice(GObject.Object): def add_drawing(self, drawing): self.drawings.append(drawing) + def notify_button_press_required(self): + logger.debug("Sending ButtonPressRequired signal") + self._connection.emit_signal(None, self.objpath, INTF_DEVICE, + "ButtonPressRequired", None) + class TuhiDBusServer(GObject.Object): """ diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 176af47..7864568 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -124,6 +124,8 @@ class WacomDevice(GObject.Object): (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), "done": (GObject.SIGNAL_RUN_FIRST, None, ()), + "button-press-required": + (GObject.SIGNAL_RUN_FIRST, None, ()), } def __init__(self, device): @@ -578,6 +580,7 @@ class WacomDevice(GObject.Object): def pair_device_slate(self): self.register_connection() logger.info("Press the button now to confirm") + self.emit('button-press-required') data = self.wait_nordic_data([0xe4, 0xb3], 10) if data.opcode == 0xb3: # generic ACK @@ -604,6 +607,7 @@ class WacomDevice(GObject.Object): self.send_nordic_command(command=0xe3, arguments=[0x01]) logger.info("Press the button now to confirm") + self.emit('button-press-required') # Wait for the button confirmation event, or any error data = self.wait_nordic_data([0xe4, 0xb3], 10) if data.opcode == 0xb3: