Split some sources

Sat, 28 Nov 2015 21:00:29 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 28 Nov 2015 21:00:29 +0100
changeset 442
1193bd7d460f
parent 441
bde74a8f2ad7
child 443
6b80a37fdf8d

Split some sources

brewco/Makefile file | annotate | diff | comparison | revisions
brewco/brewco.c file | annotate | diff | comparison | revisions
brewco/prompt.c file | annotate | diff | comparison | revisions
brewco/prompt.h file | annotate | diff | comparison | revisions
brewco/setup.c file | annotate | diff | comparison | revisions
brewco/setup.h file | annotate | diff | comparison | revisions
--- a/brewco/Makefile	Sat Nov 28 20:15:38 2015 +0100
+++ b/brewco/Makefile	Sat Nov 28 21:00:29 2015 +0100
@@ -56,14 +56,16 @@
 # Dependencies generated by make depend
 slcd.o: brewco.h slcd.h futil.h xutil.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
 futil.o: brewco.h futil.h
-brewco.o: brewco.h rdconfig.h rdsession.h futil.h xutil.h lcd-pcf8574.h slcd.h lock.h devices.h keyboard.h simulator.h
+brewco.o: brewco.h rdconfig.h rdsession.h futil.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
-rdsession.o: brewco.h rdsession.h futil.h xutil.h
 pid.o: brewco.h pid.h
 xutil.o: brewco.h xutil.h
 keyboard.o: brewco.h lcd-pcf8574.h slcd.h keyboard.h
 simulator.o: brewco.h simulator.h
 rdconfig.o: rdconfig.h brewco.h futil.h xutil.h
+rdsession.o: brewco.h rdsession.h futil.h xutil.h
+prompt.o: brewco.h slcd.h prompt.h
 # End of generated dependencies
--- a/brewco/brewco.c	Sat Nov 28 20:15:38 2015 +0100
+++ b/brewco/brewco.c	Sat Nov 28 21:00:29 2015 +0100
@@ -31,6 +31,9 @@
 #include "devices.h"
 #include "keyboard.h"
 #include "simulator.h"
+#include "prompt.h"
+#include "setup.h"
+
 
 
 int			my_shutdown = FALSE;
@@ -81,208 +84,6 @@
 
 
 
-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
-}
-
-
-
-void editUnit(units_list *unit)
-{
-    if (debug)
-    	fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid);
-
-    if (debug)
-	fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid);
-}
-
-
-
-void addUnit(int number)
-{
-    units_list	*tmpu, *unit = (units_list *)malloc(sizeof(units_list));
-    char	name[81];
-    uuid_t	uu;
-
-    if (debug)
-	fprintf(stdout, "Adding new brewsystem %d\n", number);
-    unit->next = NULL;
-    unit->version = 1;
-    unit->uuid = malloc(37);
-    uuid_generate(uu);
-    uuid_unparse(uu, unit->uuid);
-    snprintf(name, 20, "System %d", number);
-    unit->name = xstrcpy(name);
-    unit->number = number;
-    if (number == 1)
-	unit->active = 1;
-    else
-	unit->active = 0;
-    unit->hlt_sensor = unit->mlt_sensor = NULL;
-    unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL;
-    unit->hlt_heater_mltfirst = 1;
-    unit->pump_cycle = 7;
-    unit->pump_rest = 2;
-    unit->pump_premash = 1;
-    unit->pump_onmash = 1;
-    unit->pump_mashout = 0;
-    unit->pump_onboil = 0;
-    unit->pump_stop = 90;
-    unit->skip_add = 0;
-    unit->skip_remove = 0;
-    unit->skip_iodine = 0;
-    unit->iodine_time = 90;
-    unit->whirlpool = 1;
-    unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var));
-    unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var));
-    InitPID(unit->PID_hlt);
-    InitPID(unit->PID_mlt);
-
-    editUnit(unit);
-
-    if (Config.units == NULL) {
-	Config.units = unit;
-    } else {
-	for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
-	    if (tmpu->next == NULL) {
-		tmpu->next = unit;
-		break;
-	    }
-	}
-    }
-    syslog(LOG_NOTICE, "Brewsystem %d added to the configuration", number);
-    if (debug)
-	fprintf(stdout, "Brewsystem %d added to the configuration\n", number);
-}
-
-
-
 int server(void);
 int server(void)
 {
@@ -420,6 +221,8 @@
 	    prompt(101);
 	    prompt(401);
 	    key = keywait();
+	    if (key == KEY_ENTER)
+		setup();
 	}
 
 	usleep(100000);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brewco/prompt.c	Sat Nov 28 21:00:29 2015 +0100
@@ -0,0 +1,167 @@
+/*****************************************************************************
+ * Copyright (C) 2015
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of the mbsePi-apps
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * mbsePi-apps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+#include "brewco.h"
+#include "slcd.h"
+#include "prompt.h"
+
+
+extern int              debug;
+extern sys_config       Config;
+extern int              lcdHandle;
+extern int		slcdHandle;
+
+
+
+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 Devices   ");
+			break;
+	case 205:	snprintf(message, Config.lcd_cols + 1, "  Manage Simulators ");
+			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, "---  ---  quit  ok  ");
+			break;
+	case 406:       snprintf(message, Config.lcd_cols + 1, "UP* *DWN  heat  pmp ");
+			break;
+	case 407:       snprintf(message, Config.lcd_cols + 1, "---  ---   No   Yes ");
+			break;
+	case 408:	snprintf(message, Config.lcd_cols + 1, "---  ---   Ok   --- ");
+			break;
+	case 409:	snprintf(message, Config.lcd_cols + 1, "UP* *DWN  Pause --- ");
+			break;
+	case 410:	snprintf(message, Config.lcd_cols + 1, " Continue: Yes  No  ");
+			break;
+	case 411:	snprintf(message, Config.lcd_cols + 1, "UP* *DWN  ---   pmp ");
+			break;
+	case 412:	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
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brewco/prompt.h	Sat Nov 28 21:00:29 2015 +0100
@@ -0,0 +1,6 @@
+#ifndef _PROMPT_H
+#define	_PROMPT_H
+
+void prompt(int);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brewco/setup.c	Sat Nov 28 21:00:29 2015 +0100
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (C) 2015
+ *   
+ * Michiel Broek <mbroek at mbse dot eu>
+ *
+ * This file is part of the mbsePi-apps
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * mbsePi-apps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with ThermFerm; see the file COPYING.  If not, write to the Free
+ * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *****************************************************************************/
+
+#include "brewco.h"
+#include "slcd.h"
+#include "setup.h"
+#include "prompt.h"
+#include "xutil.h"
+#include "keyboard.h"
+
+
+extern int		my_shutdown;
+extern int              debug;
+extern sys_config       Config;
+extern int              lcdHandle;
+extern int		slcdHandle;
+
+
+
+void editUnit(units_list *unit)
+{
+    if (debug)
+    	fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid);
+
+    if (debug)
+	fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid);
+}
+
+
+
+void addUnit(int number)
+{
+    units_list	*tmpu, *unit = (units_list *)malloc(sizeof(units_list));
+    char	name[81];
+    uuid_t	uu;
+
+    if (debug)
+	fprintf(stdout, "Adding new brewsystem %d\n", number);
+    unit->next = NULL;
+    unit->version = 1;
+    unit->uuid = malloc(37);
+    uuid_generate(uu);
+    uuid_unparse(uu, unit->uuid);
+    snprintf(name, 20, "System %d", number);
+    unit->name = xstrcpy(name);
+    unit->number = number;
+    if (number == 1)
+	unit->active = 1;
+    else
+	unit->active = 0;
+    unit->hlt_sensor = unit->mlt_sensor = NULL;
+    unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL;
+    unit->hlt_heater_mltfirst = 1;
+    unit->pump_cycle = 7;
+    unit->pump_rest = 2;
+    unit->pump_premash = 1;
+    unit->pump_onmash = 1;
+    unit->pump_mashout = 0;
+    unit->pump_onboil = 0;
+    unit->pump_stop = 90;
+    unit->skip_add = 0;
+    unit->skip_remove = 0;
+    unit->skip_iodine = 0;
+    unit->iodine_time = 90;
+    unit->whirlpool = 1;
+    unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var));
+    unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var));
+    InitPID(unit->PID_hlt);
+    InitPID(unit->PID_mlt);
+
+    editUnit(unit);
+
+    if (Config.units == NULL) {
+	Config.units = unit;
+    } else {
+	for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
+	    if (tmpu->next == NULL) {
+		tmpu->next = unit;
+		break;
+	    }
+	}
+    }
+    syslog(LOG_NOTICE, "Brewsystem %d added to the configuration", number);
+    if (debug)
+	fprintf(stdout, "Brewsystem %d added to the configuration\n", number);
+}
+
+
+
+void setup(void)
+{
+    int		key, option = 202;
+
+    for (;;) {
+	if (debug)
+	    fprintf(stdout, "setup() option=%d\n", option);
+	prompt(0);
+	prompt(102);
+	prompt(option);
+	if (option == 202)
+	    prompt(402);
+#ifdef USE_SIMULATOR
+	else if (option == 205)
+#else
+	else if (option == 204)
+#endif
+	    prompt(404);
+	else
+	    prompt(403);
+
+	key = keywait();
+
+	if ((key == KEY_RETURN) || my_shutdown)
+	    return;
+	if ((key == KEY_UP) && (option > 202)) {
+	    option--;
+	}
+#ifdef USE_SIMULATOR
+	if ((key == KEY_DOWN) && (option < 205)) {
+#else
+	if ((key == KEY_DOWN) && (option < 204)) {
+#endif
+	    option++;
+	}
+
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/brewco/setup.h	Sat Nov 28 21:00:29 2015 +0100
@@ -0,0 +1,9 @@
+#ifndef _SETUP_H
+#define	_SETUP_H
+
+
+void editUnit(units_list *);
+void addUnit(int);
+void setup(void);
+
+#endif

mercurial