# HG changeset patch # User Michiel Broek # Date 1450728576 -3600 # Node ID f4d75ef899f46dc8747b5554858d87f4d89d0157 # Parent 49a5318256f02e931642ab51d5ab9a1e14e61833 Finished manual mode. diff -r 49a5318256f0 -r f4d75ef899f4 brewco/brewco.c --- a/brewco/brewco.c Sun Dec 20 23:26:03 2015 +0100 +++ b/brewco/brewco.c Mon Dec 21 21:09:36 2015 +0100 @@ -138,22 +138,47 @@ { char text[81]; - snprintf(text, 7, "%5.1f\001", hlttemp); + snprintf(text, 8, "%6.2f\001", hlttemp); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); - lcdPosition(lcdHandle, 2, 1); + lcdPosition(lcdHandle, 1, 1); + lcdPuts(lcdHandle, text); +#endif + slcdPosition(slcdHandle, 1, 1); + slcdPuts(slcdHandle, text); + + snprintf(text, 8, "%6.2f\001", mlttemp); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); + lcdPosition(lcdHandle, 10, 1); lcdPuts(lcdHandle, text); #endif - slcdPosition(slcdHandle, 2, 1); + slcdPosition(slcdHandle, 10, 1); + slcdPuts(slcdHandle, text); +} + + + +void percstatus(int hltp, int mltp) +{ + char text[11]; + + snprintf(text, 8, "HLT%3d%%", hltp); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); + lcdPosition(lcdHandle, 1, 2); + lcdPuts(lcdHandle, text); +#endif + slcdPosition(slcdHandle, 1, 2); slcdPuts(slcdHandle, text); - snprintf(text, 7, "%5.1f\001", mlttemp); + snprintf(text, 8, "MLT%3d%%", mltp); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); - lcdPosition(lcdHandle, 11, 1); + lcdPosition(lcdHandle, 10, 2); lcdPuts(lcdHandle, text); #endif - slcdPosition(slcdHandle, 11, 1); + slcdPosition(slcdHandle, 10, 2); slcdPuts(slcdHandle, text); } @@ -163,19 +188,19 @@ { switch (manual) { case MANUAL_SELHLT: prompt(104, NULL); /* " MANUAL MODE " */ - prompt(219, NULL); /* " Manual HLT " */ + prompt(303, NULL); /* " Manual HLT " */ prompt(402, NULL); /* "--- dwn quit ok " */ break; case MANUAL_SELMLT: prompt(104, NULL); /* " MANUAL MODE " */ - prompt(220, NULL); /* " Manual MLT " */ + prompt(304, NULL); /* " Manual MLT " */ prompt(404, NULL); /* " up --- quit ok " */ break; - case MANUAL_HLT: prompt(0, NULL); - prompt(104, NULL); /* " MANUAL MODE " */ + case MANUAL_HLT: prompt(104, NULL); /* " MANUAL MODE " */ + prompt(300, NULL); /* " " */ prompt(413, NULL); /* "UP* *DWN heat --- " */ break; - case MANUAL_MLT: prompt(0, NULL); - prompt(104, NULL); /* " MANUAL MODE " */ + case MANUAL_MLT: prompt(104, NULL); /* " MANUAL MODE " */ + prompt(300, NULL); /* " " */ prompt(406, NULL); /* "UP* *DWN heat pmp " */ break; } @@ -227,7 +252,8 @@ } break; case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); - + percstatus(man_hlt_heat, man_mlt_heat); + slcdDummy(slcdHandle); key = keycheck(); if (key == KEY_RETURN) { @@ -248,6 +274,7 @@ } break; case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); + percstatus(man_hlt_heat, man_mlt_heat); slcdDummy(slcdHandle); key = keycheck(); @@ -426,6 +453,12 @@ do { if (my_shutdown) { run = 0; + unit->hlt_heater.value = 0; + unit->mlt_heater.value = 0; + unit->mlt_pump.value = 0; + device_out(unit->hlt_heater.uuid, 0); + device_out(unit->mlt_heater.uuid, 0); + device_out(unit->mlt_pump.uuid, 0); break; } @@ -436,6 +469,11 @@ if (debug) fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name); syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name); + + prompt(0, NULL); + prompt(101, NULL); /* " Brewco x.x.x " */ + prompt(401, NULL); /* "--- MAN AUTO SETUP" */ + /* * Turn everything off */ @@ -452,15 +490,12 @@ hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0; hltOutput = mltOutput = 0; PID_init(unit->PID_hlt, &hltInput, &hltOutput, &hltSetpoint, unit->PID_hlt->dispKd, unit->PID_hlt->dispKi, unit->PID_hlt->dispKd, unit->PID_hlt->Direction); - PID_setOutputLimits(unit->PID_hlt, 0, 5000); + PID_setOutputLimits(unit->PID_hlt, 0, 100); PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime); PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKd, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction); - PID_setOutputLimits(unit->PID_mlt, 0, 5000); + PID_setOutputLimits(unit->PID_mlt, 0, 100); PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime); - prompt(0, NULL); - prompt(101, NULL); - prompt(401, NULL); manual = MANUAL_NONE; do_init = FALSE; @@ -483,7 +518,13 @@ // fprintf(stdout, " mlt rc=%d\n"); /* - * 50 mSeconds loop for heater elements timing. + * This is the serial heaters schedule loop. The total + * loop time is 5 seconds, heating is 0..100% so we + * have 5 mSeconds timeslots. The MLT has priority over + * the HLT heater, so the HLT heater can get too little + * power. TODO: simultaneous use must be implemented. + * In sequentiel mode, the total drawn power is the same + * as the power used by the largest heater element. */ nowmillis = millis(); if (nowmillis > (perctimer + 50)) { @@ -495,23 +536,23 @@ HLTp = 100 - MLTp; /* The HLT has lower priority */ if (MLTp) { percfase = PERC_MLT; + device_out(unit->hlt_heater.uuid, 0); device_out(unit->mlt_heater.uuid, 1); } else if (HLTp) { percfase = PERC_HLT; device_out(unit->hlt_heater.uuid, 1); + device_out(unit->mlt_heater.uuid, 0); } else { percfase = PERC_REST; + device_out(unit->hlt_heater.uuid, 0); + device_out(unit->mlt_heater.uuid, 0); } if (debug) - fprintf(stdout, " perslot MLT=%d%% HLT=%d%% fase=%d\n", MLTp, HLTp, percfase); + fprintf(stdout, " perslot=%d MLT=%d%% HLT=%d%% fase=%d\n", percslot, MLTp, HLTp, percfase); } else if (percfase == PERC_MLT) { if (percslot > MLTp) { - if (debug) - fprintf(stdout, " perslot %d MLT off\n", percslot); device_out(unit->mlt_heater.uuid, 0); if (HLTp) { - if (debug) - fprintf(stdout, " perslot %d HLT on\n", percslot); device_out(unit->hlt_heater.uuid, 1); percfase = PERC_HLT; } else { @@ -520,18 +561,13 @@ } } else if (percfase == PERC_HLT) { if (percslot > (MLTp + HLTp)) { - if (debug) - fprintf(stdout, " perslot %d HLT off\n", percslot); device_out(unit->hlt_heater.uuid, 0); percfase = PERC_REST; } } - if (percslot == 100) { + if (percslot == 100) { /* End of the loop, start over */ percslot = 0; percfase = PERC_INIT; - device_out(unit->hlt_heater.uuid, 0); - device_out(unit->mlt_heater.uuid, 0); - fprintf(stdout, " perslot complete\n"); } perctimer = nowmillis; } @@ -590,9 +626,9 @@ /* * Rewrite the display */ - prompt(0, NULL); - prompt(101, NULL); - prompt(401, NULL); + prompt(101, NULL); /* " Brewco x.x.x " */ + prompt(300, NULL); /* " " */ + prompt(401, NULL); /* "--- MAN AUTO SETUP" */ } } else { /* @@ -602,9 +638,8 @@ key = keycheck(); if (key == KEY_ENTER) { setup(); - prompt(0, NULL); - prompt(101, NULL); - prompt(401, NULL); + prompt(101, NULL); /* " Brewco x.x.x " */ + prompt(401, NULL); /* "--- MAN AUTO SETUP" */ } else if (key == KEY_DOWN) { manual = MANUAL_SELHLT; manual_prompt(); @@ -620,21 +655,13 @@ fprintf(stdout, (char *)"Out of loop\n"); prompt(0, NULL); - prompt(101, NULL); - prompt(302, NULL); - - /* - * Stop units processing in a neat way - */ - for (unit = Config.units; unit; unit = unit->next) { - - } + prompt(101, NULL); /* " Brewco x.x.x " */ + prompt(302, NULL); /* " Shutting down " */ /* * Give threads time to cleanup */ usleep(1500000); - prompt(0, NULL); // stopLCD(); if (sock != -1) { @@ -643,9 +670,9 @@ } sock = -1; } + wrrecipes(); wrconfig(); - ulockprog((char *)"brewco"); return 0; } diff -r 49a5318256f0 -r f4d75ef899f4 brewco/prompt.c --- a/brewco/prompt.c Sun Dec 20 23:26:03 2015 +0100 +++ b/brewco/prompt.c Mon Dec 21 21:09:36 2015 +0100 @@ -48,7 +48,10 @@ piUnlock(LOCK_LCD); #endif return; - case 100: snprintf(message, Config.lcd_cols + 1, text); + case 100: if (text == NULL) + snprintf(message, Config.lcd_cols + 1, " "); + else + snprintf(message, Config.lcd_cols + 1, text); break; case 101: snprintf(message, Config.lcd_cols + 1, " Brewco %s \007", VERSION); break; @@ -114,7 +117,10 @@ break; case 196: snprintf(message, Config.lcd_cols + 1, " Edit Hopstand "); break; - case 200: snprintf(message, Config.lcd_cols + 1, text); + case 200: if (text == NULL) + snprintf(message, Config.lcd_cols + 1, " "); + else + snprintf(message, Config.lcd_cols + 1, text); break; case 202: snprintf(message, Config.lcd_cols + 1, " Manage Recipes "); break; @@ -150,23 +156,30 @@ break; case 218: snprintf(message, Config.lcd_cols + 1, " Add Brewsystem? "); break; - case 219: snprintf(message, Config.lcd_cols + 1, " Manual HLT "); - break; - case 220: snprintf(message, Config.lcd_cols + 1, " Manual MLT "); - break; + case 221: snprintf(message, Config.lcd_cols + 1, " Select Recipe "); break; case 222: snprintf(message, Config.lcd_cols + 1, " Select Brewsystem "); break; case 223: snprintf(message, Config.lcd_cols + 1, " Select Device "); break; - case 300: snprintf(message, Config.lcd_cols + 1, text); + case 300: if (text == NULL) + snprintf(message, Config.lcd_cols + 1, " "); + else + snprintf(message, Config.lcd_cols + 1, text); break; case 301: snprintf(message, Config.lcd_cols + 1, " Finished "); break; case 302: snprintf(message, Config.lcd_cols + 1, " Shutting down "); break; - case 400: snprintf(message, Config.lcd_cols + 1, text); + case 303: snprintf(message, Config.lcd_cols + 1, " Manual HLT "); + break; + case 304: snprintf(message, Config.lcd_cols + 1, " Manual MLT "); + break; + case 400: if (text == NULL) + snprintf(message, Config.lcd_cols + 1, " "); + else + snprintf(message, Config.lcd_cols + 1, text); break; case 401: snprintf(message, Config.lcd_cols + 1, "--- MAN AUTO SETUP"); break;