-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrollwheel.py
115 lines (104 loc) · 2.79 KB
/
scrollwheel.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
from sys import platform
from config import *
import sys_manager
def processInput(app, input):
global wheel_position, last_button, last_interaction
position = input[2]
button = input[0]
button_state = input[1]
if button == 29 and button_state == 0:
wheel_position = -1
elif wheel_position == -1:
wheel_position = position
elif position % 2 != 0:
pass
elif wheel_position <=1 and position > 44:
onDownPressed()
wheel_position = position
elif wheel_position >=44 and position < 1:
onUpPressed()
wheel_position = position
elif abs(wheel_position - position) > 6:
wheel_position = -1
elif wheel_position > position:
onDownPressed()
wheel_position = position
elif wheel_position < position:
onUpPressed()
wheel_position = position
if button_state == 0:
last_button = -1
elif button == last_button:
pass
elif button == 7:
onSelectPressed()
last_button = button
elif button == 11:
onBackPressed()
last_button = button
elif button == 10:
onPlayPressed()
last_button = button
elif button == 8:
onNextPressed()
last_button = button
elif button == 9:
onPrevPressed()
last_button = button
now = time.time()
if (now - last_interaction > SCREEN_TIMEOUT_SECONDS):
print("waking")
sys_manager.screen_wake()
last_interaction = now
def onKeyPress(event):
c = event.keycode
if (c == UP_KEY_CODE):
onUpPressed()
elif (c == DOWN_KEY_CODE):
onDownPressed()
elif (c == RIGHT_KEY_CODE):
onSelectPressed()
elif (c == LEFT_KEY_CODE):
onBackPressed()
elif (c == NEXT_KEY_CODE):
onNextPressed()
elif (c == PREV_KEY_CODE):
onPrevPressed()
elif (c == PLAY_KEY_CODE):
onPlayPressed()
else:
print("unrecognized key: ", c)
def onPlayPressed():
global page, app
page.nav_play()
render(app, page.render())
def onSelectPressed():
global page, app
if (not page.has_sub_page):
return
page.render().unsubscribe()
page = page.nav_select()
render(app, page.render())
def onBackPressed():
global page, app
previous_page = page.nav_back()
if (previous_page):
page.render().unsubscribe()
page = previous_page
render(app, page.render())
def onNextPressed():
global page, app
page.nav_next()
render(app, page.render())
def onPrevPressed():
global page, app
page.nav_prev()
render(app, page.render())
def onUpPressed():
global page, app
page.nav_up()
render(app, page.render())
def onDownPressed():
global page, app
page.nav_down()
render(app, page.render())