mirror of https://github.com/tuhiproject/tuhi.git
protocol: the spark doesn't support get width/height
Let's make those noop messages that return the hardcoded width/height instead. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>pull/170/head
parent
ff2618e68a
commit
57aa0de954
|
@ -238,35 +238,17 @@ class TestProtocolAny(unittest.TestCase):
|
|||
self.assertEqual(msg.battery_is_charging, battery[0])
|
||||
self.assertEqual(msg.battery_percent, battery[1])
|
||||
|
||||
def test_get_width(self, cb=None, width=1234):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
self.assertEqual(request.opcode, 0xea)
|
||||
self.assertEqual(request.length, 2)
|
||||
self.assertEqual(request[0], 3)
|
||||
|
||||
data = [0x03, 0x00] + list(width.to_bytes(4, byteorder='little'))
|
||||
return NordicData([0xeb, len(data)] + data)
|
||||
|
||||
cb = cb or _cb
|
||||
|
||||
p = Protocol(self.protocol_version, callback=cb)
|
||||
def test_get_width(self, cb=None):
|
||||
# this is hardcoded for the spark
|
||||
p = Protocol(self.protocol_version, callback=None)
|
||||
msg = p.execute(Interactions.GET_WIDTH)
|
||||
self.assertEqual(msg.width, width)
|
||||
self.assertEqual(msg.width, 21000)
|
||||
|
||||
def test_get_height(self, cb=None, width=4321):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
self.assertEqual(request.opcode, 0xea)
|
||||
self.assertEqual(request.length, 2)
|
||||
self.assertEqual(request[0], 4)
|
||||
|
||||
data = [0x04, 0x00] + list(width.to_bytes(4, byteorder='little'))
|
||||
return NordicData([0xeb, len(data)] + data)
|
||||
|
||||
cb = cb or _cb
|
||||
|
||||
p = Protocol(self.protocol_version, callback=cb)
|
||||
def test_get_height(self, cb=None):
|
||||
# this is hardcoded for the spark
|
||||
p = Protocol(self.protocol_version, callback=None)
|
||||
msg = p.execute(Interactions.GET_HEIGHT)
|
||||
self.assertEqual(msg.height, width)
|
||||
self.assertEqual(msg.height, 14800)
|
||||
|
||||
def test_unknown_e3(self, cb=None):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
|
@ -410,6 +392,36 @@ class TestProtocolSpark(TestProtocolAny):
|
|||
class TestProtocolSlate(TestProtocolSpark):
|
||||
protocol_version = ProtocolVersion.SLATE
|
||||
|
||||
def test_get_width(self, cb=None, width=1234):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
self.assertEqual(request.opcode, 0xea)
|
||||
self.assertEqual(request.length, 2)
|
||||
self.assertEqual(request[0], 3)
|
||||
|
||||
data = [0x03, 0x00] + list(width.to_bytes(4, byteorder='little'))
|
||||
return NordicData([0xeb, len(data)] + data)
|
||||
|
||||
cb = cb or _cb
|
||||
|
||||
p = Protocol(self.protocol_version, callback=cb)
|
||||
msg = p.execute(Interactions.GET_WIDTH)
|
||||
self.assertEqual(msg.width, width)
|
||||
|
||||
def test_get_height(self, cb=None, height=4321):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
self.assertEqual(request.opcode, 0xea)
|
||||
self.assertEqual(request.length, 2)
|
||||
self.assertEqual(request[0], 4)
|
||||
|
||||
data = [0x04, 0x00] + list(height.to_bytes(4, byteorder='little'))
|
||||
return NordicData([0xeb, len(data)] + data)
|
||||
|
||||
cb = cb or _cb
|
||||
|
||||
p = Protocol(self.protocol_version, callback=cb)
|
||||
msg = p.execute(Interactions.GET_HEIGHT)
|
||||
self.assertEqual(msg.height, height)
|
||||
|
||||
def test_get_strokes(self, cb=None, count=1024, ts=time.time()):
|
||||
def _cb(request, requires_reply=True, userdata=None, timeout=5):
|
||||
self.assertEqual(request.opcode, 0xcc)
|
||||
|
|
|
@ -792,7 +792,25 @@ class MsgGetBattery(Msg):
|
|||
self.battery_is_charging = reply[1] == 1
|
||||
|
||||
|
||||
class MsgGetWidth(Msg):
|
||||
class MsgGetWidthSpark(Msg):
|
||||
'''
|
||||
This is a fake message. The Spark doesn't seem to have a getter for this
|
||||
one, it just times out. We just hardcode the value here.
|
||||
|
||||
.. attribute:: width
|
||||
|
||||
The width of the tablet in points (mm/100)
|
||||
'''
|
||||
interaction = Interactions.GET_WIDTH
|
||||
opcode = Msg.OPCODE_NOOP
|
||||
protocol = ProtocolVersion.ANY
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.width = 21000
|
||||
|
||||
|
||||
class MsgGetWidthSlate(Msg):
|
||||
'''
|
||||
.. attribute:: width
|
||||
|
||||
|
@ -800,7 +818,7 @@ class MsgGetWidth(Msg):
|
|||
'''
|
||||
interaction = Interactions.GET_WIDTH
|
||||
opcode = 0xea
|
||||
protocol = ProtocolVersion.ANY
|
||||
protocol = ProtocolVersion.SLATE
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -816,7 +834,25 @@ class MsgGetWidth(Msg):
|
|||
self.width = little_u32(reply[2:6])
|
||||
|
||||
|
||||
class MsgGetHeight(Msg):
|
||||
class MsgGetHeightSpark(Msg):
|
||||
'''
|
||||
This is a fake message. The Spark doesn't seem to have a getter for this
|
||||
one, it just times out. We just hardcode the value here.
|
||||
|
||||
.. attribute:: height
|
||||
|
||||
The height of the tablet in points (mm/100)
|
||||
'''
|
||||
interaction = Interactions.GET_HEIGHT
|
||||
opcode = Msg.OPCODE_NOOP
|
||||
protocol = ProtocolVersion.ANY
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.height = 14800
|
||||
|
||||
|
||||
class MsgGetHeightSlate(Msg):
|
||||
'''
|
||||
.. attribute:: height
|
||||
|
||||
|
@ -824,7 +860,7 @@ class MsgGetHeight(Msg):
|
|||
'''
|
||||
interaction = Interactions.GET_HEIGHT
|
||||
opcode = 0xea
|
||||
protocol = ProtocolVersion.ANY
|
||||
protocol = ProtocolVersion.SLATE
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue