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.
This commit is contained in:
Peter Hutterer 2018-01-19 13:09:26 +10:00
parent aa1a5e6689
commit d4405cc1ef
4 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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__ = {

View File

@ -61,6 +61,8 @@ INTROSPECTION_XML = """
<arg name='json' type='s' direction='out'/>
</method>
<signal name='ButtonPressRequired' />
<signal name='ListenComplete'>
<arg name='status' type='i' />
</signal>
@ -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):
"""

View File

@ -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: