brewco/brewco.c

Sun, 27 Dec 2015 17:52:26 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Dec 2015 17:52:26 +0100
changeset 477
9167ad4c2e77
parent 476
8f159cd4f5fc
child 478
fe8bf61cde06
permissions
-rw-r--r--

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.

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 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
441 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
442
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
443 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
444 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
445 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
446 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
447 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
448 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
449 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
450 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
451 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
452 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
453 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
454 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
455 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
456 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
457
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
458 switch (mash_fase) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
459 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
460 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
461 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
462 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
463 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
464 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
465 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
466 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
467 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
468 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
469 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
470 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
471 save = TRUE;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
472 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
473 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
474
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
475 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
476 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
477 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
478 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
479 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
480 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 }
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
482 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
483 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
484 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
485 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
486 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
487 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
488 brew->mashstep++;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
489 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
490 }
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_RETURN) {
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
492 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
493 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
494 brew->mashstep = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
495 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
496 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
497
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
498 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
499 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
500 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
501 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
502 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
503 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 }
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
505 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
506 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
507 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
508 brew->timeout--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
509 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
510 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
511 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
512 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
513 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
514 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
515 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
516 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
517 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
518 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
519 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
520 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
521 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
522 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
523 }
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_ENTER) {
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 declined");
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_REST;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
527 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
528 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
529 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
530
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
531 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
532 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
533 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
534 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
535 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
536 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
537 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
538 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
539 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
540 }
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
541 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
542 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
543 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
544 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
545 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
546 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
547 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
548 if (mltInput > mltSetpoint) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
549 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
550 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
551 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
552 break;
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 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
555 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
556 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
557 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
558 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
559 hlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
560 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
561 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
562 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
563 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
564 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
565 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
566 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
567 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
568 /*
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
569 * 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
570 */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
571 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
572 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
573 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
574 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
575 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
576 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
577 brew->timeout--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
578 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
579 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
580 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
581 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
582 } 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
583 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
584 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
585 } 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
586 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
587 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
588 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
589 brew->mashstep++;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
590 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
591 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
592 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
593 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
594 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
595
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
596 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
597 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
598 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
599 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
600 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
601 brew->mashstep = 0;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
602 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
603 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
604 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
605 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
606
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
607 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
608 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
609 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
610 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
611 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
612 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
613 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
614 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
615 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
616 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
617 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
618 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
619 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
620 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
621 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
622 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
623 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
624 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
625 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
626
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
627 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
628 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
629 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
630 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
631 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
632 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
633 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
634 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
635 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
636 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
637 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
638 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
639 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
640 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
641 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
642 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
643 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
644 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
645 syslog(LOG_NOTICE, "AUTO: preboil turn off HLT");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
646 if (set_MLT_heater(unit, 1, 100.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
647 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
648 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
649 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
650 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
651 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
652 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
653 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
654 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
655 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
656
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
657 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
658 syslog(LOG_NOTICE, "AUTO: boil turn off HLT");
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
659 if (set_MLT_heater(unit, 1, 100.0))
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
660 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
661 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
662 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
663 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
664 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
665 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
666 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
667 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
668 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
669 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
670 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
671 mlt_status(1);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
672 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
673 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
674 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
675 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
676 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
677 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
678 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
679 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
680 mltstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
681 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
682 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
683 brew->boiltimer--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
684 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
685 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
686 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
687 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
688 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
689 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
690 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
691
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
700 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
701 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
702 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
703 slcdDummy(slcdHandle);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
704 key = keycheck();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
705 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
706 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
707 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
708 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
709 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
710 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
711 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
712 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
713 break;
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 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
716 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
717 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
718 hopstand = i;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
719 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
720 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
721 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
722 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
723 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
724 // 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
725 // 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
726
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
727 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
728 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
729 prompt(200, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
730 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
731 prompt(300, NULL);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
732 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
733 hlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
734 mlt_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
735 pump_status(0);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
736 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
737 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
738 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
739 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
740 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
741 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
742 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
743 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
744 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
745 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
746 break;
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 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
749 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
750 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
751 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
752 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
753 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
754 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
755 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
756
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
757 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
758 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
759 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
760 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
761 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
762 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
763 if (oldsec != seconds) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
764 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
765 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
766 brew->boiltimer--;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
767 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
768 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
769 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
770 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
771 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
772 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
773 oldsec = seconds;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
774 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
775 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
776
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
777 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
778 break;
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
779
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
780 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
781 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
782 prompt(200, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
783 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
784 prompt(400, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
785 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
786 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
787 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
788 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
789 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
790 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
791 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
792 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
793 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
794 brew->brewstep = STEP_BREWDONE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
795 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
796
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
797 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
798 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
799 prompt(200, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
800 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
801 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
802 last_step = brew->brewstep;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
803 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
804 syslog(LOG_NOTICE, "AUTO: brew done");
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
805 brew->brewstep = -1;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
806 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
807 save = TRUE;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
808 do {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
809 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
810 } while (key != KEY_RETURN);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
811 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
812 * Rewrite the display
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
813 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
814 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
815 tempstatus();
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
816 prompt(300, NULL); /* " " */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
817 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
818 break;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
819 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
820
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
821 if (save) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
822 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
823 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
824 logger(brew->name, data);
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
825 wrsession(brew);
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
826 }
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
827 }
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
828
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
829
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
830
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
831 void manual_prompt(void)
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
832 {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
833 switch (manual) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
834 case MANUAL_SELHLT: prompt(104, NULL); /* " MANUAL MODE " */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
835 prompt(303, NULL); /* " Manual HLT " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
836 prompt(402, NULL); /* "--- dwn quit ok " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
837 break;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
838 case MANUAL_SELMLT: prompt(104, NULL); /* " MANUAL MODE " */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
839 prompt(304, NULL); /* " Manual MLT " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
840 prompt(404, NULL); /* " up --- quit ok " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
841 break;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
842 case MANUAL_HLT: prompt(104, NULL); /* " MANUAL MODE " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
843 prompt(300, NULL); /* " " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
844 prompt(413, NULL); /* "UP* *DWN heat --- " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
845 break;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
846 case MANUAL_MLT: prompt(104, NULL); /* " MANUAL MODE " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
847 prompt(300, NULL); /* " " */
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
848 prompt(406, NULL); /* "UP* *DWN heat pmp " */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
849 break;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
850 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
851 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
852
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
853
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
854
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
855 /*
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
856 * Manual menu for testing your equipment.
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
857 */
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
858 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
859 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
860 {
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
861 int key;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
862
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
863 switch (manual) {
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
864 case MANUAL_SELHLT: slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
865 key = keycheck();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
866 if (key == KEY_DOWN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
867 manual = MANUAL_SELMLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
868 manual_prompt();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
869 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
870 if (key == KEY_RETURN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
871 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
872 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
873 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
874 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
875 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
876 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
877 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
878 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
879 if (key == KEY_ENTER) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
880 // TODO: prompt for water
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
881 manual = MANUAL_HLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
882 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
883 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
884 break;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
885 case MANUAL_SELMLT: slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
886 key = keycheck();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
887 if (key == KEY_UP) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
888 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
889 manual_prompt();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
890 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
891 if (key == KEY_RETURN) {
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
892 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
893 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
894 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
895 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
896 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
897 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
898 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
899 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
900 if (key == KEY_ENTER) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
901 // TODO: prompt for water
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
902 manual = MANUAL_MLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
903 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
904 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
905 break;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
906 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
907 percstatus((seconds / 2) % 4);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
908
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
909 slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
910 key = keycheck();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
911 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
912 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
913 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
914 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
915 } 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
916 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
917 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
918 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
919 }
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
920 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
921 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
922 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
923 hltSetpoint += 1.0;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
924 if (key == KEY_ESCAPE) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
925 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
926 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
927 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
928 break;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
929 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
930 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
931
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
932 slcdDummy(slcdHandle);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
933 key = keycheck();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
934 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
935 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
936 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
937 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
938 } 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
939 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
940 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
941 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
942 }
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
943 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
944 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
945 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
946 mltSetpoint += 1.0;
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
947 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
948 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
949 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
950 else
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
951 set_MLT_pump(unit, 1);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
952 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
953 if (key == KEY_ESCAPE) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
954 manual = MANUAL_SELMLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
955 manual_prompt();
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
956 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
957 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
958 break;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
959 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
960
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
961 return 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
962 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
963
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
964
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
965
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
966 char *choose_recipe(void);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
967 char *choose_recipe(void)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
968 {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
969 int total, i, key, choice = 1;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
970 static char uuid[37];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
971 a_recipe *recipe;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
972 char pmpt[81];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
973
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
974 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
975 for (;;) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
976 total = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
977 for (recipe = recipes; recipe; recipe = recipe->next)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
978 total++;
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 if (total == 0)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
981 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
982
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
983 i = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
984 for (recipe = recipes; recipe; recipe = recipe->next) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
985 i++;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
986 if (i == choice)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
987 break;
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
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
990 prompt(102, NULL); /* " SETUP MENU " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
991 prompt(221, NULL); /* " Select Recipe " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
992 if (total) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
993 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
994 prompt(300, pmpt);
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 if (total == 1)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
997 prompt(405, NULL); /* "--- --- quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
998 else if (choice == 1)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
999 prompt(402, NULL); /* "--- dwn quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1000 else if (choice == total)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1001 prompt(404, NULL); /* " up --- quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1002 else
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1003 prompt(403, NULL); /* " up dwn quit ok " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1004
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1005 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1006 if ((key == KEY_RETURN) || my_shutdown)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1007 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1008 if (key == KEY_ENTER) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1009 strcpy(uuid, recipe->uuid);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1010 return uuid;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1011 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1012 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
1013 choice--;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1014 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1015 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
1016 choice++;
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 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1019
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
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1022 int server(void);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1023 int server(void)
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1024 {
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1025 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
1026 int do_init = TRUE, seconds = 0, minutes = 0;
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1027 units_list *unit;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1028 a_recipe *recipe = NULL;
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1029 brew_session *brew = NULL;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1030 #ifndef HAVE_WIRINGPI_H
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1031 long t = 0;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1032 #endif
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1033 time_t now, last = (time_t)0;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1034 long nowmillis, perctimer;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1035 struct tm *tm;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1036
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
1037 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
1038
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
1039 /*
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
1040 * 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
1041 */
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
1042 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
1043 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 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
1052
465
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1053 if (lockprog((char *)"brewco")) {
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1054 syslog(LOG_NOTICE, "Can't lock");
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1055 return 1;
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1056 }
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1057
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1058 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1059 fprintf(stdout, "Begin server()\n");
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1060
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1061 if ((rc = devices_detect())) {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1062 syslog(LOG_NOTICE, "Detected %d new devices", rc);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1063 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1064 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
1065 wrconfig();
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1066 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1067
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1068 #ifdef HAVE_WIRINGPI_H
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1069 rc = piThreadCreate(my_devices_loop);
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1070 #else
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1071 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
1072 #endif
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1073 if (rc) {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1074 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
1075 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
1076 #ifndef HAVE_WIRINGPI_H
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1077 } else {
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1078 t++;
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1079 #endif
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1080 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1081
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1082 #ifdef HAVE_WIRINGPI_H
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1083 rc = piThreadCreate(my_keyboard_loop);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1084 #else
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1085 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
1086 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1087 if (rc) {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1088 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
1089 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
1090 #ifndef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1091 } else {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1092 t++;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1093 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1094 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1095
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1096 #ifdef USE_SIMULATOR
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1097 #ifdef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1098 rc = piThreadCreate(my_simulator_loop);
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1099 #else
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1100 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
1101 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1102 if (rc) {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1103 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
1104 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
1105 #ifndef HAVE_WIRINGPI_H
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1106 } else {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1107 t++;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1108 #endif
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1109 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1110 #endif
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1111
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1112 if (! Config.units) {
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1113 /*
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1114 * 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
1115 */
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
1116 prompt(218, NULL); /* Add Brewsystem? */
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1117 prompt(407, NULL); /* --- --- Ok --- */
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1118
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1119 do {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1120 key = keywait();
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1121 } while (key != KEY_RETURN);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1122
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1123 if (key == KEY_RETURN) {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1124 addUnit(1);
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1125 }
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1126 }
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1127
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1128 /*
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1129 * Initialize units for processing
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1130 */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1131 for (unit = Config.units; unit; unit = unit->next) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1132 if (unit->active)
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1133 break;
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1134 }
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1135
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1136 if (! unit->active) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1137 fprintf(stdout, "No active units found\n");
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1138 }
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1139
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 * Safety, turn everything off
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1142 */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1143 if (unit->active) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1144 if (debug)
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1145 fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name);
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1146 syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name);
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1147 }
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 /*
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1150 * During automation there will be a state file:
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1151 * ~/.brewco/var/brewing.xml
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1152 * If this file is present, there has been a crash.
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1153 */
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1154 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
1155 rc = rdsession(brew);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1156 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
1157 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1158 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
1159
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1160 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
1161 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
1162 if (rc == 0) {
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, "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
1165 } else if (rc == -1) {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1166 free(brew);
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1167 brew = NULL;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1168 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1169 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
1170 } else {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1171 unlink(mypath);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1172 free(brew);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1173 brew = NULL;
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, "Error brew session found\n");
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1176 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1177 free(mypath);
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1178 mypath = NULL;
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1179
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1180 do {
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1181 if (my_shutdown) {
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1182 run = 0;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1183 unit->hlt_heater.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1184 unit->mlt_heater.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1185 unit->mlt_pump.value = 0;
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1186 device_out(unit->hlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1187 device_out(unit->mlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1188 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
1189 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
1190 mlt_status(0);
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1191 break;
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1192 }
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1193
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1194 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1195 * 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
1196 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1197 if (do_init) {
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1198 if (debug)
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1199 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
1200 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
1201
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1202 prompt(0, NULL);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1203 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1204 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1205
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1206 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1207 * Turn everything off
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1208 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1209 unit->hlt_heater.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1210 unit->mlt_heater.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1211 unit->mlt_pump.value = 0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1212 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
1213 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
1214 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
1215
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1216 /*
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1217 * Initialize PID's
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1218 */
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1219 hltInput = hltSetpoint = mltInput = mltSetpoint = 20.0;
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1220 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
1221 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
1222 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
1223 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
1224 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
1225 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
1226 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
1227 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
1228 mlt_status(0);
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1229
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1230 manual = MANUAL_NONE;
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1231
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1232 do_init = FALSE;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1233 nowmillis = perctimer = millis();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1234 percslot = 0;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1235 percfase = PERC_INIT;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1236 dosave = 0;
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1237
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1238 if (brew) {
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1239 /*
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1240 * Restore session
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1241 */
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1242 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1243 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
1244 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
1245 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
1246 break;
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 }
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1249 if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1250 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
1251 }
453
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1252 }
76418c89b480 Moved manual menu to it's own function.
Michiel Broek <mbroek@mbse.eu>
parents: 452
diff changeset
1253
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1254 /* run_pause code here */
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1255
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1256 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1257 * 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
1258 * the scheduling by themselves.
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1259 */
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1260 rc = PID_compute(unit->PID_hlt);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1261 rc = PID_compute(unit->PID_mlt);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1262
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1263 /*
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1264 * This is the serial heaters schedule loop. The total
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1265 * loop time is 5 seconds, heating is 0..100% so we
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1266 * have 5 mSeconds timeslots. The MLT has priority over
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1267 * the HLT heater, so the HLT heater can get too little
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1268 * power. TODO: simultaneous use must be implemented.
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1269 * In sequentiel mode, the total drawn power is the same
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1270 * 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
1271 */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1272 nowmillis = millis();
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1273 if (nowmillis > (perctimer + 50)) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1274 percslot++;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1275 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
1276 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
1277 MLTp = (int)mltOutput;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1278 if ((MLTp + HLTp) > 100)
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1279 HLTp = 100 - MLTp; /* The HLT has lower priority */
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1280 if (MLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1281 percfase = PERC_MLT;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1282 device_out(unit->hlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1283 device_out(unit->mlt_heater.uuid, 1);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1284 } else if (HLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1285 percfase = PERC_HLT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1286 device_out(unit->hlt_heater.uuid, 1);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1287 device_out(unit->mlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1288 } else {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1289 percfase = PERC_REST;
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1290 device_out(unit->hlt_heater.uuid, 0);
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1291 device_out(unit->mlt_heater.uuid, 0);
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1292 }
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1293 // if (debug)
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1294 // 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
1295 } else if (percfase == PERC_MLT) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1296 if (percslot > MLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1297 device_out(unit->mlt_heater.uuid, 0);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1298 if (HLTp) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1299 device_out(unit->hlt_heater.uuid, 1);
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1300 percfase = PERC_HLT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1301 } else {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1302 percfase = PERC_REST;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1303 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1304 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1305 } else if (percfase == PERC_HLT) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1306 if (percslot > (MLTp + HLTp)) {
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1307 device_out(unit->hlt_heater.uuid, 0);
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 }
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1311 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
1312 percslot = 0;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1313 percfase = PERC_INIT;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1314 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1315 perctimer = nowmillis;
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1316 }
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1317
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1318 now = time(NULL);
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1319 if (now != last) {
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1320 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1321 * Each second
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1322 */
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1323 last = now;
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1324 seconds++;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1325
455
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1326 if (seconds > 59) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1327 seconds = 0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1328 minutes++;
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1329 dosave = 1;
455
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1330 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1331
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1332 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
1333 if (rc == DEVPRESENT_YES) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1334 hltInput = temp / 1000.0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1335 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
1336 } 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
1337 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
1338 } else {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1339 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
1340 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1341 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
1342 if (rc == DEVPRESENT_YES) {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1343 mltInput = temp / 1000.0;
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1344 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
1345 } 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
1346 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
1347 } else {
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1348 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
1349 }
f84501d8dd87 Most parts of the simulator are working, needs some tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 454
diff changeset
1350
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1351 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
1352 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
1353 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
1354 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
1355 }
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1356
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1357 }
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1358
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1359 if (brew) {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1360 /*
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1361 * Automate mode
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1362 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1363 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
1364 dosave = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1365 if (brew->brewstep == -1) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1366 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1367 * Save session and move it
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1368 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1369 wrsession(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1370 char *fpath, *tpath;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1371 fpath = xstrcpy(etcpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1372 fpath = xstrcat(fpath, (char *)"brewing.xml");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1373 tpath = xstrcpy(varpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1374 tpath = xstrcat(tpath, (char *)"old/brewing.xml.");
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1375 mkdirs(tpath, 0755);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1376 tpath = xstrcat(tpath, brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1377 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1378 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
1379 file_cp(fpath, tpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1380 unlink(fpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1381 free(fpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1382 free(tpath);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1383
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1384 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1385 * Free memory, session is over.
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1386 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1387 if (brew->name)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1388 free(brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1389 if (brew->uuid_recipe)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1390 free(brew->uuid_recipe);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1391 if (brew->uuid_unit)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1392 free(brew->uuid_unit);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1393 free(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1394 brew = NULL;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1395 }
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1396
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1397 } else if (manual != MANUAL_NONE) {
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1398 /*
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1399 * Manual mode
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1400 */
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
1401 manual_menu(unit, seconds);
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1402 if (manual == MANUAL_NONE) {
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1403 /*
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1404 * Rewrite the display
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1405 */
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1406 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1407 prompt(300, NULL); /* " " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1408 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1409 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1410 } else {
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1411 /*
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1412 * Not running.
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1413 */
473
fdd30e935079 The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents: 472
diff changeset
1414 tempstatus();
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1415 key = keycheck();
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1416 if (key == KEY_ENTER) {
442
1193bd7d460f Split some sources
Michiel Broek <mbroek@mbse.eu>
parents: 441
diff changeset
1417 setup();
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1418 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
1419 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
1420 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
1421 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
1422 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
1423 pump_status(0);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1424 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
472
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1425 } else if (key == KEY_RETURN && ! brew) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1426 int i, isOk = TRUE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1427 char message[41];
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1428
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1429 tm = localtime(&now);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1430 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
1431 brew = (brew_session *)malloc(sizeof(brew_session));
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1432 brew->uuid_recipe = xstrcpy(choose_recipe());
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1433 brew->uuid_unit = xstrcpy(unit->uuid);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1434 brew->name = xstrcpy(message);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1435 brew->brewstep = STEP_NA;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1436 brew->mashstep = MASH_NA;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1437 brew->timeout = brew->boiltimer = 0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1438 brew->starttime = brew->endtime = (time_t)0;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1439 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1440 * Now check if everything is sane
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1441 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1442 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
1443 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1444 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
1445 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1446 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
1447 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1448 if (isOk) {
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 for (recipe = recipes; recipe; recipe = recipe->next) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1451 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
1452 isOk = TRUE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1453 if (! recipe->boiltime)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1454 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1455 for (i = 0; i < 8; i++) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1456 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
1457 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1458 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1459 for (i = 0; i < 3; i++) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1460 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
1461 isOk = FALSE;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1462 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1463 break;
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 }
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1466 if (isOk == FALSE) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1467 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
1468 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1469 fprintf(stdout, "brew init: recipe error\n");
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
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1473 if (debug)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1474 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
1475
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1476 if (isOk) {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1477 wrsession(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1478 } else {
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1479 prompt(300, message);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1480 prompt(408, NULL); /* "--- --- Ok --- " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1481 key = keywait();
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1482 if (brew->name)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1483 free(brew->name);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1484 if (brew->uuid_recipe)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1485 free(brew->uuid_recipe);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1486 if (brew->uuid_unit)
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1487 free(brew->uuid_unit);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1488 free(brew);
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1489 brew = NULL;
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1490 /*
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1491 * Rewrite the display
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1492 */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1493 prompt(101, NULL); /* " Brewco x.x.x " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1494 prompt(300, NULL); /* " " */
55bcbf92ecab Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents: 471
diff changeset
1495 prompt(401, NULL); /* "--- MAN AUTO SETUP" */
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
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1498 } else if (key == KEY_DOWN) {
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1499 manual = MANUAL_SELHLT;
466
49a5318256f0 Manual mode works with heat percentages.
Michiel Broek <mbroek@mbse.eu>
parents: 465
diff changeset
1500 manual_prompt();
451
2247970de278 Manual mode added.
Michiel Broek <mbroek@mbse.eu>
parents: 450
diff changeset
1501 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1502 }
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1503
454
78242696c15a Beginning of the main program loop
Michiel Broek <mbroek@mbse.eu>
parents: 453
diff changeset
1504 usleep(5000); /* 5 mSec */
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1505
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1506 } while (run);
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1507
440
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1508 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
1509 if (debug)
8df3252b688f Added prompts for the LCD. Basic processing loop written.
Michiel Broek <mbroek@mbse.eu>
parents: 438
diff changeset
1510 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
1511
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
1512 prompt(0, NULL);
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1513 prompt(101, NULL); /* " Brewco x.x.x " */
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1514 prompt(302, NULL); /* " Shutting down " */
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1515
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1516 /*
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1517 * Give threads time to cleanup
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1518 */
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1519 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
1520 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
1521 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
1522
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1523 if (sock != -1) {
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1524 if (shutdown(sock, SHUT_RDWR)) {
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1525 syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno));
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1526 }
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1527 sock = -1;
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1528 }
467
f4d75ef899f4 Finished manual mode.
Michiel Broek <mbroek@mbse.eu>
parents: 466
diff changeset
1529
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
1530 wrrecipes();
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1531 wrconfig();
465
3aac3276689d Added program locking.
Michiel Broek <mbroek@mbse.eu>
parents: 464
diff changeset
1532 ulockprog((char *)"brewco");
438
7d1ec160d751 Added simulator configuration.
Michiel Broek <mbroek@mbse.eu>
parents: 434
diff changeset
1533 return 0;
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1534 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1535
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1536
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1537
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
1538 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
1539 {
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
1540 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
1541 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
1542
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
1543 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
1544 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
1545 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
1546 {"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
1547 {"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
1548 {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
1549 };
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
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 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
1552 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
1553 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
1554
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 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
1556 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
1557 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
1558 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
1559 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
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 }
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
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 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
1564 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
1565 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
1566 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
1567
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
1568 /*
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
1569 * 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
1570 */
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
1571 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
1572 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
1573 } 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
1574 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
1575 }
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 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
1577 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
1578 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
1579 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
1580 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
1581 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
1582
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
1583 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
1584 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
1585 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
1586 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
1587 }
441
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1588 if (debug)
bde74a8f2ad7 Added automate state file.
Michiel Broek <mbroek@mbse.eu>
parents: 440
diff changeset
1589 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
1590
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
1591 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
1592 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
1593 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
1594 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
1595 }
1f88be70f253 Added the beginning of the recipes editor. Added load and save of recipes file.
Michiel Broek <mbroek@mbse.eu>
parents: 456
diff changeset
1596 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
1597 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
1598
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
1599 /*
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
1600 * 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
1601 * 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
1602 * 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
1603 */
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
1604 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
1605 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
1606 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
1607 }
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
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 #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
1610 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
1611 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
1612 #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
1613
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1614 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
1615 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
1616 return 1;
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1617 }
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1618
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1619 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
1620
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
1621 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
434
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1622 if (debug)
eb724767860d Brewco first phase development configuration structure.
Michiel Broek <mbroek@mbse.eu>
parents: 419
diff changeset
1623 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
1624 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
1625 }
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

mercurial