brewco/brewco.c

Sun, 27 Dec 2015 20:52:52 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Dec 2015 20:52:52 +0100
changeset 479
0e6a1163e6e3
parent 478
fe8bf61cde06
permissions
-rw-r--r--

Bild target temperature 0.1 degree higher. Removed debug log from the simulator

409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2015
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
23 #include "brewco.h"
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 #include "rdconfig.h"
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
25 #include "rdsession.h"
459
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
26 #include "rdrecipes.h"
446
78e9d5234d15 Switched to PID code from Arduino
Michiel Broek <mbroek@mbse.eu>
parents: 444
diff changeset
27 #include "util.h"
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "xutil.h"
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
29 #include "lcd-pcf8574.h"
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
30 #include "slcd.h"
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
31 #include "lock.h"
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
32 #include "devices.h"
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
33 #include "keyboard.h"
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
34 #include "simulator.h"
442
1193bd7d460f Split some sources
Michiel Broek <mbroek@mbse.eu>
parents: 441
diff changeset
35 #include "prompt.h"
1193bd7d460f Split some sources
Michiel Broek <mbroek@mbse.eu>
parents: 441
diff changeset
36 #include "setup.h"
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
37 #include "logger.h"
442
1193bd7d460f Split some sources
Michiel Broek <mbroek@mbse.eu>
parents: 441
diff changeset
38
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 int my_shutdown = FALSE;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
42 int mlt_pump_state = 0;
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
43
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
44 double hltInput; /* HLT PID variables */
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
45 double hltOutput;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
46 double hltSetpoint;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
47 double mltInput; /* MLT PID variables */
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
48 double mltOutput;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
49 double mltSetpoint;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
50
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 extern int debug;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 extern sys_config Config;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
53 extern a_recipe *recipes;
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 extern int lcdHandle;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
55 extern int slcdHandle;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
56 extern int sock;
474
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
57
456
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
58 #ifdef USE_SIMULATOR
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
59 extern int SIM_cooler;
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
60 #endif
464
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
61 char *etcpath = NULL;
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
62 char *varpath = NULL;
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
63
456
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
64
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
65
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
66 #ifndef HAVE_WIRINGPI_H
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
67 pthread_t threads[5];
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 #endif
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
71 #define MANUAL_NONE 0
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
72 #define MANUAL_SELHLT 1
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
73 #define MANUAL_SELMLT 2
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
74 #define MANUAL_HLT 11
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
75 #define MANUAL_MLT 12
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
76
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
77 #define PERC_INIT 0
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
78 #define PERC_MLT 1
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
79 #define PERC_HLT 2
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
80 #define PERC_REST 3
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
81
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
82
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
83 int manual = MANUAL_NONE;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
84
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
85
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
86
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
87 /*
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
88 * CGRAM characters
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
89 */
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
90 unsigned char degC[8] = { 0b01000, 0b10100, 0b01000, 0b00111, 0b01000, 0b01000, 0b01000, 0b00111 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
91 unsigned char degF[8] = { 0b01000, 0b10100, 0b01000, 0b00111, 0b00100, 0b00110, 0b00100, 0b00100 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
92 unsigned char SP_Symbol[8] = { 0b11100, 0b10000, 0b11100, 0b00111, 0b11101, 0b00111, 0b00100, 0b00100 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
93 unsigned char PumpONOFF[8] = { 0b00000, 0b01110, 0b01010, 0b01110, 0b01000, 0b01000, 0b01000, 0b00000 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
94 unsigned char RevPumpONOFF[8] = { 0b11111, 0b10001, 0b10101, 0b10001, 0b10111, 0b10111, 0b10111, 0b11111 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
95 unsigned char HeatONOFF[8] = { 0b00000, 0b01010, 0b01010, 0b01110, 0b01110, 0b01010, 0b01010, 0b00000 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
96 unsigned char RevHeatONOFF[8] = { 0b11111, 0b10101, 0b10101, 0b10001, 0b10001, 0b10101, 0b10101, 0b11111 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
97 unsigned char Language[8] = { 0b11111, 0b00010, 0b01000, 0b11111, 0b00000, 0b10001, 0b10101, 0b11111 };
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
98
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
99
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 void help(void);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 void die(int);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 void help(void)
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 fprintf(stdout, "mbsePi-apps brewco v%s starting\n\n", VERSION);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 fprintf(stdout, "Usage: brewco [-d] [-h]\n");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 fprintf(stdout, " -d --debug Debug and run in foreground\n");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 fprintf(stdout, " -h --help Display this help\n");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 void die(int onsig)
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 switch (onsig) {
456
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
118 #ifdef USE_SIMULATOR
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
119 case SIGUSR1: syslog(LOG_NOTICE, "Got SIGUSR1, start cooler");
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
120 SIM_cooler = TRUE;
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
121 return;
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
122 case SIGUSR2: syslog(LOG_NOTICE, "Got SIGUSR2, stop cooler");
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
123 SIM_cooler = FALSE;
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
124 return;
045db83dd013 Build a simulated immersion chiller. It will start on SIGUSR1 signal and stop on a SIGUSR2 signal. Hardcoded is te coolwater temperature at 14 degrees celcius.
Michiel Broek <mbroek@mbse.eu>
parents: 455
diff changeset
125 #endif
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 case SIGSEGV: syslog(LOG_NOTICE, "Got SIGSEGV, shutting down");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 my_shutdown = TRUE;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 exit(SIGSEGV);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 default: syslog(LOG_NOTICE, "die() on signal %d", onsig);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 my_shutdown = TRUE;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
144 void tempstatus(void)
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
145 {
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
146 char text[81];
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
147
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
148 snprintf(text, 8, "%6.2f\001", hltInput);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
149 #ifdef HAVE_WIRINGPI_H
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
150 piLock(LOCK_LCD);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
151 lcdPosition(lcdHandle, 1, 1);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
152 lcdPuts(lcdHandle, text);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
153 #endif
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
154 slcdPosition(slcdHandle, 1, 1);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
155 slcdPuts(slcdHandle, text);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
156
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
157 snprintf(text, 8, "%6.2f\001", mltInput);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
158 #ifdef HAVE_WIRINGPI_H
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
159 piLock(LOCK_LCD);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
160 lcdPosition(lcdHandle, 10, 1);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
161 lcdPuts(lcdHandle, text);
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
162 #endif
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
163 slcdPosition(slcdHandle, 10, 1);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
164 slcdPuts(slcdHandle, text);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
165 }
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
166
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
167
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
168
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
169 /*
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
170 * Third line, show setPoints or heater percentage.
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
171 */
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
172 void percstatus(int which)
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
173 {
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
174 char text[21];
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
175
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
176 if (which)
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
177 snprintf(text, 8, "%6.2f\002", hltSetpoint);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
178 else
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
179 snprintf(text, 8, "HLT%3d%%", (int)hltOutput);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
180 #ifdef HAVE_WIRINGPI_H
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
181 piLock(LOCK_LCD);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
182 lcdPosition(lcdHandle, 1, 2);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
183 lcdPuts(lcdHandle, text);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
184 #endif
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
185 slcdPosition(slcdHandle, 1, 2);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
186 slcdPuts(slcdHandle, text);
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
187
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
188 if (which)
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
189 snprintf(text, 8, "%6.2f\002", mltSetpoint);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
190 else
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
191 snprintf(text, 8, "MLT%3d%%", (int)mltOutput);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
192 #ifdef HAVE_WIRINGPI_H
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
193 piLock(LOCK_LCD);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
194 lcdPosition(lcdHandle, 10, 2);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
195 lcdPuts(lcdHandle, text);
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
196 #endif
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
197 slcdPosition(slcdHandle, 10, 2);
452
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
198 slcdPuts(slcdHandle, text);
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
199 }
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
200
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
201
edc86e2d2eaa Changed device outputs and status leds.
Michiel Broek <mbroek@mbse.eu>
parents: 451
diff changeset
202
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
203 /*
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
204 * Third line during boil, only MLT status
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
205 */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
206 void mltstatus(void)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
207 {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
208 char text[21];
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
209
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
210 snprintf(text, 20, "MLT %3d%% %6.2f\002 ", (int)mltOutput, mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
211 #ifdef HAVE_WIRINGPI_H
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
212 piLock(LOCK_LCD);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
213 lcdPosition(lcdHandle, 0, 2);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
214 lcdPuts(lcdHandle, text);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
215 #endif
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
216 slcdPosition(slcdHandle, 0, 2);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
217 slcdPuts(slcdHandle, text);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
218 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
219
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
220
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
221
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
222 void timestatus(int row, int timeval)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
223 {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
224 char text[21];
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
225 int hours, mins, val = timeval;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
226
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
227 hours = val / 3600;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
228 val -= (hours * 3600);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
229 mins = val / 60;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
230 val -= (mins * 60);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
231
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
232 snprintf(text, 20, " %02d:%02d:%02d ", hours, mins, val);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
233 #ifdef HAVE_WIRINGPI_H
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
234 piLock(LOCK_LCD);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
235 lcdPosition(lcdHandle, 0, row);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
236 lcdPuts(lcdHandle, text);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
237 #endif
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
238 slcdPosition(slcdHandle, 0, row);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
239 slcdPuts(slcdHandle, text);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
240 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
241
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
242
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
243
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
244 int set_HLT_heater(units_list *unit, int state, double val)
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
245 {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
246 if (strcmp(unit->hlt_heater.uuid, (char *)"00000000-0000-0000-0000-000000000000") == 0)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
247 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
248
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
249 hltSetpoint = val;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
250
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
251 if (state && (PID_getMode(unit->PID_hlt) == P_MANUAL)) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
252 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
253 PID_setMode(unit->PID_hlt, P_AUTOMATIC);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
254 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
255 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
256 if (! state && (PID_getMode(unit->PID_hlt) == P_AUTOMATIC)) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
257 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
258 PID_setMode(unit->PID_hlt, P_MANUAL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
259 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
260 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
261
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
262 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
263 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
264
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
265
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
266
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
267 int set_MLT_heater(units_list *unit, int state, double val)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
268 {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
269 if (strcmp(unit->mlt_heater.uuid, (char *)"00000000-0000-0000-0000-000000000000") == 0)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
270 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
271
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
272 mltSetpoint = val;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
273
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
274 if (state && (PID_getMode(unit->PID_mlt) == P_MANUAL)) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
275 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
276 PID_setMode(unit->PID_mlt, P_AUTOMATIC);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
277 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
278 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
279 if (! state && (PID_getMode(unit->PID_mlt) == P_AUTOMATIC)) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
280 mlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
281 PID_setMode(unit->PID_mlt, P_MANUAL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
282 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
283 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
284
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
285 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
286 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
287
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
288
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
289
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
290 int set_MLT_pump(units_list *unit, int state)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
291 {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
292 if (strcmp(unit->mlt_pump.uuid, (char *)"00000000-0000-0000-0000-000000000000") == 0)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
293 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
294
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
295 if (state && ! mlt_pump_state) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
296 device_out(unit->mlt_pump.uuid, 1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
297 mlt_pump_state = 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
298 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
299 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
300 if (! state && mlt_pump_state) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
301 device_out(unit->mlt_pump.uuid, 0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
302 mlt_pump_state = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
303 return 1;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
304 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
305
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
306 return 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
307 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
308
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
309
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
310
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
311 void automatic_brew(units_list *, brew_session *, a_recipe *, int, int);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
312 void automatic_brew(units_list *unit, brew_session *brew, a_recipe *recipe, int dosave, int seconds)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
313 {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
314 int key, save = dosave, i;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
315 char data[128];
474
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
316 static int mash_fase = MASH_NA, hopstand = 0, last_step = STEP_NA, last_fase = -1, oldsec = 75, startdelay = 0;
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
317
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
318 if (brew->brewstep != last_step) {
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
319 snprintf(data, 40, brewstep_name(last_step));
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
320 syslog(LOG_NOTICE, "AUTO: brewstep %s to %s", data, brewstep_name(brew->brewstep));
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
321 }
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
322
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
323 switch (brew->brewstep) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
324 case STEP_NA: if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
325 fprintf(stdout, "auto: init recipe: %s-%s unit: %s\n", recipe->code, recipe->name, unit->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
326 syslog(LOG_NOTICE, "AUTO: starting new brew, recipe: %s-%s unit: %s", recipe->code, recipe->name, unit->name);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
327 brew->brewstep = STEP_BREWINIT;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
328 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
329
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
330 case STEP_BREWINIT: prompt(103, NULL); /* " AUTOMATIC MODE " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
331 prompt(207, NULL); /* " Delay start? " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
332 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
333 prompt(407, NULL); /* "--- --- No Yes " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
334 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
335 fprintf(stdout, "step brewinit\n");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
336 key = keywait();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
337 if (key == KEY_RETURN) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
338 brew->brewstep = STEP_WATERCHECK;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
339 startdelay = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
340 syslog(LOG_NOTICE, "AUTO: brew initialize, direct start selected");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
341 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
342 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
343 if (key == KEY_ENTER) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
344 startdelay = 30;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
345 editInteger(&startdelay, 10, 960, 10, (char *)"Start delay", (char *)"mins");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
346 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
347 syslog(LOG_NOTICE, "AUTO: brew initialize");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
348 brew->brewstep = STEP_WATERCHECK;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
349 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
350
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
351 case STEP_WATERCHECK: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
352 prompt(111, NULL); /* "AUTO --> Mash In " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
353 prompt(209, NULL); /* " Water Added? " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
354 prompt(300, NULL);
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
355 prompt(407, NULL); /* "--- --- No Yes " */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
356 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
357 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
358 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
359 key = keycheck();
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
360 if (key == KEY_ENTER) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
361 brew->brewstep = STEP_PUMPPRIME;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
362 syslog(LOG_NOTICE, "AUTO: confirmed water added");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
363 }
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
364 if (key == KEY_RETURN) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
365 syslog(LOG_NOTICE, "AUTO: aborted water added");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
366 brew->brewstep = STEP_CLEANUP;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
367 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
368 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
369
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
370 case STEP_PUMPPRIME: if (brew->brewstep != last_step) {
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
371 prompt(100, NULL); /* " " */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
372 prompt(210, NULL); /* " Pump Prime " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
373 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
374 prompt(400, NULL); /* " " */
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
375 hlt_status(0);
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
376 mlt_status(0);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
377 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
378 }
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
379 for (i = 1; i < 6; i++) {
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
380 if (set_MLT_pump(unit, 1))
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
381 syslog(LOG_NOTICE, "AUTO: pump prime %d turn %s MLT pump", i, mlt_pump_state ? "on":"off");
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
382 usleep(750000 + (i * 250000)); /* 250 + i * 250 mSec */
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
383 if (set_MLT_pump(unit, 0))
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
384 syslog(LOG_NOTICE, "AUTO: pump prime %d turn %s MLT pump", i, mlt_pump_state ? "on":"off");
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
385 usleep(350000); /* 350 mSec */
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
386 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
387 brew->brewstep = STEP_WAITSTART;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
388 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
389
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
390 case STEP_WAITSTART: if (startdelay == 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
391 brew->brewstep = STEP_PREMASH;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
392 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
393 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
394 if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
395 brew->timeout = startdelay * 60;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
396 prompt(111, NULL); /* "AUTO --> Mash In " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
397 prompt(212, NULL); /* " To be started in " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
398 prompt(410, NULL); /* " Continue: Yes No " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
399 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
400 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
401 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
402 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
403 brew->timeout--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
404 if (brew->timeout <= 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
405 syslog(LOG_NOTICE, "AUTO: delayed start time reached");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
406 brew->brewstep = STEP_PREMASH;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
407 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
408 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
409 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
410 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
411 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
412 if (key == KEY_RETURN) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
413 syslog(LOG_NOTICE, "AUTO: delayed start skipped by user");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
414 brew->brewstep = STEP_PREMASH;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
415 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
416 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
417
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
418 case STEP_PREMASH: if (brew->brewstep != last_step) {
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
419 prompt(111, NULL); /* "AUTO --> Prepare " */
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
420 prompt(300, NULL); /* " " */
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
421 prompt(418, NULL); /* "--- --- Pause --- " */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
422 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
423 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
424 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
425 pump_status(unit->pump_premash);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
426 last_step = brew->brewstep;
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
427 initlog(brew->name);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
428 }
478
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
429 if (oldsec != seconds) {
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
430 tempstatus();
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
431 percstatus((seconds / 2) % 4);
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
432 oldsec = seconds;
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
433 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
434 if (set_HLT_heater(unit, 1, 85.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
435 syslog(LOG_NOTICE, "AUTO: premash turn on HLT at %6.2f", hltSetpoint);
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
436 if (set_MLT_heater(unit, 1, 10.0))
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
437 syslog(LOG_NOTICE, "AUTO: premash turn on MLT at %6.2f", mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
438 if (set_MLT_pump(unit, unit->pump_premash))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
439 syslog(LOG_NOTICE, "AUTO: premash turn %s MLT pump", mlt_pump_state ? "on":"off");
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
440 if (hltInput >= 85.0) {
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
441 brew->brewstep = STEP_MASHING;
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
442 brew->mashstep = 0;
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
443 mash_fase = MASH_NA;
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
444 save = TRUE;
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
445 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
446 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
447
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
448 case STEP_MASHING: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
449 prompt(111 + brew->mashstep, NULL); /* "AUTO --> [mashname] " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
450 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
451 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
452 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
453 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
454 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
455 pump_status(unit->pump_onmash);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
456 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
457 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
458 if (set_HLT_heater(unit, 1, 85.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
459 syslog(LOG_NOTICE, "AUTO: mash turn on HLT at %6.2f", hltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
460 if (set_MLT_heater(unit, 1, recipe->mash[brew->mashstep].setpoint))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
461 syslog(LOG_NOTICE, "AUTO: mash turn on MLT at %6.2f", mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
462
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
463 switch (mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
464 case MASH_NA: if (recipe->mash[brew->mashstep].skip) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
465 syslog(LOG_NOTICE, "AUTO: skipping mash step %d", brew->mashstep);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
466 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
467 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
468 mltSetpoint = recipe->mash[brew->mashstep].setpoint;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
469 brew->timeout = recipe->mash[brew->mashstep].duration * 60;
476
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
470 mash_fase = MASH_HEATING;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
471 syslog(LOG_NOTICE, "AUTO: mash step %d fase NA, setpoint %6.2f, duration %d",
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
472 brew->mashstep, mltSetpoint, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
473 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
474 if (brew->mashstep == 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
475 brew->starttime = time(NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
476 save = TRUE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
477 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
478 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
479
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
480 case MASH_PROMPT: if (last_fase != mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
481 prompt(111 + brew->mashstep, NULL); /* "AUTO --> [mashname] " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
482 prompt(219, NULL); /* " Mash added? " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
483 prompt(300, NULL);
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
484 prompt(407, NULL); /* "--- --- No Yes " */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
485 last_fase = mash_fase;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
486 }
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
487 if (set_MLT_pump(unit, 0)) /* Off during mash add */
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
488 syslog(LOG_NOTICE, "AUTO: mash turn %s MLT pump", mlt_pump_state ? "on":"off");
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
489 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
490 key = keycheck();
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
491 if (key == KEY_ENTER) {
476
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
492 mash_fase = MASH_NA;
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
493 brew->mashstep++;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
494 syslog(LOG_NOTICE, "AUTO: confirmed mash added");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
495 }
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
496 if (key == KEY_RETURN) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
497 syslog(LOG_NOTICE, "AUTO: aborted mash added");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
498 brew->brewstep = STEP_CLEANUP;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
499 brew->mashstep = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
500 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
501 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
502
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
503 case MASH_IODINE: if (last_fase != mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
504 prompt(118, NULL); /* "AUTO --> Mash Out " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
505 prompt(213, NULL); /* " Iodine test " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
506 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
507 prompt(410, NULL); /* " Continue: Yes No " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
508 last_fase = mash_fase;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
509 }
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
510 if (set_MLT_pump(unit, unit->pump_onmash))
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
511 syslog(LOG_NOTICE, "AUTO: mash turn %s MLT pump", mlt_pump_state ? "on":"off");
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
512 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
513 brew->timeout--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
514 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
515 if (brew->timeout <= 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
516 syslog(LOG_NOTICE, "AUTO: mash IODINE test timeout");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
517 mash_fase = MASH_NA;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
518 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
519 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
520 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
521 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
522 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
523 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
524 if (key == KEY_RETURN) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
525 syslog(LOG_NOTICE, "AUTO: mash IODINE test confirmed");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
526 mash_fase = MASH_NA;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
527 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
528 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
529 if (key == KEY_ENTER) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
530 syslog(LOG_NOTICE, "AUTO: mash IODINE test declined");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
531 mash_fase = MASH_REST;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
532 brew->timeout = 600; /* Add 10 more minutes */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
533 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
534 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
535
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
536 case MASH_HEATING: if (last_fase != mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
537 prompt(111 + brew->mashstep, NULL); /* "AUTO --> [mashname] " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
538 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
539 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
540 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
541 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
542 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
543 pump_status(unit->pump_onmash);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
544 last_fase = mash_fase;
478
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
545 syslog(LOG_NOTICE, "AUTO: mash step %d fase HEATING started", brew->mashstep);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
546 }
477
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
547 if (set_MLT_pump(unit, unit->pump_onmash))
9167ad4c2e77 Renamed Mash-in step to Prepare on the display. Don't run the pump when the mash is added. When preparing the mash, first heat the HLT, and then the MLT so that both have the chance to reach their target temperatures.
Michiel Broek <mbroek@mbse.eu>
parents: 476
diff changeset
548 syslog(LOG_NOTICE, "AUTO: mash turn %s MLT pump", mlt_pump_state ? "on":"off");
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
549 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
550 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
551 percstatus((seconds / 2) % 4);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
552 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
553 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
554 if (mltInput > mltSetpoint) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
555 syslog(LOG_NOTICE, "AUTO: mash step %d fase HEATING reached %6.2f", brew->mashstep, mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
556 mash_fase = MASH_REST;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
557 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
558 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
559
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
560 case MASH_REST: if (last_fase != mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
561 prompt(111 + brew->mashstep, NULL); /* "AUTO --> [mashname] " */
474
fe1c3e3e90dc Improved steps logging. Some small fixes in the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 473
diff changeset
562 prompt(200, NULL);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
563 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
564 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
565 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
566 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
567 pump_status(unit->pump_onmash);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
568 last_fase = mash_fase;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
569 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
570 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
571 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
572 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
573 if (brew->mashstep == 7) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
574 /*
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
575 * During mash-out rest, allow the grain to sink
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
576 */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
577 if (set_MLT_pump(unit, unit->pump_mashout))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
578 syslog(LOG_NOTICE, "AUTO: mash-out turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
579 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
580 if (set_MLT_pump(unit, unit->pump_onmash))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
581 syslog(LOG_NOTICE, "AUTO: mash turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
582 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
583 brew->timeout--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
584 if (brew->timeout <= 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
585 syslog(LOG_NOTICE, "AUTO: mash step %d fase REST done", brew->mashstep);
476
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
586 if ((brew->mashstep == 0) && ! unit->skip_add) {
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
587 mash_fase = MASH_PROMPT;
8f159cd4f5fc Moved mash added question to after mash rest mash-in step.
Michiel Broek <mbroek@mbse.eu>
parents: 475
diff changeset
588 } else if ((brew->mashstep == 6) && ! unit->skip_iodine) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
589 mash_fase = MASH_IODINE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
590 brew->timeout = unit->iodine_time * 60;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
591 } else if (brew->mashstep == 7) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
592 mash_fase = MASH_DONE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
593 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
594 mash_fase = MASH_NA;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
595 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
596 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
597 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
598 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
599 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
600 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
601
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
602 case MASH_DONE: syslog(LOG_NOTICE, "AUTO: mash step %d fase DONE", brew->mashstep);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
603 if (set_MLT_heater(unit, 1, recipe->mash[7].setpoint))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
604 syslog(LOG_NOTICE, "AUTO: mash done turn MLT off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
605 if (set_MLT_pump(unit, 0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
606 syslog(LOG_NOTICE, "AUTO: mash done turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
607 brew->mashstep = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
608 brew->brewstep = STEP_MASHREMOVE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
609 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
610 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
611 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
612
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
613 case STEP_MASHREMOVE: if (unit->skip_remove) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
614 syslog(LOG_NOTICE, "AUTO: skipping Mash remove");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
615 brew->brewstep = STEP_PREBOIL;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
616 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
617 if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
618 prompt(118, NULL); /* "AUTO --> Mash Out " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
619 prompt(220, NULL); /* " Mash Removed? " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
620 prompt(300, NULL);
478
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
621 prompt(407, NULL); /* "--- --- No Yes " */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
622 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
623 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
624 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
625 key = keycheck();
478
fe8bf61cde06 The simulator now simulates the heater power in Watts. Changed Mash Remove? prompt.
Michiel Broek <mbroek@mbse.eu>
parents: 477
diff changeset
626 if (key == KEY_ENTER) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
627 syslog(LOG_NOTICE, "AUTO: Confirmed Mash removed");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
628 brew->brewstep = STEP_PREBOIL;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
629 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
630 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
631 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
632
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
633 case STEP_PREBOIL: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
634 prompt(119, NULL); /* "AUTO --> Boil " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
635 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
636 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
637 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
638 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
639 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
640 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
641 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
642 pump_status(unit->pump_onboil && (mltInput < unit->pump_stop));
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
643 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
644 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
645 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
646 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
647 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
648 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
649 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
650 if (set_HLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
651 syslog(LOG_NOTICE, "AUTO: preboil turn off HLT");
479
0e6a1163e6e3 Bild target temperature 0.1 degree higher. Removed debug log from the simulator
Michiel Broek <mbroek@mbse.eu>
parents: 478
diff changeset
652 if (set_MLT_heater(unit, 1, 100.1))
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
653 syslog(LOG_NOTICE, "AUTO: preboil turn on MLT to boil");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
654 if (set_MLT_pump(unit, unit->pump_onboil && (mltInput < unit->pump_stop)))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
655 syslog(LOG_NOTICE, "AUTO: preboil turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
656 if (mltInput > 99.2) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
657 syslog(LOG_NOTICE, "AUTO: reached boil temperature %.2f, start %d minutes boil", mltInput, recipe->boiltime);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
658 brew->brewstep = STEP_BOILING;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
659 brew->boiltimer = recipe->boiltime * 60;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
660 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
661 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
662
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
663 case STEP_BOILING: if (set_HLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
664 syslog(LOG_NOTICE, "AUTO: boil turn off HLT");
479
0e6a1163e6e3 Bild target temperature 0.1 degree higher. Removed debug log from the simulator
Michiel Broek <mbroek@mbse.eu>
parents: 478
diff changeset
665 if (set_MLT_heater(unit, 1, 100.1))
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
666 syslog(LOG_NOTICE, "AUTO: boil turn on MLT to boil");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
667 if (set_MLT_pump(unit, unit->pump_onboil && (mltInput < unit->pump_stop)))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
668 syslog(LOG_NOTICE, "AUTO: boil turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
669 if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
670 prompt(119, NULL); /* "AUTO --> Boil " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
671 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
672 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
673 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
674 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
675 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
676 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
677 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
678 pump_status(unit->pump_onboil && (mltInput < unit->pump_stop));
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
679 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
680 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
681 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
682 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
683 if ((seconds / 2) % 4) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
684 timestatus(2, brew->boiltimer);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
685 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
686 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
687 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
688 if (brew->boiltimer >= 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
689 brew->boiltimer--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
690 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
691 brew->brewstep = STEP_BOILDONE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
692 syslog(LOG_NOTICE, "AUTO: boil is done");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
693 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
694 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
695 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
696 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
697
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
698 case STEP_BOILDONE: if (set_MLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
699 syslog(LOG_NOTICE, "AUTO: after boil turn off MLT heater");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
700 if (set_MLT_pump(unit, 0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
701 syslog(LOG_NOTICE, "AUTO: after boil turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
702 if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
703 prompt(120, NULL); /* "AUTO --> Cooling " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
704 prompt(214, NULL); /* " START COOLING " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
705 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
706 prompt(410, NULL); /* " Continue: Yes No " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
707 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
708 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
709 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
710 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
711 if (key == KEY_ENTER) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
712 brew->brewstep = STEP_CLEANUP;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
713 syslog(LOG_NOTICE, "AUTO: user skipped cooling");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
714 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
715 if (key == KEY_RETURN) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
716 brew->brewstep = STEP_COOLING;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
717 syslog(LOG_NOTICE, "AUTO: user started cooling");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
718 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
719 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
720
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
721 case STEP_COOLING: for (i = 0; i < 3; i++) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
722 if ((recipe->hopstand[i].skip == 0) && (mltInput <= recipe->hopstand[i].max) && (mltInput >= recipe->hopstand[i].min)) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
723 brew->brewstep = STEP_HOPSTAND;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
724 hopstand = i;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
725 syslog(LOG_NOTICE, "AUTO: starting hopstand %d", i+1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
726 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
727 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
728 if (brew->brewstep == STEP_HOPSTAND)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
729 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
730 // hot whirlpool start at 85 degrees
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
731 // cold whirlpool start at 30 degrees
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
732
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
733 if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
734 prompt(120, NULL); /* "AUTO --> Cooling " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
735 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
736 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
737 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
738 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
739 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
740 mlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
741 pump_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
742 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
743 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
744 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
745 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
746 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
747 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
748 if (mltInput <= recipe->coolto) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
749 syslog(LOG_NOTICE, "AUTO: cool temperture %.2f reached", recipe->coolto);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
750 brew->brewstep = STEP_CLEANUP;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
751 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
752 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
753
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
754 case STEP_HOPSTAND: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
755 prompt(122 + hopstand, NULL); /* "AUTO --> Hopstand n " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
756 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
757 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
758 prompt(418, NULL); /* "--- --- Pause --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
759 brew->boiltimer = recipe->hopstand[hopstand].duration * 60;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
760 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
761 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
762
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
763 if (recipe->hopstand[hopstand].hold) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
764 if (set_MLT_heater(unit, 1, recipe->hopstand[hopstand].setpoint))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
765 syslog(LOG_NOTICE, "AUTO: hopstand 1 turn on MLT at %6.2f", mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
766 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
767 if (set_MLT_pump(unit, 1))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
768 syslog(LOG_NOTICE, "AUTO: hopstand 1 turn %s MLT pump", mlt_pump_state ? "on":"off");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
769 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
770 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
771 timestatus(2, brew->timeout);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
772 brew->boiltimer--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
773 if (brew->boiltimer <= 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
774 syslog(LOG_NOTICE, "AUTO: hopstand %d done", hopstand+1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
775 if (set_MLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
776 syslog(LOG_NOTICE, "AUTO: hopstand 1 turn off MLT at %6.2f", mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
777 brew->brewstep = STEP_COOLING;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
778 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
779 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
780 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
781 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
782
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
783 case STEP_WHIRLPOOL: prompt(121, NULL); /* "AUTO --> Whirlpool " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
784 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
785
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
786 case STEP_CLEANUP: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
787 prompt(101, NULL); /* " Brewco x.x.x " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
788 prompt(200, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
789 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
790 prompt(400, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
791 last_step = brew->brewstep;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
792 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
793 syslog(LOG_NOTICE, "AUTO: cleanup");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
794 if (set_HLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
795 syslog(LOG_NOTICE, "AUTO: cleanup turn on HLT at %6.2f", hltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
796 if (set_MLT_heater(unit, 0, 10.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
797 syslog(LOG_NOTICE, "AUTO: cleanup turn on MLT at %6.2f", mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
798 if (set_MLT_pump(unit, 0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
799 syslog(LOG_NOTICE, "AUTO: cleanup turn %s MLT pump", mlt_pump_state ? "on":"off");
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
800 brew->brewstep = STEP_BREWDONE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
801 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
802
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
803 case STEP_BREWDONE: if (brew->brewstep != last_step) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
804 prompt(101, NULL); /* " Brewco x.x.x " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
805 prompt(200, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
806 prompt(301, NULL); /* " Finished " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
807 prompt(408, NULL); /* "--- --- Ok --- " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
808 last_step = brew->brewstep;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
809 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
810 syslog(LOG_NOTICE, "AUTO: brew done");
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
811 brew->brewstep = -1;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
812 brew->endtime = time(NULL);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
813 save = TRUE;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
814 do {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
815 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
816 } while (key != KEY_RETURN);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
817 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
818 * Rewrite the display
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
819 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
820 prompt(101, NULL); /* " Brewco x.x.x " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
821 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
822 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
823 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
824 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
825 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
826
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
827 if (save) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
828 snprintf(data, 127, "%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", brew->brewstep,
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
829 hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
830 logger(brew->name, data);
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
831 wrsession(brew);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
832 }
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
833 }
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
834
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
835
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
836
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
837 void manual_prompt(void)
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
838 {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
839 switch (manual) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
840 case MANUAL_SELHLT: prompt(104, NULL); /* " MANUAL MODE " */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
841 prompt(303, NULL); /* " Manual HLT " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
842 prompt(402, NULL); /* "--- dwn quit ok " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
843 break;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
844 case MANUAL_SELMLT: prompt(104, NULL); /* " MANUAL MODE " */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
845 prompt(304, NULL); /* " Manual MLT " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
846 prompt(404, NULL); /* " up --- quit ok " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
847 break;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
848 case MANUAL_HLT: prompt(104, NULL); /* " MANUAL MODE " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
849 prompt(300, NULL); /* " " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
850 prompt(413, NULL); /* "UP* *DWN heat --- " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
851 break;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
852 case MANUAL_MLT: prompt(104, NULL); /* " MANUAL MODE " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
853 prompt(300, NULL); /* " " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
854 prompt(406, NULL); /* "UP* *DWN heat pmp " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
855 break;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
856 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
857 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
858
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
859
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
860
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
861 /*
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
862 * Manual menu for testing your equipment.
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
863 */
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
864 int manual_menu(units_list *, int);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
865 int manual_menu(units_list *unit, int seconds)
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
866 {
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
867 int key;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
868
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
869 switch (manual) {
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
870 case MANUAL_SELHLT: slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
871 key = keycheck();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
872 if (key == KEY_DOWN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
873 manual = MANUAL_SELMLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
874 manual_prompt();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
875 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
876 if (key == KEY_RETURN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
877 manual = MANUAL_NONE;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
878 mlt_pump_state = 0;
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
879 PID_setMode(unit->PID_mlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
880 PID_setMode(unit->PID_hlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
881 hlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
882 mlt_status(0);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
883 device_out(unit->mlt_pump.uuid, mlt_pump_state);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
884 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
885 if (key == KEY_ENTER) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
886 // TODO: prompt for water
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
887 manual = MANUAL_HLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
888 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
889 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
890 break;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
891 case MANUAL_SELMLT: slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
892 key = keycheck();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
893 if (key == KEY_UP) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
894 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
895 manual_prompt();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
896 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
897 if (key == KEY_RETURN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
898 manual = MANUAL_NONE;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
899 mlt_pump_state = 0;
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
900 PID_setMode(unit->PID_mlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
901 PID_setMode(unit->PID_hlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
902 hlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
903 mlt_status(0);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
904 device_out(unit->mlt_pump.uuid, mlt_pump_state);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
905 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
906 if (key == KEY_ENTER) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
907 // TODO: prompt for water
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
908 manual = MANUAL_MLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
909 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
910 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
911 break;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
912 case MANUAL_HLT: tempstatus();
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
913 percstatus((seconds / 2) % 4);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
914
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
915 slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
916 key = keycheck();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
917 if (key == KEY_RETURN) {
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
918 if (PID_getMode(unit->PID_hlt) == P_MANUAL) {
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
919 PID_setMode(unit->PID_hlt, P_AUTOMATIC);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
920 hlt_status(1);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
921 } else {
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
922 PID_setMode(unit->PID_hlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
923 hlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
924 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
925 }
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
926 if ((key == KEY_DOWN) && (hltSetpoint > 10))
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
927 hltSetpoint -= 1.0;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
928 if ((key == KEY_UP) && (hltSetpoint < 100))
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
929 hltSetpoint += 1.0;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
930 if (key == KEY_ESCAPE) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
931 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
932 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
933 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
934 break;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
935 case MANUAL_MLT: tempstatus();
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
936 percstatus((seconds / 2) % 4);
455
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
937
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
938 slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
939 key = keycheck();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
940 if (key == KEY_RETURN) {
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
941 if (PID_getMode(unit->PID_mlt) == P_MANUAL) {
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
942 PID_setMode(unit->PID_mlt, P_AUTOMATIC);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
943 mlt_status(1);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
944 } else {
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
945 PID_setMode(unit->PID_mlt, P_MANUAL);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
946 mlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
947 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
948 }
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
949 if ((key == KEY_DOWN) && (mltSetpoint > 10))
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
950 mltSetpoint -= 1.0;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
951 if ((key == KEY_UP) && (mltSetpoint < 100))
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
952 mltSetpoint += 1.0;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
953 if (key == KEY_ENTER) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
954 if (mlt_pump_state)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
955 set_MLT_pump(unit, 0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
956 else
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
957 set_MLT_pump(unit, 1);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
958 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
959 if (key == KEY_ESCAPE) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
960 manual = MANUAL_SELMLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
961 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
962 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
963 device_out(unit->mlt_pump.uuid, mlt_pump_state);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
964 break;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
965 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
966
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
967 return 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
968 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
969
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
970
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
971
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
972 char *choose_recipe(void);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
973 char *choose_recipe(void)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
974 {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
975 int total, i, key, choice = 1;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
976 static char uuid[37];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
977 a_recipe *recipe;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
978 char pmpt[81];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
979
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
980 strcpy(uuid, (char *)"00000000-0000-0000-0000-000000000000");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
981 for (;;) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
982 total = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
983 for (recipe = recipes; recipe; recipe = recipe->next)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
984 total++;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
985
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
986 if (total == 0)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
987 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
988
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
989 i = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
990 for (recipe = recipes; recipe; recipe = recipe->next) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
991 i++;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
992 if (i == choice)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
993 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
994 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
995
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
996 prompt(102, NULL); /* " SETUP MENU " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
997 prompt(221, NULL); /* " Select Recipe " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
998 if (total) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
999 snprintf(pmpt, Config.lcd_cols + 1, "%s %s ", recipe->code, recipe->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1000 prompt(300, pmpt);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1001 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1002 if (total == 1)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1003 prompt(405, NULL); /* "--- --- quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1004 else if (choice == 1)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1005 prompt(402, NULL); /* "--- dwn quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1006 else if (choice == total)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1007 prompt(404, NULL); /* " up --- quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1008 else
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1009 prompt(403, NULL); /* " up dwn quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1010
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1011 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1012 if ((key == KEY_RETURN) || my_shutdown)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1013 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1014 if (key == KEY_ENTER) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1015 strcpy(uuid, recipe->uuid);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1016 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1017 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1018 if ((key == KEY_UP) && (total > 1) && (choice > 1)) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1019 choice--;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1020 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1021 if ((key == KEY_DOWN) && (total > 1) && (choice < total))
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1022 choice++;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1023 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1024 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1025
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1026
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1027
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1028 int server(void);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1029 int server(void)
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1030 {
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1031 int rc = 0, run = 1, dosave, key, temp, MLTp, HLTp, percslot, percfase = PERC_INIT;
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1032 int do_init = TRUE, seconds = 0, minutes = 0;
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1033 units_list *unit;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1034 a_recipe *recipe = NULL;
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1035 brew_session *brew = NULL;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1036 #ifndef HAVE_WIRINGPI_H
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1037 long t = 0;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1038 #endif
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1039 time_t now, last = (time_t)0;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1040 long nowmillis, perctimer;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1041 struct tm *tm;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1042
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1043 prompt(101, NULL);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1044
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1045 /*
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1046 * Define special characters in the display CGRAM
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1047 */
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1048 if (Config.tempFormat == 'C')
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1049 slcdCharDef(slcdHandle, 1, degC);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1050 else
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1051 slcdCharDef(slcdHandle, 1, degF);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1052 slcdCharDef(slcdHandle, 2, SP_Symbol);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1053 slcdCharDef(slcdHandle, 3, PumpONOFF);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1054 slcdCharDef(slcdHandle, 4, RevPumpONOFF);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1055 slcdCharDef(slcdHandle, 5, HeatONOFF);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1056 slcdCharDef(slcdHandle, 6, RevHeatONOFF);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1057 slcdCharDef(slcdHandle, 7, Language);
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1058
465
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1059 if (lockprog((char *)"brewco")) {
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1060 syslog(LOG_NOTICE, "Can't lock");
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1061 return 1;
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1062 }
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1063
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1064 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1065 fprintf(stdout, "Begin server()\n");
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1066
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1067 if ((rc = devices_detect())) {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1068 syslog(LOG_NOTICE, "Detected %d new devices", rc);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1069 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1070 fprintf(stdout, "Detected %d new devices\n", rc);
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1071 wrconfig();
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1072 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1073
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1074 #ifdef HAVE_WIRINGPI_H
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1075 rc = piThreadCreate(my_devices_loop);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1076 #else
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1077 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1078 #endif
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1079 if (rc) {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1080 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1081 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1082 #ifndef HAVE_WIRINGPI_H
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1083 } else {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1084 t++;
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1085 #endif
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1086 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1087
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1088 #ifdef HAVE_WIRINGPI_H
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1089 rc = piThreadCreate(my_keyboard_loop);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1090 #else
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1091 rc = pthread_create(&threads[t], NULL, my_keyboard_loop, (void *)t );
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1092 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1093 if (rc) {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1094 fprintf(stderr, "my_keyboard_loop thread didn't start rc=%d\n", rc);
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1095 syslog(LOG_NOTICE, "my_keyboard_loop thread didn't start rc=%d", rc);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1096 #ifndef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1097 } else {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1098 t++;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1099 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1100 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1101
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1102 #ifdef USE_SIMULATOR
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1103 #ifdef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1104 rc = piThreadCreate(my_simulator_loop);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1105 #else
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1106 rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t );
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1107 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1108 if (rc) {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1109 fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc);
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1110 syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1111 #ifndef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1112 } else {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1113 t++;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1114 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1115 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1116 #endif
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1117
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1118 if (! Config.units) {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1119 /*
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1120 * No brewsystems defined, add the first
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1121 */
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1122 prompt(218, NULL); /* Add Brewsystem? */
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1123 prompt(407, NULL); /* --- --- Ok --- */
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1124
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1125 do {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1126 key = keywait();
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1127 } while (key != KEY_RETURN);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1128
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1129 if (key == KEY_RETURN) {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1130 addUnit(1);
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1131 }
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1132 }
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1133
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1134 /*
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1135 * Initialize units for processing
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1136 */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1137 for (unit = Config.units; unit; unit = unit->next) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1138 if (unit->active)
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1139 break;
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1140 }
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1141
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1142 if (! unit->active) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1143 fprintf(stdout, "No active units found\n");
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1144 }
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1145
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1146 /*
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1147 * Safety, turn everything off
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1148 */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1149 if (unit->active) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1150 if (debug)
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1151 fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name);
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1152 syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name);
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1153 }
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1154
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1155 /*
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1156 * During automation there will be a state file:
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1157 * ~/.brewco/var/brewing.xml
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1158 * If this file is present, there has been a crash.
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1159 */
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1160 brew = (brew_session *)malloc(sizeof(brew_session));
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1161 rc = rdsession(brew);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1162 syslog(LOG_NOTICE, "rdsession: rc=%d", rc);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1163 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1164 fprintf(stdout, "rdsession: rc=%d\n", rc);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1165
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1166 char *mypath = xstrcpy(etcpath);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1167 mypath = xstrcat(mypath, (char *)"brewing.xml");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1168 if (rc == 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1169 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1170 fprintf(stdout, "Active brew session found\n");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1171 } else if (rc == -1) {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1172 free(brew);
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1173 brew = NULL;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1174 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1175 fprintf(stdout, "No active brew session found\n");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1176 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1177 unlink(mypath);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1178 free(brew);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1179 brew = NULL;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1180 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1181 fprintf(stdout, "Error brew session found\n");
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1182 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1183 free(mypath);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1184 mypath = NULL;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1185
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1186 do {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1187 if (my_shutdown) {
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1188 run = 0;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1189 unit->hlt_heater.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1190 unit->mlt_heater.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1191 unit->mlt_pump.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1192 device_out(unit->hlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1193 device_out(unit->mlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1194 device_out(unit->mlt_pump.uuid, 0);
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1195 hlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1196 mlt_status(0);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1197 break;
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1198 }
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1199
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1200 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1201 * Do we need to initialize this unit?
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1202 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1203 if (do_init) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1204 if (debug)
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1205 fprintf(stdout, "Initialize brewsystem %d `%s'\n", unit->number, unit->name);
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1206 syslog(LOG_NOTICE, "Initialize brewsystem %d `%s'", unit->number, unit->name);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1207
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1208 prompt(0, NULL);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1209 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1210 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1211
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1212 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1213 * Turn everything off
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1214 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1215 unit->hlt_heater.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1216 unit->mlt_heater.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1217 unit->mlt_pump.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1218 device_out(unit->hlt_heater.uuid, 0);
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1219 device_out(unit->mlt_heater.uuid, 0);
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1220 device_out(unit->mlt_pump.uuid, 0);
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1221
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1222 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1223 * Initialize PID's
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1224 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1225 hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1226 hltOutput = mltOutput = 0;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1227 PID_init(unit->PID_hlt, &hltInput, &hltOutput, &hltSetpoint, unit->PID_hlt->dispKp, unit->PID_hlt->dispKi, unit->PID_hlt->dispKd, unit->PID_hlt->Direction);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1228 PID_setOutputLimits(unit->PID_hlt, 0, 100);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1229 PID_setSampleTime(unit->PID_hlt, unit->PID_hlt->SampleTime);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1230 PID_init(unit->PID_mlt, &mltInput, &mltOutput, &mltSetpoint, unit->PID_mlt->dispKp, unit->PID_mlt->dispKi, unit->PID_mlt->dispKd, unit->PID_mlt->Direction);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1231 PID_setOutputLimits(unit->PID_mlt, 0, 100);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1232 PID_setSampleTime(unit->PID_mlt, unit->PID_mlt->SampleTime);
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1233 hlt_status(0);
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1234 mlt_status(0);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1235
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1236 manual = MANUAL_NONE;
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1237
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1238 do_init = FALSE;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1239 nowmillis = perctimer = millis();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1240 percslot = 0;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1241 percfase = PERC_INIT;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1242 dosave = 0;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1243
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1244 if (brew) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1245 /*
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1246 * Restore session
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1247 */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1248 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1249 fprintf(stdout, "loop_init: restoring brew session\n");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1250 for (recipe = recipes; recipe; recipe = recipe->next) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1251 if (strcmp(recipe->uuid, brew->uuid_recipe) == 0) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1252 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1253 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1254 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1255 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1256 fprintf(stdout, "loop_init: brewstep=%d mashstep=%d recipe=%s\n", brew->brewstep, brew->mashstep, recipe->code);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1257 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1258 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1259
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1260 /* run_pause code here */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1261
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1262 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1263 * Update PID's, even if they are off. Both PID's will do
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1264 * the scheduling by themselves.
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1265 */
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1266 rc = PID_compute(unit->PID_hlt);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1267 rc = PID_compute(unit->PID_mlt);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1268
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1269 /*
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1270 * This is the serial heaters schedule loop. The total
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1271 * loop time is 5 seconds, heating is 0..100% so we
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1272 * have 5 mSeconds timeslots. The MLT has priority over
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1273 * the HLT heater, so the HLT heater can get too little
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1274 * power. TODO: simultaneous use must be implemented.
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1275 * In sequentiel mode, the total drawn power is the same
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1276 * as the power used by the largest heater element.
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1277 */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1278 nowmillis = millis();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1279 if (nowmillis > (perctimer + 50)) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1280 percslot++;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1281 if (percfase == PERC_INIT) {
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1282 HLTp = (int)hltOutput;
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1283 MLTp = (int)mltOutput;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1284 if ((MLTp + HLTp) > 100)
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1285 HLTp = 100 - MLTp; /* The HLT has lower priority */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1286 if (MLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1287 percfase = PERC_MLT;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1288 device_out(unit->hlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1289 device_out(unit->mlt_heater.uuid, 1);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1290 } else if (HLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1291 percfase = PERC_HLT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1292 device_out(unit->hlt_heater.uuid, 1);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1293 device_out(unit->mlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1294 } else {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1295 percfase = PERC_REST;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1296 device_out(unit->hlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1297 device_out(unit->mlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1298 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1299 // if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1300 // fprintf(stdout, " perslot=%d MLT=%d%% HLT=%d%% fase=%d\n", percslot, MLTp, HLTp, percfase);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1301 } else if (percfase == PERC_MLT) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1302 if (percslot > MLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1303 device_out(unit->mlt_heater.uuid, 0);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1304 if (HLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1305 device_out(unit->hlt_heater.uuid, 1);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1306 percfase = PERC_HLT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1307 } else {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1308 percfase = PERC_REST;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1309 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1310 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1311 } else if (percfase == PERC_HLT) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1312 if (percslot > (MLTp + HLTp)) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1313 device_out(unit->hlt_heater.uuid, 0);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1314 percfase = PERC_REST;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1315 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1316 }
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1317 if (percslot == 100) { /* End of the loop, start over */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1318 percslot = 0;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1319 percfase = PERC_INIT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1320 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1321 perctimer = nowmillis;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1322 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1323
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1324 now = time(NULL);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1325 if (now != last) {
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1326 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1327 * Each second
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1328 */
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1329 last = now;
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1330 seconds++;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1331
455
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1332 if (seconds > 59) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1333 seconds = 0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1334 minutes++;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1335 dosave = 1;
455
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1336 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1337
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1338 rc = device_in(unit->hlt_sensor.uuid, &temp);
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1339 if (rc == DEVPRESENT_YES) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1340 hltInput = temp / 1000.0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1341 unit->hlt_sensor.state = 0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1342 } else if (rc == DEVPRESENT_ERROR) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1343 unit->hlt_sensor.state = 1;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1344 } else {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1345 unit->hlt_sensor.state = 2;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1346 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1347 rc = device_in(unit->mlt_sensor.uuid, &temp);
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1348 if (rc == DEVPRESENT_YES) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1349 mltInput = temp / 1000.0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1350 unit->mlt_sensor.state = 0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1351 } else if (rc == DEVPRESENT_ERROR) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1352 unit->mlt_sensor.state = 1;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1353 } else {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1354 unit->mlt_sensor.state = 2;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1355 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1356
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1357 if (debug && ((seconds % 10) == 1)) {
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1358 fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d HLT: In=%.2lf Out=%.2lf Set=%.2lf Stat=%d\n",
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1359 mltInput, mltOutput, mltSetpoint, PID_getMode(unit->PID_mlt),
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1360 hltInput, hltOutput, hltSetpoint, PID_getMode(unit->PID_hlt));
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1361 }
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1362
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1363 }
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1364
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1365 if (brew) {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1366 /*
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1367 * Automate mode
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1368 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1369 automatic_brew(unit, brew, recipe, dosave, seconds);
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1370 dosave = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1371 if (brew->brewstep == -1) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1372 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1373 * Save session and move it
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1374 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1375 wrsession(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1376 char *fpath, *tpath;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1377 fpath = xstrcpy(etcpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1378 fpath = xstrcat(fpath, (char *)"brewing.xml");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1379 tpath = xstrcpy(varpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1380 tpath = xstrcat(tpath, (char *)"old/brewing.xml.");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1381 mkdirs(tpath, 0755);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1382 tpath = xstrcat(tpath, brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1383 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1384 fprintf(stdout, "auto: saving as %s\n", tpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1385 file_cp(fpath, tpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1386 unlink(fpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1387 free(fpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1388 free(tpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1389
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1390 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1391 * Free memory, session is over.
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1392 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1393 if (brew->name)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1394 free(brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1395 if (brew->uuid_recipe)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1396 free(brew->uuid_recipe);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1397 if (brew->uuid_unit)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1398 free(brew->uuid_unit);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1399 free(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1400 brew = NULL;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1401 }
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1402
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1403 } else if (manual != MANUAL_NONE) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1404 /*
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1405 * Manual mode
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1406 */
471
1564b60558b1 Manual mode now uses the PID's. The display shows heating percentage and the setpoints alternated very 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 468
diff changeset
1407 manual_menu(unit, seconds);
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1408 if (manual == MANUAL_NONE) {
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1409 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1410 * Rewrite the display
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1411 */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1412 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1413 prompt(300, NULL); /* " " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1414 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1415 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1416 } else {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1417 /*
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1418 * Not running.
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1419 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1420 tempstatus();
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1421 key = keycheck();
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1422 if (key == KEY_ENTER) {
442
1193bd7d460f Split some sources
Michiel Broek <mbroek@mbse.eu>
parents: 441
diff changeset
1423 setup();
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1424 prompt(101, NULL); /* " Brewco x.x.x " */
475
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
1425 prompt(200, NULL);
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
1426 prompt(300, NULL);
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
1427 hlt_status(0);
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
1428 mlt_status(0);
bec993331061 Updated several prompts. Added pump prime. Added first part of a test plan.
Michiel Broek <mbroek@mbse.eu>
parents: 474
diff changeset
1429 pump_status(0);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1430 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1431 } else if (key == KEY_RETURN && ! brew) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1432 int i, isOk = TRUE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1433 char message[41];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1434
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1435 tm = localtime(&now);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1436 snprintf(message, 40, "%04d%02d%02d-%02d%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1437 brew = (brew_session *)malloc(sizeof(brew_session));
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1438 brew->uuid_recipe = xstrcpy(choose_recipe());
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1439 brew->uuid_unit = xstrcpy(unit->uuid);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1440 brew->name = xstrcpy(message);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1441 brew->brewstep = STEP_NA;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1442 brew->mashstep = MASH_NA;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1443 brew->timeout = brew->boiltimer = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1444 brew->starttime = brew->endtime = (time_t)0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1445 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1446 * Now check if everything is sane
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1447 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1448 if (strcmp(brew->uuid_recipe, (char *)"00000000-0000-0000-0000-000000000000") == 0) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1449 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1450 snprintf(message, Config.lcd_cols + 1, " No recipe selected ");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1451 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1452 fprintf(stdout, "brew init: No recipe selected\n");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1453 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1454 if (isOk) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1455 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1456 for (recipe = recipes; recipe; recipe = recipe->next) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1457 if (strcmp(recipe->uuid, brew->uuid_recipe) == 0) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1458 isOk = TRUE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1459 if (! recipe->boiltime)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1460 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1461 for (i = 0; i < 8; i++) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1462 if (! recipe->mash[i].skip && ! recipe->mash[i].setpoint)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1463 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1464 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1465 for (i = 0; i < 3; i++) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1466 if (! recipe->hopstand[i].skip && recipe->hopstand[i].hold && (recipe->hopstand[i].setpoint == 0))
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1467 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1468 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1469 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1470 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1471 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1472 if (isOk == FALSE) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1473 snprintf(message, Config.lcd_cols + 1, " Recipe error ");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1474 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1475 fprintf(stdout, "brew init: recipe error\n");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1476 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1477 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1478
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1479 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1480 fprintf(stdout, "init brew: %s\n", isOk ? (char *)"Ok":(char *)"Error");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1481
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1482 if (isOk) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1483 wrsession(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1484 } else {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1485 prompt(300, message);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1486 prompt(408, NULL); /* "--- --- Ok --- " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1487 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1488 if (brew->name)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1489 free(brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1490 if (brew->uuid_recipe)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1491 free(brew->uuid_recipe);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1492 if (brew->uuid_unit)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1493 free(brew->uuid_unit);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1494 free(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1495 brew = NULL;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1496 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1497 * Rewrite the display
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1498 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1499 prompt(101, NULL); /* " Brewco x.x.x " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1500 prompt(300, NULL); /* " " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1501 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1502 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1503
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1504 } else if (key == KEY_DOWN) {
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1505 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1506 manual_prompt();
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1507 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1508 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1509
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1510 usleep(5000); /* 5 mSec */
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1511
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1512 } while (run);
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1513
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1514 syslog(LOG_NOTICE, "Out of loop");
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1515 if (debug)
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1516 fprintf(stdout, (char *)"Out of loop\n");
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1517
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1518 prompt(0, NULL);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1519 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1520 prompt(302, NULL); /* " Shutting down " */
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1521
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1522 /*
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1523 * Give threads time to cleanup
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1524 */
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1525 usleep(1500000);
443
6b80a37fdf8d Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
Michiel Broek <mbroek@mbse.eu>
parents: 442
diff changeset
1526 prompt(0, NULL);
468
e8203e891b0e Removed LCD auto dim mode, the display is allways on if this program runs.
Michiel Broek <mbroek@mbse.eu>
parents: 467
diff changeset
1527 setBacklight(0);
e8203e891b0e Removed LCD auto dim mode, the display is allways on if this program runs.
Michiel Broek <mbroek@mbse.eu>
parents: 467
diff changeset
1528
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1529 if (sock != -1) {
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1530 if (shutdown(sock, SHUT_RDWR)) {
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1531 syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno));
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1532 }
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1533 sock = -1;
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1534 }
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1535
459
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1536 wrrecipes();
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1537 wrconfig();
465
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1538 ulockprog((char *)"brewco");
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1539 return 0;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1540 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1541
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1542
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1543
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1544 int main(int argc, char *argv[])
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1545 {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1546 int rc = 0, c, i;
464
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1547 char *homepath = NULL;
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1548
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1549 while (1) {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1550 int option_index = 0;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1551 static struct option long_options[] = {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1552 {"debug", 0, 0, 'c'},
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1553 {"help", 0, 0, 'h'},
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1554 {0, 0, 0, 0}
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1555 };
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1556
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1557 c = getopt_long(argc, argv, "dh", long_options, &option_index);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1558 if (c == -1)
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1559 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1560
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1561 switch (c) {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1562 case 'd': debug = TRUE;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1563 break;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1564 case 'h': help();
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1565 return 1;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1566 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1567 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1568
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1569 openlog("brewco", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_USER);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1570 syslog(LOG_NOTICE, "mbsePi-apps brewco v%s starting", VERSION);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1571 if (debug)
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1572 fprintf(stdout, "mbsePi-apps brewco v%s starting\n", VERSION);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1573
464
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1574 /*
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1575 * Set home directory path
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1576 */
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1577 if (getenv((char *)"USER") == NULL) {
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1578 homepath = xstrcpy((char *)"/root");
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1579 } else {
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1580 homepath = xstrcpy(getenv((char *)"HOME"));
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1581 }
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1582 varpath = xstrcpy(homepath);
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1583 varpath = xstrcat(varpath, (char *)"/.brewco/var/");
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1584 etcpath = xstrcpy(homepath);
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1585 etcpath = xstrcat(etcpath, (char *)"/.brewco/etc/");
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1586 mkdirs(varpath, 0755);
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1587 mkdirs(etcpath, 0755);
4a624c071ca9 Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents: 459
diff changeset
1588
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1589 if (rdconfig()) {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1590 fprintf(stderr, "Error reading configuration\n");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1591 syslog(LOG_NOTICE, "Error reading configuration: halted");
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1592 return 1;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1593 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1594 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1595 fprintf(stdout, "configuration loaded\n");
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1596
459
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1597 if (rdrecipes()) {
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1598 fprintf(stderr, "Error reading recipes\n");
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1599 syslog(LOG_NOTICE, "Error reading recipes: halted");
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1600 return 1;
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1601 }
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1602 if (debug)
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1603 fprintf(stdout, "recipes loaded\n");
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1604
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1605 /*
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1606 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1607 * but that's live. This daemon should only be stopped by SIGTERM.
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1608 * Don't catch SIGCHLD.
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1609 */
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1610 for (i = 0; i < NSIG; i++) {
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1611 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP))
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1612 signal(i, (void (*))die);
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1613 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1614
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1615 #ifdef HAVE_WIRINGPI_H
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1616 if (wiringPiSetup () )
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1617 return 1;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1618 #endif
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1619
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1620 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1621 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1622 return 1;
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1623 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1624
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1625 rc = server();
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1626
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1627 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1628 if (debug)
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1629 fprintf(stdout, "Finished, rc=%d\n", rc);
409
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1630 return rc;
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1631 }
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1632
cdf68044adaf Added a new brewpanel program that runs on an SDL/X screen. It will be an emulator for the hardware panels. Development version 0.5.0
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1633

mercurial