-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket_minitouch.py
More file actions
75 lines (55 loc) · 2.02 KB
/
websocket_minitouch.py
File metadata and controls
75 lines (55 loc) · 2.02 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
"""Low-level touch control via WebSocket (minitouch)."""
import asyncio
from devicebase import DeviceBaseClient
SERIAL = "device123"
async def basic_touch():
"""Basic tap and swipe using MinitouchClient."""
client = DeviceBaseClient()
minitouch = client.minitouch_client(SERIAL)
async with minitouch:
# Tap at coordinates
await minitouch.tap(540, 960)
# Swipe from bottom to top
await minitouch.swipe(540, 1600, 540, 400, duration_ms=500)
# Multi-point gestures
# Two-finger zoom simulation
await minitouch.touch_down(0, 300, 960)
await minitouch.touch_down(1, 780, 960)
await minitouch.commit()
# Move fingers apart
for i in range(10):
await minitouch.touch_move(0, 300 - i * 20, 960)
await minitouch.touch_move(1, 780 + i * 20, 960)
await minitouch.commit()
await asyncio.sleep(0.02)
await minitouch.touch_up(0)
await minitouch.touch_up(1)
await minitouch.commit()
print("Touch sequence completed")
client.close()
async def drag_and_drop():
"""Drag and drop gesture simulation."""
client = DeviceBaseClient()
minitouch = client.minitouch_client(SERIAL)
start_x, start_y = 540, 1600
end_x, end_y = 540, 400
async with minitouch:
# Touch down
await minitouch.touch_down(0, start_x, start_y)
await minitouch.commit()
# Move in steps (simulate drag)
steps = 20
for i in range(1, steps + 1):
progress = i / steps
x = int(start_x + (end_x - start_x) * progress)
y = int(start_y + (end_y - start_y) * progress)
await minitouch.touch_move(0, x, y)
await minitouch.commit()
await asyncio.sleep(0.02) # 20ms between steps
# Touch up
await minitouch.touch_up(0, end_x, end_y)
await minitouch.commit()
print("Drag completed")
client.close()
if __name__ == "__main__":
asyncio.run(basic_touch())