52 #define MANUAL_SELHLT 1 |
52 #define MANUAL_SELHLT 1 |
53 #define MANUAL_SELMLT 2 |
53 #define MANUAL_SELMLT 2 |
54 #define MANUAL_HLT 11 |
54 #define MANUAL_HLT 11 |
55 #define MANUAL_MLT 12 |
55 #define MANUAL_MLT 12 |
56 |
56 |
|
57 int manual = MANUAL_NONE; |
|
58 |
|
59 |
57 |
60 |
58 /* |
61 /* |
59 * CGRAM characters |
62 * CGRAM characters |
60 */ |
63 */ |
61 unsigned char degC[8] = { 0b01000, 0b10100, 0b01000, 0b00111, 0b01000, 0b01000, 0b01000, 0b00111 }; |
64 unsigned char degC[8] = { 0b01000, 0b10100, 0b01000, 0b00111, 0b01000, 0b01000, 0b01000, 0b00111 }; |
127 slcdPuts(slcdHandle, text); |
130 slcdPuts(slcdHandle, text); |
128 } |
131 } |
129 |
132 |
130 |
133 |
131 |
134 |
|
135 int manual_menu(units_list *); |
|
136 int manual_menu(units_list *unit) |
|
137 { |
|
138 int key; |
|
139 static int man_hlt_heat, man_mlt_heat, man_mlt_pump; |
|
140 |
|
141 switch (manual) { |
|
142 case MANUAL_SELHLT: prompt(104, NULL); |
|
143 prompt(219, NULL); |
|
144 prompt(402, NULL); |
|
145 key = keywait(); |
|
146 if (key == KEY_DOWN) |
|
147 manual = MANUAL_SELMLT; |
|
148 if (key == KEY_RETURN) |
|
149 manual = MANUAL_NONE; |
|
150 if (key == KEY_ENTER) { |
|
151 // TODO: prompt for water |
|
152 manual = MANUAL_HLT; |
|
153 prompt(0, NULL); |
|
154 man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0; |
|
155 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
156 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
157 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
158 } |
|
159 break; |
|
160 case MANUAL_SELMLT: prompt(104, NULL); |
|
161 prompt(220, NULL); |
|
162 prompt(404, NULL); |
|
163 key = keywait(); |
|
164 if (key == KEY_UP) |
|
165 manual = MANUAL_SELHLT; |
|
166 if (key == KEY_RETURN) |
|
167 manual = MANUAL_NONE; |
|
168 if (key == KEY_ENTER) { |
|
169 // TODO: prompt for water |
|
170 manual = MANUAL_MLT; |
|
171 prompt(0, NULL); |
|
172 man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0; |
|
173 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
174 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
175 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
176 } |
|
177 break; |
|
178 case MANUAL_HLT: prompt(104, NULL); |
|
179 prompt(413, NULL); |
|
180 |
|
181 key = keywait(); |
|
182 if (key == KEY_RETURN) { |
|
183 if (man_hlt_heat) |
|
184 man_hlt_heat = 0; |
|
185 else |
|
186 man_hlt_heat = 1; |
|
187 } |
|
188 if (key == KEY_ESCAPE) { |
|
189 manual = MANUAL_SELHLT; |
|
190 man_hlt_heat = 0; |
|
191 } |
|
192 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
193 if (debug) |
|
194 fprintf(stdout, "device_out(%s, %d) HLT heater\n", unit->hlt_heater.uuid, man_hlt_heat); |
|
195 break; |
|
196 case MANUAL_MLT: prompt(104, NULL); |
|
197 prompt(406, NULL); |
|
198 key = keywait(); |
|
199 if (key == KEY_RETURN) { |
|
200 if (man_mlt_heat) |
|
201 man_mlt_heat = 0; |
|
202 else |
|
203 man_mlt_heat = 1; |
|
204 } |
|
205 if (key == KEY_ENTER) { |
|
206 if (man_mlt_pump) |
|
207 man_mlt_pump = 0; |
|
208 else |
|
209 man_mlt_pump = 1; |
|
210 } |
|
211 if (key == KEY_ESCAPE) { |
|
212 manual = MANUAL_SELMLT; |
|
213 man_mlt_heat = man_mlt_pump = 0; |
|
214 } |
|
215 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
216 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
217 break; |
|
218 } |
|
219 |
|
220 return 0; |
|
221 } |
|
222 |
|
223 |
|
224 |
132 int server(void); |
225 int server(void); |
133 int server(void) |
226 int server(void) |
134 { |
227 { |
135 int rc = 0, run = 1, key, manual = MANUAL_NONE; |
228 int rc = 0, run = 1, key; |
136 int man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0; |
229 int do_init = TRUE; |
137 units_list *unit; |
230 units_list *unit; |
138 brew_session *brew = NULL; |
231 brew_session *brew = NULL; |
139 #ifndef HAVE_WIRINGPI_H |
232 #ifndef HAVE_WIRINGPI_H |
140 long t = 0; |
233 long t = 0; |
141 #endif |
234 #endif |
|
235 double hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint; |
142 |
236 |
143 prompt(101, NULL); |
237 prompt(101, NULL); |
144 |
238 |
145 /* |
239 /* |
146 * Define special characters in the display CGRAM |
240 * Define special characters in the display CGRAM |
248 */ |
342 */ |
249 if (unit->active) { |
343 if (unit->active) { |
250 if (debug) |
344 if (debug) |
251 fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name); |
345 fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name); |
252 syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name); |
346 syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name); |
253 |
|
254 unit->hlt_heater.value = 0; |
|
255 unit->mlt_heater.value = 0; |
|
256 unit->mlt_pump.value = 0; |
|
257 } |
347 } |
258 |
348 |
259 /* |
349 /* |
260 * During automation there will be a state file: |
350 * During automation there will be a state file: |
261 * ~/.brewco/var/brewing.xml |
351 * ~/.brewco/var/brewing.xml |
275 if (my_shutdown) { |
365 if (my_shutdown) { |
276 run = 0; |
366 run = 0; |
277 break; |
367 break; |
278 } |
368 } |
279 |
369 |
|
370 /* |
|
371 * Do we need to initialize this unit? |
|
372 */ |
|
373 if (do_init) { |
|
374 if (debug) |
|
375 fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name); |
|
376 syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name); |
|
377 /* |
|
378 * Turn everything off |
|
379 */ |
|
380 unit->hlt_heater.value = 0; |
|
381 unit->mlt_heater.value = 0; |
|
382 unit->mlt_pump.value = 0; |
|
383 device_out(unit->hlt_heater.uuid, 0); |
|
384 device_out(unit->mlt_heater.uuid, 0); |
|
385 device_out(unit->mlt_pump.uuid, 0); |
|
386 |
|
387 /* |
|
388 * Initialize PID's |
|
389 */ |
|
390 hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0; |
|
391 hltOutput = mltOutput = 0; |
|
392 PID_init(unit->PID_hlt, &hltInput, &hltOutput, &hltSetpoint, unit->PID_hlt->dispKd, unit->PID_hlt->dispKi, unit->PID_hlt->dispKd, unit->PID_hlt->Direction); |
|
393 PID_setOutputLimits(unit->PID_hlt, 0, 5000); |
|
394 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime); |
|
395 PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKd, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction); |
|
396 PID_setOutputLimits(unit->PID_mlt, 0, 5000); |
|
397 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime); |
|
398 |
|
399 do_init = FALSE; |
|
400 } |
|
401 |
280 /* run_pause code here */ |
402 /* run_pause code here */ |
281 |
403 |
282 if (brew) { |
404 if (brew) { |
283 /* |
405 /* |
284 * Automate mode |
406 * Automate mode |
286 |
408 |
287 } else if (manual != MANUAL_NONE) { |
409 } else if (manual != MANUAL_NONE) { |
288 /* |
410 /* |
289 * Manual mode |
411 * Manual mode |
290 */ |
412 */ |
291 switch (manual) { |
413 manual_menu(unit); |
292 case MANUAL_SELHLT: prompt(0, NULL); |
|
293 prompt(104, NULL); |
|
294 prompt(219, NULL); |
|
295 prompt(402, NULL); |
|
296 key = keywait(); |
|
297 if (key == KEY_DOWN) |
|
298 manual = MANUAL_SELMLT; |
|
299 if (key == KEY_RETURN) |
|
300 manual = MANUAL_NONE; |
|
301 if (key == KEY_ENTER) { |
|
302 // TODO: prompt for water |
|
303 manual = MANUAL_HLT; |
|
304 prompt(0, NULL); |
|
305 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
306 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
307 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
308 } |
|
309 break; |
|
310 case MANUAL_SELMLT: prompt(0, NULL); |
|
311 prompt(104, NULL); |
|
312 prompt(220, NULL); |
|
313 prompt(404, NULL); |
|
314 key = keywait(); |
|
315 if (key == KEY_UP) |
|
316 manual = MANUAL_SELHLT; |
|
317 if (key == KEY_RETURN) |
|
318 manual = MANUAL_NONE; |
|
319 if (key == KEY_ENTER) { |
|
320 // TODO: prompt for water |
|
321 manual = MANUAL_MLT; |
|
322 prompt(0, NULL); |
|
323 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
324 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
325 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
326 } |
|
327 break; |
|
328 case MANUAL_HLT: prompt(104, NULL); |
|
329 prompt(413, NULL); |
|
330 |
|
331 key = keywait(); |
|
332 if (key == KEY_RETURN) { |
|
333 if (man_hlt_heat) |
|
334 man_hlt_heat = 0; |
|
335 else |
|
336 man_hlt_heat = 1; |
|
337 } |
|
338 if (key == KEY_ESCAPE) { |
|
339 manual = MANUAL_SELHLT; |
|
340 man_hlt_heat = 0; |
|
341 } |
|
342 device_out(unit->hlt_heater.uuid, man_hlt_heat); |
|
343 if (debug) |
|
344 fprintf(stdout, "device_out(%s, %d) HLT heater\n", unit->hlt_heater.uuid, man_hlt_heat); |
|
345 break; |
|
346 case MANUAL_MLT: prompt(104, NULL); |
|
347 prompt(406, NULL); |
|
348 key = keywait(); |
|
349 if (key == KEY_RETURN) { |
|
350 if (man_mlt_heat) |
|
351 man_mlt_heat = 0; |
|
352 else |
|
353 man_mlt_heat = 1; |
|
354 } |
|
355 if (key == KEY_ENTER) { |
|
356 if (man_mlt_pump) |
|
357 man_mlt_pump = 0; |
|
358 else |
|
359 man_mlt_pump = 1; |
|
360 } |
|
361 if (key == KEY_ESCAPE) { |
|
362 manual = MANUAL_SELMLT; |
|
363 man_mlt_heat = man_mlt_pump = 0; |
|
364 } |
|
365 device_out(unit->mlt_heater.uuid, man_mlt_heat); |
|
366 device_out(unit->mlt_pump.uuid, man_mlt_pump); |
|
367 break; |
|
368 } |
|
369 } else { |
414 } else { |
370 /* |
415 /* |
371 * Not running. |
416 * Not running. |
372 */ |
417 */ |
373 prompt(0, NULL); |
418 prompt(0, NULL); |