-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradio.py
More file actions
99 lines (72 loc) · 2.41 KB
/
radio.py
File metadata and controls
99 lines (72 loc) · 2.41 KB
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
# encoding:utf-8
from hardware.rotary import RotaryEncoder_proc
from hardware.rotary.RotaryEncoder_proc import REException
from hardware.lcd import LCD_proc
from multiprocessing import Queue
import RPi.GPIO
import time
DEBUG = True
def on_startup():
if DEBUG:
time.sleep(1)
else:
time.sleep(100)
RPi.GPIO.setwarnings(False)
line_1 = Queue()
line_2 = Queue()
line_3 = Queue()
line_4 = Queue()
encoders = Queue()
line_1.put({'text':'', 'style':'center'})
line_2.put({'text':'3Radio', 'style':'center'})
line_3.put({'text':'------', 'style':'center'})
line_4.put({'text':'', 'style':'center'})
pe1 = RotaryEncoder_proc.RE_runner(encoders, 1, 8, 9, 7)
pe2 = RotaryEncoder_proc.RE_runner(encoders, 2, 0, 2, 3)
pe3 = RotaryEncoder_proc.RE_runner(encoders, 3, 12, 13, 14)
plcd = LCD_proc.LCD_runner(line_1, line_2, line_3, line_4)
state = {'button_1': False,
'button_2': False,
'button_3': False,
're_1': 0,
're_2': 80,
're_3': 0
}
lines = [line_1, line_2, line_3, line_4]
encoders_proces = [pe1, pe2, pe3]
main(state, encoders_proces, lines, encoders)
def terminate_all(lines, encoders_proces):
lines[3].put({'stop': None})
for ep in encoders_proces:
ep.terminate()
def stop_all(state):
if (state['button_1'] == True) and (state['button_3'] == True):
return True
def on_button(state, message, id):
if message['button'] == 1:
state['button_'+str(id)] = True
elif message['button'] == 0:
state['button_'+str(id)] = False
else:
raise REException('Unexpected button state.')
return state
def re_event(state, message):
if 'rot' in message:
state['re_' + str(message['name'])] += message['rot']
elif 'button' in message:
state = on_button(state, message, message['name'])
else:
raise REException('Unexpected Rotary Encoder message.')
def main(state, encoders_proces, lines, input):
def line(id, text):
lines[id-1].put({'text': str(text), 'style': 'center'})
message = input.get(block=True)
while True:
if message['dev'] == 're':
re_event(state, message)
if stop_all(state):
break
message = input.get(block=True)
terminate_all(lines, encoders_proces)
if __name__ == '__main__':
on_startup()