Commit Graph

206 Commits (a7244955023cbae742e5839e18f8a42434a85ff5)

Author SHA1 Message Date
Peter Hutterer 4b3914d49c tuhi: take the mainloop out of Tuhi
If we want to integrate this with TuhiGui, we can't have multiple mainloops.
And there's nothing with Tuhi that needs it anyway, it's all about how it is
being called. Which means we can just move this to the main method.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-18 12:19:29 +10:00
Peter Hutterer db08e1a82f wacom: improve a debug message 2019-07-17 18:25:40 +10:00
Peter Hutterer bc612f9e0e wacom: fix the firmware version retrieval for the base protocol
Introduced in dbd60675a9
2019-07-17 18:25:36 +10:00
Peter Hutterer 498a867558 Revert "base: once the device is registered, we're done"
This broke device initialization in some cases (not sure why it worked until
today though). Where a device is in register mode but the ManufacturerData has
not yet updated to the 4-byte string (i.e. a device previously known
normally), the device would now always call listen(). The firmware - in
register mode - would start initializing the connection though and get
rejected, leaving us with a device that cannot be registered.

This reverts commit a061240b11.
2019-07-15 21:57:24 +10:00
Peter Hutterer 48a339c3b7 wacom: device time must be interpreted as UTC 2019-07-15 09:38:19 +02:00
Peter Hutterer a1e3e8eafb wacom: move device state debugging to the functions themselves 2019-07-15 09:38:19 +02:00
Peter Hutterer aff38c26a3 wacom: fetch both dimensions in one go
No need for the caller to call this twice everywhere, let's just do this here.
2019-07-15 09:38:19 +02:00
Peter Hutterer dbd60675a9 wacom: fetch firmware data in one go
No need for the caller to call this twice everywhere, let's just do this here.
2019-07-15 09:38:19 +02:00
Peter Hutterer bf5e53b62b wacom: simplify the battery state debug message 2019-07-15 09:38:19 +02:00
Peter Hutterer 5d53ec8005 Bubble up the width/height from the protocol to the dbus interface
Fixes #135
2019-07-15 09:38:19 +02:00
Peter Hutterer d3156110b7 wacom: disable a duplicate debugging, enable another one
Print the dimensions during register too. And the "received" message is
duplicate because we log this as the data comes in from the nordic anyway.
2019-07-15 09:38:19 +02:00
Peter Hutterer 4611692b2c wacom: minor tidyup
No functional change, it just uses a dict now to pick the protocol class which
makes it *slightly* easier to read.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-15 09:38:19 +02:00
Peter Hutterer b6494efd40 wacom: move the fw logging into a custom class
Instead of just doing a single log line, let's log this to a yaml file so we
have a permanent record of the interactions with the device for bug reports.
2019-07-15 09:38:19 +02:00
Peter Hutterer bcdf730a72 base: make sure we only connect once to the bluez connect/disconnect signals
This was getting stacked - once on init and once whenever we actually made a
connecting, resulting in the signal never getting disconnected properly and
some races because we tried to sync twice.

The whole "listen()" vs "listening" vs "connected" etc. is a bit of a mess and
should be reworked for a proper fix to this. But for now this will do.

This may fix #124
2019-07-15 09:38:19 +02:00
Peter Hutterer b16a16abde Add a SyncState signal to the DBus interface
Propagated whenever we start talking to the device (and then again when we
stop). The purpose of this signal is merely that a UI can show e.g. a progress
bar while we're talking to the device to ensure the user something is
happening.

Fixes #138
2019-07-15 09:38:19 +02:00
Peter Hutterer 05fd213940 wacom: fetch the battery state during register
Any decent UI will want to know this given the device is online right now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-15 09:38:19 +02:00
Peter Hutterer f488d4e130 wacom: make 0xb3 the expected opcode
Virtually all the commands we have that don't have a specific opcode expect
0xb3. Since that's the general ACK command, we can default to that and make
everything else the exception.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-15 09:38:19 +02:00
Peter Hutterer a061240b11 base: once the device is registered, we're done
This method is called whenever a bluez property changes, don't prompt the user
(in the logs) to register the device we just finished registering.
2019-07-15 09:38:19 +02:00
Peter Hutterer de3386a88d base: add a helpful comment
This it's more obvious that add_device can really be called every second or so
2019-07-15 10:43:35 +10:00
Peter Hutterer 6aced355b5 wacom: minor change to a debug message 2019-07-15 10:43:35 +10:00
Peter Hutterer 72507b687a wacom: remove some superfluous ''' 2019-07-15 10:43:35 +10:00
Peter Hutterer caa52e0c51 base: when search is turned off, remove unregistered devices again
This is what the dbusserver module does as well, so we end up with a weird
mismatch: to the base module the device is still known and unregistered on the
next search start. So when we see the bluez properties float past, we don't
add a new devices.

To the dbusserver the device is gone though and since we don't add it again in
the base module, we never send a signal for it.

Since there's a reasonable assumption that if we don't register the device, we
don't want it anyway, let's delete it from the base device list too.

This doesn't fix the issue of a device timing out while waiting for a button
press. That device will count as known until the next search stop. But at
least now we don't have to restart tuhi.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-08 10:52:39 +02:00
Peter Hutterer 6ff9f34d08 wacom: fix type error when registering a Intuos Pro paper
gmtime() and localtime() both take seconds, not a struct time.
2019-07-08 10:52:39 +02:00
Peter Hutterer 0ddc33a37b drawing: fix deprecation warning
tuhi/drawing.py:46: PyGIDeprecationWarning: GObject.property is deprecated;
use GObject.Property instead
  @GObject.property

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-07 15:35:59 +10:00
Daniel Martin b52891f8fd ble: prefix all device logs with address
Use a logger child in BlueZDevice prefixing all log messages with the
device address.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
2019-06-07 08:34:07 +10:00
Daniel Martin c719ecf2e2 ble: use properties instead of variables
Replace variables (objpath, interface, uuid) with properties.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
2019-06-07 08:34:07 +10:00
Daniel Martin 7f9e58e587 ble: simplify GATT characteristic lookup
No need to get triggered by BlueZDeviceManager when it finds any GATT
characteristic. The BlueZDevice just needs its 'ServicesResolved' and
can resolve the GATT characteristics itself.

This solves a FIXME.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
2019-06-07 08:34:07 +10:00
Daniel Martin e7f8cc2bc2 ble: make object manager return sorted object list
The object list returned by object managers get_objects() function is
not sorted. Though, we rely on objects being sorted by their object
path.

Replace the object managers get_objects() function with a variant
fixing that. Additionally, our variant makes it possible to filter
the returned object list by object path and interface.

Examples:

- get_objects():
  /
  /org/bluez
  /org/bluez/hci0
  /org/bluez/hci0/dev_00_00_00_00_00_00
  /org/bluez/hci0/dev_00_00_00_00_00_00/service0000
  /org/bluez/hci0/dev_00_00_00_00_00_00/service0000/char0000
  /org/bluez/hci0/dev_00_00_00_00_00_00/service1111
  /org/bluez/hci0/dev_00_00_00_00_00_00/service1111/char1111
  /org/bluez/hci0/dev_FF_FF_FF_FF_FF_FF
  /org/bluez/hci0/dev_FF_FF_FF_FF_FF_FF/serviceffff
  /org/bluez/hci0/dev_FF_FF_FF_FF_FF_FF/serviceffff/charffff

- get_objects(interface='org.bluez.Adapter1'):
  /org/bluez/hci0

- get_objects(interface='org.bluez.GattCharacteristic1'
              base_path='/org/bluez/hci0/dev_00_00_00_00_00_00'):
  /org/bluez/hci0/dev_00_00_00_00_00_00/service0000/char0000
  /org/bluez/hci0/dev_00_00_00_00_00_00/service1111/char1111

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
2019-06-07 08:34:07 +10:00
Peter Hutterer 1b9b7760fd wacom: let's assume any 0xb3 with nonzero data is an error
b3 01 00 seems to be a generic "I'm happy" and the few others we've seen
are errors. So let's encode that and reconsider if it turns out to be false.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-05 11:14:48 +02:00
Peter Hutterer c1283289b7 wacom: sort the error handling
and use elif for clarity (even though we have exceptions here)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-05 11:14:48 +02:00
Peter Hutterer 4b02a6f51c Fix flake8-3 complaints
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-05 10:58:21 +02:00
Peter Hutterer 82b81b1c34 base: add timestamps to the logs
Fixes #127

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-05 10:54:44 +02:00
Ishak BELAHMAR f2263e72cf wacom/live: read Slate dimensions before starting live mode 2019-05-03 09:56:20 +02:00
Benjamin Tissoires c21c8a4633 wacom: do not use relative data when exporting
we already are keeping a record of the x,y and p. So we are trying
to duplicate the effort by using new_rel.
The problem is that some reports have relative coordinates but absolute
pressure data. Which means we are missing the pressure change as it has
a relative value of 0.

By trusting the wacom internal state, we can have the json data that
matches it completely.
2019-04-29 09:36:11 +02:00
Benjamin Tissoires 6d74615085 tuhi: prettify the exported json
having the whole file in a single line is fine for programs, much
less for humans
2019-04-29 09:36:11 +02:00
Peter Hutterer 7e751d45c8 base: if gi.repository fails to import, warn
We need python 3.6 but old Ubuntus only have 3.5. 3.6 can be installed (and
thus we get past the 3.6 sys.version check), but the gi.repository backports
are in various states of disarray (see #103 and #104).

And Python (and in particular gi) makes it hard for users to distinguish
between "the dependencies are a mess" and "this is a bug in tuhi".

So let's catch any error during gi.repository import and print a warning to
the user, in the hope of getting less bugs caused by Ubuntu frankenpythons.
Still won't fix issues like #104, but I'm not sure how to test for those
errors.

Related to #103
2018-03-06 09:33:17 +01:00
Peter Hutterer caf1264952 dbus: add file format version negotiation for the JSON data
Export the supported versions in a Manager property and require the client to
request a specific version in GetJSONData. Without that, the server could
never update the format and clients would have to support every single
historical version to make sure they can run against any version server.

Fixes #98
2018-02-19 11:17:18 +10:00
Peter Hutterer d4ea6e3938 dbus: change the JSON timestamp argument to 64 bit
Because we're totally going to ship tuhi in embedded devices that are going to
be in use until after 2038 when time resets to zero, the world goes big bang
and the only survivers will be 64-bit species. Or something like that. Either
way, the API documentation already said so anyway and the DrawingsAvailable
property is already 64 bit too.

Semi-confusingly: the dbus 64 bit unsigned type is 't', it doesn't stand for
'timestamp'.
2018-02-19 11:16:27 +10:00
Benjamin Tissoires 789c098e82 wacom: do not timeout on long drawing retrievals
It can easily take more than 5 seconds when reading the data. The current
timeout just cuts the connection while it is still reading.

We *could* just remove the timeout here as the device will gracefully
send us a 0xc8 opcode with a blank CRC if we shut the device down while
retrieving the data.

However, better being on the safe side and keep a timeout, but restart it
if we are still getting pen data during the timeout.

Fixes #91
2018-02-16 10:52:49 +01:00
Benjamin Tissoires a5cb084a31 wacom: use semaphore instead of polling
Using polling is bad, true, but it worked. However, using a Semaphore
is better and we can directly benefit from the internal timeout
implementation.
2018-02-16 10:51:09 +01:00
Benjamin Tissoires be2ac9fed3 wacom/live: take into account 'physical' borders of the bloc of paper
When using the live mode on the Slate, the bloc note actually hampers
the pen and prevents it to address all of the pixels on the screen.

Add some artificial boundaries that roughly match the primary design
of the device.

The Intuos Pro has a clip where you put a regular sheet of paper, so there
is no point restraining the active surface.

Fixes #88
2018-02-16 10:47:19 +01:00
Benjamin Tissoires 013de2a6e4 wacom/live: do not fetch the width and height, rely on stored values
It's not like we are handling hundreds of devices. And this allows us to
be more flexible in which fields are replaced in the report descriptor.
2018-02-16 10:47:19 +01:00
Benjamin Tissoires cf4d5b184e wacom/live: make the pressure dependent of the class
The Intuos Pro has 4096 levels of pressure, while the Slate and the Spark
only has 2048. We should do something about it.
2018-02-16 10:47:19 +01:00
Benjamin Tissoires 18221dfd58 wacom/live: fix physical maximums
This way, udevadm shows on the Slate:
E: ID_INPUT_HEIGHT_MM=148
E: ID_INPUT_TABLET=1
E: ID_INPUT_WIDTH_MM=216

Fixes #84
2018-02-16 10:47:19 +01:00
Benjamin Tissoires ee15b474fd wacom/live: make sure the kernel assigns INPUT_PROP_POINTER
The wacom kernel driver assigns INPUT_PROP_DIRECT if we use the
application Pen. Using the Digitizer one fixes that.
2018-02-16 10:47:19 +01:00
Peter Hutterer 7b246e0892 wacom: add packet handling of the two initial packets the IntuosPro sends
One is a fixed header, one  is the stroke timestamp
2018-02-16 15:43:28 +10:00
Peter Hutterer 31ab5f37d3 wacom: move stroke prefix handling into a packet handler 2018-02-16 15:43:28 +10:00
Peter Hutterer 5692a1f3b2 wacom: add PacketHandlers for handling special commands
For data packets other than basic motion/pressure strokes, add a PacketHandler
that can deal with that particular packet. Those handlers are part of the
class declaration, when we instantiate a protocol we pull them all into a
packet_handlers list and go through them. The first one to return True is
considered the right handler and we expect something has been done with the
packet.

This patch includes the handlers for the end-of-stroke and end-of-sequence
packets, the rest to be added later.
2018-02-16 15:43:28 +10:00
Peter Hutterer 43064b58fc wacom: add a WacomPacket class
Instad of carrying around a lot of parameters, move this into a class with
properties. Eventually we can subclass that one for the special opcodes (or
something...)
2018-02-16 15:43:28 +10:00
Peter Hutterer 23e18cea67 drawing: add a stroke.seal() functionality
Makes end-of-stroke handling easier, we can call seal() on the current stroke
and it'll make drawing.current_stroke() None, which is something we can deal
with.
2018-02-16 15:43:28 +10:00