thermferm/thermferm.c

Wed, 29 Oct 2014 20:27:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 29 Oct 2014 20:27:37 +0100
changeset 293
881b1ae75468
parent 289
d810df0df36a
child 297
a70527a4e56a
permissions
-rw-r--r--

Added usage counters

26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
23 #include "lock.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
24 #include "logger.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
25 #include "rdconfig.h"
160
87bfa951ffc2 Fixed wrong includes
Michiel Broek <mbroek@mbse.eu>
parents: 158
diff changeset
26 #include "devices.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
27 #include "server.h"
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
28 #include "thermferm.h"
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
29 #include "simulator.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
30 #include "lcd-pcf8574.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
31 #include "lcd-buffer.h"
198
20716bcff2b0 Added dependencies for panel
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
32 #include "panel.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
33 #include "futil.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
34 #include "xutil.h"
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
37 int my_shutdown = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 static pid_t pgrp, mypid;
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
39 int run_pause = FALSE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
40 int run_hold = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
42 extern int debug;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 extern sys_config Config;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
44 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 extern int lcdHandle;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
46 int setupmenu = MENU_NONE;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
47 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
48 profiles_list *current_profile = NULL;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
49 float temp_temp = 20.0;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
50 #endif
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
51
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
52 #ifndef HAVE_WIRINGPI_H
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
53 pthread_t threads[5];
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
54 #endif
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
55 extern const char UNITMODE[5][8];
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
56 extern const char PROFSTATE[4][6];
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
57
40
dafbbd5e9922 Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
58
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
59 int server(void);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 void help(void);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 void die(int);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
62 #ifdef HAVE_WIRINGPI_H
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
63 void sendRCswitch(char *, int);
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
64 void stopLCD(void);
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
65 void stopRCswitch(void);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
66 #endif
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
67
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 void help(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 {
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
72 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n\n", VERSION);
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
73 fprintf(stdout, "Usage: thermferm [-d] [-h]\n");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 fprintf(stdout, " -d --debug Debug and run in foreground\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 fprintf(stdout, " -h --help Display this help\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 void die(int onsig)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 switch (onsig) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 default: syslog(LOG_NOTICE, "die() on signal %d", onsig);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
92 my_shutdown = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
96
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
97 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
98 void show_mode(void)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
99 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
100 char buf[21];
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
101
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
102 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
103 lcdPuts(lcdHandle, buf);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
104 lcdPosition(lcdHandle, 0, 1);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
105 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
106
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
107
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
108
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
109 void go_menu(int menu)
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
110 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
111 char buf[21];
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
112
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
113 piLock(LOCK_LCD);
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
114 piLock(LOCK_MENU);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
115 lcdClear(lcdHandle);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
116 lcdPosition(lcdHandle, 0, 0);
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
117 syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
118 setupmenu = menu;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
119
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
120 switch (menu) {
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
121 case MENU_NONE: lcd_buf_show();
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
122 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
123
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
124 case MENU_TOP_DEFAULT: lcdPuts(lcdHandle, "Setup mode.");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
125 lcdPosition(lcdHandle, 0, 1);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
126 lcdPuts(lcdHandle, "Up&Down = Escape");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
127 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
128
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
129 case MENU_TOP_UNITS: lcdPuts(lcdHandle, "Select units");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
130 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
131
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
132 case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:");
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
133 lcdPosition(lcdHandle, 0, 1);
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
134 lcdPuts(lcdHandle, current_unit->name);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
135 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
136
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
137 case MENU_MODE_OFF: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
138 lcdPuts(lcdHandle, "New mode OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
139 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
140
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
141 case MENU_MODE_NONE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
142 lcdPuts(lcdHandle, "New mode NONE");
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
143 break;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
144
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
145 case MENU_NONE_HEAT: snprintf(buf, Config.lcd_cols, "Set heater %s", current_unit->heater_state ? "OFF":"ON");
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
146 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
147 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
148
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
149 case MENU_NONE_COOL: snprintf(buf, Config.lcd_cols, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON");
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
150 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
151 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
152
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
153 case MENU_NONE_FAN: snprintf(buf, Config.lcd_cols, "Set fan %s", current_unit->fan_state ? "OFF":"ON");
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
154 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
155 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
156
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
157 case MENU_MODE_BEER: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
158 lcdPuts(lcdHandle, "New mode BEER");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
159 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
160
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
161 case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp");
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
162 lcdPosition(lcdHandle, 0, 1);
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
163 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
164 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
165 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
166
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
167 case MENU_MODE_FRIDGE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
168 lcdPuts(lcdHandle, "New mode FRIDGE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
169 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
170
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
171 case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp");
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
172 lcdPosition(lcdHandle, 0, 1);
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
173 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
174 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
175 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
176
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
177 case MENU_MODE_PROFILE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
178 lcdPuts(lcdHandle, "New mode PROFILE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
179 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
180
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
181 case MENU_PROFILE_SELECT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
182 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
183 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
184 lcdPuts(lcdHandle, "Select profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
185 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
186
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
187 case MENU_PROFILE_START: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
188 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
189 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
190 lcdPuts(lcdHandle, "Start profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
191 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
192
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
193 case MENU_PROFILE_PAUSE: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
194 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
195 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
196 lcdPuts(lcdHandle, "Pause profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
197 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
198
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
199 case MENU_PROFILE_ABORT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
200 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
201 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
202 lcdPuts(lcdHandle, "Abort profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
203 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
204
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
205 case MENU_PROFILE_RESUME: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
206 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
207 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
208 lcdPuts(lcdHandle, "Resume profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
209 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
210
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
211 case MENU_PROFILE_GOOFF: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
212 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
213 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
214 lcdPuts(lcdHandle, "Set profile OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
215 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
216
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
217 case MENU_TOP_SYS: lcdPuts(lcdHandle, "System menu");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
218 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
219
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
220 case MENU_SYS_HALT: lcdPuts(lcdHandle, "Halt system");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
221 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
222
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
223 case MENU_SYS_REBOOT: lcdPuts(lcdHandle, "Reboot system");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
224 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
225 }
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
226
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
227 piUnlock(LOCK_MENU);
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
228 piUnlock(LOCK_LCD);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
229 }
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
230
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
231
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
232
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 void stopLCD(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 {
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
235 piLock(LOCK_LCD);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
236 lcdClear(lcdHandle);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 setBacklight(0);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
238 piUnlock(LOCK_LCD);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 }
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
240
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
241
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
242
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
243 /*
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
244 * Change mode of current_unit
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
245 */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
246 void change_mode(int mode)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
247 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
248 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF))
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
249 initlog(current_unit->name);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
250 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
251 current_unit->mode = mode;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
252 /* Allways turn everything off after a mode change */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
253 current_unit->PID_I_err = current_unit->PID_err_old = 0.0;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
254 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
255 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
256 device_out(current_unit->heater_address, current_unit->heater_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
257 device_out(current_unit->cooler_address, current_unit->cooler_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
258 device_out(current_unit->fan_address, current_unit->fan_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
259 if (current_unit->mode == UNITMODE_PROFILE) {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
260 /*
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
261 * Set a sane default until it will be overruled by the
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
262 * main processing loop.
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
263 */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
264 current_unit->prof_target = 20.0;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
265 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
266 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
267
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
268
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
269 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
270
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
271
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
272
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
273 int read_sensor(char *address, int *val)
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
274 {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
275 devices_list *device;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
276 int tmp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
277
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
278 for (device = Config.devices; device; device = device->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
279 if (strcmp(address, device->uuid) == 0) {
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
280 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
281 piLock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
282 #endif
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 207
diff changeset
283 tmp = device->value + device->offset;
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
284 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
285 piUnlock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
286 #endif
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
287 *val = tmp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
288 return device->present;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
289 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
290 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
291
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
292 return DEVPRESENT_NO;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
293 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
294
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
295
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
296
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
297 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
298 * Handle panel key events
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
299 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
300 #ifdef HAVE_WIRINGPI_H
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
301 void panel_key_events(int key)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
302 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
303 units_list *unit;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
304 profiles_list *profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
305 int rc;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
306
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
307 switch (setupmenu) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
308 case MENU_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
309 if ((key == KEY_DOWN) || (key == KEY_UP))
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
310 lcd_buf_step(key);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
311 if ((key == KEY_CONFIRM) && (setupmenu == MENU_NONE))
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
312 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
313 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
314
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
315 case MENU_TOP_DEFAULT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
316 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
317 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
318 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
319 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
320 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
321 go_menu(MENU_TOP_SYS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
322 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
323
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
324 case MENU_TOP_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
325 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
326 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
327 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
328 go_menu(MENU_TOP_SYS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
329 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
330 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
331 if ((key == KEY_ENTER) && Config.units) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
332 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
333 * Start with the first unit
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
334 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
335 current_unit = Config.units;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
336 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
337 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
338 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
339
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
340 case MENU_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
341 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
342 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
343 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
344 if (current_unit->next) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
345 current_unit = current_unit->next;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
346 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
347 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
348 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
349 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
350 for (unit = Config.units; unit; unit = unit->next) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
351 if (unit->next && (unit->next == current_unit)) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
352 current_unit = unit;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
353 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
354 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
355 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
356 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
357 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
358 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
359 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
360 * Drop into the current mode
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
361 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
362 switch (current_unit->mode) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
363 case UNITMODE_OFF: go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
364 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
365 case UNITMODE_NONE: go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
366 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
367 case UNITMODE_FRIDGE: go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
368 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
369 case UNITMODE_BEER: go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
370 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
371 case UNITMODE_PROFILE: go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
372 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
373 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
374 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
375 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
376
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
377 case MENU_MODE_OFF:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
378 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
379 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
380 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
381 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
382 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
383 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
384 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
385 change_mode(UNITMODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
386 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
387 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
388 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
389
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
390 case MENU_MODE_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
391 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
392 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
393 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
394 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
395 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
396 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
397 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
398 if (current_unit->mode == UNITMODE_NONE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
399 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
400 else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
401 change_mode(UNITMODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
402 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
403 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
404 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
405 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
406
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
407 case MENU_NONE_HEAT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
408 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
409 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
410 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
411 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
412 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
413 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
414 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
415 if (current_unit->heater_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
416 current_unit->heater_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
417 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
418 current_unit->heater_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
419 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
420 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
421 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
422
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
423 case MENU_NONE_COOL:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
424 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
425 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
426 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
427 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
428 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
429 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
430 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
431 if (current_unit->cooler_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
432 current_unit->cooler_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
433 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
434 current_unit->cooler_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
435 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
436 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
437 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
438
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
439 case MENU_NONE_FAN:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
440 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
441 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
442 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
443 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
444 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
445 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
446 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
447 if (current_unit->fan_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
448 current_unit->fan_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
449 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
450 current_unit->fan_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
451 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
452 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
453 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
454
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
455 case MENU_MODE_FRIDGE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
456 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
457 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
458 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
459 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
460 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
461 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
462 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
463 if (current_unit->mode == UNITMODE_FRIDGE) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
464 temp_temp = current_unit->fridge_set;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
465 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
466 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
467 change_mode(UNITMODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
468 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
469 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
470 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
471 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
472
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
473 case MENU_FRIDGE_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
474 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
475 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
476 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
477 if (temp_temp > current_unit->temp_set_min)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
478 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
479 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
480 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
481 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
482 if (temp_temp < current_unit->temp_set_max)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
483 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
484 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
485 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
486 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
487 if (temp_temp != current_unit->fridge_set) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
488 syslog(LOG_NOTICE, "Fridge temperature changed from %.1f to %.1f degrees from the panel", current_unit->fridge_set, temp_temp);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
489 current_unit->fridge_set = temp_temp;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
490 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
491 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
492 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
493 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
494
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
495 case MENU_MODE_BEER:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
496 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
497 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
498 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
499 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
500 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
501 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
502 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
503 if (current_unit->mode == UNITMODE_BEER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
504 temp_temp = current_unit->beer_set;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
505 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
506 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
507 change_mode(UNITMODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
508 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
509 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
510 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
511 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
512
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
513 case MENU_BEER_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
514 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
515 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
516 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
517 if (temp_temp > current_unit->temp_set_min)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
518 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
519 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
520 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
521 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
522 if (temp_temp < current_unit->temp_set_max)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
523 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
524 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
525 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
526 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
527 if (temp_temp != current_unit->beer_set) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
528 syslog(LOG_NOTICE, "Beer temperature changed from %.1f to %.1f degrees from the panel", current_unit->beer_set, temp_temp);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
529 current_unit->beer_set = temp_temp;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
530 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
531 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
532 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
533 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
534
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
535 case MENU_MODE_PROFILE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
536 if (current_unit->profile) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
537 for (current_profile = Config.profiles; current_profile; current_profile = current_profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
538 if (strcmp(current_profile->uuid, current_unit->profile) == 0)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
539 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
540 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
541 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
542 current_profile = NULL;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
543 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
544 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
545 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
546 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
547 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
548 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
549 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
550 if (key == KEY_ENTER) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
551 if (current_unit->mode == UNITMODE_PROFILE) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
552 switch (current_unit->prof_state) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
553 case PROFILE_OFF: if (current_unit->profile)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
554 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
555 else
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
556 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
557 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
558 case PROFILE_PAUSE: go_menu(MENU_PROFILE_RESUME);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
559 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
560 case PROFILE_RUN: go_menu(MENU_PROFILE_PAUSE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
561 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
562 case PROFILE_DONE: go_menu(MENU_PROFILE_GOOFF);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
563 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
564 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
565 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
566 change_mode(UNITMODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
567 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
568 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
569 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
570 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
571
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
572 case MENU_PROFILE_SELECT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
573 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
574 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
575 if (key == KEY_DOWN) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
576 if (current_profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
577 current_profile = current_profile->next;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
578 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
579 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
580 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
581 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
582 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
583 if (key == KEY_UP) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
584 for (profile = Config.profiles; profile; profile = profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
585 if (profile->next && profile->next == current_profile) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
586 current_profile = profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
587 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
588 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
589 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
590 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
591 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
592 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
593 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
594 current_unit->profile = current_profile->uuid;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
595 syslog(LOG_NOTICE, "Profile %s selected from panel", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
596 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
597 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
598 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
599
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
600 case MENU_PROFILE_START:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
601 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
602 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
603 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
604 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
605 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
606 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
607 current_unit->prof_started = time(NULL);
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
608 current_unit->prof_paused = current_unit->prof_primary_done = 0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
609 current_unit->prof_peak_abs = current_unit->prof_peak_rel = 0.0;
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
610 syslog(LOG_NOTICE, "Profile started from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
611 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
612 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
613 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
614
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
615 case MENU_PROFILE_PAUSE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
616 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
617 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
618 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
619 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
620 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
621 current_unit->prof_state = PROFILE_PAUSE;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
622 syslog(LOG_NOTICE, "Profile pause from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
623 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
624 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
625 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
626
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
627 case MENU_PROFILE_ABORT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
628 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
629 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
630 if ((key == KEY_DOWN) || (key == KEY_UP)) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
631 if (current_unit->prof_state == PROFILE_PAUSE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
632 go_menu(MENU_PROFILE_RESUME);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
633 else if (current_unit->prof_state == PROFILE_RUN)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
634 go_menu(MENU_PROFILE_PAUSE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
635 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
636 if ((key == KEY_ENTER) && ((current_unit->prof_state == PROFILE_RUN) || (current_unit->prof_state == PROFILE_PAUSE))) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
637 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
638 current_unit->prof_started = 0;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
639 syslog(LOG_NOTICE, "Profile aborted from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
640 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
641 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
642 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
643
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
644 case MENU_PROFILE_RESUME:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
645 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
646 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
647 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
648 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
649 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
650 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
651 syslog(LOG_NOTICE, "Profile resume from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
652 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
653 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
654 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
655
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
656 case MENU_PROFILE_GOOFF:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
657 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
658 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
659 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
660 if (current_unit->prof_state == PROFILE_DONE) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
661 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
662 syslog(LOG_NOTICE, "Profile from done to off from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
663 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
664 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
665 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
666
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
667 case MENU_TOP_SYS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
668 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
669 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
670 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
671 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
672 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
673 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
674 if (key == KEY_ENTER)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
675 go_menu(MENU_SYS_HALT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
676 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
677
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
678 case MENU_SYS_HALT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
679 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
680 go_menu(MENU_TOP_SYS);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
681 if ((key == KEY_DOWN) || (key == KEY_UP))
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
682 go_menu(MENU_SYS_REBOOT);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
683 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
684 rc = system("/sbin/halt");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
685 syslog(LOG_NOTICE, "System halt from panel: /sbin/halt rc=%d", rc);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
686 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
687 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
688 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
689
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
690 case MENU_SYS_REBOOT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
691 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
692 go_menu(MENU_TOP_SYS);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
693 if ((key == KEY_DOWN) || (key == KEY_UP))
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
694 go_menu(MENU_SYS_HALT);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
695 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
696 rc = system("/sbin/reboot");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
697 syslog(LOG_NOTICE, "System reboot from panel: /sbin/reboot rc=%d", rc);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
698 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
699 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
700 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
701 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
702 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
703 #endif
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
704
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
705
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
706
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
707
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708 int main(int argc, char *argv[])
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 int rc, c, i;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 pid_t frk;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 while (1) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714 int option_index = 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 static struct option long_options[] = {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 {"debug", 0, 0, 'c'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 {"help", 0, 0, 'h'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 {0, 0, 0, 0}
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 };
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 c = getopt_long(argc, argv, "dh", long_options, &option_index);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 if (c == -1)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 switch (c) {
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
726 case 'd': debug = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728 case 'h': help();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
731 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
732
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
733 openlog("thermferm", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_USER);
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
734 syslog(LOG_NOTICE, "mbsePi-apps thermferm v%s starting", VERSION);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 if (debug)
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
736 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n", VERSION);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
738 if (rdconfig()) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739 fprintf(stderr, "Error reading configuration\n");
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
740 syslog(LOG_NOTICE, "Error reading configuration: halted");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
741 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
742 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
743
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
744 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 * but that's live. This daemon should only be stopped by SIGTERM.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747 * Don't catch SIGCHLD.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749 for (i = 0; i < NSIG; i++) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP))
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 signal(i, (void (*))die);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
753
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
754 #ifdef HAVE_WIRINGPI_H
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
755 if (wiringPiSetup () )
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
756 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
757
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
758 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
762 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
763
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 if (debug) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 * For debugging run in foreground.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 } else {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 * Server initialization is complete. Now we can fork the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 * daemon and return to the user. We need to do a setpgrp
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 * so that the daemon will no longer be assosiated with the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 * users control terminal. This is done before the fork, so
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775 * that the child will not be a process group leader. Otherwise,
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 * if the child were to open a terminal, it would become
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777 * associated with that terminal as its control terminal.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779 if ((pgrp = setpgid(0, 0)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
780 syslog(LOG_NOTICE, "setpgpid failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783 frk = fork();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784 switch (frk) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 case -1:
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
786 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno));
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
787 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 stopLCD();
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
789 #endif
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 exit(1);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791 case 0: /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 * Run the daemon
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794 fclose(stdin);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 if (open("/dev/null", O_RDONLY) != 0) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
796 syslog(LOG_NOTICE, "Reopen of stdin to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 fclose(stdout);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
801 syslog(LOG_NOTICE, "Reopen of stdout to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804 fclose(stderr);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
806 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 mypid = getpid();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 /* Not reached */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813 default:
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 * Here we detach this process and let the child
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 * run the deamon process.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818 syslog(LOG_NOTICE, "Starting daemon with pid %d", frk);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819 exit(0);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 return rc;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829 int server(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 {
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
831 char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40];
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
832 time_t now, last = (time_t)0;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
833 units_list *unit;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
834 profiles_list *profile;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
835 prof_step *step;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
836 int rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
837 int run_seconds, run_minutes, run_hours, tot_minutes;
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
838 float err = 0.0, sp, pv, P_err, D_err, Out;
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
839 #ifdef HAVE_WIRINGPI_H
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
840 struct tm *tm;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
841 int row, key;
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
842 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
843 long t = 0;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
844 #endif
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
845 int current_step, valid_step, time_until_now;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
846 float previous_target;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
848 if (lockprog((char *)"thermferm")) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
849 syslog(LOG_NOTICE, "Can't lock");
34
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
850 return 1;
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
851 }
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
852
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
853 rc = devices_detect();
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
854 if (rc) {
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
855 syslog(LOG_NOTICE, "Detected %d new devices", rc);
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
856 wrconfig();
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
857 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
858
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
859 #ifdef HAVE_WIRINGPI_H
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
860 rc = piThreadCreate(my_devices_loop);
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
861 #else
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
862 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
863 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
864 if (rc) {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
865 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
866 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc);
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
867 #ifndef HAVE_WIRINGPI_H
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
868 } else {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
869 t++;
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
870 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
871 }
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
872
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
873 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
874 rc = piThreadCreate(my_server_loop);
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
875 #else
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
876 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
877 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
878 if (rc) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
879 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
880 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc);
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
881 #ifndef HAVE_WIRINGPI_H
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
882 } else {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
883 t++;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
884 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
885 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
886
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
887 #ifdef HAVE_WIRINGPI_H
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
888 rc = piThreadCreate(my_panel_loop);
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
889 if (rc) {
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
890 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
891 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc);
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
892 }
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
893 #endif
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
894
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
895
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
896 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
897 #ifdef HAVE_WIRINGPI_H
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
898 rc = piThreadCreate(my_simulator_loop);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
899 #else
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
900 rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t );
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
901 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
902 if (rc) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
903 fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
904 syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
905 #ifndef HAVE_WIRINGPI_H
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
906 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
907 t++;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
908 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
909 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
910 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
911
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
912 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
913 * Initialize units for processing
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
914 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
915 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
916 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
917 * Safety, turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
918 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
919 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
920 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
921 if (unit->mode == UNITMODE_PROFILE) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
922 if (!unit->profile)
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
923 syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name);
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
924 else
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
925 syslog(LOG_NOTICE, "Starting unit %s in profile state %s.", unit->name, PROFSTATE[unit->prof_state]);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
926 } else if (unit->mode == UNITMODE_BEER) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
927 syslog(LOG_NOTICE, "Starting unit %s beer cooler at %.1f degrees", unit->name, unit->beer_set);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
928 } else if (unit->mode == UNITMODE_FRIDGE) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
929 syslog(LOG_NOTICE, "Starting unit %s as refridgerator at %.1f degrees", unit->name, unit->fridge_set);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
930 } else if (unit->mode == UNITMODE_NONE) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
931 syslog(LOG_NOTICE, "Starting unit %s in inactive state", unit->name);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
932 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
933 syslog(LOG_NOTICE, "Starting unit %s in off state", unit->name);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
934 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
935 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
936
93
b759f814469d Added units processing thread
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
937
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
938 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
939 piLock(LOCK_LCD);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
940 lcd_buf_write(1, (char *)" ThermFerm ");
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
941 lcd_buf_write(2, (char *)" Version %s ", VERSION);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
942 piUnlock(LOCK_LCD);
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
943 #endif
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
944
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
945 for (unit = Config.units; unit; unit = unit->next) {
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
946 if (unit->mode != UNITMODE_OFF) {
155
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 150
diff changeset
947 initlog(unit->name);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
948 }
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
949 }
33
2357e8636a60 Added user log with temperatures and cooler state
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
950
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951 do {
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
952 if (my_shutdown)
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
953 run = 0;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
954
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
955 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
956 * Use to stop processing units. Should be used when a unit is
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
957 * added or removed.
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
958 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
959 if (run_pause) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
960 run_hold = TRUE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
961 syslog(LOG_NOTICE, "run_pause: entering hold state");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
962 for (;;) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
963 usleep(100000);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
964 if (! run_pause)
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
965 break;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
966 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
967 syslog(LOG_NOTICE, "run_pause: leaving hold state");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
968 run_hold = FALSE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
969 #ifdef HAVE_WIRINGPI_H
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
970 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
971 * In case the LCD buffers were cleared, setup the first page.
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
972 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
973 piLock(LOCK_LCD);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
974 lcd_buf_write(1, (char *)" ThermFerm ");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
975 lcd_buf_write(2, (char *)" Version %s ", VERSION);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
976 piUnlock(LOCK_LCD);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
977 #endif
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
978 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
979
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
980 now = time(NULL);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
981 if (now != last) {
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
982 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
983 * Each second
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
984 */
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
985 last = now;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
986 seconds++;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
987
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
988 #ifdef HAVE_WIRINGPI_H
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
989 row = 3;
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
990 tm = localtime(&now);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
991 piLock(LOCK_LCD);
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
992 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
993 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
994 piUnlock(LOCK_LCD);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
995 #endif
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
996
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
997 if (Config.temp_address) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
998 rc = read_sensor(Config.temp_address, &temp);
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
999 if (rc == DEVPRESENT_YES) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1000 Config.temp_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1001 Config.temp_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1002 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1003 piLock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1004 lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1005 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1006 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1007 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1008 Config.temp_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1009 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1010 Config.temp_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1011 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1012 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1013
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1014 if (Config.hum_address) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1015 rc = read_sensor(Config.hum_address, &temp);
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1016 if (rc == DEVPRESENT_YES) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1017 Config.hum_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1018 Config.hum_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1019 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1020 piLock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1021 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1022 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1023 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1024 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1025 Config.hum_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1026 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1027 Config.hum_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1028 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1029 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1030
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1031 for (unit = Config.units; unit; unit = unit->next) {
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1032 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1033 piLock(LOCK_LCD);
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1034 lcd_buf_write(row++, "Unit %s ", unit->name);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1035 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1036 piUnlock(LOCK_LCD);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1037 #endif
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1038
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1039 if (unit->air_address) {
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1040 rc = read_sensor(unit->air_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1041 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1042 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1043 * It is possible to have read errors or extreme values.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1044 * This can happen with bad connections so we compare the
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1045 * value with the previous one. If the difference is too
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1046 * much, we don't send that value. That also means that if
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1047 * the next value is ok again, it will be marked invalid too.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1048 * Maximum error is 40 degrees for now.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1049 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1050 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1051 if ((unit->air_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1052 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1053 unit->air_temperature = temp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1054 unit->air_state = 0;
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1055 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1056 piLock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1057 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1058 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1059 #endif
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1060 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1061 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1062 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1063 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1064 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1065 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1066 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1067 unit->air_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1068 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1069 unit->air_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1070 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1071 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1072
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1073 if (unit->beer_address) {
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1074 rc = read_sensor(unit->beer_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1075 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1076 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1077 if ((unit->beer_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1078 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1079 unit->beer_temperature = temp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1080 unit->beer_state = 0;
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1081 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1082 piLock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1083 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1084 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1085 #endif
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1086 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1087 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1088 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1089 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1090 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1091 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1092 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1093 unit->beer_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1094 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1095 unit->beer_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1096 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1097 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1098
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1099 /*
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1100 * Handle profile
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1101 */
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1102 if ((unit->mode == UNITMODE_PROFILE) && (unit->profile)) {
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1103 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1104 * unit->profile - uuid of the selected profile.
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1105 * unit->prof_started - start time or 0 if not yet running.
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1106 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1107 * unit->prof_target - Calculated target temperature.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1108 * unit->prof_paused - Internal pause counter.
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1109 * unit->prof_peak_abs - Peak temperature of the beer.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1110 * unit->prof_peak_rel - Peak temperature between beer and fridge.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1111 * unit->prof_primary_done - time when primary fermentation was over the peak.
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1112 */
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1113 for (profile = Config.profiles; profile; profile = profile->next) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1114 if (strcmp(unit->profile, profile->uuid) == 0) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1115
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1116 switch (unit->prof_state) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1117 case PROFILE_OFF:
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1118 unit->prof_target = profile->inittemp;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1119 unit->prof_percent = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1120 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1121 case PROFILE_PAUSE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1122 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1123 * Keep current temperature, measure pause time. For
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1124 * temperature fall thru.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1125 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1126 unit->prof_paused++;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1127 case PROFILE_RUN:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1128 /*
288
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1129 * Calculate current profile step and desired temperature.
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1130 * When all steps are done, set state to PROFILE_DONE.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1131 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1132 previous_target = profile->inittemp;
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1133 time_until_now = current_step = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1134 run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1135 run_minutes = run_seconds / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1136 run_hours = run_minutes / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1137 if (debug)
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1138 fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1139
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1140 /*
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1141 * Primary fermentation tests
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1142 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1143 if ((unit->beer_temperature / 1000.0) > unit->prof_peak_abs)
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1144 unit->prof_peak_abs = unit->beer_temperature / 1000.0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1145 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) > unit->prof_peak_rel)
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1146 unit->prof_peak_rel = (unit->beer_temperature - unit->air_temperature) / 1000.0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1147 if (unit->prof_primary_done == 0) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1148 if (unit->cooler_address) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1149 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1150 * There is a cooler. If the difference between the beer and air temperature
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1151 * drops we assume the primary fermentation is done.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1152 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1153 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1154 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1155 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", profile->name);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1156 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1157 } else {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1158 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1159 * This method works if the unit has no cooling or if the profile allowd the
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1160 * beer temperature to rise freely.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1161 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1162 if ((unit->beer_temperature / 1000.0) < (unit->prof_peak_abs - 0.5)) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1163 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1164 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", profile->name);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1165 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1166 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1167 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1168
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1169 /*
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1170 * See how long this profile will take
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1171 */
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1172 tot_minutes = 0;
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1173 for (step = profile->steps; step; step = step->next) {
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1174 tot_minutes += ((step->steptime + step->resttime) * 60);
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1175 }
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1176
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1177 valid_step = FALSE;
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1178 for (step = profile->steps; step; step = step->next) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1179 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1180 * step->steptime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1181 * step->resttime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1182 * step->target
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1183 */
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1184 current_step++;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1185 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1186 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1187 * This is our current step
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1188 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1189 valid_step = TRUE;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1190 if (debug)
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1191 fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f ",
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1192 current_step, run_hours - time_until_now,
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1193 step->steptime, step->resttime, step->target);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1194 if ((run_hours - time_until_now) < step->steptime) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1195 unit->prof_target = previous_target + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target - previous_target));
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1196 if (debug)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1197 fprintf(stdout, "tempshift=%.1f minutes=%d duration=%d temp_move=%.3f ",
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1198 step->target - previous_target, run_minutes - (time_until_now * 60),
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1199 step->steptime * 60, unit->prof_target);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1200 } else {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1201 unit->prof_target = step->target;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1202 fprintf(stdout, "resting target=%.1f ", step->target);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1203 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1204 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1205 }
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1206 time_until_now += step->steptime + step->resttime;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1207 previous_target = step->target;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1208 }
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1209 if (debug)
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1210 fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds);
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1211
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1212 if (valid_step == TRUE) {
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1213 unit->prof_percent = (100 * run_minutes) / tot_minutes;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
1214 if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
1215 syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %.3f degrees",
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
1216 profile->name, run_hours / 24, run_hours % 24, run_minutes % 60, current_step,
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1217 unit->prof_percent, unit->prof_target);
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1218 }
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1219 } else {
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1220 /*
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1221 * No more steps to do
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1222 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1223 unit->prof_state = PROFILE_DONE;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1224 unit->prof_percent = 100;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1225 syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1226 }
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1227 break;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1228
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1229 case PROFILE_DONE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1230 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1231 * Keep this state, set target temperature to the last step.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1232 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1233 previous_target = profile->inittemp;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1234 for (step = profile->steps; step; step = step->next) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1235 if (step->steptime == 0)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1236 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1237 previous_target = step->target;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1238 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1239 unit->prof_target = previous_target;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1240 unit->prof_percent = 100;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1241 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1242 } /* switch */
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1243 }
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1244 }
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1245 }
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1246
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1247 /*
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1248 * Manual switching
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1249 */
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1250 if (unit->mode == UNITMODE_NONE) {
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1251 device_out(unit->heater_address, unit->heater_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1252 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1253 device_out(unit->fan_address, unit->fan_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1254 }
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1255
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1256 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1257 * Usage counters
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1258 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1259 if (unit->heater_address && unit->heater_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1260 unit->heater_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1261 if (unit->cooler_address && unit->cooler_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1262 unit->cooler_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1263 if (unit->fan_address && unit->fan_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1264 unit->fan_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1265
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1266 #ifdef HAVE_WIRINGPI_H
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1267 if (unit->heater_address && unit->cooler_address) {
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1268 piLock(LOCK_LCD);
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1269 if (unit->heater_state) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1270 lcd_buf_write(row++, "Heater On ");
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1271 } else if (unit->cooler_state) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1272 lcd_buf_write(row++, "Cooler On ");
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1273 } else {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1274 lcd_buf_write(row++, "Standby ");
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1275 }
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1276 piUnlock(LOCK_LCD);
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1277 piLock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1278 switch (unit->mode) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1279 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1280 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1281 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1282 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1283 case UNITMODE_PROFILE: if (unit->prof_state != PROFILE_OFF)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1284 lcd_buf_write(row++, "Target %.1f %cC ", unit->prof_target, 0xdf);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1285 else
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1286 lcd_buf_write(row++, "Target not set ");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1287 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1288 default: lcd_buf_write(row++, "Target not set ");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1289 }
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1290 piUnlock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1291 } else {
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1292 piLock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1293 if (unit->heater_address) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1294 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1295 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1296 if (unit->cooler_address) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1297 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1298 }
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1299 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1300 }
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1301 #endif
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1302 }
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1303
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1304 piddelay++;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1305 if (piddelay == 15) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1306 piddelay = 0;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1307
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1308 for (unit = Config.units; unit; unit = unit->next) {
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1309 if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE)) {
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1310 /*
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1311 * PID controller
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1312 */
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1313 sp = unit->beer_set;
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1314 pv = unit->beer_temperature / 1000.0;
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1315 if (unit->mode == UNITMODE_FRIDGE) {
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1316 sp = unit->fridge_set;
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 177
diff changeset
1317 pv = unit->air_temperature / 1000.0;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1318 } else if (unit->mode == UNITMODE_PROFILE) {
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1319 sp = unit->prof_target;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1320 }
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1321
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1322 unit->PID_err_old = err;
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1323 err = sp - pv;
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1324 if (err < unit->idle_rangeH && err > unit->idle_rangeL) {
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1325 err = 0;
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1326 unit->PID_I_err -= unit->PID_err_old;
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1327 } else {
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1328 unit->PID_I_err += unit->PID_err_old;
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1329 }
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1330 /* Limit intergral error */
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1331 if (unit->PID_I_err < -10.0)
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1332 unit->PID_I_err = -10.0;
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1333 if (unit->PID_I_err > 10.0)
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1334 unit->PID_I_err = 10.0;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1335 P_err = err;
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1336 D_err = err - unit->PID_err_old;
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1337
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1338 /*
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1339 * A postive value means heating, a negative value cooling.
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1340 */
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1341 Out = (10.0*P_err) + (0.1*unit->PID_I_err) + (5*D_err);
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1342 // Kp 0.1 Ki 0.3 Kd 0.02
267
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1343 if (err != 0.0) {
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1344 if (debug)
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1345 fprintf(stdout, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f\n",
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1346 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
267
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1347 syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f",
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1348 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
a84792cab21c Don't log debug pid messages if there is no error difference
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1349 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1350 if (unit->heater_address) {
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1351 if (Out >= 2) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1352 if (unit->heater_wait < unit->heater_delay) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1353 unit->heater_wait++;
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1354 syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay);
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1355 } else {
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1356 if (! unit->heater_state && ! unit->cooler_state) {
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1357 syslog(LOG_NOTICE, "Heater Off => On");
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1358 unit->heater_state = 100;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1359 }
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1360 }
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1361 } else {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1362 if (unit->heater_wait > 0) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1363 unit->heater_wait--;
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1364 syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay);
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1365 } else {
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1366 if (unit->heater_state) {
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1367 syslog(LOG_NOTICE, "Heater On => Off");
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1368 unit->heater_state = 0;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1369 }
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1370 }
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1371 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1372 device_out(unit->heater_address, unit->heater_state);
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1373 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1374 if (unit->cooler_address) {
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1375 if (Out <= -2) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1376 if (unit->cooler_wait < unit->cooler_delay) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1377 unit->cooler_wait++;
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1378 syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay);
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1379 } else {
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1380 if (! unit->cooler_state && ! unit->heater_state) {
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1381 syslog(LOG_NOTICE, "Cooler Off => On");
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1382 unit->cooler_state = 100;
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1383 }
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1384 }
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1385 } else {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1386 if (unit->cooler_wait > 0) {
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1387 unit->cooler_wait--;
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1388 syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1389 } else {
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1390 if (unit->cooler_state) {
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1391 syslog(LOG_NOTICE, "Cooler On => Off");
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1392 unit->cooler_state = 0;
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1393 }
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1394 }
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1395 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1396 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1397 }
233
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1398 if (unit->heater_address && unit->cooler_address && unit->fan_address) {
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1399 /*
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1400 * If the temperature difference between air and beer is more then
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1401 * xxx degrees, turn the fan on to make an airflow.
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1402 * Maybe, run the fan too if the heater is on because the heater in
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1403 * most cases will be some sort of radiating heat device.
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1404 * For cooling ??? dunno yet.
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1405 */
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1406 if (((unit->air_temperature - unit->beer_temperature) > 1000) ||
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1407 ((unit->air_temperature - unit->beer_temperature) < -1000)) {
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1408 if (! unit->fan_state)
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1409 syslog(LOG_NOTICE, "Fan Off => On");
233
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1410 unit->fan_state = 100;
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1411 } else {
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1412 if (unit->fan_state)
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1413 syslog(LOG_NOTICE, "Fan On => Off");
233
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1414 unit->fan_state = 0;
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1415 }
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1416 device_out(unit->fan_address, unit->fan_state);
5874a6480322 Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents: 227
diff changeset
1417 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1418 } else {
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1419 err = 0.0;
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1420 unit->PID_I_err = 0.0;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1421 unit->PID_err_old = 0.0;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1422 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1423 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1424 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1425
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
1426 #ifdef HAVE_WIRINGPI_H
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
1427 piLock(LOCK_MENU);
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1428 if (setupmenu == MENU_NONE) {
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1429 piLock(LOCK_LCD);
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1430 lcd_buf_show();
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1431 piUnlock(LOCK_LCD);
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1432 }
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
1433 piUnlock(LOCK_MENU);
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
1434 #endif
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1435
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1436 if (seconds == 60) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1437 seconds = 0;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1438
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1439 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1440 * Log temperature and status every minute if unit is active.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1441 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1442 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1443 if (unit->mode != UNITMODE_OFF) {
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1444
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1445 snprintf(target, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1446 snprintf(heater, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1447 snprintf(cooler, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1448 snprintf(fan, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1449 snprintf(door, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1450
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1451 if (unit->mode == UNITMODE_BEER)
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1452 snprintf(target, 39, "%.1f", unit->beer_set);
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1453 else if (unit->mode == UNITMODE_FRIDGE)
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1454 snprintf(target, 39, "%.1f", unit->fridge_set);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1455 else if (unit->mode == UNITMODE_PROFILE)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1456 snprintf(target, 39, "%.1f", unit->prof_target);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1457
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1458 if (unit->heater_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1459 snprintf(heater, 39, "%d", unit->heater_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1460 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1461 if (unit->cooler_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1462 snprintf(cooler, 39, "%d", unit->cooler_state);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1463 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1464 if (unit->fan_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1465 snprintf(fan, 39, "%d", unit->fan_state);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1466 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1467 if (unit->door_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1468 snprintf(door, 39, "%d", unit->door_state);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1469 }
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1470
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1471 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s",
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1472 UNITMODE[unit->mode], unit->air_temperature / 1000.0,
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1473 unit->beer_temperature / 1000.0, target, heater, cooler, fan, door);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1474 filename = xstrcpy(unit->name);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1475 filename = xstrcat(filename, (char *)".log");
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1476 logger(filename, buf);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1477 free(filename);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1478 filename = NULL;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1479 }
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1480 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1481
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1482 minutes++;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1483 if (minutes == 60) {
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1484 minutes = 0;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1485 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1486 * Log usage counters every hour
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1487 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1488 for (unit = Config.units; unit; unit = unit->next) {
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1489 syslog(LOG_NOTICE, "Unit `%s' usage heater=%d cooler=%d fan=%d", unit->name, unit->heater_usage, unit->cooler_usage, unit->fan_usage);
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1490 }
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1491 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1492
227
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1493 /*
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1494 * Save the configuration each half hour.
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1495 */
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1496 if ((minutes == 15) || (minutes == 45))
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1497 wrconfig();
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
1498 }
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1499 }
200
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
1500
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
1501 #ifdef HAVE_WIRINGPI_H
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1502 key = keycheck();
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1503 if (key != KEY_NONE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1504 panel_key_events(key);
200
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
1505 #endif
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
1506
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1507 usleep(100000);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1508
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1509 } while (run);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1510
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1511 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1512 * Stop units processing in a neat way
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1513 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1514 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1515 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1516 * Turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1517 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1518 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1519 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1520 device_out(unit->heater_address, unit->heater_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1521 device_out(unit->cooler_address, unit->cooler_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1522 device_out(unit->fan_address, unit->fan_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1523 syslog(LOG_NOTICE, "Stopped unit %s mode %s", unit->name, UNITMODE[unit->mode]);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1524 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1525
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1526 if (debug)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1527 fprintf(stdout, (char *)"Out of loop\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1528
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1529 /*
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1530 * Give threads time to cleanup
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1531 */
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1532 usleep(1500000);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1533
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1534 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1535 stopLCD();
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1536 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1537
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
1538 wrconfig();
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
1539
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
1540 ulockprog((char *)"thermferm");
34
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1541
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1542 if (debug)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1543 fprintf(stdout, "Goodbye\n");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1544
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1545 return 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1546 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1547

mercurial