Moved manual menu to it's own function.

Thu, 10 Dec 2015 21:34:28 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Dec 2015 21:34:28 +0100
changeset 453
76418c89b480
parent 452
edc86e2d2eaa
child 454
78242696c15a

Moved manual menu to it's own function.

brewco/brewco.c file | annotate | diff | comparison | revisions
--- a/brewco/brewco.c	Thu Dec 10 17:31:45 2015 +0100
+++ b/brewco/brewco.c	Thu Dec 10 21:34:28 2015 +0100
@@ -54,6 +54,9 @@
 #define	MANUAL_HLT	11
 #define	MANUAL_MLT	12
 
+int manual		= MANUAL_NONE;
+
+
 
 /*
  * CGRAM characters
@@ -129,16 +132,107 @@
 
 
 
+int manual_menu(units_list *);
+int manual_menu(units_list *unit)
+{
+    int		key;
+    static int	man_hlt_heat, man_mlt_heat, man_mlt_pump;
+
+    switch (manual) {
+        case MANUAL_SELHLT:     prompt(104, NULL);
+                                prompt(219, NULL);
+                                prompt(402, NULL);
+                                key = keywait();
+                                if (key == KEY_DOWN)
+                                    manual = MANUAL_SELMLT;
+                                if (key == KEY_RETURN)
+                                    manual = MANUAL_NONE;
+                                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);
+                                }
+                                break;
+        case MANUAL_SELMLT:     prompt(104, NULL);
+                                prompt(220, NULL);
+                                prompt(404, NULL);
+                                key = keywait();
+                                if (key == KEY_UP)
+                                    manual = MANUAL_SELHLT;
+                                if (key == KEY_RETURN)
+                                    manual = MANUAL_NONE;
+                                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);
+                                }
+                                break;
+        case MANUAL_HLT:        prompt(104, NULL);
+                                prompt(413, NULL);
+
+                                key = keywait();
+                                if (key == KEY_RETURN) {
+                                    if (man_hlt_heat)
+                                        man_hlt_heat = 0;
+                                    else
+                                        man_hlt_heat = 1;
+                                }
+                                if (key == KEY_ESCAPE) {
+                                    manual = MANUAL_SELHLT;
+                                    man_hlt_heat = 0;
+                                }
+                                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);
+                                key = keywait();
+                                if (key == KEY_RETURN) {
+                                    if (man_mlt_heat)
+                                        man_mlt_heat = 0;
+                                    else
+                                        man_mlt_heat = 1;
+                                }
+                                if (key == KEY_ENTER) {
+                                    if (man_mlt_pump)
+                                        man_mlt_pump = 0;
+                                    else
+                                        man_mlt_pump = 1;
+                                }
+                                if (key == KEY_ESCAPE) {
+                                    manual = MANUAL_SELMLT;
+                                    man_mlt_heat = man_mlt_pump = 0;
+                                }
+                                device_out(unit->mlt_heater.uuid, man_mlt_heat);
+                                device_out(unit->mlt_pump.uuid, man_mlt_pump);
+                                break;
+    }
+
+    return 0;
+}
+
+
+
 int server(void);
 int server(void)
 {
-    int 		rc = 0, run = 1, key, manual = MANUAL_NONE;
-    int			man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0;
+    int 		rc = 0, run = 1, key;
+    int			do_init = TRUE;
     units_list		*unit;
     brew_session	*brew = NULL;
 #ifndef HAVE_WIRINGPI_H
     long		t = 0;
 #endif
+    double		hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint;
 
     prompt(101, NULL);
 
@@ -250,10 +344,6 @@
 	if (debug)
 	    fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name);
 	syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name);
-
-	unit->hlt_heater.value = 0;
-	unit->mlt_heater.value = 0;
-	unit->mlt_pump.value = 0;
     }
 
     /*
@@ -277,6 +367,38 @@
 	    break;
 	}
 
+	/*
+	 * Do we need to initialize this unit?
+	 */
+	if (do_init) {
+	    if (debug)
+		fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name);
+	    syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name);
+	    /*
+	     * Turn everything off
+	     */
+	    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);
+
+	    /*
+	     * Initialize PID's
+	     */
+	    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_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_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime);
+
+	    do_init = FALSE;
+	}
+
 	/* run_pause code here */
 
 	if (brew) {
@@ -288,84 +410,7 @@
 	    /*
 	     * Manual mode
 	     */
-	    switch (manual) {
-		case MANUAL_SELHLT:	prompt(0, NULL);
-					prompt(104, NULL);
-					prompt(219, NULL);
-					prompt(402, NULL);
-					key = keywait();
-					if (key == KEY_DOWN)
-					    manual = MANUAL_SELMLT;
-					if (key == KEY_RETURN)
-					    manual = MANUAL_NONE;
-					if (key == KEY_ENTER) {
-						// TODO: prompt for water
-					    manual = MANUAL_HLT;
-					    prompt(0, NULL);
-					    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);
-					}
-					break;
-		case MANUAL_SELMLT:	prompt(0, NULL);
-					prompt(104, NULL);
-					prompt(220, NULL);
-					prompt(404, NULL);
-					key = keywait();
-					if (key == KEY_UP)
-					    manual = MANUAL_SELHLT;
-					if (key == KEY_RETURN)
-					    manual = MANUAL_NONE;
-					if (key == KEY_ENTER) {
-						// TODO: prompt for water
-					    manual = MANUAL_MLT;
-					    prompt(0, NULL);
-					    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);
-					}
-					break;
-		case MANUAL_HLT:	prompt(104, NULL);
-					prompt(413, NULL);
-
-					key = keywait();
-					if (key == KEY_RETURN) {
-					    if (man_hlt_heat)
-						man_hlt_heat = 0;
-					    else
-						man_hlt_heat = 1;
-					}
-					if (key == KEY_ESCAPE) {
-					    manual = MANUAL_SELHLT;
-					    man_hlt_heat = 0;
-					}
-					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);
-					key = keywait();
-					if (key == KEY_RETURN) {
-					    if (man_mlt_heat)
-						man_mlt_heat = 0;
-					    else
-						man_mlt_heat = 1;
-					}
-					if (key == KEY_ENTER) {
-					    if (man_mlt_pump)
-						man_mlt_pump = 0;
-					    else
-						man_mlt_pump = 1;
-					}
-					if (key == KEY_ESCAPE) {
-					    manual = MANUAL_SELMLT;
-					    man_mlt_heat = man_mlt_pump = 0;
-					}
-					device_out(unit->mlt_heater.uuid, man_mlt_heat);
-					device_out(unit->mlt_pump.uuid, man_mlt_pump);
-					break;
-	    }
+	    manual_menu(unit);
 	} else {
 	    /*
 	     * Not running.
@@ -382,7 +427,7 @@
 	    }
 	}
 
-	usleep(100000);
+	usleep(10000);	/* 10 mSec */
 
     } while (run);
 

mercurial