Manual mode added.

Thu, 10 Dec 2015 15:58:01 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 10 Dec 2015 15:58:01 +0100
changeset 451
2247970de278
parent 450
8fe99759c27f
child 452
edc86e2d2eaa

Manual mode added.

brewco/Makefile file | annotate | diff | comparison | revisions
brewco/brewco.c file | annotate | diff | comparison | revisions
brewco/devices.c file | annotate | diff | comparison | revisions
brewco/keyboard.c file | annotate | diff | comparison | revisions
brewco/keyboard.h file | annotate | diff | comparison | revisions
brewco/prompt.c file | annotate | diff | comparison | revisions
--- a/brewco/Makefile	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/Makefile	Thu Dec 10 15:58:01 2015 +0100
@@ -54,8 +54,8 @@
 
 # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
 # Dependencies generated by make depend
-setup.o: brewco.h slcd.h setup.h prompt.h xutil.h keyboard.h
-devices.o: brewco.h devices.h xutil.h keyboard.h
+setup.o: brewco.h slcd.h setup.h prompt.h xutil.h keyboard.h rdconfig.h
+devices.o: brewco.h devices.h xutil.h keyboard.h slcd.h
 xutil.o: brewco.h xutil.h
 brewco.o: brewco.h rdconfig.h rdsession.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
--- a/brewco/brewco.c	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/brewco.c	Thu Dec 10 15:58:01 2015 +0100
@@ -48,6 +48,13 @@
 #endif
 
 
+#define	MANUAL_NONE	0
+#define	MANUAL_SELHLT	1
+#define	MANUAL_SELMLT	2
+#define	MANUAL_HLT	11
+#define	MANUAL_MLT	12
+
+
 /*
  * CGRAM characters
  */
@@ -100,7 +107,8 @@
 int server(void);
 int server(void)
 {
-    int 		rc = 0, run = 1, key;
+    int 		rc = 0, run = 1, key, manual = MANUAL_NONE;
+    int			man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0;
     units_list		*unit;
     brew_session	*brew = NULL;
 #ifndef HAVE_WIRINGPI_H
@@ -182,26 +190,12 @@
     }
 #endif
 
-    /*
-     * Initialize units for processing
-     */
-    for (unit = Config.units; unit; unit = unit->next) {
-	/*
-	 * Safety, turn everything off
-	 */
-	if (unit->active) {
-	    unit->hlt_heater.value = 0;
-	    unit->mlt_heater.value = 0;
-	    unit->mlt_pump.value = 0;
-	}
-    }
-
     if (! Config.units) {
 	/*
 	 * No brewsystems defined, add the first
 	 */
 	prompt(218, NULL);	/*   Add Brewsystem?   */
-	prompt(407, NULL);    /* ---  ---   Ok   --- */
+	prompt(407, NULL);	/* ---  ---   Ok   --- */
 
 	do {
 	    key = keywait();
@@ -213,6 +207,31 @@
     }
 
     /*
+     * Initialize units for processing
+     */
+    for (unit = Config.units; unit; unit = unit->next) {
+	if (unit->active)
+	    break;
+    }
+
+    if (! unit->active) {
+	fprintf(stdout, "No active units found\n");
+    }
+
+    /*
+     * Safety, turn everything off
+     */
+    if (unit->active) {
+	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;
+    }
+
+    /*
      * During automation there will be a state file:
      * ~/.brewco/var/brewing.xml
      * If this file is present, there has been a crash.
@@ -233,11 +252,85 @@
 	    break;
 	}
 
+	/* run_pause code here */
+
 	if (brew) {
 	    /*
 	     * Automate mode
 	     */
 
+	} else if (manual != MANUAL_NONE) {
+	    /*
+	     * 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)
+					    manual = MANUAL_HLT;
+					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)
+					    manual = MANUAL_MLT;
+					break;
+		case MANUAL_HLT:	prompt(0, NULL);
+					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(0, NULL);
+					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;
+	    }
 	} else {
 	    /*
 	     * Not running.
@@ -248,6 +341,9 @@
 	    key = keywait();
 	    if (key == KEY_ENTER)
 		setup();
+	    else if (key == KEY_DOWN) {
+		manual = MANUAL_SELHLT;
+	    }
 	}
 
 	usleep(100000);
--- a/brewco/devices.c	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/devices.c	Thu Dec 10 15:58:01 2015 +0100
@@ -24,6 +24,7 @@
 #include "devices.h"
 #include "xutil.h"
 #include "keyboard.h"
+#include "slcd.h"
 
 
 extern int		debug;
@@ -32,8 +33,10 @@
 
 #ifdef USE_SIMULATOR
 
-extern int	SIM_hlt_value;
-extern int	SIM_mlt_value;
+extern int		SIM_hlt_value;
+extern int		SIM_mlt_value;
+extern uint16_t		leds;
+extern int		slcdHandle;
 
 #endif
 
@@ -207,17 +210,38 @@
 
 #ifdef USE_SIMULATOR
 		if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) {
-		    if ((strcmp((char *)"SimHLTheater", device->address) == 0) || (strcmp((char *)"SimMLTheater", device->address) == 0)) {
+		    if ((strcmp((char *)"SimHLTheater", device->address) == 0) || 
+			(strcmp((char *)"SimMLTheater", device->address) == 0) || 
+		        (strcmp((char *)"SimMLTpump", device->address) == 0)) {
 			if (value != device->value) {
 			    syslog(LOG_NOTICE, "SIM %s value=%d", device->address, value);
 			    if (debug)
 			    	fprintf(stdout, "SIM %s value=%d\n", device->address, value);
 			}
 			device->value = value;
-			if (strcmp((char *)"SimHLTheater", device->address) == 0)
+			if (strcmp((char *)"SimHLTheater", device->address) == 0) {
 			    SIM_hlt_value = value;
-			if (strcmp((char *)"SimMLTheater", device->address) == 0)
+			    if (value)
+				leds |= SLED_HLTH;
+			    else
+				leds &= ~SLED_HLTH;
+			    slcdLEDs(slcdHandle);
+			}
+			if (strcmp((char *)"SimMLTheater", device->address) == 0) {
 			    SIM_mlt_value = value;
+			    if (value)
+				leds |= SLED_MLTH;
+			    else
+				leds &= ~SLED_MLTH;
+			    slcdLEDs(slcdHandle);
+			}
+			if (strcmp((char *)"SimMLTpump", device->address) == 0) {
+			    if (value)
+				leds |= SLED_MLTP;
+			    else
+				leds &= ~SLED_MLTP;
+			    slcdLEDs(slcdHandle);
+			}
 		    }
 		}
 #endif
@@ -524,15 +548,15 @@
 			ndev->address = xstrcpy((char *)"SimMLTtemp");
 			ndev->description = xstrcpy((char *)"Simulated MLT temperature");
 			break;
-		case 3:	ndev->direction = DEVDIR_OUT_ANALOG;
+		case 3:	ndev->direction = DEVDIR_OUT_BIN;
 			ndev->address = xstrcpy((char *)"SimHLTheater");
 			ndev->description = xstrcpy((char *)"Simulated HLT heater");
 			break;
-		case 4:	ndev->direction = DEVDIR_OUT_ANALOG;
+		case 4:	ndev->direction = DEVDIR_OUT_BIN;
 			ndev->address = xstrcpy((char *)"SimMLTheater");
 			ndev->description = xstrcpy((char *)"Simulated MLT heater");
 			break;
-		case 5:	ndev->direction = DEVDIR_OUT_ANALOG;
+		case 5:	ndev->direction = DEVDIR_OUT_BIN;
 			ndev->address = xstrcpy((char *)"SimMLTpump");
 			ndev->description = xstrcpy((char *)"Simulated MLT pump");
 			break;
--- a/brewco/keyboard.c	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/keyboard.c	Thu Dec 10 15:58:01 2015 +0100
@@ -108,6 +108,8 @@
 {
     if (Key_Enter && Key_Up && Key_Down && Key_Return)
 	return KEY_ALL;
+    if (Key_Up && Key_Down)
+	return KEY_ESCAPE;
     if (Key_Up)
 	return KEY_UP;
     if (Key_Down)
--- a/brewco/keyboard.h	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/keyboard.h	Thu Dec 10 15:58:01 2015 +0100
@@ -20,6 +20,7 @@
 #define	KEY_DOWN	2
 #define	KEY_RETURN	3
 #define	KEY_ENTER	4
+#define	KEY_ESCAPE	12
 #define	KEY_ALL		99
 
 
--- a/brewco/prompt.c	Sun Dec 06 20:23:31 2015 +0100
+++ b/brewco/prompt.c	Thu Dec 10 15:58:01 2015 +0100
@@ -132,6 +132,10 @@
 			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 300:	snprintf(message, Config.lcd_cols + 1, text);
 			break;
 	case 301:	snprintf(message, Config.lcd_cols + 1, "      Finished      ");
@@ -164,6 +168,8 @@
 			break;
 	case 412:	snprintf(message, Config.lcd_cols + 1, "Up   Dwn  Exit  Ok  ");
 			break;
+	case 413:	snprintf(message, Config.lcd_cols + 1, "UP* *DWN  heat  --- ");
+			break;
 			//                                      12345678901234567890
 	default:	snprintf(message, Config.lcd_cols + 1, "   N/A        N/A");
     }

mercurial