If the sender disappear, we should stop listening for incoming events.
We match the Start/StopListening() that way, but if a client forgets
to call StopListening() before leaving and some data are being retrieved,
it's not our problem.
This implements the ListeningStopped signal (especially the EAGAIN if we're
already listening) but does not yet actually trigger the listening on the
device.
There is still no timeout, and no signal gets emitted.
The current way of testing this is:
- call StartListening() on the DBus device
- start discovery on the adapter by some other mean
- press the button on the device -> the sync will happen
- call StopDiscovery()
- press the button on the device -> the sync will *not* happen
We need to be able to selectively enable/disable listening mode per
device, and the Listening property needs to be updated.
The current approach uses a Listening property as a public state, and the
StartListening()/StopListening() calls to start/stop. The ListeningStopped
signal is just there to carry error codes.
The current design only allows for a single client to trigger listening,
anyone else will see -EAGAIN and has to wait for the property to update.
Remember the devices we are pairing and subscribe to the Manager.Devices
property changed notification. If a device moves from just existing to be part
of Manager.Devices it has been successfully paired.
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.
This allows to create the device even if the conditions were not met
while starting up tuhi (if bluez considers the device still in
pairing mode).
This will also allow us to retrieve the button presses from the devices,
as they are triggering a BLE advertisement.
The coordinates are provided from the top-left position, but the sensor
is effectively turned. So on the Spark and the Slate, X goes down, and
Y is reversed and goes left.
If the index is not valid, a python exception was raised, and the dbus
message was left without and answer.
Coincidentally, this matches the documentation
I guess this code was tested with an existing config file only, because
I have the following:
DEBUG: tuhi.config: E0:61:C6:BF:14:4E: adding new config, uuid 8bbc6be4347a
Traceback (most recent call last):
File "./tuhi.py", line 153, in _on_uuid_updated
self.config.new_device(bluez_device.address, wacom_device.uuid)
File "tuhi/tuhi/config.py", line 89, in new_device
config['Device']['Address'] = address
File "/usr/lib64/python3.6/configparser.py", line 959, in __getitem__
raise KeyError(key)
KeyError: 'Device'
When the uuid changes, it means the device just has been paired.
We should therefore update the paired property or a subsequent connect
to retrieve the data will result in an attempt to pair to the device.
Make the uuid property a GObject.Property so we can listen to it. Notify about
the uuid change at the end of the pairing process, then write that value into
the device's config file.
The previous process had a problem: the device object didn't exist until after
pairing was complete. But to pair we need some user interaction (press button
on device) and thus the ability to send notifications from the device to the
dbus client at the right time. This wasn't possible with the previous
approach.
The new approach:
* renames Start/StopPairing to Start/StopSearch to indicate we're just
searching, not pairing in the manager
* creates a org.freedesktop.tuhi1.Device object when a suitable device is
found. That object is not in Manager.Devices, it's "hidden" unless you know
the object path.
* Sends a PairableDevice signal with the new device's object path
* Requires the client to call Pair() on the device
* If the timeout expires without pairing, the device is removed again
When the device is in pairing mode (blinking blue), the manufacturer
data contains less than 7 fields. We should ignore those devices
as we are not supposed to pull pen data out of them.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Ignore any requests to sync the device while the previous sync is still
ongoing. This should be the exception anyway, we shouldn't get another
"connected" signal from the device while we're syncing.
Previously we created a new instance on every connected signal. We should
instead create the device once and then just re-start the sync process when
we get the connected data.