Commit Graph

352 Commits (master)

Author SHA1 Message Date
Peter Hutterer 32091d9a7b wacom: improve a timestamp debug message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:21:24 +10:00
Peter Hutterer e5375a55dd wacom: name an argument to make it more obvious what the magic 5 means
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:21:24 +10:00
Peter Hutterer d73da09e26 protocol: 0xc7 on the spark seems to be in big-endian
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:10:25 +10:00
Peter Hutterer 790d8c5e31 wacom: fix pressure range for the IntuosPro
8191 seems to be the max value

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:05:49 +10:00
Peter Hutterer 85f2e3c67a wacom: fix the dimensions for the Spark
The reachable range is 2100x14800, highest pressure is 1023. Unlike the slate
the paper block still affords to address almost the whole range even though
the paper is slightly narrower than the range - but it can slide left/right by
about 5mm.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:05:49 +10:00
Peter Hutterer bd6278a305 wacom: change the raw log file name to include the timestamp
Because it's annoying when there's an issue with the timestamp in the file and
you have to grep for the file name.

And while we're there, change the human readable date to be actually readable.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 14:58:41 +10:00
Peter Hutterer 35acce3ea6 wacom: log the raw yaml data into a subdirectory
It gets a bit too confusing otherwise with all the weirdly named files around

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 14:58:41 +10:00
Peter Hutterer 6bf7715e83 wacom: write just the timestamp to the log file
Easier to parse than a strftime. And we can just add that one in a comment
anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 14:58:41 +10:00
Peter Hutterer 7f8222b351 wacom: add missing linebreaks to the yml log file
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 14:58:41 +10:00
Peter Hutterer e6057e256d Merge tuhigui into tuhi.gui
Let's make this a submodule of tuhi so we can share some code.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 08:18:39 +10:00
Peter Hutterer 547aec3d9b config: use super() instead of named base class
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 08:18:39 +10:00
Peter Hutterer c014393adb wacom: time_to_bytes is obsolete now
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 1ea89d2f09 protocol: split GET_DIMENSIONS up into two messages
It's the same message with a different argument, let's try not to do
gymnastics in the Msg code just so we can return a tuple.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 73bc782a53 protocol: 0xec is simply the GATT selection for file transfers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer c39c20ede2 protocol: drop the UNKNOWN_B1 class
0xb1 is the SetMode command, the rest is just the argument for which mode we
want

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 5e4ab89f41 Drop the semi-duplicate separate Protocol class
We can hook into the ProtocolVersion here, so let's de-duplicate this.
Should be backwards-compatible for config files but new config files will have
the uppercase name written now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 552e06a0fc wacom: drop the now-obsolete send_nordic_command_sync
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer b34f8794e4 wacom: switch registering the device to the new protocol handling
This is still a bit awkward because the communication of the spark especially
is so strange. It sends a (rejected) uuid, then a single command to register
that UUID. The Slate and the IntuosPro are more sensible, they seem to have a
special message to register a UUID - that one either fails or succeeds.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 6e20faa737 protocol: add a timeout argument to the new protocol handlers
The default timeout is too short for registering a button, let's control this
from the message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer f68ffa6733 wacom: pass the timestamp in seconds down parse_pen_data
We don't carea about the struct time here

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer a08aa02607 wacom: drop a bunch of now-duplicate functions
This is all handled by the matching Msg now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 023decb1d4 wacom: use the new protocol implemenation for all "normal" messages
This is an in-situ replacement of the old functionality vs the new one,
resulting in a bit of duplication. Now that the Protocol takes care of the
device-specifics most of our functions look identical. This will be fixed in a
follow-up commit.

Missing from the conversion here is the initial register handling (too
convoluted right now) and the parsing of the pen data.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer bcbb0982c8 wacom: drop our NordicData, use the one from the protocol
Same thing anyway, this is just namespace handling

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer a817d10cc7 protocol: start a new attempt at handling the protocol
This is only the framework for a new protocol handler that should simplify
adding, extending and debugging the actual protocol messages.

The summary is:
- each protocol interaction is a subclass of Msg() that handles the data sent
  and received from the device.
- the list of messages for each device is stored in a dictionary the caller
  initializes by providing the protocol version
- those messages are addressable via the Interactions enum through the
  Protocol class
- the messages can be run via execute(), taking and setting the obvious
  properties on the object
- actual communication is done via a single callback that takes/returns a
  NordicData object for the request/reply.

So after the basic setup, the caller can do this:
   p = Protocol(ProtocolVersion.INTUOS_PRO)
   name = p.execute(Interactions.GET_NAME).name
   p.execute(Interactions.SET_TIME, time.time())

This completely separates the protocol from the implementation where we want
the result of that exchange, ideally paving the way for better testing and
easier debugging of what's happening on the wire. Well, ether.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 910bea8898 wacom: add another nordic function that just takes and returns data
This function doesn't process the data beyond the logging required. It simply
sends the request and returns the reply, whatever that is.

Currently unused, this is prep work for later.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer fd02453279 wacom: allow for "no specific requested opcode" where we just return the data
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 16c22a95ec base: add a flag to control the config directory
For testing it's a lot easier to just provide a /tmp/ directory than having to
clear out the normal one that may contain useful drawings for debugging.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-13 19:12:53 +10:00
Peter Hutterer ee5640b783 Merge branch 'master' into wip/tuhigui 2019-08-09 15:22:07 +10:00
Peter Hutterer 28cb94bc89 base: fix failing registration of new devices
Regression introduced in e1a3675439

Where a device has no config entry, the e1a367 change would return early. This
is fine for devices previously seen and still lingering in the config but for
completely new devices, we'll never get past that KeyError.

Return to the old behaviour: where we don't have a stored UUID we continue
with the None UUID.

Fixes #148

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-09 15:18:00 +10:00
Peter Hutterer 341b91349e wacom: fix the data logger being off by one
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer 96df9fc416 wacom: make sure we only return the data packet size we want
If we have more data than our packet [1], let's not return the whole data
array. Slice it to size instead.

[1] this never happens with the current code, we don't work asynchronously

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer eacc03b6ea wacom: rename a function to make it more obvious
We're not checking for data here, we're taking the next message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer 075fae13f9 flake 8 fixes
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer 6e27d70517 wacom: de-duplicate an opcode check
we don't need the same-ish check twice, we can just pop our non-list into a
list an go from there.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer c84f3f8c63 wacom: error code 0x05 is an unrecognized command
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer d3726420cf wacom: add a comment describing where to we store stuff
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer b009ea3c96 wacom: rename the mysterious bits to sysevent
These bits are used for system notifications

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer cda4300388 wacom: visually align the UUIDs
And add # NOQA to shut up flake8

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-02 09:30:36 +02:00
Peter Hutterer 92a9628adf base: drop the separate function for bluez updates
A lambda does the job here without increasing the class profile
2019-07-30 14:06:49 +10:00
Peter Hutterer 08e3ec532e base: drop the extra function for checking if the device is in register mode
Now that it's just a one-liner, we don't need an extra function
2019-07-30 14:06:49 +10:00
Peter Hutterer 37b9b2eefa base: simplify check for in register mode
With a "or []" we can force this to be at least a 0-length list, obsoleting
the None check.
2019-07-30 14:06:49 +10:00
Peter Hutterer e1a3675439 base: ignore anything not from the known vendor IDs
We don't want to accidentally start talking to a device and brick it.
2019-07-30 14:06:49 +10:00
Peter Hutterer deb2c3ad2f base: rename the hotplugged argument
This one is a bit confusing, because most of the time it's not a hotplug
event, it's just the RSSI property updating.
2019-07-30 14:06:49 +10:00
Peter Hutterer 5b73c8ea2d Add a few more comments to the codebase 2019-07-30 14:06:49 +10:00
Peter Hutterer 764ad45ca2 wacom: normalize the pressure to the advertised [0, 0xffff] range
This requires adjusting the svg conversion in kete as well, afaict the 1000
range there was chosen because it's (almost) the midpoint of the Bamboo series
with 2048 pressure grades. So let's use half of 0x10000 instead, which is
approximately 0x8000 as the crow flies.

Fixes #142
2019-07-30 14:05:01 +10:00
Peter Hutterer 3c3163261f wacom: normalize the pressure to the advertised [0, 0xffff] range
This requires adjusting the svg conversion in kete as well, afaict the 1000
range there was chosen because it's (almost) the midpoint of the Bamboo series
with 2048 pressure grades. So let's use half of 0x10000 instead, which is
approximately 0x8000 as the crow flies.

Fixes #142
2019-07-19 14:37:51 +10:00
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
Peter Hutterer 155a11104c wacom: print an error if our device is more than 5 mins out 2018-02-16 15:43:28 +10:00
Peter Hutterer 09bfe44dd7 drawing: rename the stroke from 'l' to 's'
Leftover copy/paste error from when this class had a Layer subclass
2018-02-16 15:43:28 +10:00
Peter Hutterer 9fbfe17e13 ble: disable a debug message
Now that we got the basics running and reliable, this debug message is mostly
just noise, especially when in an office with lots of bluetooth devices
around. Comment it out, to be enabled when necessary.
2018-02-16 15:43:28 +10:00
Benjamin Tissoires 17dc80bea3 wacom: fix report descriptor logical min/max
Changing the python representation is not enough. We also need to change
the HID marker with the correct size.

Fixes 67b4d2b8fe
2018-02-14 13:11:37 +01:00
Peter Hutterer 67b4d2b8fe wacom: allow 4 bytes for width/height
Intuos Paper needs more than 16 bits

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-02-14 15:52:34 +10:00
Peter Hutterer 138497a73b wacom: add support for the Intuos Pro 2 paper 2018-02-14 15:03:02 +10:00
Peter Hutterer 7796d3c110 wacom: don't add points to the log until we have an absolute value
On the Intuos Pro at least we sometimes get events that are all relative at
first and it can take several events for us to have all three values as
absolute. This is likely a parsing error on our side, but meanwhile don't
write the data until we have at least one known value for all three axes.

And because the SVG writer isn't happy with empty strokes, add a seal()
function to the drawing to purge empty strokes.

Fixed #92 or at least works around it
2018-02-14 14:54:17 +10:00
Peter Hutterer 6c156efc01 wacom: make relative/abs events more obvious in the log
Mark the deltas with a * if they're the ones that changed.
2018-02-14 14:50:49 +10:00
Peter Hutterer 80d0066cef wacom: we only have one drawing per exchange
skip putting a single drawing in a list
2018-02-14 14:50:49 +10:00
Peter Hutterer c39b735e1e wacom: factor out the 'next stroke data' parsing 2018-02-14 14:50:49 +10:00
Peter Hutterer 8ecc397303 wacom: skip over the prefix when handling pen data
The prefix (4 bytes on the spark/slate) is some data that we don't know yet.
It *could* be the size of a tablet/drawing in LE byte order: 14434x29794
although that doesn't quite match the Intuos Pro data where the prefix is
different.

Either way, having this be an opcode of 0x3800 was probably just coincidence.
Let's skip over the header normally and assume that once we have a prefix, we
have a drawing. This opcode never occurs a second time within the same
drawing.
2018-02-14 14:50:49 +10:00
Peter Hutterer 876f35f806 wacom: factor out the prefix handling
The Intuos Pro has a different prefix, we'll need to override this. Dropping
the comment about the 8bt, on the intuos pro the prefix is nonsensical so
let's not leave a false lead there.
2018-02-14 14:50:45 +10:00
Peter Hutterer 726362107b wacom: append multiple nordic answers to each other
On the Spark, the 0xc9 CRC comes almost immediately after the 0xc8
end-of-sequence. This causes a race condition where sometimes we process the
0xc8 before the 0xc9 arrives, other times the 0xc9 overwrites the current
nordic_answer value before we get to it - triggering an unexpected opcode
exception.

Fix this by appending the nordic answer and only ever pulling off enough to
satisfy the current request.

Fixes #90
2018-02-14 11:25:13 +10:00
Peter Hutterer 240b982070 wacom: fix Spark CRC check
All it needs is less reversing
2018-02-14 11:25:13 +10:00
Peter Hutterer 45d4d6fb9b wacom: merge two debug strings 2018-02-14 09:45:49 +10:00
Benjamin Tissoires 422045e2fd wacom: insert proper ranges for X and Y in the uhid device
Also fix the pressure range to be 2047
2018-02-14 06:23:25 +10:00
Benjamin Tissoires d295e12310 wacom: create a uhid device on live mode
uhid code taken from https://github.com/bentiss/hid-tools and stripped out
from the not required parts here
2018-02-14 06:23:25 +10:00
Benjamin Tissoires d4dd672b2f live-mode: properly pack the fds over DBus
Keeping this one as a separate commit, so we can use it as a future
reference.
2018-02-14 06:23:25 +10:00
Benjamin Tissoires 1a6d0205df tuhi: hook up live mode
Currently just enable/disable live mode.
The int parameter is doomed to be an opened fd to the uhid node
2018-02-14 06:23:25 +10:00
Peter Hutterer 7ff760dcbf wacom: add support for a set_name on the Spark
Part of #82
2018-02-13 15:23:05 +01:00
Peter Hutterer 30620dfbf0 tuhi: when a device toggles 'registered', send out the required signal
Related to #80
2018-02-13 14:51:40 +01:00
Peter Hutterer ad0e81b395 base: push the mode down to the TuhiDevice
A device isn't registered or not, it's merely in a *state* of being
registering or not. Pass the current mode down to the TuhiDevice instead of a
boolean for 'registered'. The 'registered' gobject property is left in-place
for now, the dbus server needs it.
2018-02-13 14:51:40 +01:00
Peter Hutterer 720955db7c tuhi: try to register even if the device is not in register mode
Let's throw an exception when trying to connect.
2018-02-13 14:51:40 +01:00
Peter Hutterer 393056d5e8 base: remove another register_mode in favour of DeviceMode 2018-02-13 14:51:40 +01:00
Peter Hutterer 637f539194 ble: drop the 'event' argument from device-added
An 'event' boolean is less than obvious ('is-event' may be better). This
signalled the difference between a device-added during Manager startup and the
device-added at runtime (i.e. device goes online).

We don't need that differentiation. The manager adds all existing devices
immediately after connnect_to_bluez(). All we have to do is run through the
device list, add them locally and then subscribe to the signal.

This keeps the is-event confusion within one file only instead of spreading it
across two and an internal API. And we can re-name it to hotplugged.
2018-02-13 14:51:40 +01:00
Peter Hutterer 2ff4f8bca6 base: make the register/listen call handling more literal
Calling listen on an unregistered device currently triggers a register on the
device. This can happen when the device has been registered but the
ManufacturerData has not yet been updated.

Disentangle this by only calling the right function based on what we're trying
to get. This also requires that the connected/disconnected signals are only
handled when we're actually trying to do something with them.

Fixes #79 (multiple patches required)
2018-02-13 14:51:40 +01:00
Peter Hutterer 4661cf9ae8 wacom: remove state-based decision of whether to listen or register
Previously, we set self._mode and used that to determine what connection to
attempt. This can sometimes lead to a device attempting to register in
response to a listen() request (and vice versa).

Make this dependent on the caller arguments only. So when listen() is
requested do exactly that and generate the right exception if the device is in
the wrong mode.

Fixes #79 (multiple patches required)
2018-02-13 14:51:40 +01:00
Peter Hutterer 0d825e2e3c wacom: replace the signal forwarders with lambdas
We're doing nothing but forwarding the signal here, so let's just replace them
with lambdas so it's immediately obvious what we do with the signal.
2018-02-13 14:51:32 +01:00
Peter Hutterer de033c3b6a wacom: 0x05 appears to be the error for 'invalid opcode' 2018-02-12 15:30:16 +10:00
Peter Hutterer c9d48ed4b2 wacom: document the signals we send 2018-02-12 15:30:14 +10:00
Peter Hutterer 7cd9a89f3b wacom: prettify the 'returned time' debug message 2018-02-12 12:49:48 +10:00
Peter Hutterer 3cbbfbf056 base: remove write-only variable registering_mode 2018-02-12 09:41:54 +10:00
Peter Hutterer 60535a6859 wacom: remove unused define 2018-02-12 09:41:54 +10:00
Peter Hutterer 46ec85d718 ble: make manufacturer_data a property
We only ever used it in conjunction with vendor_id, so we can just make this a
normal property and send GObject notifies when it changes. This allows us to
listen for the MD to change when it finished registration.

[BT: do not add the second indirection by calling vendor_id]
2018-02-09 11:34:42 +01:00
Benjamin Tissoires 72523df3af ble: make sure the length of the manufacturer data is at least 1
We never encounter the issue, but I bet we will
2018-02-09 11:34:42 +01:00
Peter Hutterer 6cff3b8f79 wacom: split the time parsing functions out
Doesn't gain us that much, but we can re-use it when parsing stroke data
lateron.

This also will be useful for the Intuos Pro support
2018-02-09 10:39:18 +01:00
Peter Hutterer b5e6ad6559 wacom: make room for a more diverse register_device
Fold register_connection into register_device and (with comments) handle the
spark and slate here. This makes it easier to handle the Intuos Pro paper
later.
2018-02-09 10:31:37 +01:00
Peter Hutterer b45977c2d2 wacom: fix typo 2018-02-09 10:31:37 +01:00
Peter Hutterer bc95a0b414 wacom: prettify a debug message 2018-02-09 10:31:37 +01:00
Peter Hutterer 654dea6810 wacom: pass the uuid up to the slate's super() constructor 2018-02-09 10:31:37 +01:00
Peter Hutterer ae41b23c10 ble: don't make property updates exclusive
A single event may be sent for multiple properties, we need to check all of
them.
2018-02-09 10:28:43 +01:00
Benjamin Tissoires c2bba6bd43 wacom: move protocol instantiation into a class
During the first attempt to register, we might not know before hand
the protocol of the device. Have a special class for it, and then
instantiate the correct protocol before continuing.

This makes the 'Protocol' entry in the config file mandatory
2018-02-09 13:31:11 +10:00
Benjamin Tissoires 59db1a28ae wacom: make the slate a subclass of the spark
The Slate is more recent than the Spark. We better have the Spark as a
base class that we will never touch again and make the Slate depend on it.

When adding the Intuos Paper, we should make it a subclass of the Slate,
as the 2 protocols are similar.
2018-02-09 13:31:11 +10:00
Benjamin Tissoires f6e7c72d9d wacom: Split out the Nordic communication protocol in its own class
So the low level bits are not in the same class than the protocols
2018-02-09 13:31:11 +10:00
Peter Hutterer 82e7dbf515 wacom: remove the Spark's 0xb3 opcode from register_connection
This is handled in the subclass now
2018-02-09 13:31:11 +10:00
Benjamin Tissoires d62a97a8cd wacom: have subclasses to distinguish between protocols
The Intuos Pro Paper is close enough to the Slate but with some
subtleties. Instead of having a bunch of ifs, let's have nice subclasses
for the differences in the protocol.
2018-02-09 13:31:11 +10:00
Benjamin Tissoires 1f843b1434 wacom: split out the low level protocol from the interface with Tuhi
We are already handling 2 protocols, one for the Spark, and one for
the Slate. That's one too many, and given that there are some subtleties
in the Intuos Pro Paper (see #56), we better start splitting the protocol
from the interface, so we can have different protocols for different
devices instead of having a bunch of 'ifs'
2018-02-09 13:31:11 +10:00
Benjamin Tissoires 4b494917b1 wacom: load the protocol of the device from the config file
We can store this once for all, which will allow to keep the logic
of detecting the protocol while registering only
2018-02-09 13:31:11 +10:00
Benjamin Tissoires ecd99ea9b6 config: store the protocol used by the device in the config file
Instead of having to detect the protocol multiple times, we should just
store it once so we can detect oddities when they arrive.
2018-02-09 13:31:11 +10:00
Peter Hutterer 8f2ad50fa5 base: allow for multiple company IDs
The Intuos Paper uses a different one, because of course it does.
The 'company ID' from the Paper will be added while adding support for it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-02-09 13:31:11 +10:00
Peter Hutterer 7f230859fe wacom: don't save the current time
This is a write-only value. And for read_time() if we want to compare
timestamps we can just do so with time.time()
2018-02-09 13:31:11 +10:00
Benjamin Tissoires f684a0efb3 wacom: decipher 0xbb command
It's just the name of the device :)
2018-02-09 13:31:11 +10:00
Peter Hutterer 112b689bf8 wacom: drop Orientation from the Tuhi daemon
This isn't something we need in the daemon, it depends too much on what the
client expects so let the client save this data and handle the rotation
accordingly.

Note that the sensor in Sparks and Slates is in landscape format, i.e. every
picture is 90 deg rotated from what you'd expect.

Fixes #33 (wontfix)
2018-02-09 13:31:11 +10:00
Peter Hutterer ad145cc078 base: require Python 3.6
Instead of failing with a syntax error on format strings, actually bail out
instead. Likewise for setup.py, require 3.6 and add this to the classifiers
too while we're there.

Related to #71
2018-02-07 09:18:11 +01:00