-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeKitV3action.py
180 lines (176 loc) · 4.94 KB
/
LeKitV3action.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from machine import Timer,Pin
import time
Touch_Pin1=Pin(18, Pin.IN)
Touch_Pin2=Pin(5, Pin.IN)
que=[["",0],["",0],["",0]]
start_time=time.ticks_ms()
actions={'key_A_click':[],'key_A_dclick':[],'key_A_press':[],
'key_B_click':[],'key_B_dclick':[],'key_B_press':[],
'slide_up':[],'slide_down':[],'dlongclick':[]}
'按键事件绑定'
def setcb(action,function):
if not action in actions:
print("%s error!action name must in key_A_click,key_A_dclick,key_A_press,key_B_click,key_B_dclick,key_B_press,slide_up,slide_down"%(action))
return False
actions[action]=[function]
return True
'按键事件解除'
def delcb(action):
if not action in actions:
print("%s error!action name must in key_A_click,key_A_dclick,key_A_press,key_B_click,key_B_dclick,key_B_press,slide_up,slide_down"%(action))
return False
actions[action]=[]
return True
'A单击事件'
def t1_click():
# print('t1_click')
fs=actions['key_A_click']
try:
fs[0]()
except:
pass
'A双击事件'
def t1_dclick():
# print('t1_dclick')
fs=actions['key_A_dclick']
try:
fs[0]()
except:
pass
'A滑动事件'
def t1_scroll():
# print('t1_scroll')
fs=actions['slide_down']
try:
fs[0]()
except:
pass
'A长按事件'
def t1_longclick():
# print('t1_longclick')
fs=actions['key_A_press']
try:
fs[0]()
except:
pass
'B单击事件'
def t2_click():
# print('t2_click')
fs=actions['key_B_click']
try:
fs[0]()
except:
pass
'B双击事件'
def t2_dclick():
# print('t2_dclick')
fs=actions['key_B_dclick']
try:
fs[0]()
except:
pass
'B滑动事件'
def t2_scroll():
# print('t2_scroll')
fs=actions['slide_up']
try:
fs[0]()
except:
pass
'B长按事件'
def t2_longclick():
# print('t2_longclick')
fs=actions['key_B_press']
try:
fs[0]()
except:
pass
def dlongclick():
# print('dlongclick')
fs=actions['dlongclick']
try:
fs[0]()
except:
pass
'定时器回调事件'
def clock(self):
if que[-1][0]=='1d' and time.ticks_ms()-que[-1][1]>2000:
if Touch_Pin2.value() == 1:
dlongclick()
else:
t1_longclick()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if (que[-3][0]=='1u' and que[-2][0]=='2d' and que[-1][0]=='2u') or (que[-3][0]=='2d' and que[-2][0]=='1u' and que[-1][0]=='2u'):
if que[-1][1]-que[-3][1]<300:
t1_scroll()
# print(que)
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if que[-2][0]=='1d' and que[-1][0]=='1u':
if 200<que[-1][1]-que[-2][1]<1000:
# print(que)
t1_click()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if que[-3][0]=='1u' and que[-2][0]=='1d' and que[-1][0]=='1u':
if que[-1][1]-que[-3][1]<300:
# print(que)
t1_dclick()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
#---------------------------------------------------------------
if que[-1][0]=='2d' and time.ticks_ms()-que[-1][1]>2000:
if Touch_Pin1.value() == 1:
dlongclick()
else:
t2_longclick()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if (que[-3][0]=='2u' and que[-2][0]=='1d' and que[-1][0]=='1u') or (que[-3][0]=='1d' and que[-2][0]=='2u' and que[-1][0]=='1u'):
if que[-1][1]-que[-3][1]<300:
t2_scroll()
# print(que)
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if que[-2][0]=='2d' and que[-1][0]=='2u':
if 200<que[-1][1]-que[-2][1]<1000:
# print(que)
t2_click()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
if que[-3][0]=='2u' and que[-2][0]=='2d' and que[-1][0]=='2u':
if que[-1][1]-que[-3][1]<300:
# print(que)
t2_dclick()
for i in range(3):
que.pop(0)
que.append(["",time.ticks_ms()])
'A触摸回调事件'
def t1(self):
global que
if Touch_Pin1.value() == 1:
que.pop(0)
que.append(["1d",time.ticks_ms()])
else:
que.pop(0)
que.append(["1u",time.ticks_ms()])
'B触摸回调事件'
def t2(self):
if Touch_Pin2.value() == 1:
que.pop(0)
que.append(["2d",time.ticks_ms()])
else:
que.pop(0)
que.append(["2u",time.ticks_ms()])
Touch_Pin1.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING,handler =t1)
Touch_Pin2.irq(trigger=Pin.IRQ_RISING|Pin.IRQ_FALLING,handler =t2)
Timer(1).init(period=100, mode=Timer.PERIODIC, callback=clock)
'8.30改'