Commit Graph

276 Commits (a8d864144299c95d4ba760a7d1b2bdab37edb298)

Author SHA1 Message Date
Peter Hutterer 1e31e6cba7 dbus: add a helper for sending signals 2018-01-25 09:18:59 +10:00
Peter Hutterer ba7c62fc0c dbus: add helper for properties changed signal 2018-01-25 09:18:47 +10:00
Peter Hutterer 584925a0d9 dbus: add a DBus base object
Currently just handling some properties that are common, but will do other
things soon.
2018-01-24 21:40:42 +10:00
Peter Hutterer 1a6071b93d dbus: use self.objpath instead of the hardcoded BASE_PATH in the manager 2018-01-24 21:39:56 +10:00
Peter Hutterer fc8f0f6716 __init__: remove empty line that snuck in during rebasing 2018-01-24 21:39:56 +10:00
Peter Hutterer 8bb971cdcd tuhi: don't use a timeout for searching
We track the searching client now, so the timeout is no longer required
2018-01-24 19:25:00 +10:00
Peter Hutterer cfa4aca2df dbus: limit StartSearch to one client only
Basically copied from the device's Listening approach.

While it's possible to have multiple clients searching at the same time it's a
niche case and the effort at fixing the race conditions that come from that is
likely not worth the effort.

Let's add multiple simultaneous clients when we have a real need for it.
2018-01-24 19:23:20 +10:00
Peter Hutterer cce63d267b dbus: stop discovery when the searching client disappears
This is the single-client version only, we can deal with multiple clients
later.

Fixes #21
2018-01-24 19:23:20 +10:00
Peter Hutterer eb5efd2e1c tuhi: move everything to base.py
Let tuhi.py just be the script that calls main. This way we're somewhat
setup.py compatible.
2018-01-24 19:08:12 +10:00
Peter Hutterer 5e32dc4872 dbus: don't update self.paired unless it changes
TuhDevice.paired is set on every device update (RSSI changes!) and that sends
a GObject.notify() for the property. Filter those, otherwise
we're just spamming dbus with PropertiesChanged notify events even
though nothing has actually changed.
2018-01-23 14:57:00 +10:00
Peter Hutterer 7aa4314c3d wacom: use .format instead of hex to generate the timestring
hex() skips leading zeroes, so 180123 turns into 18, 12, 3
2018-01-23 14:44:01 +10:00
Peter Hutterer 44a2d5e8eb ble: if we connect twice, log the error as debug
We likely get multiple 'udpated' notifications as the RSSI property changes,
all causing a Connect() on the device and an ugly error message (that we used
to catch and print). Make that error message prettier.
2018-01-23 14:22:33 +10:00
Peter Hutterer f9ba9fe6ca ble: don't crash if a device doesn't have a Name attribute
Hello, tradies next door with your weird phones...
2018-01-23 14:22:33 +10:00
Peter Hutterer 63ba0462ea dbus: send out PropertiesChanged when we update the drawings 2018-01-23 14:22:33 +10:00
Benjamin Tissoires ca82af78de tuhi: handle cold-plugged devices
When bluez restarts (or the tuhi daemon restarts), the values we have
in the bluez device's field ManufacturerData are quite not accurate.

When bluez restarts they are empty, and if the last time we saw the
device was for the pairing process, the device will still be marked
as in the pairing mode.

So we should mark the cold-plug sequence differently from the hot-plug
one, and we should be more confident in the current configuration we
have stored to export the currently known devices over dbus.

Fixes #13
2018-01-23 14:22:33 +10:00
Benjamin Tissoires ea890958d6 Start discovery mode when one device requests it
We need to check when the discovery stops (timeout from StartSearch)
if we should keep the discover one or not.
2018-01-23 14:22:33 +10:00
Benjamin Tissoires a51663342f dbus: keep track of the senders of the StartListening() method
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.
2018-01-23 14:22:33 +10:00
Benjamin Tissoires e3fff4015a implement a basic Start/StopListening
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
2018-01-23 14:22:33 +10:00
Peter Hutterer 010c651d6f dbus: add a __repr__ for the TuhiDBusDevice
And remove a now obsolete debugging statement, this was just put there to
debug the PropertyChanged code
2018-01-23 14:22:33 +10:00
Peter Hutterer d3192dc070 dbus: Send out a PropertyChanged event when a device is paired
Just updating the array isn't enough, we need to bubble up the property
change and then manually send the PropertyChanged event
2018-01-22 17:14:37 +10:00
Peter Hutterer daac6e6d96 dbus: drop the "paired" flag from create_device
We can get this from the device now
2018-01-22 17:14:37 +10:00
Peter Hutterer 645c7577fe config: use uppercase 'UUID' in debug message 2018-01-22 17:14:37 +10:00
Peter Hutterer a2fd3cd8d1 dbus: on StartSearch(), emit PairableDevice signals for already known devices
If we created a device before StartSearch was called, we need to manually
send the signal to make sure the client sees it.
2018-01-22 15:25:34 +10:00
Peter Hutterer 0b7f756ba0 dbus: add the device's Address to the introspection XML
Code was already there, but the XML was missing the address
2018-01-22 15:24:56 +10:00
Benjamin Tissoires 3e5ef6c939 ble: remove the duplicate events filter
So we get more chances of capturing the advertisement from the device
if it is rather static.
2018-01-22 15:24:56 +10:00
Benjamin Tissoires 380518d0c7 ble: keep track of Start/StopDiscovery
discovery-stopped may call stop_discovery() if there
is no client listening, resulting in an infinite loop
2018-01-22 15:24:26 +10:00
Benjamin Tissoires f6d09d7086 dbus: fix timeout error if the index is invalid
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
2018-01-20 12:37:50 +10:00
Benjamin Tissoires 1b73de68b2 config: make sure we create the config file properly
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'
2018-01-20 12:37:50 +10:00
Peter Hutterer 4ee07a18b6 Hook up UUID changes to be written in the config file
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.
2018-01-19 16:17:44 +10:00
Peter Hutterer 8e50421f2e wacom: generate the uuid on pairing
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-01-19 16:17:44 +10:00
Peter Hutterer 76449bf608 config: add a basic storage backend
$XDG_DATA_HOME/tuhi/<mac address>/settings.ini

And that file contains a [Device] section with two entries, address and uuid.
2018-01-19 16:17:44 +10:00
Peter Hutterer 5f9766cb71 ble: catch and ignore the InProgress error when we're already listening 2018-01-19 13:45:32 +10:00
Peter Hutterer d4405cc1ef 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.
2018-01-19 13:40:26 +10:00
Peter Hutterer aa1a5e6689 Revamp the pairing process and rename to Search
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
2018-01-19 13:40:26 +10:00
Peter Hutterer f6519016f9 wacom: rename the register* calls to pair* calls
Because that's what we call them everywhere else
2018-01-19 13:40:26 +10:00
Peter Hutterer 81033c3139 wacom: drop the multiple definitions of SMARTPAD_UUID
Let's use deadbeef for now until we have the generation code in place.
2018-01-19 13:40:26 +10:00
Benjamin Tissoires 06e8d69e9d Implement pairing of a new device
This includes the new pairing code for the Spark which is slightly different
to the one from the Slate
2018-01-19 13:40:26 +10:00
Peter Hutterer aa1820e21c Send out the PairableDevice signal when we have a device 2018-01-19 11:15:12 +10:00
Benjamin Tissoires c073ff2f06 ignore Wacom devices that are in pairing mode
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>
2018-01-19 11:08:16 +10:00
Peter Hutterer 43b1c4057c dbus: implement StartPairing/StopPairing on the manager
Triggers a StartDiscovery()/StopDiscovery() on the bluetooth adapters, but
with a fixed timeout of 30s.
2018-01-19 11:07:25 +10:00
Peter Hutterer 5f5ce71aef dbus: properly return from Listen()
If we don't do the dbus dance for returning a value here, we get a timeout
eventually.
2018-01-17 13:41:35 +01:00
Peter Hutterer f9756a71ce Add commandline arguments to enable verbose mode
Create a logger hierarchy, that way we only need to set the root logger to
DEBUG and the rest goes along with it.
2018-01-17 13:41:35 +01:00
Benjamin Tissoires 8a81b1c245 Make sure we retrieve the data atomically
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.
2018-01-17 13:41:35 +01:00
Benjamin Tissoires f88a5b2222 wacom: disconnect when we have finished retrieving the data
There is no point keeping the connection alive just to drain the battery.
2018-01-17 13:41:35 +01:00
Peter Hutterer dde2ad4b46 ble: use ServicesResolved for the connected signal 2018-01-17 13:41:35 +01:00
Benjamin Tissoires f30f47d454 wacom: fix from_bytes little/big endianness
Looks like they are all the wrong way but the time_offset one.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-17 13:41:35 +01:00
Peter Hutterer 1841508c33 Pass the timestamps to the json file 2018-01-15 16:15:35 +10:00
Peter Hutterer 3a23610e08 Connect the WacomDevice drawings to the TuhiDrawings
And fixing a few issues with pressure, etc. on the way
2018-01-15 16:15:35 +10:00
Peter Hutterer cf68ebc9ce tuhi: create a TuhiDevice as glue object between front and backends 2018-01-15 16:15:33 +10:00
Peter Hutterer b7ce16fd38 dbus: remove the now-obsolete main() method 2018-01-15 16:14:19 +10:00
Peter Hutterer f293ef6e14 dbus: use the logging class too 2018-01-15 16:14:11 +10:00
Peter Hutterer febde33f0a ble: wrap the DBus properties into property functions 2018-01-15 16:14:11 +10:00
Peter Hutterer 6de262d2e9 ble: more documentation 2018-01-15 16:14:11 +10:00
Peter Hutterer 35e75b4aa7 ble: match the disconnected signal with 'connect'
No need to pass self as argument, it's the first argument to the signal
handler anyway
2018-01-15 16:14:11 +10:00
Peter Hutterer 20b78b89b7 wacom: remove superfluous time.sleep()
Leftover from an earlier debugging process
2018-01-15 16:14:11 +10:00
Peter Hutterer f3a39ee57c ble: remove leftover wacom-specific code 2018-01-15 16:14:11 +10:00
Peter Hutterer 4ec3069f78 ble: add two FIXMEs, we need to handle ServicesResolved
Connected can be True when ServicesResolved is False but without the latter we
can't do anything.
2018-01-15 11:59:57 +10:00
Peter Hutterer e29c201756 ble: remove obsolete comment
Filtering is done a layer above now
2018-01-15 11:50:52 +10:00
Peter Hutterer 5336f02df1 wacom: use int.from_bytes to convert from signed char to int 2018-01-15 11:34:46 +10:00
Peter Hutterer 1527fae191 wacom: replace the list2le/be helpers with int.from_bytes 2018-01-15 11:34:46 +10:00
Peter Hutterer c64446b48c ble: drop unused objectpath variable 2018-01-15 11:34:46 +10:00
Peter Hutterer c4b0807c3c dbusserver: emit the bus-name-owned when we have the bus
And rename from 'owned' to 'acquired', that's better english
2018-01-15 09:14:29 +10:00
Benjamin Tissoires 0d88d9d0e7 ble: fix flake8 warnings
./tuhi/ble.py:14:1: F401 'sys' imported but unused
./tuhi/ble.py:15:1: F401 'enum.Enum' imported but unused
./tuhi/ble.py:16:1: F401 'gi.repository.GLib' imported but unused
./tuhi/ble.py:26:1: E302 expected 2 blank lines, found 1
./tuhi/ble.py:81:1: W293 blank line contains whitespace
./tuhi/ble.py:84:13: E126 continuation line over-indented for hanging indent
./tuhi/ble.py:85:17: E131 continuation line unaligned for hanging indent
./tuhi/ble.py:203:39: F821 undefined name 'WACOM_CHRC_LIVE_PEN_DATA_UUID'
./tuhi/ble.py:204:38: E128 continuation line under-indented for visual indent
./tuhi/ble.py:205:39: F821 undefined name 'WACOM_OFFLINE_CHRC_PEN_DATA_UUID'
./tuhi/ble.py:206:38: E128 continuation line under-indented for visual indent
./tuhi/ble.py:207:39: F821 undefined name 'NORDIC_UART_CHRC_RX_UUID'
./tuhi/ble.py:208:38: E128 continuation line under-indented for visual indent
./tuhi/ble.py:232:1: E302 expected 2 blank lines, found 1
./tuhi/ble.py:240:13: E126 continuation line over-indented for hanging indent
./tuhi/ble.py:241:17: E131 continuation line unaligned for hanging indent
./tuhi/ble.py:250:21: E126 continuation line over-indented for hanging indent
./tuhi/ble.py:263:43: W291 trailing whitespace
./tuhi/ble.py:272:72: W291 trailing whitespace
./tuhi/ble.py:310:1: W391 blank line at end of file

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires af42bc1b27 dbusserver.py: fix flake8 warnings
./tuhi/dbusserver.py:55:1: E302 expected 2 blank lines, found 1
./tuhi/dbusserver.py:75:17: E126 continuation line over-indented for hanging indent
./tuhi/dbusserver.py:77:29: E203 whitespace before ':'
./tuhi/dbusserver.py:155:13: E126 continuation line over-indented for hanging indent
./tuhi/dbusserver.py:156:17: E131 continuation line unaligned for hanging indent

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires 3491ff68e4 wacom: fix flake8 warnings
tuhi/wacom.py:18:1: F401 'sys' imported but unused
tuhi/wacom.py:22:1: F401 'tuhi.dbusserver.TuhiDBusServer' imported but unused
tuhi/wacom.py:23:1: F401 'tuhi.ble.BlueZDeviceManager' imported but unused
tuhi/wacom.py:52:1: E302 expected 2 blank lines, found 1
tuhi/wacom.py:140:13: E126 continuation line over-indented for hanging indent
tuhi/wacom.py:141:17: E131 continuation line unaligned for hanging indent
tuhi/wacom.py:592:1: W391 blank line at end of file

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires 79a95bbe18 Handle tablet orientation
It didn't make quite sense to have y before x, and with some inverted
x value. The sensors are designed in the landscape mode, and the rotation
needs to be determined in the software.
Implement an orientation parameter to WacomDevice so we always have
normal X and Y

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires bbeca669e2 wacom: turn back the log lines to be greater than 79 chars
It's better to have a full log on one line. However, flake8 now complains.
I am not that happy with this situation, we should figure out a way
to selectively disable the length check for logger messages only.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires 7437cb6f93 wacom: opcode 0xeeff is the time since boot
This is an actual timestamp

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 20:23:47 +01:00
Benjamin Tissoires b49225c890 wacom: add helpers for big/little endian conversions
There is for sure some standard ones, but this will fit in the meantime.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 19:50:23 +01:00
Benjamin Tissoires bbded4f558 wacom: fix slate logging
leftover from a conversion

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-01-12 19:42:55 +01:00
Peter Hutterer 4aca12b6e7 Add the signals to expose the device over Tuhi's DBus interface
bus_own_name is asynchronous, so we first need to send a signal back and then
we can start connecting to the devices. Otherwise we'll have to implement a
queue which would be a lot harder than just waiting.
2018-01-12 20:32:09 +10:00
Peter Hutterer 8e907ba81a wacom: notify via signal when a drawing is available 2018-01-12 16:18:40 +10:00
Peter Hutterer 723282eb56 wacom: make the stroke object more generic, less SVG 2018-01-12 16:18:20 +10:00
Peter Hutterer d214778a1c Add the wacom nordic communication bits
Mostly copy/paste from an earlier project. Needs some more cleanup for
integration with Tuhi
2018-01-12 16:11:00 +10:00
Peter Hutterer bf2c000b57 Add a BLE abstraction layer 2018-01-12 16:00:24 +10:00
Peter Hutterer 89cf8ef67d Add the basic DBus server implementation 2018-01-12 07:46:06 +10:00