# HG changeset patch # User Michiel Broek # Date 1450796366 -3600 # Node ID 1564b60558b189eb816906f3e32c0f8434f0e827 # Parent c2794ae0def36068b04c85651ec9c31039972b15 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds. diff -r c2794ae0def3 -r 1564b60558b1 brewco/Makefile --- a/brewco/Makefile Mon Dec 21 22:53:29 2015 +0100 +++ b/brewco/Makefile Tue Dec 22 15:59:26 2015 +0100 @@ -56,13 +56,13 @@ # Dependencies generated by make depend rdrecipes.o: brewco.h rdrecipes.h util.h xutil.h setup.o: brewco.h slcd.h setup.h prompt.h xutil.h keyboard.h rdconfig.h rdrecipes.h -devices.o: brewco.h devices.h xutil.h keyboard.h slcd.h +devices.o: brewco.h devices.h util.h xutil.h keyboard.h slcd.h xutil.o: brewco.h xutil.h brewco.o: brewco.h rdconfig.h rdsession.h rdrecipes.h util.h xutil.h lcd-pcf8574.h slcd.h lock.h devices.h keyboard.h simulator.h prompt.h setup.h lock.o: lock.h brewco.h lcd-pcf8574.o: brewco.h lcd-pcf8574.h slcd.h pid.o: brewco.h pid.h util.h -util.o: brewco.h util.h +util.o: brewco.h util.h slcd.h keyboard.o: brewco.h lcd-pcf8574.h slcd.h keyboard.h simulator.o: brewco.h simulator.h rdconfig.o: rdconfig.h brewco.h util.h xutil.h diff -r c2794ae0def3 -r 1564b60558b1 brewco/brewco.c --- a/brewco/brewco.c Mon Dec 21 22:53:29 2015 +0100 +++ b/brewco/brewco.c Tue Dec 22 15:59:26 2015 +0100 @@ -38,11 +38,15 @@ int my_shutdown = FALSE; -int HLTpercent = 0; -int MLTpercent = 0; int man_mlt_pump = 0; -int man_hlt_heat = 50; -int man_mlt_heat = 50; + +double hltInput; /* HLT PID variables */ +double hltOutput; +double hltSetpoint; +double mltInput; /* MLT PID variables */ +double mltOutput; +double mltSetpoint; + extern int debug; extern sys_config Config; extern int lcdHandle; @@ -138,7 +142,7 @@ { char text[81]; - snprintf(text, 8, "%6.2f\001", hlttemp); + snprintf(text, 8, "%6.2f\001", hltInput); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); lcdPosition(lcdHandle, 1, 1); @@ -147,7 +151,7 @@ slcdPosition(slcdHandle, 1, 1); slcdPuts(slcdHandle, text); - snprintf(text, 8, "%6.2f\001", mlttemp); + snprintf(text, 8, "%6.2f\001", mltInput); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); lcdPosition(lcdHandle, 10, 1); @@ -159,11 +163,17 @@ -void percstatus(int hltp, int mltp) +/* + * Third line, show setPoints or heater percentage. + */ +void percstatus(int which) { - char text[11]; + char text[21]; - snprintf(text, 8, "HLT%3d%%", hltp); + if (which) + snprintf(text, 8, "%6.2f\002", hltSetpoint); + else + snprintf(text, 8, "HLT%3d%%", (int)hltOutput); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); lcdPosition(lcdHandle, 1, 2); @@ -172,7 +182,10 @@ slcdPosition(slcdHandle, 1, 2); slcdPuts(slcdHandle, text); - snprintf(text, 8, "MLT%3d%%", mltp); + if (which) + snprintf(text, 8, "%6.2f\002", mltSetpoint); + else + snprintf(text, 8, "MLT%3d%%", (int)mltOutput); #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); lcdPosition(lcdHandle, 10, 2); @@ -184,6 +197,13 @@ +void automatic_brew(units_list *, brew_session *); +void automatic_brew(units_list *unit, brew_session *brew) +{ +} + + + void manual_prompt(void) { switch (manual) { @@ -211,8 +231,8 @@ /* * Manual menu for testing your equipment. */ -int manual_menu(units_list *, double, double); -int manual_menu(units_list *unit, double hlt, double mlt) +int manual_menu(units_list *, int); +int manual_menu(units_list *unit, int seconds) { int key; @@ -225,7 +245,11 @@ } if (key == KEY_RETURN) { manual = MANUAL_NONE; - HLTpercent = MLTpercent = man_mlt_pump = 0; + man_mlt_pump = 0; + PID_setMode(unit->PID_mlt, P_MANUAL); + PID_setMode(unit->PID_hlt, P_MANUAL); + hlt_status(0); + mlt_status(0); device_out(unit->mlt_pump.uuid, man_mlt_pump); } if (key == KEY_ENTER) { @@ -242,7 +266,11 @@ } if (key == KEY_RETURN) { manual = MANUAL_NONE; - HLTpercent = MLTpercent = man_mlt_pump = 0; + man_mlt_pump = 0; + PID_setMode(unit->PID_mlt, P_MANUAL); + PID_setMode(unit->PID_hlt, P_MANUAL); + hlt_status(0); + mlt_status(0); device_out(unit->mlt_pump.uuid, man_mlt_pump); } if (key == KEY_ENTER) { @@ -252,44 +280,46 @@ } break; case MANUAL_HLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); - percstatus(man_hlt_heat, man_mlt_heat); + percstatus((seconds / 2) % 4); slcdDummy(slcdHandle); key = keycheck(); if (key == KEY_RETURN) { - if (HLTpercent) - HLTpercent = 0; - else - HLTpercent = man_hlt_heat; + if (PID_getMode(unit->PID_hlt) == P_MANUAL) { + PID_setMode(unit->PID_hlt, P_AUTOMATIC); + hlt_status(1); + } else { + PID_setMode(unit->PID_hlt, P_MANUAL); + hlt_status(0); + } } - if ((key == KEY_DOWN) && (man_hlt_heat > 1)) - man_hlt_heat--; - if ((key == KEY_UP) && (man_hlt_heat < 100)) - man_hlt_heat++; - if (HLTpercent) - HLTpercent = man_hlt_heat; + if ((key == KEY_DOWN) && (hltSetpoint > 10)) + hltSetpoint -= 1.0; + if ((key == KEY_UP) && (hltSetpoint < 100)) + hltSetpoint += 1.0; if (key == KEY_ESCAPE) { manual = MANUAL_SELHLT; manual_prompt(); } break; case MANUAL_MLT: tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); - percstatus(man_hlt_heat, man_mlt_heat); + percstatus((seconds / 2) % 4); slcdDummy(slcdHandle); key = keycheck(); if (key == KEY_RETURN) { - if (MLTpercent) - MLTpercent = 0; - else - MLTpercent = man_mlt_heat; + if (PID_getMode(unit->PID_mlt) == P_MANUAL) { + PID_setMode(unit->PID_mlt, P_AUTOMATIC); + mlt_status(1); + } else { + PID_setMode(unit->PID_mlt, P_MANUAL); + mlt_status(0); + } } - if ((key == KEY_DOWN) && (man_mlt_heat > 1)) - man_mlt_heat--; - if ((key == KEY_UP) && (man_mlt_heat < 100)) - man_mlt_heat++; - if (MLTpercent) - MLTpercent = man_mlt_heat; + if ((key == KEY_DOWN) && (mltSetpoint > 10)) + mltSetpoint -= 1.0; + if ((key == KEY_UP) && (mltSetpoint < 100)) + mltSetpoint += 1.0; if (key == KEY_ENTER) { if (man_mlt_pump) man_mlt_pump = 0; @@ -320,7 +350,6 @@ long t = 0; #endif time_t now, last = (time_t)0; - static double hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint; long nowmillis, perctimer; prompt(101, NULL); @@ -459,6 +488,8 @@ device_out(unit->hlt_heater.uuid, 0); device_out(unit->mlt_heater.uuid, 0); device_out(unit->mlt_pump.uuid, 0); + hlt_status(0); + mlt_status(0); break; } @@ -495,6 +526,8 @@ 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, 100); PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime); + hlt_status(0); + mlt_status(0); manual = MANUAL_NONE; @@ -530,8 +563,8 @@ if (nowmillis > (perctimer + 50)) { percslot++; if (percfase == PERC_INIT) { - HLTp = HLTpercent; - MLTp = MLTpercent; + HLTp = (int)hltOutput; + MLTp = (int)mltOutput; if ((MLTp + HLTp) > 100) HLTp = 100 - MLTp; /* The HLT has lower priority */ if (MLTp) { @@ -606,8 +639,9 @@ } if (debug && ((seconds % 10) == 1)) { - fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf HLT: In=%.2lf Out=%.2lf Set=%.2lf\n", - mltInput, mltOutput, mltSetpoint, hltInput, hltOutput, hltSetpoint); + fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d HLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d\n", + mltInput, mltOutput, mltSetpoint, PID_getMode(unit->PID_mlt), + hltInput, hltOutput, hltSetpoint, PID_getMode(unit->PID_hlt)); } } @@ -616,12 +650,13 @@ /* * Automate mode */ + automatic_brew(unit, brew); } else if (manual != MANUAL_NONE) { /* * Manual mode */ - manual_menu(unit, hltInput, mltInput); + manual_menu(unit, seconds); if (manual == MANUAL_NONE) { /* * Rewrite the display diff -r c2794ae0def3 -r 1564b60558b1 brewco/devices.c --- a/brewco/devices.c Mon Dec 21 22:53:29 2015 +0100 +++ b/brewco/devices.c Tue Dec 22 15:59:26 2015 +0100 @@ -22,6 +22,7 @@ #include "brewco.h" #include "devices.h" +#include "util.h" #include "xutil.h" #include "keyboard.h" #include "slcd.h" @@ -137,27 +138,11 @@ void hlt_heater(int value) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); - lcdPosition(lcdHandle, 0, 1); -#endif - slcdPosition(slcdHandle, 0, 1); if (value) { leds |= SLED_HLTH; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 5); -#endif - slcdPutchar(slcdHandle, 5); } else { leds &= ~SLED_HLTH; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 6); -#endif - slcdPutchar(slcdHandle, 6); } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif slcdLEDs(slcdHandle); } @@ -165,27 +150,11 @@ void mlt_heater(int value) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); - lcdPosition(lcdHandle, 18, 1); -#endif - slcdPosition(slcdHandle, 18, 1); if (value) { leds |= SLED_MLTH; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 5); -#endif - slcdPutchar(slcdHandle, 5); } else { leds &= ~SLED_MLTH; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 6); -#endif - slcdPutchar(slcdHandle, 6); } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif slcdLEDs(slcdHandle); } @@ -193,27 +162,12 @@ void mlt_pump(int value) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); - lcdPosition(lcdHandle, 19, 1); -#endif - slcdPosition(slcdHandle, 19, 1); + pump_status(value); if (value) { leds |= SLED_MLTP; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 3); -#endif - slcdPutchar(slcdHandle, 3); } else { leds &= ~SLED_MLTP; -#ifdef HAVE_WIRINGPI_H - lcdPutchar(lcdHandle, 4); -#endif - slcdPutchar(slcdHandle, 4); } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif slcdLEDs(slcdHandle); } diff -r c2794ae0def3 -r 1564b60558b1 brewco/util.c --- a/brewco/util.c Mon Dec 21 22:53:29 2015 +0100 +++ b/brewco/util.c Tue Dec 22 15:59:26 2015 +0100 @@ -22,6 +22,10 @@ #include "brewco.h" #include "util.h" +#include "slcd.h" + + +extern int slcdHandle; /* @@ -149,6 +153,81 @@ +void hlt_status(int value) +{ +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); + lcdPosition(lcdHandle, 0, 1); +#endif + slcdPosition(slcdHandle, 0, 1); + if (value) { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 5); +#endif + slcdPutchar(slcdHandle, 5); + } else { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 6); +#endif + slcdPutchar(slcdHandle, 6); + } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_LCD); +#endif +} + + + +void mlt_status(int value) +{ +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); + lcdPosition(lcdHandle, 18, 1); +#endif + slcdPosition(slcdHandle, 18, 1); + if (value) { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 5); +#endif + slcdPutchar(slcdHandle, 5); + } else { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 6); +#endif + slcdPutchar(slcdHandle, 6); + } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_LCD); +#endif +} + + + +void pump_status(int value) +{ +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); + lcdPosition(lcdHandle, 19, 1); +#endif + slcdPosition(slcdHandle, 19, 1); + if (value) { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 3); +#endif + slcdPutchar(slcdHandle, 3); + } else { +#ifdef HAVE_WIRINGPI_H + lcdPutchar(lcdHandle, 4); +#endif + slcdPutchar(slcdHandle, 4); + } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_LCD); +#endif +} + + + /* From ArdBir */ float Arrotonda025(float Num){ // Appoggio la parte intera diff -r c2794ae0def3 -r 1564b60558b1 brewco/util.h --- a/brewco/util.h Mon Dec 21 22:53:29 2015 +0100 +++ b/brewco/util.h Tue Dec 22 15:59:26 2015 +0100 @@ -6,6 +6,9 @@ int file_exist(char *, int); int file_cp(char *, char *); long millis(void); +void hlt_status(int); +void mlt_status(int); +void pump_status(int); #endif