Skip to content

Commit e151961

Browse files
committed
[evdev] test touchscreen
1 parent b89e5e6 commit e151961

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tests/general/uasge_evdev.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
from maix import event, display, image
22
from select import select
3-
3+
import os
4+
os.system("insmod /lib/modules/4.9.118/cst816.ko")
45
dev = event.InputDevice("/dev/input/event1")
6+
img = display.as_image()
57
while True:
8+
display.show(img)
69
r, w, x = select([dev], [], [], 0) # if r == 0 or set 0 will read() raise BlockingIOError
710
if r:
8-
img = display.as_image()
9-
img.draw_rectangle(0, 0, 240, 240, color=(255, 0, 0), thickness=-1)
10-
x, y = 0, 0
11+
x, y, e = 0, 0, 0
1112
for data in dev.read():
1213
if (data.type == 0x03):
13-
print(' type: ', data.type, ' code: ', hex(data.code), ' value: ', hex(data.value))
14+
# print(' type: ', data.type, ' code: ', hex(data.code), ' value: ', hex(data.value))
1415
if data.code == 0x35: # ABS_MT_POSITION_X
1516
x = data.value
1617
if data.code == 0x36: # ABS_MT_POSITION_Y
1718
y = data.value
1819
if data.code == 0x30: # ABS_MT_TOUCH_MAJOR
19-
tmp = "(%d, %d, %d)" % (x, y, hex(data.value))
20+
e = data.value
21+
if data.code == 0x32: # ABS_MT_WIDTH_MAJOR
22+
if data.value == 0:
23+
img.draw_rectangle(0, 0, 240, 240, color=(0, 0, 0), thickness=-1)
24+
else:
25+
img.draw_circle(x, y, 2, color=(255, 0, 0), thickness=-1)
26+
tmp = "(%d, %d, %d, %s)" % (data.value, x, y, hex(e))
2027
w, h = image.get_string_size(tmp)
21-
img.draw_string(120 - w // 2, 120, tmp)
22-
display.show(img)
28+
bak = image.new(size=(w + 20, h + 2))
29+
bak.draw_string(0, 0, tmp)
30+
img.draw_image(bak, 120 - w // 2, 120)
31+

0 commit comments

Comments
 (0)