|
103 | 103 |
|
104 | 104 | # Worker for Camera |
105 | 105 | try: |
106 | | - CONFIGS["camera"]["redis"] = r |
107 | | - c = CameraWorker(CONFIGS['camera'], main_thread_running, system_ready, camera_available) |
108 | | - print('MudPi Camera...\t\t\t\033[1;32m Initializing\033[0;0m') |
109 | | - workers.append(c) |
110 | | - camera_available.set() |
| 106 | + if len(CONFIGS["camera"]) > 0: |
| 107 | + CONFIGS["camera"]["redis"] = r |
| 108 | + c = CameraWorker(CONFIGS['camera'], main_thread_running, system_ready, camera_available) |
| 109 | + print('MudPi Camera...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 110 | + workers.append(c) |
| 111 | + camera_available.set() |
111 | 112 | except KeyError: |
112 | 113 | print('MudPi Pi Camera...\t\t\t\033[1;31m Disabled\033[0;0m') |
113 | 114 |
|
114 | 115 | # Workers for pi (Sensors, Controls, Relays, I2C) |
115 | 116 | try: |
116 | | - for worker in CONFIGS['workers']: |
117 | | - # Create worker for worker |
118 | | - worker["redis"] = r |
119 | | - if worker['type'] == "sensor": |
120 | | - pw = PiSensorWorker(worker, main_thread_running, system_ready) |
121 | | - print('MudPi Sensors...\t\t\t\033[1;32m Initializing\033[0;0m') |
122 | | - elif worker['type'] == "control": |
123 | | - pw = PiControlWorker(worker, main_thread_running, system_ready) |
124 | | - print('MudPi Controls...\t\t\t\033[1;32m Initializing\033[0;0m') |
125 | | - elif worker['type'] == "i2c": |
126 | | - pw = PiI2CWorker(worker, main_thread_running, system_ready) |
127 | | - print('MudPi I2C...\t\t\t\t\033[1;32m Initializing\033[0;0m') |
128 | | - elif worker['type'] == "lcd": |
129 | | - for lcd in worker['lcds']: |
130 | | - lcd["redis"] = r |
131 | | - pw = LcdWorker(lcd, main_thread_running, system_ready, lcd_available) |
132 | | - lcd_available.set() |
133 | | - print('MudPi LCD Displays...\t\t\t\033[1;32m Initializing\033[0;0m') |
134 | | - elif worker['type'] == "relay": |
135 | | - # Add Relay Worker Here for Better Config Control |
136 | | - print('MudPi Relay...\t\t\t\033[1;32m Initializing\033[0;0m') |
137 | | - else: |
138 | | - raise Exception("Unknown Worker Type: " + worker['type']) |
139 | | - workers.append(pw) |
| 117 | + if len(CONFIGS["workers"]) > 0: |
| 118 | + for worker in CONFIGS['workers']: |
| 119 | + # Create worker for worker |
| 120 | + worker["redis"] = r |
| 121 | + if worker['type'] == "sensor": |
| 122 | + pw = PiSensorWorker(worker, main_thread_running, system_ready) |
| 123 | + print('MudPi Sensors...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 124 | + elif worker['type'] == "control": |
| 125 | + pw = PiControlWorker(worker, main_thread_running, system_ready) |
| 126 | + print('MudPi Controls...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 127 | + elif worker['type'] == "i2c": |
| 128 | + pw = PiI2CWorker(worker, main_thread_running, system_ready) |
| 129 | + print('MudPi I2C...\t\t\t\t\033[1;32m Initializing\033[0;0m') |
| 130 | + elif worker['type'] == "lcd": |
| 131 | + for lcd in worker['lcds']: |
| 132 | + lcd["redis"] = r |
| 133 | + pw = LcdWorker(lcd, main_thread_running, system_ready, lcd_available) |
| 134 | + lcd_available.set() |
| 135 | + print('MudPi LCD Displays...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 136 | + elif worker['type'] == "relay": |
| 137 | + # Add Relay Worker Here for Better Config Control |
| 138 | + print('MudPi Relay...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 139 | + else: |
| 140 | + raise Exception("Unknown Worker Type: " + worker['type']) |
| 141 | + workers.append(pw) |
140 | 142 | except KeyError as e: |
141 | 143 | print('MudPi Pi Workers...\t\t\t\033[1;31m Disabled\033[0;0m') |
142 | 144 | print(e) |
143 | 145 |
|
144 | 146 | # Worker for relays attached to pi |
145 | 147 | try: |
146 | | - for relay in CONFIGS['relays']: |
147 | | - relay["redis"] = r |
148 | | - relayState = { |
149 | | - "available": threading.Event(), # Event to allow relay to activate |
150 | | - "active": threading.Event() # Event to signal relay to open/close |
151 | | - } |
152 | | - relayEvents[relay.get("key", relay_index)] = relayState |
153 | | - rw = RelayWorker(relay, main_thread_running, system_ready, relayState['available'], relayState['active']) |
154 | | - workers.append(rw) |
155 | | - # Make the relays available, this event is toggled off elsewhere if we need to disable relays |
156 | | - relayState['available'].set() |
157 | | - relay_index +=1 |
| 148 | + if len(CONFIGS["relays"]) > 0: |
| 149 | + for relay in CONFIGS['relays']: |
| 150 | + relay["redis"] = r |
| 151 | + relayState = { |
| 152 | + "available": threading.Event(), # Event to allow relay to activate |
| 153 | + "active": threading.Event() # Event to signal relay to open/close |
| 154 | + } |
| 155 | + relayEvents[relay.get("key", relay_index)] = relayState |
| 156 | + rw = RelayWorker(relay, main_thread_running, system_ready, relayState['available'], relayState['active']) |
| 157 | + workers.append(rw) |
| 158 | + # Make the relays available, this event is toggled off elsewhere if we need to disable relays |
| 159 | + relayState['available'].set() |
| 160 | + relay_index +=1 |
158 | 161 | except KeyError: |
159 | 162 | print('MudPi Relays Workers...\t\t\033[1;31m Disabled\033[0;0m') |
160 | 163 |
|
161 | 164 | # Load in Actions |
162 | 165 | try: |
163 | | - for action in CONFIGS["actions"]: |
164 | | - print('MudPi Actions...\t\t\t\033[1;32m Initializing\033[0;0m') |
165 | | - action["redis"] = r |
166 | | - a = Action(action) |
167 | | - a.init_action() |
168 | | - actions[a.key] = a |
| 166 | + if len(CONFIGS["actions"]) > 0: |
| 167 | + for action in CONFIGS["actions"]: |
| 168 | + print('MudPi Actions...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 169 | + action["redis"] = r |
| 170 | + a = Action(action) |
| 171 | + a.init_action() |
| 172 | + actions[a.key] = a |
169 | 173 | except KeyError: |
170 | 174 | print('MudPi Actions...\t\t\t\033[1;31m Disabled\033[0;0m') |
171 | 175 |
|
172 | 176 | # Worker for Triggers |
173 | | - try: |
174 | | - CONFIGS["triggers"]["redis"] = r |
175 | | - t = TriggerWorker(CONFIGS['triggers'], main_thread_running, system_ready, actions) |
176 | | - print('MudPi Triggers...\t\t\t\033[1;32m Initializing\033[0;0m') |
177 | | - workers.append(t) |
| 177 | + try: |
| 178 | + if len(CONFIGS["triggers"]) > 0: |
| 179 | + CONFIGS["triggers"]["redis"] = r |
| 180 | + t = TriggerWorker(CONFIGS['triggers'], main_thread_running, system_ready, actions) |
| 181 | + print('MudPi Triggers...\t\t\t\033[1;32m Initializing\033[0;0m') |
| 182 | + workers.append(t) |
178 | 183 | except KeyError: |
179 | 184 | print('MudPi Triggers...\t\t\t\033[1;31m Disabled\033[0;0m') |
180 | 185 |
|
181 | 186 | # Worker for nodes attached to pi via serial or wifi[esp8266, esp32] |
182 | 187 | # Supported nodes: arduinos, esp8266, ADC-MCP3xxx, probably others (esp32 with custom nanpy fork) |
183 | 188 | try: |
184 | | - for node in CONFIGS['nodes']: |
185 | | - node["redis"] = r |
186 | | - if node['type'] == "arduino": |
187 | | - if NANPY_ENABLED: |
188 | | - print('MudPi Arduino Workers...\t\t\033[1;32m Initializing\033[0;0m') |
189 | | - t = ArduinoWorker(node, main_thread_running, system_ready) |
190 | | - else: |
191 | | - print('Error Loading Nanpy library. Did you pip3 install -r requirements.txt?') |
192 | | - elif node['type'] == "ADC-MCP3008": |
193 | | - if MCP_ENABLED: |
194 | | - print('MudPi ADC Workers...\t\t\033[1;32m Initializing\033[0;0m') |
195 | | - t = ADCMCP3008Worker(node, main_thread_running, system_ready) |
| 189 | + if len(CONFIGS["nodes"]) > 0: |
| 190 | + for node in CONFIGS['nodes']: |
| 191 | + node["redis"] = r |
| 192 | + if node['type'] == "arduino": |
| 193 | + if NANPY_ENABLED: |
| 194 | + print('MudPi Arduino Workers...\t\t\033[1;32m Initializing\033[0;0m') |
| 195 | + t = ArduinoWorker(node, main_thread_running, system_ready) |
| 196 | + else: |
| 197 | + print('Error Loading Nanpy library. Did you pip3 install -r requirements.txt?') |
| 198 | + elif node['type'] == "ADC-MCP3008": |
| 199 | + if MCP_ENABLED: |
| 200 | + print('MudPi ADC Workers...\t\t\033[1;32m Initializing\033[0;0m') |
| 201 | + t = ADCMCP3008Worker(node, main_thread_running, system_ready) |
| 202 | + else: |
| 203 | + print('Error Loading MCP3xxx library. Did you pip3 install -r requirements.txt;?') |
196 | 204 | else: |
197 | | - print('Error Loading MCP3xxx library. Did you pip3 install -r requirements.txt;?') |
198 | | - else: |
199 | | - raise Exception("Unknown Node Type: " + node['type']) |
200 | | - nodes.append(t) |
| 205 | + raise Exception("Unknown Node Type: " + node['type']) |
| 206 | + nodes.append(t) |
201 | 207 | except KeyError as e: |
202 | 208 | print('MudPi Node Workers...\t\t\t\033[1;31m Disabled\033[0;0m') |
203 | 209 |
|
|
0 commit comments