-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
162 lines (142 loc) · 4.26 KB
/
menu.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
from datetime import datetime
import time
import clock
import status
import gfx
menu_items = {
'brightness': [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 1, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
'clock': [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0],
[0, 1, 1, 1, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 1, 1, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
'time': [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 1, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0],
],
'hour': [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 0, 1, 0, 1, 0, 0],
[0, 1, 0, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
],
'rotation': [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 1, 1, 1, 0],
[0, 1, 0, 0, 1, 0, 1, 0],
[0, 1, 0, 0, 1, 0, 1, 0],
[0, 1, 0, 0, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
]
}
class Mode:
menu_order = [
'clock',
'time',
'hour',
'rotation',
'brightness'
]
def __init__(self, dmd):
self.dmd = dmd
self.index = 0
self.animator = gfx.Animator()
def start(self):
slide_in = gfx.Slide(self.dmd, y_step=-1)
self.animator.add(slide_in.update, 0.1)
def next(self):
self.index += 1
if self.index >= len(self.menu_order):
self.index = 0
slide_left = gfx.Slide(self.dmd, x_step=1)
self.animator.add(slide_left.update, 0.1)
def previous(self):
self.index -= 1
if self.index < 0:
self.index = len(self.menu_order) - 1
slide_right = gfx.Slide(self.dmd, x_step=-1)
self.animator.add(slide_right.update, 0.1)
def stop(self):
pass
def service(self, event_queue):
while len(event_queue) > 0:
event = event_queue.pop()
if event == 'exit':
return {'mode': 'clock'}
if event == 'up':
self.next()
if event == 'down':
self.previous()
if event == 'enter':
return {'mode': 'clock-select'}
selected = self.menu_order[self.index]
display = menu_items[selected]
self.dmd.clear()
gfx.render_bitmap(self.dmd, display, (0x00, 0x00, 0xff))
self.animator.service(time.time())
class ClockSelectMode:
def __init__(self, dmd):
self.clocks = [
clock.XY(dmd),
clock.Numeric(dmd),
]
self.index = 0
self.clock = self.clocks[self.index]
self.demo_time = datetime(2019, 1, 1, 20)
def start(self):
self.clock.update(self.demo_time)
def stop(self):
self.clock.stop()
def next(self):
self.clock.stop()
self.index += 1
if self.index >= len(self.clocks):
self.index = 0
self.clock = self.clocks[self.index]
self.clock.update(self.demo_time)
def previous(self):
self.clock.stop()
self.index -= 1
if self.index < 0:
self.index = len(self.clocks) - 1
self.clock = self.clocks[self.index]
self.clock.update(self.demo_time)
def service(self, event_queue):
while len(event_queue) > 0:
event = event_queue.pop()
if event == 'up':
self.next()
if event == 'down':
self.previous()
if event == 'exit':
return {'mode': 'menu'}
if event == 'enter':
return status.ok({'mode': 'menu'})
self.demo_time += self.clock.demo_time_step
self.clock.next(self.demo_time)