-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_builder.lua
116 lines (100 loc) · 2.83 KB
/
action_builder.lua
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
local mesh_ret = require "mesh_builder"
-- local mesh = mesh_ret.mesh
local mesh2coords = mesh_ret.mesh2coords
local meshshot = mesh_ret.meshshot
local acts = {}
--
-- speed 6px/ms
local SPEED = 3
local SHORT_SLEEP_TIME = 9000 -- 0.010s
local MEDIUM_SLEEP_TIME = 40000 -- 0.050s
local LONG_SLEEP_TIME = 1000000 -- 1.000s
--[[
local SHORT_SLEEP_TIME = 200000 -- 0.20s
local MEDIUM_SLEEP_TIME = 500000 -- 0.50s
local LONG_SLEEP_TIME = 5000000 -- 5.00s
--]]
local FINGER_ID = 9
local floor = math.floor
local max = math.max
local abs = math.abs
local sx, sy
local function meshTo2(r, c)
local nx, ny = mesh2coords(r, c)
local dx = nx - sx
local dy = ny - sy
local dist = abs(dx) + abs(dy)
local speed_x = SPEED * dx / dist
local speed_y = SPEED * dy / dist
local xx, yy = sx, sy
local n_steps = floor(abs(dx / speed_x))
for k = 1, n_steps do
xx = xx + speed_x
yy = yy + speed_y
touchMove(FINGER_ID, xx, yy)
usleep(SHORT_SLEEP_TIME)
end
sx, sy = nx, ny
touchMove(FINGER_ID, sx, sy)
usleep(SHORT_SLEEP_TIME*40)
end
local function tap(r, c)
sx, sy = mesh2coords(r, c)
touchDown(FINGER_ID, sx, sy)
usleep(MEDIUM_SLEEP_TIME)
touchUp(FINGER_ID, sx, sy)
usleep(MEDIUM_SLEEP_TIME)
end
local function meshDown(r, c)
sx, sy = mesh2coords(r, c)
touchDown(FINGER_ID, sx, sy)
usleep(MEDIUM_SLEEP_TIME)
end
local function meshUp()
touchUp(FINGER_ID, sx, sy)
usleep(MEDIUM_SLEEP_TIME)
end
local function meshTo(r, c)
sx, sy = mesh2coords(r, c)
touchMove(FINGER_ID, sx, sy)
usleep(SHORT_SLEEP_TIME)
end
local function roll(r, c, ...)
local stops = {...}
local n = #stops
meshDown(r, c)
local last_r, last_c = r, c
--local last_r, last_c = stops[1], stops[2]
--meshDown(last_r, last_c)
local dr, dc, d_max, step_r, step_c
for i = 1, n, 2 do
meshTo(stops[i], stops[i+1])
usleep(SHORT_SLEEP_TIME)
usleep(SHORT_SLEEP_TIME)
--[[
dr = stops[i] - last_r
dc = stops[i+1] - last_c
d_max = max(abs(dr), abs(dc))
step_r = dr / d_max
step_c = dc / d_max
--log(string.format("last_r: %f last_c: %f\ndr: %f dc: %f\nd_max: %f\nstep_r: %f, step_c: %f",
-- last_r, last_c, dr, dc, d_max, step_r, step_c))
for i = 1, d_max do
local tmp_r = last_r + step_r * i
local tmp_c = last_c + step_c * i
--log(string.format("row: %f col: %f", tmp_r, tmp_c))
meshTo(tmp_r, tmp_c)
--meshTo(last_r + step_r * i, last_c + step_c * i)
end
last_r, last_c = stops[i], stops[i+1]
]]--
end
meshUp()
end
acts.tap = tap
acts.meshDown = meshDown
acts.meshUp = meshUp
acts.meshTo = meshTo
acts.roll = roll
acts.meshshot = meshshot
return acts