-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathk0001rpifunc.py
184 lines (151 loc) · 6.42 KB
/
k0001rpifunc.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
181
182
183
184
# import libraries
import wiringpi
import yaml
import json
from k0001def import inputs, outputs, requests, sequence, timers, appConfig, rpiConfig
from k0001func import set_defaults
#
def start_func():
print('TLC started...')
# initialise wiringpi
wiringpi.wiringPiSetup()
if 'wiringpi' in rpiConfig:
for wiringpiConfig in rpiConfig['wiringpi']:
# lowest available starting number is 65
pin_base = wiringpiConfig['pin_base']
# A0, A1, A2 pins all wired to GND
i2c_addr = wiringpiConfig['i2c_addr']
wiringpi.mcp23017Setup(pin_base, i2c_addr)
if 'fasecycli' in rpiConfig:
for fc in rpiConfig['fasecycli']:
if 'rood' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['rood']:
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['rood'], 1)
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['rood'], 0)
if 'groen' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['groen']:
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['groen'], 1)
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['groen'], 0)
if 'geel' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['geel']:
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['geel'], 1)
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['geel'], 0)
if 'detectie' in rpiConfig:
for d in appConfig['detectie']:
if rpiConfig['detectie'][d]:
wiringpi.pinMode(rpiConfig['detectie'][d], 0)
wiringpi.digitalWrite(rpiConfig['detectie'][d], 0)
#
def set_gui_inputs():
try:
with open('data/data_from_gui.yaml', 'r') as f:
guiData = yaml.load(f)
except:
pass
if guiData:
for d in guiData['d']:
inputs[d] = guiData['d'][d]
for i in guiData['is']:
inputs[i] = guiData['is'][i]
#
def set_state():
for fc in appConfig['fasecycli']:
if outputs[fc]['WR'] or outputs[fc]['RVG']:
# Turn off the yellow LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['geel'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['geel'], 0)
if fc in rpiConfig['fasecycli']:
# Turn on the red LED
if rpiConfig['fasecycli'][fc]['rood'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['rood'], 1)
#
elif outputs[fc]['VG'] or outputs[fc]['VAG1'] or outputs[fc]['VAG2'] or outputs[fc]['WG'] or \
outputs[fc]['VAG3'] or outputs[fc]['MVG'] or outputs[fc]['VAG4']:
# Turn off the red LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['rood'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['rood'], 0)
# Turn on the green LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['groen'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['groen'], 1)
#
elif outputs[fc]['GL']:
# Turn off the green LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['groen'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['groen'], 0)
# Turn on the yellow LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['geel'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['geel'], 1)
#
else:
# Turn off the red LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['rood'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['rood'], 0)
# Turn off the green LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['groen'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['groen'], 0)
# Turn off the yellow LED
if fc in rpiConfig['fasecycli']:
if rpiConfig['fasecycli'][fc]['geel'] > 64:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['geel'], 0)
#
try:
with open('/websites/MAP_K0001/www/data/data_to_gui.json', 'w') as jsonFile:
jsonFile.write(json.dumps(outputs))
except:
pass
#
def finally_func():
#
set_defaults()
#
for fc in appConfig['fasecycli']:
outputs[fc]['WR'] = False
outputs[fc]['RVG'] = False
outputs[fc]['VG'] = False
outputs[fc]['VAG1'] = False
outputs[fc]['VAG2'] = False
outputs[fc]['WG'] = False
outputs[fc]['VAG3'] = False
outputs[fc]['MVG'] = False
outputs[fc]['VAG4'] = False
outputs[fc]['GL'] = False
outputs[fc]['demand'] = False
outputs[fc]['sequence'] = 0
outputs[fc]['delay'] = 0
requests[fc] = False
sequence[fc] = 0
timers[fc]['delay'] = 0
#
try:
with open('/websites/MAP_K0001/www/data/data_to_gui.json', 'w') as jsonFile:
jsonFile.write(json.dumps(outputs))
except:
pass
#
if 'fasecycli' in rpiConfig:
for fc in rpiConfig['fasecycli']:
if 'rood' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['rood']:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['rood'], 0)
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['rood'], 0)
if 'groen' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['groen']:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['groen'], 0)
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['groen'], 0)
if 'geel' in rpiConfig['fasecycli'][fc]:
if rpiConfig['fasecycli'][fc]['geel']:
wiringpi.digitalWrite(rpiConfig['fasecycli'][fc]['geel'], 0)
wiringpi.pinMode(rpiConfig['fasecycli'][fc]['geel'], 0)
#
if 'detectie' in rpiConfig:
for d in appConfig['detectie']:
if rpiConfig['detectie'][d]:
wiringpi.digitalWrite(rpiConfig['detectie'][d], 0)
wiringpi.pinMode(rpiConfig['detectie'][d], 0)