|
1 | 1 | from maix import event, display, image
|
2 | 2 | from select import select
|
3 |
| - |
| 3 | +import os |
| 4 | +os.system("insmod /lib/modules/4.9.118/cst816.ko") |
4 | 5 | dev = event.InputDevice("/dev/input/event1")
|
| 6 | +img = display.as_image() |
5 | 7 | while True:
|
| 8 | + display.show(img) |
6 | 9 | r, w, x = select([dev], [], [], 0) # if r == 0 or set 0 will read() raise BlockingIOError
|
7 | 10 | 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 |
11 | 12 | for data in dev.read():
|
12 | 13 | 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)) |
14 | 15 | if data.code == 0x35: # ABS_MT_POSITION_X
|
15 | 16 | x = data.value
|
16 | 17 | if data.code == 0x36: # ABS_MT_POSITION_Y
|
17 | 18 | y = data.value
|
18 | 19 | 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)) |
20 | 27 | 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