Manual mode works with heat percentages.

Sun, 20 Dec 2015 23:26:03 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 20 Dec 2015 23:26:03 +0100
changeset 466
49a5318256f0
parent 465
3aac3276689d
child 467
f4d75ef899f4

Manual mode works with heat percentages.

brewco/brewco.c file | annotate | diff | comparison | revisions
--- a/brewco/brewco.c	Sun Dec 20 20:52:37 2015 +0100
+++ b/brewco/brewco.c	Sun Dec 20 23:26:03 2015 +0100
@@ -38,6 +38,11 @@
 
 
 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;
 extern int              debug;
 extern sys_config       Config;
 extern int              lcdHandle;
@@ -62,6 +67,12 @@
 #define	MANUAL_HLT	11
 #define	MANUAL_MLT	12
 
+#define	PERC_INIT	0
+#define	PERC_MLT	1
+#define	PERC_HLT	2
+#define	PERC_REST	3
+
+
 int manual		= MANUAL_NONE;
 
 
@@ -148,91 +159,110 @@
 
 
 
+void manual_prompt(void)
+{
+    switch (manual) {
+	case MANUAL_SELHLT:	prompt(104, NULL);      /* "    MANUAL MODE     " */
+				prompt(219, NULL);      /* "     Manual HLT     " */
+				prompt(402, NULL);      /* "---  dwn  quit  ok  " */
+				break;
+	case MANUAL_SELMLT:	prompt(104, NULL);      /* "    MANUAL MODE     " */
+				prompt(220, NULL);      /* "     Manual MLT     " */
+				prompt(404, NULL);      /* " up  ---  quit  ok  " */
+				break;
+	case MANUAL_HLT:	prompt(0, NULL);
+				prompt(104, NULL);      /* "    MANUAL MODE     " */
+				prompt(413, NULL);      /* "UP* *DWN  heat  --- " */
+				break;
+	case MANUAL_MLT:	prompt(0, NULL);
+				prompt(104, NULL);      /* "    MANUAL MODE     " */
+				prompt(406, NULL);      /* "UP* *DWN  heat  pmp " */
+				break;
+    }
+}
+
+
+
+/*
+ * Manual menu for testing your equipment.
+ */
 int manual_menu(units_list *, double, double);
 int manual_menu(units_list *unit, double hlt, double mlt)
 {
-    int		key, i;
-    static int	man_hlt_heat, man_mlt_heat, man_mlt_pump;
+    int		key;
 
     switch (manual) {
-        case MANUAL_SELHLT:     prompt(104, NULL);
-                                prompt(219, NULL);
-                                prompt(402, NULL);
-                                key = keywait();
-                                if (key == KEY_DOWN)
+        case MANUAL_SELHLT:     slcdDummy(slcdHandle);
+				key = keycheck();
+                                if (key == KEY_DOWN) {
                                     manual = MANUAL_SELMLT;
-                                if (key == KEY_RETURN)
+				    manual_prompt();
+				}
+                                if (key == KEY_RETURN) {
                                     manual = MANUAL_NONE;
+				    HLTpercent = MLTpercent = man_mlt_pump = 0;
+				    device_out(unit->mlt_pump.uuid, man_mlt_pump);
+				}
                                 if (key == KEY_ENTER) {
                                                 // TODO: prompt for water
                                     manual = MANUAL_HLT;
-                                    prompt(0, NULL);
-				    man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0;
-                                    device_out(unit->hlt_heater.uuid, man_hlt_heat);
-                                    device_out(unit->mlt_heater.uuid, man_mlt_heat);
-                                    device_out(unit->mlt_pump.uuid, man_mlt_pump);
+				    manual_prompt();
                                 }
                                 break;
-        case MANUAL_SELMLT:     prompt(104, NULL);
-                                prompt(220, NULL);
-                                prompt(404, NULL);
-                                key = keywait();
-                                if (key == KEY_UP)
+        case MANUAL_SELMLT:     slcdDummy(slcdHandle);
+				key = keycheck();
+                                if (key == KEY_UP) {
                                     manual = MANUAL_SELHLT;
-                                if (key == KEY_RETURN)
+				    manual_prompt();
+				}
+                                if (key == KEY_RETURN) {
                                     manual = MANUAL_NONE;
+				    HLTpercent = MLTpercent = man_mlt_pump = 0;
+				    device_out(unit->mlt_pump.uuid, man_mlt_pump);
+				}
                                 if (key == KEY_ENTER) {
                                                 // TODO: prompt for water
                                     manual = MANUAL_MLT;
-                                    prompt(0, NULL);
-				    man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0;
-                                    device_out(unit->hlt_heater.uuid, man_hlt_heat);
-                                    device_out(unit->mlt_heater.uuid, man_mlt_heat);
-                                    device_out(unit->mlt_pump.uuid, man_mlt_pump);
+				    manual_prompt();
                                 }
                                 break;
-        case MANUAL_HLT:        prompt(104, NULL);
-                                prompt(413, NULL);
-				tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
+        case MANUAL_HLT:        tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
 				
-				for (i = 1; i < 100; i++) {
-				    usleep(10000);
-				    slcdDummy(slcdHandle);
-                                    key = keycheck();
-				    if ((key != KEY_NONE) || my_shutdown)
-					break;
-				}
+				slcdDummy(slcdHandle);
+                                key = keycheck();
                                 if (key == KEY_RETURN) {
-                                    if (man_hlt_heat)
-                                        man_hlt_heat = 0;
-                                    else
-                                        man_hlt_heat = 1;
+				    if (HLTpercent)
+					HLTpercent = 0;
+				    else
+					HLTpercent = man_hlt_heat;
                                 }
+				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_ESCAPE) {
                                     manual = MANUAL_SELHLT;
-                                    man_hlt_heat = 0;
+				    manual_prompt();
                                 }
-                                device_out(unit->hlt_heater.uuid, man_hlt_heat);
-                                if (debug)
-                                    fprintf(stdout, "device_out(%s, %d) HLT heater\n", unit->hlt_heater.uuid, man_hlt_heat);
                                 break;
-        case MANUAL_MLT:        prompt(104, NULL);
-                                prompt(406, NULL);
-				tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
+        case MANUAL_MLT:        tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput);
 
-				for (i = 1; i < 100; i++) {
-				    usleep(10000);
-				    slcdDummy(slcdHandle);
-				    key = keycheck();
-				    if ((key != KEY_NONE) || my_shutdown)
-					break;
-				}
+				slcdDummy(slcdHandle);
+				key = keycheck();
                                 if (key == KEY_RETURN) {
-                                    if (man_mlt_heat)
-                                        man_mlt_heat = 0;
-                                    else
-                                        man_mlt_heat = 1;
+				    if (MLTpercent)
+					MLTpercent = 0;
+				    else
+					MLTpercent = man_mlt_heat;
                                 }
+				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_ENTER) {
                                     if (man_mlt_pump)
                                         man_mlt_pump = 0;
@@ -241,9 +271,8 @@
                                 }
                                 if (key == KEY_ESCAPE) {
                                     manual = MANUAL_SELMLT;
-                                    man_mlt_heat = man_mlt_pump = 0;
+				    manual_prompt();
                                 }
-                                device_out(unit->mlt_heater.uuid, man_mlt_heat);
                                 device_out(unit->mlt_pump.uuid, man_mlt_pump);
                                 break;
     }
@@ -256,7 +285,7 @@
 int server(void);
 int server(void)
 {
-    int 		rc = 0, run = 1, key, temp;
+    int 		rc = 0, run = 1, key, temp, MLTp, HLTp, percslot, percfase = PERC_INIT;
     int			do_init = TRUE, seconds = 0, minutes = 0;
     units_list		*unit;
     brew_session	*brew = NULL;
@@ -265,6 +294,7 @@
 #endif
     time_t		now, last = (time_t)0;
     static double	hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint;
+    long		nowmillis, perctimer;
 
     prompt(101, NULL);
 
@@ -434,6 +464,9 @@
 	    manual = MANUAL_NONE;
 
 	    do_init = FALSE;
+	    nowmillis = perctimer = millis();
+	    percslot = 0;
+	    percfase = PERC_INIT;
 	}
 
 	/* run_pause code here */
@@ -449,6 +482,60 @@
 //	if (seconds < 3)
 //		        fprintf(stdout, "   mlt rc=%d\n");
 
+	/*
+	 *  50 mSeconds loop for heater elements timing.
+	 */
+	nowmillis = millis();
+	if (nowmillis > (perctimer + 50)) {
+	    percslot++;
+	    if (percfase == PERC_INIT) {
+		HLTp = HLTpercent;
+		MLTp = MLTpercent;
+		if ((MLTp + HLTp) > 100)
+		    HLTp = 100 - MLTp;		/* The HLT has lower priority	*/
+		if (MLTp) {
+		    percfase = PERC_MLT;
+		    device_out(unit->mlt_heater.uuid, 1);
+		} else if (HLTp) {
+		    percfase = PERC_HLT;
+		    device_out(unit->hlt_heater.uuid, 1);
+		} else { 
+		    percfase = PERC_REST;
+		}
+		if (debug)
+		    fprintf(stdout, "  perslot MLT=%d%% HLT=%d%% fase=%d\n", 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 {
+			percfase = PERC_REST;
+		    }
+		}
+	    } 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) {
+		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;
+	}
+
 	now = time(NULL);
 	if (now != last) {
 	    /*
@@ -520,6 +607,7 @@
 		prompt(401, NULL);
 	    } else if (key == KEY_DOWN) {
 		manual = MANUAL_SELHLT;
+		manual_prompt();
 	    }
 	}
 

mercurial