-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathlp_events.py
62 lines (50 loc) · 1.48 KB
/
lp_events.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
import copy, threading, time
import lp_colors
RUN_DELAY = 0.005 #0.005 == 200 FPS
def unbound_press(x, y):
print("[lp_events] ("+str(x)+", "+str(y)+") Unbound button...")
press_funcs = [[unbound_press for y in range(9)] for x in range(9)]
pressed = [[False for y in range(9)] for x in range(9)]
timer = None
def init(lp_object):
global timer
global press_funcs
timer = threading.Timer(RUN_DELAY, run, (lp_object,))
def run(lp_object):
global timer
while True:
event = lp_object.ButtonStateXY()
if event != []:
x = event[0]
y = event[1]
if event[2] == 0:
pressed[x][y] = False
else:
pressed[x][y] = True
press_funcs[x][y](x, y)
lp_colors.updateXY(x, y)
else:
break
init(lp_object)
timer.start()
def start(lp_object):
lp_colors.init(lp_object)
init(lp_object)
run(lp_object)
lp_colors.update_all()
def bind_func_with_colors(x, y, func, off_color):
global press_funcs
press_funcs[x][y] = func
lp_colors.setXY(x, y, off_color)
def unbind(x, y):
global press_funcs
press_funcs[x][y] = unbound_press
lp_colors.setXY(x, y, [0,0,0])
lp_colors.updateXY(x, y)
def unbind_all():
global press_funcs
press_funcs = [[unbound_press for y in range(9)] for x in range(9)]
for x in range(9):
for y in range(9):
lp_colors.setXY(x, y, [0,0,0])
lp_colors.raw_clear()