-
Notifications
You must be signed in to change notification settings - Fork 3
/
rmDebugWacomInput.py
executable file
·63 lines (54 loc) · 1.62 KB
/
rmDebugWacomInput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
'''
Meant to run on the reMarkable.
Shows data read from Wacom device using evdev
'''
import struct
# Source: https://github.com/canselcik/libremarkable/blob/master/src/input/wacom.rs
EV_SYNC = 0
EV_KEY = 1
EV_ABS = 3
WACOM_EVCODE_PRESSURE = 24
WACOM_EVCODE_DISTANCE = 25
WACOM_EVCODE_XTILT = 26
WACOM_EVCODE_YTILT = 27
WACOM_EVCODE_XPOS = 0
WACOM_EVCODE_YPOS = 1
# ----------
lastXPos = -1
lastYPos = -1
lastXTilt = -1
lastYTilt = -1
lastDistance = -1
lastPressure = -1
# EvDev (Event Device) basically is a struct repeadetly read from this socket/file
# Struct from https://github.com/reMarkable/linux/blob/b82cb2adc32411c98ffc0db86cdd12858c8b39df/include/uapi/linux/input.h#L24
#struct input_event {
# struct timeval time; # <-- 64 bits
# __u16 type;
# __u16 code;
# __s32 value;
#};
wacomEvents = open('/dev/input/event0', 'rb')
try:
while True:
# Basically what the evdev-lib does (only more dynamic):
_, evType, evCode, evValue = struct.unpack('QHHi', wacomEvents.read(16))
if evType != EV_ABS:
continue
if evCode == WACOM_EVCODE_XPOS:
lastXPos = evValue
elif evCode == WACOM_EVCODE_YPOS:
lastYPos = evValue
elif evCode == WACOM_EVCODE_XTILT:
lastXTilt = evValue
elif evCode == WACOM_EVCODE_YTILT:
lastYTilt = evValue
elif evCode == WACOM_EVCODE_DISTANCE:
lastDistance = evValue
elif evCode == WACOM_EVCODE_PRESSURE:
lastPressure = evValue
print('XPos: %5d | YPos: %5d | XTilt: %5d | YTilt: %5d | Distance: %3d | Pressure: %4d' % (lastXPos, lastYPos, lastXTilt, lastYTilt, lastDistance, lastPressure))
except KeyboardInterrupt:
print('Exiting...')
wacomEvents.close()