From 876f35f806dd120dbaa5e7e8b3ca659199c90bbf Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 14 Feb 2018 09:48:02 +1000 Subject: [PATCH] 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. --- tuhi/wacom.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index d54e0d3..4a465d6 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -586,6 +586,16 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): is_rel = True return v, dv, is_rel + def parse_pen_data_prefix(self, data): + expected_prefix = b'\x62\x38\x62\x74' + prefix = data[:4] + # 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 True + def parse_pen_data(self, data, timestamp): ''' :param timestamp: a tuple with 9 entries, corresponding to the @@ -599,6 +609,10 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): drawings = [] drawing = None stroke = None + + if not self.parse_pen_data_prefix(data): + return [] + while offset < len(data): bitmask, opcode, raw_args, args, offset = self.next_pen_data(data, offset) if opcode == 0x3800: @@ -652,13 +666,9 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): pen_data = self.wait_for_end_read() str_pen = binascii.hexlify(bytes(pen_data)) logger.info(f'received {str_pen}') - prefix = pen_data[:4] - # not sure if we really need this check - # note: \x38\x62\x74 translates to '8bt' - if bytes(prefix) == b'\x62\x38\x62\x74': - drawings = self.parse_pen_data(pen_data, timestamp) - for drawing in drawings: - self.emit('drawing', drawing) + drawings = self.parse_pen_data(pen_data, timestamp) + for drawing in drawings: + self.emit('drawing', drawing) self.ack_transaction() transaction_count += 1 return transaction_count