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>
pull/153/head
Peter Hutterer 2019-08-12 19:56:31 +10:00
parent 73bc782a53
commit 1ea89d2f09
2 changed files with 37 additions and 22 deletions

View File

@ -65,7 +65,8 @@ class Interactions(enum.Enum):
SET_TIME = enum.auto()
GET_FIRMWARE = enum.auto()
GET_BATTERY = enum.auto()
GET_DIMENSIONS = enum.auto()
GET_WIDTH = enum.auto()
GET_HEIGHT = enum.auto()
SET_MODE = enum.auto()
GET_STROKES = enum.auto()
GET_DATA_AVAILABLE = enum.auto()
@ -763,39 +764,52 @@ class MsgGetBattery(Msg):
self.battery_is_charging = reply[1] == 1
class MsgGetDimensions(Msg):
class MsgGetWidth(Msg):
'''
.. attribute:: width
The width of the tablet in points (mm/100)
.. attribute:: height
The height of the tablet in points (mm/100)
'''
interaction = Interactions.GET_DIMENSIONS
interaction = Interactions.GET_WIDTH
opcode = 0xea
protocol = ProtocolVersion.ANY
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.args = [0x03, 0x00]
def _handle_reply(self, reply):
if reply.opcode != 0xeb:
raise UnexpectedReply(self)
if self.args[0] not in [0x3, 0x4] or len(reply) != 6:
if reply[0] != 0x3 or len(reply) != 6:
raise UnexpectedDataError(reply)
if self.args[0] == 0x3:
self.width = int.from_bytes(reply[2:4], byteorder='little')
if self.args[0] == 0x4:
self.height = int.from_bytes(reply[2:4], byteorder='little')
self.width = int.from_bytes(reply[2:4], byteorder='little')
def execute(self):
# We need two requests with different args to get both w and h
self.args = [0x3, 0x00]
super().execute()
self.args = [0x4, 0x00]
super().execute()
return self
class MsgGetHeight(Msg):
'''
.. attribute:: height
The height of the tablet in points (mm/100)
'''
interaction = Interactions.GET_HEIGHT
opcode = 0xea
protocol = ProtocolVersion.ANY
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.args = [0x04, 0x00]
def _handle_reply(self, reply):
if reply.opcode != 0xeb:
raise UnexpectedReply(self)
if reply[0] != 0x4 or len(reply) != 6:
raise UnexpectedDataError(reply)
self.height = int.from_bytes(reply[2:4], byteorder='little')
class MsgUnknownE3Command(Msg):

View File

@ -716,9 +716,10 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
return name
def get_dimensions(self):
msg = self.p.execute(Interactions.GET_DIMENSIONS)
logger.info(f'dimensions: {msg.width}x{msg.height}')
return msg.width, msg.height
w = self.p.execute(Interactions.GET_WIDTH).width
h = self.p.execute(Interactions.GET_HEIGHT).height
logger.info(f'dimensions: {w}x{h}')
return w, h
def select_transfer_gatt(self):
self.p.execute(Interactions.SET_FILE_TRANSFER_REPORTING_TYPE)