brewco/brewco.c

changeset 471
1564b60558b1
parent 468
e8203e891b0e
child 472
55bcbf92ecab
equal deleted inserted replaced
470:c2794ae0def3 471:1564b60558b1
36 #include "setup.h" 36 #include "setup.h"
37 37
38 38
39 39
40 int my_shutdown = FALSE; 40 int my_shutdown = FALSE;
41 int HLTpercent = 0;
42 int MLTpercent = 0;
43 int man_mlt_pump = 0; 41 int man_mlt_pump = 0;
44 int man_hlt_heat = 50; 42
45 int man_mlt_heat = 50; 43 double hltInput; /* HLT PID variables */
44 double hltOutput;
45 double hltSetpoint;
46 double mltInput; /* MLT PID variables */
47 double mltOutput;
48 double mltSetpoint;
49
46 extern int debug; 50 extern int debug;
47 extern sys_config Config; 51 extern sys_config Config;
48 extern int lcdHandle; 52 extern int lcdHandle;
49 extern int slcdHandle; 53 extern int slcdHandle;
50 extern int sock; 54 extern int sock;
136 140
137 void tempstatus(double hlttemp, double mlttemp) 141 void tempstatus(double hlttemp, double mlttemp)
138 { 142 {
139 char text[81]; 143 char text[81];
140 144
141 snprintf(text, 8, "%6.2f\001", hlttemp); 145 snprintf(text, 8, "%6.2f\001", hltInput);
142 #ifdef HAVE_WIRINGPI_H 146 #ifdef HAVE_WIRINGPI_H
143 piLock(LOCK_LCD); 147 piLock(LOCK_LCD);
144 lcdPosition(lcdHandle, 1, 1); 148 lcdPosition(lcdHandle, 1, 1);
145 lcdPuts(lcdHandle, text); 149 lcdPuts(lcdHandle, text);
146 #endif 150 #endif
147 slcdPosition(slcdHandle, 1, 1); 151 slcdPosition(slcdHandle, 1, 1);
148 slcdPuts(slcdHandle, text); 152 slcdPuts(slcdHandle, text);
149 153
150 snprintf(text, 8, "%6.2f\001", mlttemp); 154 snprintf(text, 8, "%6.2f\001", mltInput);
151 #ifdef HAVE_WIRINGPI_H 155 #ifdef HAVE_WIRINGPI_H
152 piLock(LOCK_LCD); 156 piLock(LOCK_LCD);
153 lcdPosition(lcdHandle, 10, 1); 157 lcdPosition(lcdHandle, 10, 1);
154 lcdPuts(lcdHandle, text); 158 lcdPuts(lcdHandle, text);
155 #endif 159 #endif
157 slcdPuts(slcdHandle, text); 161 slcdPuts(slcdHandle, text);
158 } 162 }
159 163
160 164
161 165
162 void percstatus(int hltp, int mltp) 166 /*
167 * Third line, show setPoints or heater percentage.
168 */
169 void percstatus(int which)
163 { 170 {
164 char text[11]; 171 char text[21];
165 172
166 snprintf(text, 8, "HLT%3d%%", hltp); 173 if (which)
174 snprintf(text, 8, "%6.2f\002", hltSetpoint);
175 else
176 snprintf(text, 8, "HLT%3d%%", (int)hltOutput);
167 #ifdef HAVE_WIRINGPI_H 177 #ifdef HAVE_WIRINGPI_H
168 piLock(LOCK_LCD); 178 piLock(LOCK_LCD);
169 lcdPosition(lcdHandle, 1, 2); 179 lcdPosition(lcdHandle, 1, 2);
170 lcdPuts(lcdHandle, text); 180 lcdPuts(lcdHandle, text);
171 #endif 181 #endif
172 slcdPosition(slcdHandle, 1, 2); 182 slcdPosition(slcdHandle, 1, 2);
173 slcdPuts(slcdHandle, text); 183 slcdPuts(slcdHandle, text);
174 184
175 snprintf(text, 8, "MLT%3d%%", mltp); 185 if (which)
186 snprintf(text, 8, "%6.2f\002", mltSetpoint);
187 else
188 snprintf(text, 8, "MLT%3d%%", (int)mltOutput);
176 #ifdef HAVE_WIRINGPI_H 189 #ifdef HAVE_WIRINGPI_H
177 piLock(LOCK_LCD); 190 piLock(LOCK_LCD);
178 lcdPosition(lcdHandle, 10, 2); 191 lcdPosition(lcdHandle, 10, 2);
179 lcdPuts(lcdHandle, text); 192 lcdPuts(lcdHandle, text);
180 #endif 193 #endif
181 slcdPosition(slcdHandle, 10, 2); 194 slcdPosition(slcdHandle, 10, 2);
182 slcdPuts(slcdHandle, text); 195 slcdPuts(slcdHandle, text);
196 }
197
198
199
200 void automatic_brew(units_list *, brew_session *);
201 void automatic_brew(units_list *unit, brew_session *brew)
202 {
183 } 203 }
184 204
185 205
186 206
187 void manual_prompt(void) 207 void manual_prompt(void)
209 229
210 230
211 /* 231 /*
212 * Manual menu for testing your equipment. 232 * Manual menu for testing your equipment.
213 */ 233 */
214 int manual_menu(units_list *, double, double); 234 int manual_menu(units_list *, int);
215 int manual_menu(units_list *unit, double hlt, double mlt) 235 int manual_menu(units_list *unit, int seconds)
216 { 236 {
217 int key; 237 int key;
218 238
219 switch (manual) { 239 switch (manual) {
220 case MANUAL_SELHLT: slcdDummy(slcdHandle); 240 case MANUAL_SELHLT: slcdDummy(slcdHandle);
223 manual = MANUAL_SELMLT; 243 manual = MANUAL_SELMLT;
224 manual_prompt(); 244 manual_prompt();
225 } 245 }
226 if (key == KEY_RETURN) { 246 if (key == KEY_RETURN) {
227 manual = MANUAL_NONE; 247 manual = MANUAL_NONE;
228 HLTpercent = MLTpercent = man_mlt_pump = 0; 248 man_mlt_pump = 0;
249 PID_setMode(unit->PID_mlt, P_MANUAL);
250 PID_setMode(unit->PID_hlt, P_MANUAL);
251 hlt_status(0);
252 mlt_status(0);
229 device_out(unit->mlt_pump.uuid, man_mlt_pump); 253 device_out(unit->mlt_pump.uuid, man_mlt_pump);
230 } 254 }
231 if (key == KEY_ENTER) { 255 if (key == KEY_ENTER) {
232 // TODO: prompt for water 256 // TODO: prompt for water
233 manual = MANUAL_HLT; 257 manual = MANUAL_HLT;
240 manual = MANUAL_SELHLT; 264 manual = MANUAL_SELHLT;
241 manual_prompt(); 265 manual_prompt();
242 } 266 }
243 if (key == KEY_RETURN) { 267 if (key == KEY_RETURN) {
244 manual = MANUAL_NONE; 268 manual = MANUAL_NONE;
245 HLTpercent = MLTpercent = man_mlt_pump = 0; 269 man_mlt_pump = 0;
270 PID_setMode(unit->PID_mlt, P_MANUAL);
271 PID_setMode(unit->PID_hlt, P_MANUAL);
272 hlt_status(0);
273 mlt_status(0);
246 device_out(unit->mlt_pump.uuid, man_mlt_pump); 274 device_out(unit->mlt_pump.uuid, man_mlt_pump);
247 } 275 }
248 if (key == KEY_ENTER) { 276 if (key == KEY_ENTER) {
249 // TODO: prompt for water 277 // TODO: prompt for water
250 manual = MANUAL_MLT; 278 manual = MANUAL_MLT;
251 manual_prompt(); 279 manual_prompt();
252 } 280 }
253 break; 281 break;
254 case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); 282 case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
255 percstatus(man_hlt_heat, man_mlt_heat); 283 percstatus((seconds / 2) % 4);
256 284
257 slcdDummy(slcdHandle); 285 slcdDummy(slcdHandle);
258 key = keycheck(); 286 key = keycheck();
259 if (key == KEY_RETURN) { 287 if (key == KEY_RETURN) {
260 if (HLTpercent) 288 if (PID_getMode(unit->PID_hlt) == P_MANUAL) {
261 HLTpercent = 0; 289 PID_setMode(unit->PID_hlt, P_AUTOMATIC);
262 else 290 hlt_status(1);
263 HLTpercent = man_hlt_heat; 291 } else {
292 PID_setMode(unit->PID_hlt, P_MANUAL);
293 hlt_status(0);
294 }
264 } 295 }
265 if ((key == KEY_DOWN) && (man_hlt_heat > 1)) 296 if ((key == KEY_DOWN) && (hltSetpoint > 10))
266 man_hlt_heat--; 297 hltSetpoint -= 1.0;
267 if ((key == KEY_UP) && (man_hlt_heat < 100)) 298 if ((key == KEY_UP) && (hltSetpoint < 100))
268 man_hlt_heat++; 299 hltSetpoint += 1.0;
269 if (HLTpercent)
270 HLTpercent = man_hlt_heat;
271 if (key == KEY_ESCAPE) { 300 if (key == KEY_ESCAPE) {
272 manual = MANUAL_SELHLT; 301 manual = MANUAL_SELHLT;
273 manual_prompt(); 302 manual_prompt();
274 } 303 }
275 break; 304 break;
276 case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); 305 case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
277 percstatus(man_hlt_heat, man_mlt_heat); 306 percstatus((seconds / 2) % 4);
278 307
279 slcdDummy(slcdHandle); 308 slcdDummy(slcdHandle);
280 key = keycheck(); 309 key = keycheck();
281 if (key == KEY_RETURN) { 310 if (key == KEY_RETURN) {
282 if (MLTpercent) 311 if (PID_getMode(unit->PID_mlt) == P_MANUAL) {
283 MLTpercent = 0; 312 PID_setMode(unit->PID_mlt, P_AUTOMATIC);
284 else 313 mlt_status(1);
285 MLTpercent = man_mlt_heat; 314 } else {
315 PID_setMode(unit->PID_mlt, P_MANUAL);
316 mlt_status(0);
317 }
286 } 318 }
287 if ((key == KEY_DOWN) && (man_mlt_heat > 1)) 319 if ((key == KEY_DOWN) && (mltSetpoint > 10))
288 man_mlt_heat--; 320 mltSetpoint -= 1.0;
289 if ((key == KEY_UP) && (man_mlt_heat < 100)) 321 if ((key == KEY_UP) && (mltSetpoint < 100))
290 man_mlt_heat++; 322 mltSetpoint += 1.0;
291 if (MLTpercent)
292 MLTpercent = man_mlt_heat;
293 if (key == KEY_ENTER) { 323 if (key == KEY_ENTER) {
294 if (man_mlt_pump) 324 if (man_mlt_pump)
295 man_mlt_pump = 0; 325 man_mlt_pump = 0;
296 else 326 else
297 man_mlt_pump = 1; 327 man_mlt_pump = 1;
318 brew_session *brew = NULL; 348 brew_session *brew = NULL;
319 #ifndef HAVE_WIRINGPI_H 349 #ifndef HAVE_WIRINGPI_H
320 long t = 0; 350 long t = 0;
321 #endif 351 #endif
322 time_t now, last = (time_t)0; 352 time_t now, last = (time_t)0;
323 static double hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint;
324 long nowmillis, perctimer; 353 long nowmillis, perctimer;
325 354
326 prompt(101, NULL); 355 prompt(101, NULL);
327 356
328 /* 357 /*
457 unit->mlt_heater.value = 0; 486 unit->mlt_heater.value = 0;
458 unit->mlt_pump.value = 0; 487 unit->mlt_pump.value = 0;
459 device_out(unit->hlt_heater.uuid, 0); 488 device_out(unit->hlt_heater.uuid, 0);
460 device_out(unit->mlt_heater.uuid, 0); 489 device_out(unit->mlt_heater.uuid, 0);
461 device_out(unit->mlt_pump.uuid, 0); 490 device_out(unit->mlt_pump.uuid, 0);
491 hlt_status(0);
492 mlt_status(0);
462 break; 493 break;
463 } 494 }
464 495
465 /* 496 /*
466 * Do we need to initialize this unit? 497 * Do we need to initialize this unit?
493 PID_setOutputLimits(unit->PID_hlt, 0, 100); 524 PID_setOutputLimits(unit->PID_hlt, 0, 100);
494 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime); 525 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime);
495 PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKd, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction); 526 PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKd, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction);
496 PID_setOutputLimits(unit->PID_mlt, 0, 100); 527 PID_setOutputLimits(unit->PID_mlt, 0, 100);
497 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime); 528 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime);
529 hlt_status(0);
530 mlt_status(0);
498 531
499 manual = MANUAL_NONE; 532 manual = MANUAL_NONE;
500 533
501 do_init = FALSE; 534 do_init = FALSE;
502 nowmillis = perctimer = millis(); 535 nowmillis = perctimer = millis();
528 */ 561 */
529 nowmillis = millis(); 562 nowmillis = millis();
530 if (nowmillis > (perctimer + 50)) { 563 if (nowmillis > (perctimer + 50)) {
531 percslot++; 564 percslot++;
532 if (percfase == PERC_INIT) { 565 if (percfase == PERC_INIT) {
533 HLTp = HLTpercent; 566 HLTp = (int)hltOutput;
534 MLTp = MLTpercent; 567 MLTp = (int)mltOutput;
535 if ((MLTp + HLTp) > 100) 568 if ((MLTp + HLTp) > 100)
536 HLTp = 100 - MLTp; /* The HLT has lower priority */ 569 HLTp = 100 - MLTp; /* The HLT has lower priority */
537 if (MLTp) { 570 if (MLTp) {
538 percfase = PERC_MLT; 571 percfase = PERC_MLT;
539 device_out(unit->hlt_heater.uuid, 0); 572 device_out(unit->hlt_heater.uuid, 0);
604 } else { 637 } else {
605 unit->mlt_sensor.state = 2; 638 unit->mlt_sensor.state = 2;
606 } 639 }
607 640
608 if (debug && ((seconds % 10) == 1)) { 641 if (debug && ((seconds % 10) == 1)) {
609 fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf HLT: In=%.2lf Out=%.2lf Set=%.2lf\n", 642 fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d HLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d\n",
610 mltInput, mltOutput, mltSetpoint, hltInput, hltOutput, hltSetpoint); 643 mltInput, mltOutput, mltSetpoint, PID_getMode(unit->PID_mlt),
644 hltInput, hltOutput, hltSetpoint, PID_getMode(unit->PID_hlt));
611 } 645 }
612 646
613 } 647 }
614 648
615 if (brew) { 649 if (brew) {
616 /* 650 /*
617 * Automate mode 651 * Automate mode
618 */ 652 */
653 automatic_brew(unit, brew);
619 654
620 } else if (manual != MANUAL_NONE) { 655 } else if (manual != MANUAL_NONE) {
621 /* 656 /*
622 * Manual mode 657 * Manual mode
623 */ 658 */
624 manual_menu(unit, hltInput, mltInput); 659 manual_menu(unit, seconds);
625 if (manual == MANUAL_NONE) { 660 if (manual == MANUAL_NONE) {
626 /* 661 /*
627 * Rewrite the display 662 * Rewrite the display
628 */ 663 */
629 prompt(101, NULL); /* " Brewco x.x.x " */ 664 prompt(101, NULL); /* " Brewco x.x.x " */

mercurial