Skip to content

Instantly share code, notes, and snippets.

@TobleMiner
Last active December 4, 2019 15:24
Show Gist options
  • Save TobleMiner/3fa78da21da14828682900c03ea1d907 to your computer and use it in GitHub Desktop.
Save TobleMiner/3fa78da21da14828682900c03ea1d907 to your computer and use it in GitHub Desktop.
Serial touchscreen protocol of some old shitty touchscreen terminal
#!/usr/bin/env python3
'''
standard message:
0x55 0x54 <action> <x lo> <x hi> <y lo> <y hi> 0xFF 0x00 <checksum>
actions:
- 0x01 - touch down
- 0x02 - touch hold
- 0x04 - touch up
'''
import sys
import functools
fname = sys.argv[1]
actions = [
'<invalid>',
'DOWN',
'HOLD',
'<invalid>',
'UP'
]
def hexdump(bytes):
for byte in bytes:
print('{:02x} '.format(byte), end='')
print()
def humandump(bytes):
if len(bytes) < 10:
print("Partial packet with {} bytes: ".format(len(bytes)), end='')
hexdump(bytes)
return
if len(bytes) > 10:
print("Oversize packet with {} bytes: ".format(len(bytes)), end='')
hexdump(bytes)
return
action = actions[bytes[2]]
x = bytes[3] + bytes[4] * 256
y = bytes[5] + bytes[6] * 256
print("{} @({},{})".format(action, x, y))
data = b''
with open(fname, 'rb') as f:
while True:
data += f.read(20)
# hexdump(data)
sep = b'UT'
touches = data.split(sep)
data = touches[-1]
touches = [ sep + touch for touch in touches[:-1] ]
for touch in touches:
humandump(touch)
# hexdump(touch)
# csum = (0xaa + functools.reduce(lambda acc, c: acc + c, touch[:-1], 0)) % 256
# print('{:02x}'.format(csum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment