Added prompts for the LCD. Basic processing loop written.

Sat, 28 Nov 2015 13:47:00 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 28 Nov 2015 13:47:00 +0100
changeset 440
8df3252b688f
parent 439
27f7f634c6d3
child 441
bde74a8f2ad7

Added prompts for the LCD. Basic processing loop written.

brewco/brewco.c file | annotate | diff | comparison | revisions
--- a/brewco/brewco.c	Fri Nov 27 22:56:26 2015 +0100
+++ b/brewco/brewco.c	Sat Nov 28 13:47:00 2015 +0100
@@ -80,10 +80,141 @@
 
 
 
+void prompt(int index)
+{
+    char	message[81];
+    int		line;
+
+    switch (index) {
+	case 0:
+#ifdef HAVE_WIRINGPI_H
+			piLock(LOCK_LCD);
+			lcdClear(lcdHandle);
+#endif
+			slcdClear(slcdHandle);
+#ifdef HAVE_WIRINGPI_H
+			piUnlock(LOCK_LCD);
+#endif
+			return;
+	case 101:	snprintf(message, Config.lcd_cols + 1, "    Brewco %s    ", VERSION);
+			break;
+	case 102:	snprintf(message, Config.lcd_cols + 1, "     SETUP MENU     ");
+			break;
+	case 103:	snprintf(message, Config.lcd_cols + 1, "   AUTOMATIC MODE   ");
+			break;
+	case 104:	snprintf(message, Config.lcd_cols + 1, "    MANUAL MODE     ");
+			break;
+	case 111:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Mash In    ");
+			break;
+	case 112:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Fitasi     ");
+			break;
+	case 113:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Glucanasi  ");
+			break;
+	case 114:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Proteasi   ");
+			break;
+	case 115:	snprintf(message, Config.lcd_cols + 1, "AUTO --> B-amilasi  ");
+			break;
+	case 116:	snprintf(message, Config.lcd_cols + 1, "AUTO --> A-amilasi 1");
+			break;
+	case 117:	snprintf(message, Config.lcd_cols + 1, "AUTO --> A-amilasi 2");
+			break;
+	case 118:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Mash Out   ");
+			break;
+	case 121:	snprintf(message, Config.lcd_cols + 1, "AUTO --> Hop   xx   ");
+			break;
+	case 202:	snprintf(message, Config.lcd_cols + 1, "   Manage Recipes   ");
+			break;
+	case 203:	snprintf(message, Config.lcd_cols + 1, " Manage Brewsystems ");
+			break;
+	case 204:	snprintf(message, Config.lcd_cols + 1, "  Manage Simulator  ");
+			break;
+	case 205:	snprintf(message, Config.lcd_cols + 1, "  System parameters ");
+			break;
+	case 206:	snprintf(message, Config.lcd_cols + 1, "   Set Automation   ");
+			break;
+	case 207:	snprintf(message, Config.lcd_cols + 1, "    Delay start?    ");
+			break;
+	case 208:	snprintf(message, Config.lcd_cols + 1, "   Resume Process   ");
+			break;
+	case 209:	snprintf(message, Config.lcd_cols + 1, "    Water Added?    ");
+			break;
+	case 210:	snprintf(message, Config.lcd_cols + 1, "     Pump Prime     ");
+			break;
+	case 211:	snprintf(message, Config.lcd_cols + 1, "    Setting Delay   ");
+			break;
+	case 212:	snprintf(message, Config.lcd_cols + 1, "  To be started in  ");
+			break;
+	case 213:	snprintf(message, Config.lcd_cols + 1, "    Iodine test     ");
+			break;
+	case 214:	snprintf(message, Config.lcd_cols + 1, "   START COOLING    ");
+			break;
+	case 215:	snprintf(message, Config.lcd_cols + 1, "     WHIRLPOOL      ");
+			break;
+	case 216:	snprintf(message, Config.lcd_cols + 1, "  Timing Whirlpool  ");
+			break;
+	case 217:	snprintf(message, Config.lcd_cols + 1, "  Brewing Process   ");
+			break;
+	case 218:	snprintf(message, Config.lcd_cols + 1, "  Add Brewsystem?   ");
+			break;
+	case 301:	snprintf(message, Config.lcd_cols + 1, "     Finished       ");
+			break;
+	case 302:	snprintf(message, Config.lcd_cols + 1, "    Shutting down   ");
+			break;
+	case 401:       snprintf(message, Config.lcd_cols + 1, " --- MAN  AUTO SETUP");
+			break;
+	case 402:       snprintf(message, Config.lcd_cols + 1, " --- dwn  quit  ok  ");
+			break;
+	case 403:       snprintf(message, Config.lcd_cols + 1, " up  dwn  quit  ok  ");
+			break;
+	case 404:       snprintf(message, Config.lcd_cols + 1, " up  ---  quit  ok  ");
+			break;
+	case 405:       snprintf(message, Config.lcd_cols + 1, " UP* *DWN  heat pmp ");
+			break;
+	case 406:       snprintf(message, Config.lcd_cols + 1, " ---  ---  No   Yes ");
+			break;
+	case 407:	snprintf(message, Config.lcd_cols + 1, " ---  ---  Ok   --- ");
+			break;
+	case 408:	snprintf(message, Config.lcd_cols + 1, " UP* *DWN Pause --- ");
+			break;
+	case 409:	snprintf(message, Config.lcd_cols + 1, " Continue: Yes   No ");
+			break;
+	case 410:	snprintf(message, Config.lcd_cols + 1, " UP* *DWN  ---  pmp ");
+			break;
+	case 411:	snprintf(message, Config.lcd_cols + 1, "  Up  Dwn  Exit Ok  ");
+			break;
+			//                                      12345678901234567890
+	default:	snprintf(message, Config.lcd_cols + 1, "   N/A        N/A");
+    }
+
+    if (index < 200)
+	line = 0;
+    else if (index < 300)
+	line = 1;
+    else if (index < 400)
+	line = 2;
+    else
+	line = 3;
+
+    fprintf(stdout, "%d %d '%s'\n", line, Config.lcd_cols, message);
+
+#ifdef HAVE_WIRINGPI_H
+    piLock(LOCK_LCD);
+    lcdPosition(lcdHandle, 0, line);
+    lcdPuts(lcdHandle, message);
+
+#endif
+    slcdPosition(slcdHandle, 0, line);
+    slcdPuts(slcdHandle, message);
+#ifdef HAVE_WIRINGPI_H
+    piUnlock(LOCK_LCD);
+#endif
+}
+
+
 int server(void);
 int server(void)
 {
-    int 	rc = 0, run = 1;
+    int 	rc = 0, run = 1, key;
     units_list	*unit;
 #ifndef HAVE_WIRINGPI_H
     long	t = 0;
@@ -114,33 +245,33 @@
     }
 
 #ifdef HAVE_WIRINGPI_H
-        rc = piThreadCreate(my_panel_loop);
+    rc = piThreadCreate(my_panel_loop);
 #else
-	    rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t );
+    rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t );
 #endif
-	        if (rc) {
-			        fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc);
-				        syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc);
+    if (rc) {
+	fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc);
+	syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc);
 #ifndef HAVE_WIRINGPI_H
-					    } else {
-						            t++;
+    } else {
+	t++;
 #endif
-							        }
+    }
 
 #ifdef USE_SIMULATOR
 #ifdef HAVE_WIRINGPI_H
-		    rc = piThreadCreate(my_simulator_loop);
+    rc = piThreadCreate(my_simulator_loop);
 #else
-		        rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t );
+    rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t );
 #endif
-			    if (rc) {
-				            fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc);
-					            syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc);
+    if (rc) {
+	fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc);
+	syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc);
 #ifndef HAVE_WIRINGPI_H
-						        } else {
-								        t++;
+    } else {
+	t++;
 #endif
-									    }
+    }
 #endif
 
     /*
@@ -154,27 +285,61 @@
 //	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 //    }
 
-#ifdef HAVE_WIRINGPI_H
-        piLock(LOCK_LCD);
-	lcdPosition(lcdHandle, 0, 0);
-        lcdPrintf(lcdHandle, "    Brewco %s", VERSION);
-#endif
-	slcdPosition(slcdHandle, 0, 0);
-	slcdPrintf(slcdHandle, "    Brewco %s", VERSION);
-#ifdef HAVE_WIRINGPI_H
-	piUnlock(LOCK_LCD);
-#endif
+    prompt(101);
+    if (! Config.units) {
+	/*
+	 * No brewsystems defined, add the first
+	 */
+	prompt(218);	/*   Add Brewsystem?   */
+	prompt(407);    /* ---  ---   Ok   --- */
 
+	do {
+	    usleep(10000);
+	    slcdDummy(slcdHandle);
+	    key = keycheck();
+	} while (key != KEY_RETURN);
+    }
+
+    /* Check for a crash and recover */
+
+    prompt(0);
+    prompt(401);
 
     do {
 	if (my_shutdown)
 	    run = 0;
 
+	/*
+	 * If there is no unit, setup a unit
+	 */
+	if (! Config.units) {
+	}
+
+	/*
+	 * Select the active unit
+	 */
+
+	/*
+	 * If running, do the things
+	 */
+
+	/*
+	 * Not running, do manual, setup etc
+	 */
+
 
 	usleep(100000);
 
     } while (run);
 
+    syslog(LOG_NOTICE, "Out of loop");
+    if (debug)
+	fprintf(stdout, (char *)"Out of loop\n");
+
+    prompt(0);
+    prompt(101);
+    prompt(302);
+
     /*
      * Stop units processing in a neat way
      */
@@ -182,15 +347,12 @@
 
     }
 
-    syslog(LOG_NOTICE, "Out of loop");
-    if (debug)
-	fprintf(stdout, (char *)"Out of loop\n");
-
     /*
      * Give threads time to cleanup
      */
     usleep(1500000);
 
+    prompt(0);
 //    stopLCD();
     if (sock != -1) {
 	if (shutdown(sock, SHUT_RDWR)) {

mercurial