From 8ecc3973032f4b07aaf90e648f652c7ae97a7759 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 14 Feb 2018 10:04:02 +1000 Subject: [PATCH] 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. --- tuhi/wacom.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 4a465d6..4d9f604 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -589,19 +589,19 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): def parse_pen_data_prefix(self, data): expected_prefix = b'\x62\x38\x62\x74' prefix = data[:4] + offset = len(prefix) # not sure if we really need this check if bytes(prefix) != expected_prefix: logger.debug(f'Expected pen data prefix {expected_prefix} but got {prefix}') - return False + return False, 0 - return True + return True, offset def parse_pen_data(self, data, timestamp): ''' :param timestamp: a tuple with 9 entries, corresponding to the local time ''' - offset = 0 x, y, p = 0, 0, 0 dx, dy, dp = 0, 0, 0 @@ -610,17 +610,16 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): drawing = None stroke = None - if not self.parse_pen_data_prefix(data): + success, offset = self.parse_pen_data_prefix(data) + if not success: return [] + drawing = Drawing(self.device.name, (self.width, self.height), timestamp) + drawings.append(drawing) + while offset < len(data): bitmask, opcode, raw_args, args, offset = self.next_pen_data(data, offset) - if opcode == 0x3800: - logger.info(f'beginning of sequence') - drawing = Drawing(self.device.name, (self.width, self.height), timestamp) - drawings.append(drawing) - continue - elif opcode == 0xeeff: + if opcode == 0xeeff: # some sort of headers time_offset = int.from_bytes(raw_args[4:], byteorder='little') logger.info(f'time offset since boot: {time_offset * 0.005} secs')