brewco/brewco.c

changeset 467
f4d75ef899f4
parent 466
49a5318256f0
child 468
e8203e891b0e
equal deleted inserted replaced
466:49a5318256f0 467:f4d75ef899f4
136 136
137 void tempstatus(double hlttemp, double mlttemp) 137 void tempstatus(double hlttemp, double mlttemp)
138 { 138 {
139 char text[81]; 139 char text[81];
140 140
141 snprintf(text, 7, "%5.1f\001", hlttemp); 141 snprintf(text, 8, "%6.2f\001", hlttemp);
142 #ifdef HAVE_WIRINGPI_H 142 #ifdef HAVE_WIRINGPI_H
143 piLock(LOCK_LCD); 143 piLock(LOCK_LCD);
144 lcdPosition(lcdHandle, 2, 1); 144 lcdPosition(lcdHandle, 1, 1);
145 lcdPuts(lcdHandle, text); 145 lcdPuts(lcdHandle, text);
146 #endif 146 #endif
147 slcdPosition(slcdHandle, 2, 1); 147 slcdPosition(slcdHandle, 1, 1);
148 slcdPuts(slcdHandle, text); 148 slcdPuts(slcdHandle, text);
149 149
150 snprintf(text, 7, "%5.1f\001", mlttemp); 150 snprintf(text, 8, "%6.2f\001", mlttemp);
151 #ifdef HAVE_WIRINGPI_H 151 #ifdef HAVE_WIRINGPI_H
152 piLock(LOCK_LCD); 152 piLock(LOCK_LCD);
153 lcdPosition(lcdHandle, 11, 1); 153 lcdPosition(lcdHandle, 10, 1);
154 lcdPuts(lcdHandle, text); 154 lcdPuts(lcdHandle, text);
155 #endif 155 #endif
156 slcdPosition(slcdHandle, 11, 1); 156 slcdPosition(slcdHandle, 10, 1);
157 slcdPuts(slcdHandle, text);
158 }
159
160
161
162 void percstatus(int hltp, int mltp)
163 {
164 char text[11];
165
166 snprintf(text, 8, "HLT%3d%%", hltp);
167 #ifdef HAVE_WIRINGPI_H
168 piLock(LOCK_LCD);
169 lcdPosition(lcdHandle, 1, 2);
170 lcdPuts(lcdHandle, text);
171 #endif
172 slcdPosition(slcdHandle, 1, 2);
173 slcdPuts(slcdHandle, text);
174
175 snprintf(text, 8, "MLT%3d%%", mltp);
176 #ifdef HAVE_WIRINGPI_H
177 piLock(LOCK_LCD);
178 lcdPosition(lcdHandle, 10, 2);
179 lcdPuts(lcdHandle, text);
180 #endif
181 slcdPosition(slcdHandle, 10, 2);
157 slcdPuts(slcdHandle, text); 182 slcdPuts(slcdHandle, text);
158 } 183 }
159 184
160 185
161 186
162 void manual_prompt(void) 187 void manual_prompt(void)
163 { 188 {
164 switch (manual) { 189 switch (manual) {
165 case MANUAL_SELHLT: prompt(104, NULL); /* " MANUAL MODE " */ 190 case MANUAL_SELHLT: prompt(104, NULL); /* " MANUAL MODE " */
166 prompt(219, NULL); /* " Manual HLT " */ 191 prompt(303, NULL); /* " Manual HLT " */
167 prompt(402, NULL); /* "--- dwn quit ok " */ 192 prompt(402, NULL); /* "--- dwn quit ok " */
168 break; 193 break;
169 case MANUAL_SELMLT: prompt(104, NULL); /* " MANUAL MODE " */ 194 case MANUAL_SELMLT: prompt(104, NULL); /* " MANUAL MODE " */
170 prompt(220, NULL); /* " Manual MLT " */ 195 prompt(304, NULL); /* " Manual MLT " */
171 prompt(404, NULL); /* " up --- quit ok " */ 196 prompt(404, NULL); /* " up --- quit ok " */
172 break; 197 break;
173 case MANUAL_HLT: prompt(0, NULL); 198 case MANUAL_HLT: prompt(104, NULL); /* " MANUAL MODE " */
174 prompt(104, NULL); /* " MANUAL MODE " */ 199 prompt(300, NULL); /* " " */
175 prompt(413, NULL); /* "UP* *DWN heat --- " */ 200 prompt(413, NULL); /* "UP* *DWN heat --- " */
176 break; 201 break;
177 case MANUAL_MLT: prompt(0, NULL); 202 case MANUAL_MLT: prompt(104, NULL); /* " MANUAL MODE " */
178 prompt(104, NULL); /* " MANUAL MODE " */ 203 prompt(300, NULL); /* " " */
179 prompt(406, NULL); /* "UP* *DWN heat pmp " */ 204 prompt(406, NULL); /* "UP* *DWN heat pmp " */
180 break; 205 break;
181 } 206 }
182 } 207 }
183 208
225 manual = MANUAL_MLT; 250 manual = MANUAL_MLT;
226 manual_prompt(); 251 manual_prompt();
227 } 252 }
228 break; 253 break;
229 case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); 254 case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
230 255 percstatus(man_hlt_heat, man_mlt_heat);
256
231 slcdDummy(slcdHandle); 257 slcdDummy(slcdHandle);
232 key = keycheck(); 258 key = keycheck();
233 if (key == KEY_RETURN) { 259 if (key == KEY_RETURN) {
234 if (HLTpercent) 260 if (HLTpercent)
235 HLTpercent = 0; 261 HLTpercent = 0;
246 manual = MANUAL_SELHLT; 272 manual = MANUAL_SELHLT;
247 manual_prompt(); 273 manual_prompt();
248 } 274 }
249 break; 275 break;
250 case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); 276 case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
277 percstatus(man_hlt_heat, man_mlt_heat);
251 278
252 slcdDummy(slcdHandle); 279 slcdDummy(slcdHandle);
253 key = keycheck(); 280 key = keycheck();
254 if (key == KEY_RETURN) { 281 if (key == KEY_RETURN) {
255 if (MLTpercent) 282 if (MLTpercent)
424 } 451 }
425 452
426 do { 453 do {
427 if (my_shutdown) { 454 if (my_shutdown) {
428 run = 0; 455 run = 0;
456 unit->hlt_heater.value = 0;
457 unit->mlt_heater.value = 0;
458 unit->mlt_pump.value = 0;
459 device_out(unit->hlt_heater.uuid, 0);
460 device_out(unit->mlt_heater.uuid, 0);
461 device_out(unit->mlt_pump.uuid, 0);
429 break; 462 break;
430 } 463 }
431 464
432 /* 465 /*
433 * Do we need to initialize this unit? 466 * Do we need to initialize this unit?
434 */ 467 */
435 if (do_init) { 468 if (do_init) {
436 if (debug) 469 if (debug)
437 fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name); 470 fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name);
438 syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name); 471 syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name);
472
473 prompt(0, NULL);
474 prompt(101, NULL); /* " Brewco x.x.x " */
475 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
476
439 /* 477 /*
440 * Turn everything off 478 * Turn everything off
441 */ 479 */
442 unit->hlt_heater.value = 0; 480 unit->hlt_heater.value = 0;
443 unit->mlt_heater.value = 0; 481 unit->mlt_heater.value = 0;
450 * Initialize PID's 488 * Initialize PID's
451 */ 489 */
452 hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0; 490 hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0;
453 hltOutput = mltOutput = 0; 491 hltOutput = mltOutput = 0;
454 PID_init(unit->PID_hlt, &hltInput, &hltOutput, &hltSetpoint, unit->PID_hlt->dispKd, unit->PID_hlt->dispKi, unit->PID_hlt->dispKd, unit->PID_hlt->Direction); 492 PID_init(unit->PID_hlt, &hltInput, &hltOutput, &hltSetpoint, unit->PID_hlt->dispKd, unit->PID_hlt->dispKi, unit->PID_hlt->dispKd, unit->PID_hlt->Direction);
455 PID_setOutputLimits(unit->PID_hlt, 0, 5000); 493 PID_setOutputLimits(unit->PID_hlt, 0, 100);
456 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime); 494 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime);
457 PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKd, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction); 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);
458 PID_setOutputLimits(unit->PID_mlt, 0, 5000); 496 PID_setOutputLimits(unit->PID_mlt, 0, 100);
459 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime); 497 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime);
460 498
461 prompt(0, NULL);
462 prompt(101, NULL);
463 prompt(401, NULL);
464 manual = MANUAL_NONE; 499 manual = MANUAL_NONE;
465 500
466 do_init = FALSE; 501 do_init = FALSE;
467 nowmillis = perctimer = millis(); 502 nowmillis = perctimer = millis();
468 percslot = 0; 503 percslot = 0;
481 rc = PID_compute(unit->PID_mlt); 516 rc = PID_compute(unit->PID_mlt);
482 // if (seconds < 3) 517 // if (seconds < 3)
483 // fprintf(stdout, " mlt rc=%d\n"); 518 // fprintf(stdout, " mlt rc=%d\n");
484 519
485 /* 520 /*
486 * 50 mSeconds loop for heater elements timing. 521 * This is the serial heaters schedule loop. The total
522 * loop time is 5 seconds, heating is 0..100% so we
523 * have 5 mSeconds timeslots. The MLT has priority over
524 * the HLT heater, so the HLT heater can get too little
525 * power. TODO: simultaneous use must be implemented.
526 * In sequentiel mode, the total drawn power is the same
527 * as the power used by the largest heater element.
487 */ 528 */
488 nowmillis = millis(); 529 nowmillis = millis();
489 if (nowmillis > (perctimer + 50)) { 530 if (nowmillis > (perctimer + 50)) {
490 percslot++; 531 percslot++;
491 if (percfase == PERC_INIT) { 532 if (percfase == PERC_INIT) {
493 MLTp = MLTpercent; 534 MLTp = MLTpercent;
494 if ((MLTp + HLTp) > 100) 535 if ((MLTp + HLTp) > 100)
495 HLTp = 100 - MLTp; /* The HLT has lower priority */ 536 HLTp = 100 - MLTp; /* The HLT has lower priority */
496 if (MLTp) { 537 if (MLTp) {
497 percfase = PERC_MLT; 538 percfase = PERC_MLT;
539 device_out(unit->hlt_heater.uuid, 0);
498 device_out(unit->mlt_heater.uuid, 1); 540 device_out(unit->mlt_heater.uuid, 1);
499 } else if (HLTp) { 541 } else if (HLTp) {
500 percfase = PERC_HLT; 542 percfase = PERC_HLT;
501 device_out(unit->hlt_heater.uuid, 1); 543 device_out(unit->hlt_heater.uuid, 1);
544 device_out(unit->mlt_heater.uuid, 0);
502 } else { 545 } else {
503 percfase = PERC_REST; 546 percfase = PERC_REST;
547 device_out(unit->hlt_heater.uuid, 0);
548 device_out(unit->mlt_heater.uuid, 0);
504 } 549 }
505 if (debug) 550 if (debug)
506 fprintf(stdout, " perslot MLT=%d%% HLT=%d%% fase=%d\n", MLTp, HLTp, percfase); 551 fprintf(stdout, " perslot=%d MLT=%d%% HLT=%d%% fase=%d\n", percslot, MLTp, HLTp, percfase);
507 } else if (percfase == PERC_MLT) { 552 } else if (percfase == PERC_MLT) {
508 if (percslot > MLTp) { 553 if (percslot > MLTp) {
509 if (debug)
510 fprintf(stdout, " perslot %d MLT off\n", percslot);
511 device_out(unit->mlt_heater.uuid, 0); 554 device_out(unit->mlt_heater.uuid, 0);
512 if (HLTp) { 555 if (HLTp) {
513 if (debug)
514 fprintf(stdout, " perslot %d HLT on\n", percslot);
515 device_out(unit->hlt_heater.uuid, 1); 556 device_out(unit->hlt_heater.uuid, 1);
516 percfase = PERC_HLT; 557 percfase = PERC_HLT;
517 } else { 558 } else {
518 percfase = PERC_REST; 559 percfase = PERC_REST;
519 } 560 }
520 } 561 }
521 } else if (percfase == PERC_HLT) { 562 } else if (percfase == PERC_HLT) {
522 if (percslot > (MLTp + HLTp)) { 563 if (percslot > (MLTp + HLTp)) {
523 if (debug)
524 fprintf(stdout, " perslot %d HLT off\n", percslot);
525 device_out(unit->hlt_heater.uuid, 0); 564 device_out(unit->hlt_heater.uuid, 0);
526 percfase = PERC_REST; 565 percfase = PERC_REST;
527 } 566 }
528 } 567 }
529 if (percslot == 100) { 568 if (percslot == 100) { /* End of the loop, start over */
530 percslot = 0; 569 percslot = 0;
531 percfase = PERC_INIT; 570 percfase = PERC_INIT;
532 device_out(unit->hlt_heater.uuid, 0);
533 device_out(unit->mlt_heater.uuid, 0);
534 fprintf(stdout, " perslot complete\n");
535 } 571 }
536 perctimer = nowmillis; 572 perctimer = nowmillis;
537 } 573 }
538 574
539 now = time(NULL); 575 now = time(NULL);
588 manual_menu(unit, hltInput, mltInput); 624 manual_menu(unit, hltInput, mltInput);
589 if (manual == MANUAL_NONE) { 625 if (manual == MANUAL_NONE) {
590 /* 626 /*
591 * Rewrite the display 627 * Rewrite the display
592 */ 628 */
593 prompt(0, NULL); 629 prompt(101, NULL); /* " Brewco x.x.x " */
594 prompt(101, NULL); 630 prompt(300, NULL); /* " " */
595 prompt(401, NULL); 631 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
596 } 632 }
597 } else { 633 } else {
598 /* 634 /*
599 * Not running. 635 * Not running.
600 */ 636 */
601 tempstatus(hltInput, mltInput); 637 tempstatus(hltInput, mltInput);
602 key = keycheck(); 638 key = keycheck();
603 if (key == KEY_ENTER) { 639 if (key == KEY_ENTER) {
604 setup(); 640 setup();
605 prompt(0, NULL); 641 prompt(101, NULL); /* " Brewco x.x.x " */
606 prompt(101, NULL); 642 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
607 prompt(401, NULL);
608 } else if (key == KEY_DOWN) { 643 } else if (key == KEY_DOWN) {
609 manual = MANUAL_SELHLT; 644 manual = MANUAL_SELHLT;
610 manual_prompt(); 645 manual_prompt();
611 } 646 }
612 } 647 }
618 syslog(LOG_NOTICE, "Out of loop"); 653 syslog(LOG_NOTICE, "Out of loop");
619 if (debug) 654 if (debug)
620 fprintf(stdout, (char *)"Out of loop\n"); 655 fprintf(stdout, (char *)"Out of loop\n");
621 656
622 prompt(0, NULL); 657 prompt(0, NULL);
623 prompt(101, NULL); 658 prompt(101, NULL); /* " Brewco x.x.x " */
624 prompt(302, NULL); 659 prompt(302, NULL); /* " Shutting down " */
625
626 /*
627 * Stop units processing in a neat way
628 */
629 for (unit = Config.units; unit; unit = unit->next) {
630
631 }
632 660
633 /* 661 /*
634 * Give threads time to cleanup 662 * Give threads time to cleanup
635 */ 663 */
636 usleep(1500000); 664 usleep(1500000);
637
638 prompt(0, NULL); 665 prompt(0, NULL);
639 // stopLCD(); 666 // stopLCD();
640 if (sock != -1) { 667 if (sock != -1) {
641 if (shutdown(sock, SHUT_RDWR)) { 668 if (shutdown(sock, SHUT_RDWR)) {
642 syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno)); 669 syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno));
643 } 670 }
644 sock = -1; 671 sock = -1;
645 } 672 }
673
646 wrrecipes(); 674 wrrecipes();
647 wrconfig(); 675 wrconfig();
648
649 ulockprog((char *)"brewco"); 676 ulockprog((char *)"brewco");
650 return 0; 677 return 0;
651 } 678 }
652 679
653 680

mercurial