mirror of https://github.com/tuhiproject/tuhi.git
protocol: rm unused class WacomPacket
parent
72d9dee37a
commit
3c1a84e1ab
|
@ -268,78 +268,6 @@ class DataLogger(object):
|
|||
self._in_context = False
|
||||
|
||||
|
||||
class WacomPacket(GObject.Object):
|
||||
'''
|
||||
A single protocol packet of variable length. The protocol format is a
|
||||
single-byte bitmask followed by up to 8 bytes (depending on the number
|
||||
of 1-bits in the bitmask). Each byte represents the matching bit in the
|
||||
bitmask, i.e. the data is non-sparse.
|
||||
|
||||
If the bitmask has 0x1 and/or 0x2 set, those two bytes make up the
|
||||
opcode of the command. So the possible layouts are:
|
||||
|
||||
| bitmask | opcode1 | opcode2 | payload ...
|
||||
| bitmask | opcode1 | payload ...
|
||||
| bitmask | opcode2 | payload ...
|
||||
| bitmask | payload
|
||||
|
||||
On most normal packets containing motion data, the opcode is not
|
||||
present.
|
||||
|
||||
Attributes:
|
||||
bitmask .. single byte with a bitmask denoting the contents
|
||||
opcode ... the 16-bit opcode or None for 'special' packets. Note that
|
||||
the opcode is converted into an integer from the
|
||||
little-endian protocol format
|
||||
bytes .... a list of the payload bytes as sent by the device. This is
|
||||
a non-sparse list matching the number of set bits in the
|
||||
bitmask. it does not include the bitmask.
|
||||
args ..... a sparse list of the payload bytes, expanded to match the
|
||||
bitmask so that args[x] is the value for each bit x in
|
||||
bitmask. it does not include the bitmask.
|
||||
length ... length of the packet in bytes, including bitmask
|
||||
'''
|
||||
def __init__(self, data):
|
||||
self.bitmask = data[0]
|
||||
nbytes = bin(self.bitmask).count('1')
|
||||
self.bytes = data[1:1 + nbytes]
|
||||
self.length = nbytes + 1 # for the bitmask
|
||||
|
||||
idx = 0
|
||||
# 2-byte opcode, but only if the bitmask is set for either byte
|
||||
opcode = 0
|
||||
if self.bitmask & 0x1:
|
||||
opcode |= self.bytes[idx]
|
||||
idx += 1
|
||||
if self.bitmask & 0x2:
|
||||
opcode |= self.bytes[idx] << 8
|
||||
idx += 1
|
||||
|
||||
self.opcode = opcode if opcode else None
|
||||
|
||||
self.args = []
|
||||
vals = self.bytes.copy()
|
||||
mask = self.bitmask
|
||||
while mask != 0:
|
||||
self.args.append(vals.pop(0) if mask & 0x1 else 0x00)
|
||||
mask >>= 1
|
||||
|
||||
def __repr__(self):
|
||||
debug_data = []
|
||||
debug_data.append(f'{self.bitmask:02x} ({self.bitmask:08b}) |')
|
||||
if self.opcode:
|
||||
debug_data.append(f'{self.opcode:04x} |')
|
||||
else:
|
||||
debug_data.append(f' |')
|
||||
|
||||
for i in range(2, 8): # start at 2 to skip the opcode
|
||||
if self.bitmask & (1 << i):
|
||||
debug_data.append(f'{self.args[i]:02x}')
|
||||
else:
|
||||
debug_data.append(' ')
|
||||
return " ".join(debug_data)
|
||||
|
||||
|
||||
class WacomProtocolLowLevelComm(GObject.Object):
|
||||
'''
|
||||
Internal class to handle the communication with the Wacom device.
|
||||
|
|
Loading…
Reference in New Issue