protocol: add the message for getting the point size
The dimensions of the tablet are in device units, the point size tells us how big the actual tablet is. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
57aa0de954
commit
643dd34476
|
@ -250,6 +250,12 @@ class TestProtocolAny(unittest.TestCase):
|
||||||
msg = p.execute(Interactions.GET_HEIGHT)
|
msg = p.execute(Interactions.GET_HEIGHT)
|
||||||
self.assertEqual(msg.height, 14800)
|
self.assertEqual(msg.height, 14800)
|
||||||
|
|
||||||
|
def test_get_point_size(self, cb=None):
|
||||||
|
# this is hardcoded for the spark
|
||||||
|
p = Protocol(self.protocol_version, callback=None)
|
||||||
|
msg = p.execute(Interactions.GET_POINT_SIZE)
|
||||||
|
self.assertEqual(msg.point_size, 10)
|
||||||
|
|
||||||
def test_unknown_e3(self, cb=None):
|
def test_unknown_e3(self, cb=None):
|
||||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||||
self.assertEqual(request.opcode, 0xe3)
|
self.assertEqual(request.opcode, 0xe3)
|
||||||
|
@ -546,6 +552,20 @@ class TestProtocolIntuosPro(TestProtocolSlate):
|
||||||
|
|
||||||
super().test_register_wait_for_button(cb or _cb)
|
super().test_register_wait_for_button(cb or _cb)
|
||||||
|
|
||||||
|
def test_get_point_size(self, cb=None, pointsize=12):
|
||||||
|
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||||
|
self.assertEqual(request.opcode, 0xea)
|
||||||
|
self.assertEqual(request.length, 2)
|
||||||
|
self.assertEqual(request[0], 0x14)
|
||||||
|
ps = little_u32(pointsize)
|
||||||
|
return NordicData([0xeb, 6, 0x14, 0x00] + list(ps))
|
||||||
|
|
||||||
|
cb = cb or _cb
|
||||||
|
|
||||||
|
p = Protocol(self.protocol_version, callback=cb)
|
||||||
|
msg = p.execute(Interactions.GET_POINT_SIZE)
|
||||||
|
self.assertEqual(msg.point_size, pointsize - 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main(sys.argv[1:])
|
unittest.main(sys.argv[1:])
|
||||||
|
|
|
@ -104,6 +104,7 @@ class Interactions(enum.Enum):
|
||||||
REGISTER_WAIT_FOR_BUTTON = enum.auto()
|
REGISTER_WAIT_FOR_BUTTON = enum.auto()
|
||||||
REGISTER_COMPLETE = enum.auto()
|
REGISTER_COMPLETE = enum.auto()
|
||||||
SET_FILE_TRANSFER_REPORTING_TYPE = enum.auto()
|
SET_FILE_TRANSFER_REPORTING_TYPE = enum.auto()
|
||||||
|
GET_POINT_SIZE = enum.auto()
|
||||||
|
|
||||||
UNKNOWN_E3 = enum.auto()
|
UNKNOWN_E3 = enum.auto()
|
||||||
|
|
||||||
|
@ -799,7 +800,7 @@ class MsgGetWidthSpark(Msg):
|
||||||
|
|
||||||
.. attribute:: width
|
.. attribute:: width
|
||||||
|
|
||||||
The width of the tablet in points (mm/100)
|
The width of the tablet in points (see :class:`MsgGetPointSize`)
|
||||||
'''
|
'''
|
||||||
interaction = Interactions.GET_WIDTH
|
interaction = Interactions.GET_WIDTH
|
||||||
opcode = Msg.OPCODE_NOOP
|
opcode = Msg.OPCODE_NOOP
|
||||||
|
@ -814,7 +815,7 @@ class MsgGetWidthSlate(Msg):
|
||||||
'''
|
'''
|
||||||
.. attribute:: width
|
.. attribute:: width
|
||||||
|
|
||||||
The width of the tablet in points (mm/100)
|
The width of the tablet in points (see :class:`MsgGetPointSize`)
|
||||||
'''
|
'''
|
||||||
interaction = Interactions.GET_WIDTH
|
interaction = Interactions.GET_WIDTH
|
||||||
opcode = 0xea
|
opcode = 0xea
|
||||||
|
@ -841,7 +842,7 @@ class MsgGetHeightSpark(Msg):
|
||||||
|
|
||||||
.. attribute:: height
|
.. attribute:: height
|
||||||
|
|
||||||
The height of the tablet in points (mm/100)
|
The height of the tablet in points (see :class:`MsgGetPointSize`)
|
||||||
'''
|
'''
|
||||||
interaction = Interactions.GET_HEIGHT
|
interaction = Interactions.GET_HEIGHT
|
||||||
opcode = Msg.OPCODE_NOOP
|
opcode = Msg.OPCODE_NOOP
|
||||||
|
@ -856,7 +857,7 @@ class MsgGetHeightSlate(Msg):
|
||||||
'''
|
'''
|
||||||
.. attribute:: height
|
.. attribute:: height
|
||||||
|
|
||||||
The height of the tablet in points (mm/100)
|
The height of the tablet in points (see :class:`MsgGetPointSize`)
|
||||||
'''
|
'''
|
||||||
interaction = Interactions.GET_HEIGHT
|
interaction = Interactions.GET_HEIGHT
|
||||||
opcode = 0xea
|
opcode = 0xea
|
||||||
|
@ -876,6 +877,52 @@ class MsgGetHeightSlate(Msg):
|
||||||
self.height = little_u32(reply[2:6])
|
self.height = little_u32(reply[2:6])
|
||||||
|
|
||||||
|
|
||||||
|
class MsgGetPointSizeSpark(Msg):
|
||||||
|
'''
|
||||||
|
This is a fake message. The Spark and Slate doesn't seem to have a
|
||||||
|
getter for this one, it just times out. We just hardcode the value here.
|
||||||
|
|
||||||
|
.. attribute:: point_size
|
||||||
|
|
||||||
|
The point_size of the tablet in µm
|
||||||
|
'''
|
||||||
|
interaction = Interactions.GET_POINT_SIZE
|
||||||
|
opcode = Msg.OPCODE_NOOP
|
||||||
|
protocol = ProtocolVersion.ANY
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.point_size = 10
|
||||||
|
|
||||||
|
|
||||||
|
class MsgGetPointSize(Msg):
|
||||||
|
'''
|
||||||
|
.. attribute:: point_size
|
||||||
|
|
||||||
|
The point size in micrometers
|
||||||
|
'''
|
||||||
|
interaction = Interactions.GET_POINT_SIZE
|
||||||
|
opcode = 0xea
|
||||||
|
protocol = ProtocolVersion.INTUOS_PRO
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.args = little_u16(0x14)
|
||||||
|
|
||||||
|
def _handle_reply(self, reply):
|
||||||
|
if reply.opcode != 0xeb:
|
||||||
|
raise UnexpectedReply(self)
|
||||||
|
|
||||||
|
if little_u16(reply[0:2]) != 0x14:
|
||||||
|
raise UnexpectedDataError(reply)
|
||||||
|
|
||||||
|
# This is strange. The return value is supposed to be the point size
|
||||||
|
# but it's off by one. The IntuosPro returns 6 but a point size of 5
|
||||||
|
# matches the physical dimensions. So let's assume there's a bug in
|
||||||
|
# the firmware or the specs are wrong or something.
|
||||||
|
self.point_size = little_u32(reply[2:6]) - 1
|
||||||
|
|
||||||
|
|
||||||
class MsgUnknownE3Command(Msg):
|
class MsgUnknownE3Command(Msg):
|
||||||
interaction = Interactions.UNKNOWN_E3
|
interaction = Interactions.UNKNOWN_E3
|
||||||
opcode = 0xe3
|
opcode = 0xe3
|
||||||
|
|
Loading…
Reference in New Issue