thermferm/thermferm.c

Tue, 02 Jun 2015 14:14:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 02 Jun 2015 14:14:20 +0200
changeset 367
b9130db48c63
parent 364
2f9bbbcd2407
child 395
e32e83550963
permissions
-rw-r--r--

Fixed compiling on a real RPi

26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
326
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
2 * Copyright (C) 2014-2015
26
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"
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
35 #include "pid.h"
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
38 int my_shutdown = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 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
40 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
41 int run_hold = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
43 extern int debug;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 extern sys_config Config;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
45 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 extern int lcdHandle;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
47 int setupmenu = MENU_NONE;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
48 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
49 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
50 float temp_temp = 20.0;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
51 #endif
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
52
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
53 #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
54 pthread_t threads[5];
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
55 #endif
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
56 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
57 extern const char PROFSTATE[4][6];
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
58
40
dafbbd5e9922 Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
59
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
60 int server(void);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 void help(void);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 void die(int);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
63 #ifdef HAVE_WIRINGPI_H
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
64 void sendRCswitch(char *, int);
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
65 void stopLCD(void);
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
66 void stopRCswitch(void);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
67 #endif
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
68
26
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
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 void help(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 {
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
73 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
74 fprintf(stdout, "Usage: thermferm [-d] [-h]\n");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 fprintf(stdout, " -d --debug Debug and run in foreground\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 fprintf(stdout, " -h --help Display this help\n");
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
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 void die(int onsig)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 switch (onsig) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 break;
326
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
90 case SIGSEGV: syslog(LOG_NOTICE, "Got SIGSEGV, shutting down");
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
91 my_shutdown = TRUE;
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
92 exit(SIGSEGV);
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
93 break;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 default: syslog(LOG_NOTICE, "die() on signal %d", onsig);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
97 my_shutdown = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
101
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
102 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
103 void show_mode(void)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
104 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
105 char buf[21];
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
106
328
1713dc0cd20f Fixed error
Michiel Broek <mbroek@mbse.eu>
parents: 326
diff changeset
107 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
108 lcdPuts(lcdHandle, buf);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
109 lcdPosition(lcdHandle, 0, 1);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
110 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
111
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
112
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
113
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
114 void go_menu(int menu)
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
115 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
116 char buf[21];
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
117
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
118 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
119 piLock(LOCK_MENU);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
120 lcdClear(lcdHandle);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
121 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
122 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
123 setupmenu = menu;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
124
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
125 switch (menu) {
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
126 case MENU_NONE: lcd_buf_show();
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_DEFAULT: lcdPuts(lcdHandle, "Setup mode.");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
130 lcdPosition(lcdHandle, 0, 1);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
131 lcdPuts(lcdHandle, "Up&Down = Escape");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
132 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
133
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
134 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
135 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
136
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
137 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
138 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
139 lcdPuts(lcdHandle, current_unit->name);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
140 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
141
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
142 case MENU_MODE_OFF: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
143 lcdPuts(lcdHandle, "New mode OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
144 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
145
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
146 case MENU_MODE_NONE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
147 lcdPuts(lcdHandle, "New mode NONE");
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
148 break;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
149
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
150 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
151 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
152 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
153
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
154 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
155 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
156 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
157
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
158 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
159 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
160 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
161
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
162 case MENU_MODE_BEER: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
163 lcdPuts(lcdHandle, "New mode BEER");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
164 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
165
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
166 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
167 lcdPosition(lcdHandle, 0, 1);
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
168 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
169 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
170 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
171
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
172 case MENU_MODE_FRIDGE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
173 lcdPuts(lcdHandle, "New mode FRIDGE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
174 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
175
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
176 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
177 lcdPosition(lcdHandle, 0, 1);
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
178 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
179 lcdPuts(lcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
180 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
181
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
182 case MENU_MODE_PROFILE: show_mode();
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
183 lcdPuts(lcdHandle, "New mode PROFILE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
184 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
185
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
186 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
187 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
188 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
189 lcdPuts(lcdHandle, "Select profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
190 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
191
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
192 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
193 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
194 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
195 lcdPuts(lcdHandle, "Start profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
196 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
197
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
198 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
199 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
200 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
201 lcdPuts(lcdHandle, "Pause profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
202 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
203
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
204 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
205 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
206 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
207 lcdPuts(lcdHandle, "Abort profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
208 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
209
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
210 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
211 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
212 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
213 lcdPuts(lcdHandle, "Resume profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
214 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
215
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
216 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
217 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
218 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
219 lcdPuts(lcdHandle, "Set profile OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
220 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
221
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
222 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
223 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
224
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
225 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
226 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
227
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
228 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
229 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
230 }
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
231
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
232 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
233 piUnlock(LOCK_LCD);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
234 }
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
235
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
236
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
237
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 void stopLCD(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 {
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
240 piLock(LOCK_LCD);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
241 lcdClear(lcdHandle);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 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
243 piUnlock(LOCK_LCD);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 }
238
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
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 /*
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
249 * Change mode of current_unit
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
250 */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
251 void change_mode(int mode)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
252 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
253 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF))
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
254 initlog(current_unit->name);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
255 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
256 current_unit->mode = mode;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
257 /* Allways turn everything off after a mode change */
367
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
258 current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
259 current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
260 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = 0;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
261 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = current_unit->light_wait = 0;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
262 device_out(current_unit->heater_address, current_unit->heater_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
263 device_out(current_unit->cooler_address, current_unit->cooler_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
264 device_out(current_unit->fan_address, current_unit->fan_state);
367
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
265 device_out(current_unit->light_address, current_unit->light_state);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
266 if (current_unit->mode == UNITMODE_PROFILE) {
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 * 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
269 * main processing loop.
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
270 */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
271 current_unit->prof_target = 20.0;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
272 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
273 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
274
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
275
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
276 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
277
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
278
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
279
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
280 int read_sensor(char *address, int *val)
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
281 {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
282 devices_list *device;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
283 int tmp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
284
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
285 for (device = Config.devices; device; device = device->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
286 if (strcmp(address, device->uuid) == 0) {
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
287 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
288 piLock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
289 #endif
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 207
diff changeset
290 tmp = device->value + device->offset;
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
291 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
292 piUnlock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 238
diff changeset
293 #endif
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
294 *val = tmp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
295 return device->present;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
296 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
297 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
298
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
299 return DEVPRESENT_NO;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
300 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
301
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
302
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
303
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
304 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
305 * Handle panel key events
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 #ifdef HAVE_WIRINGPI_H
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
308 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
309 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
310 units_list *unit;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
311 profiles_list *profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
312 int rc;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
313
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
314 switch (setupmenu) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
315 case MENU_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
316 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
317 lcd_buf_step(key);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
318 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
319 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
320 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
321
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
322 case MENU_TOP_DEFAULT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
323 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
324 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
325 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
326 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
327 if (key == KEY_UP)
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 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
330
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
331 case MENU_TOP_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
332 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
333 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
334 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
335 go_menu(MENU_TOP_SYS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
336 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
337 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
338 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
339 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
340 * Start with the first unit
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
341 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
342 current_unit = Config.units;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
343 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
344 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
345 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
346
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
347 case MENU_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
348 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
349 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
350 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
351 if (current_unit->next) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
352 current_unit = current_unit->next;
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 }
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 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
357 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
358 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
359 current_unit = unit;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
360 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
361 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
362 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
363 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
364 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
365 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
366 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
367 * Drop into the current mode
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
368 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
369 switch (current_unit->mode) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
370 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
371 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
372 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
373 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
374 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
375 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
376 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
377 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
378 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
379 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
380 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
381 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
382 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
383
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
384 case MENU_MODE_OFF:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
385 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
386 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
387 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
388 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
389 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
390 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
391 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
392 change_mode(UNITMODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
393 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
394 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
395 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
396
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
397 case MENU_MODE_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
398 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
399 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
400 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
401 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
402 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
403 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
404 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
405 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
406 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
407 else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
408 change_mode(UNITMODE_NONE);
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 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
411 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
412 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
413
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
414 case MENU_NONE_HEAT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
415 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
416 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
417 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
418 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
419 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
420 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
421 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
422 if (current_unit->heater_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
423 current_unit->heater_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
424 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
425 current_unit->heater_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
426 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
427 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
428 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
429
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
430 case MENU_NONE_COOL:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
431 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
432 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
433 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
434 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
435 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
436 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
437 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
438 if (current_unit->cooler_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
439 current_unit->cooler_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
440 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
441 current_unit->cooler_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
442 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
443 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
444 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
445
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
446 case MENU_NONE_FAN:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
447 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
448 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
449 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
450 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
451 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
452 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
453 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
454 if (current_unit->fan_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
455 current_unit->fan_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
456 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
457 current_unit->fan_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
458 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
459 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
460 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
461
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
462 case MENU_MODE_FRIDGE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
463 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
464 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
465 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
466 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
467 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
468 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
469 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
470 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
471 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
472 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
473 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
474 change_mode(UNITMODE_FRIDGE);
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 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
477 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
478 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
479
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
480 case MENU_FRIDGE_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
481 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
482 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
483 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
484 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
485 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
486 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
487 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
488 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
489 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
490 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
491 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
492 }
302
3d2bd47f35b4 Use confirm instead of enter key when stepping to a new beer or fridge temperature
Michiel Broek <mbroek@mbse.eu>
parents: 297
diff changeset
493 if (key == KEY_CONFIRM) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
494 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
495 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
496 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
497 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
498 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
499 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
500 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
501
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
502 case MENU_MODE_BEER:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
503 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
504 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
505 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
506 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
507 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
508 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
509 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
510 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
511 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
512 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
513 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
514 change_mode(UNITMODE_BEER);
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 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
517 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
518 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
519
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
520 case MENU_BEER_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
521 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
522 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
523 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
524 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
525 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
526 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
527 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
528 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
529 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
530 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
531 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
532 }
302
3d2bd47f35b4 Use confirm instead of enter key when stepping to a new beer or fridge temperature
Michiel Broek <mbroek@mbse.eu>
parents: 297
diff changeset
533 if (key == KEY_CONFIRM) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
534 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
535 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
536 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
537 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
538 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
539 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
540 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
541
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
542 case MENU_MODE_PROFILE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
543 if (current_unit->profile) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
544 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
545 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
546 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
547 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
548 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
549 current_profile = NULL;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
550 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
551 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
552 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
553 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
554 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
555 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
556 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
557 if (key == KEY_ENTER) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
558 if (current_unit->mode == UNITMODE_PROFILE) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
559 switch (current_unit->prof_state) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
560 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
561 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
562 else
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
563 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
564 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
565 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
566 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
567 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
568 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
569 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
570 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
571 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
572 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
573 change_mode(UNITMODE_PROFILE);
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 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
576 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
577 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
578
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
579 case MENU_PROFILE_SELECT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
580 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
581 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
582 if (key == KEY_DOWN) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
583 if (current_profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
584 current_profile = current_profile->next;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
585 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
586 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
587 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
588 }
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 if (key == KEY_UP) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
591 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
592 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
593 current_profile = profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
594 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
595 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
596 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
597 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
598 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
599 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
600 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
601 current_unit->profile = current_profile->uuid;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
602 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
603 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
604 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
605 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
606
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
607 case MENU_PROFILE_START:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
608 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
609 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
610 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
611 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
612 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
613 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
614 current_unit->prof_started = time(NULL);
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
615 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
616 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
617 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
618 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
619 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
620 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
621
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
622 case MENU_PROFILE_PAUSE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
623 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
624 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
625 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
626 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
627 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
628 current_unit->prof_state = PROFILE_PAUSE;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
629 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
630 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
631 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
632 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
633
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
634 case MENU_PROFILE_ABORT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
635 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
636 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
637 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
638 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
639 go_menu(MENU_PROFILE_RESUME);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
640 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
641 go_menu(MENU_PROFILE_PAUSE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
642 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
643 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
644 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
645 current_unit->prof_started = 0;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
646 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
647 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
648 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
649 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
650
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
651 case MENU_PROFILE_RESUME:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
652 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
653 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
654 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
655 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
656 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
657 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
658 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
659 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
660 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
661 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
662
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
663 case MENU_PROFILE_GOOFF:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
664 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
665 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
666 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
667 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
668 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
669 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
670 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
671 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
672 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
673
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
674 case MENU_TOP_SYS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
675 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
676 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
677 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
678 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
679 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
680 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
681 if (key == KEY_ENTER)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
682 go_menu(MENU_SYS_HALT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
683 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
684
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
685 case MENU_SYS_HALT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
686 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
687 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
688 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
689 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
690 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
691 rc = system("/sbin/halt");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
692 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
693 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
694 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
695 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
696
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
697 case MENU_SYS_REBOOT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
698 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
699 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
700 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
701 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
702 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
703 rc = system("/sbin/reboot");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
704 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
705 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
706 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
707 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
708 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
709 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
710 #endif
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
711
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
712
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
713
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
714
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
715 int main(int argc, char *argv[])
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
716 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
717 int rc, c, i;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
718 pid_t frk;
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 while (1) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721 int option_index = 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722 static struct option long_options[] = {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 {"debug", 0, 0, 'c'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 {"help", 0, 0, 'h'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 {0, 0, 0, 0}
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 };
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728 c = getopt_long(argc, argv, "dh", long_options, &option_index);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
729 if (c == -1)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
730 break;
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 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
733 case 'd': debug = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735 case 'h': help();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
736 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
737 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
738 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
739
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
740 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
741 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
742 if (debug)
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
743 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
744
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
745 if (rdconfig()) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 fprintf(stderr, "Error reading configuration\n");
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
747 syslog(LOG_NOTICE, "Error reading configuration: halted");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 * 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
753 * 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
754 * Don't catch SIGCHLD.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 for (i = 0; i < NSIG; i++) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP))
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 signal(i, (void (*))die);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
759 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
761 #ifdef HAVE_WIRINGPI_H
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
762 if (wiringPiSetup () )
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
763 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
764
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
765 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
769 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
770
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 if (debug) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
773 * For debugging run in foreground.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776 } else {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 * Server initialization is complete. Now we can fork the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779 * 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
780 * 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
781 * users control terminal. This is done before the fork, so
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782 * 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
783 * 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
784 * associated with that terminal as its control terminal.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 if ((pgrp = setpgid(0, 0)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
787 syslog(LOG_NOTICE, "setpgpid failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 frk = fork();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791 switch (frk) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 case -1:
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
793 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
794 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795 stopLCD();
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
796 #endif
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 exit(1);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 case 0: /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799 * Run the daemon
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801 fclose(stdin);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 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
803 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
804 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806 fclose(stdout);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807 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
808 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
809 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811 fclose(stderr);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812 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
813 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
814 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 mypid = getpid();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819 /* Not reached */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 default:
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 * Here we detach this process and let the child
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
823 * run the deamon process.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 syslog(LOG_NOTICE, "Starting daemon with pid %d", frk);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
826 exit(0);
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
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
830 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
831 return rc;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836 int server(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837 {
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
838 char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40];
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
839 char use_heater[40], use_cooler[40], use_fan[40], room_temp[40];
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
840 time_t now, last = (time_t)0;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
841 units_list *unit;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
842 profiles_list *profile;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
843 prof_step *step;
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
844 int rc, run = 1, seconds = 0, minutes = 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
845 int run_seconds, run_minutes, run_hours, tot_minutes;
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
846 #ifdef HAVE_WIRINGPI_H
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
847 struct tm *tm;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
848 int row, key;
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
849 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
850 long t = 0;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
851 #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
852 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
853 float previous_target;
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
854
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
856 if (lockprog((char *)"thermferm")) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
857 syslog(LOG_NOTICE, "Can't lock");
34
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
858 return 1;
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
859 }
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
860
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
861 if ((rc = devices_detect())) {
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
862 syslog(LOG_NOTICE, "Detected %d new devices", rc);
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
863 wrconfig();
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
864 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
865
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
866 #ifdef HAVE_WIRINGPI_H
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
867 rc = piThreadCreate(my_devices_loop);
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 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
870 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
871 if (rc) {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
872 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
873 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
874 #ifndef HAVE_WIRINGPI_H
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
875 } else {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
876 t++;
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
877 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
878 }
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
879
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
880 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
881 rc = piThreadCreate(my_server_loop);
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
882 #else
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
883 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
884 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
885 if (rc) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
886 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
887 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
888 #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
889 } else {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
890 t++;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
891 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
892 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
893
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
894 #ifdef HAVE_WIRINGPI_H
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
895 if ((rc = piThreadCreate(my_panel_loop))) {
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
896 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
897 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
898 }
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
899 #endif
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
900
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
901
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 #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
903 #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
904 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
905 #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
906 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
907 #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
908 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
909 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
910 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
911 #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
912 } 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
913 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
914 #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
915 }
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
916 #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
917
182
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 * Initialize units for processing
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
920 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
921 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
922 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
923 * Safety, turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
924 */
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
925 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
926 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_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
927 if (unit->mode == UNITMODE_PROFILE) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
928 if (!unit->profile)
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
929 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->name);
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
930 else
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
931 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
932 } else if (unit->mode == UNITMODE_BEER) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
933 syslog(LOG_NOTICE, "Starting unit `%s' beer cooler at %.1f degrees", unit->name, unit->beer_set);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
934 } else if (unit->mode == UNITMODE_FRIDGE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
935 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f degrees", unit->name, unit->fridge_set);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
936 } else if (unit->mode == UNITMODE_NONE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
937 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->name);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
938 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
939 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->name);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
940 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
941 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
942
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
943 #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
944 piLock(LOCK_LCD);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
945 lcd_buf_write(1, (char *)" ThermFerm ");
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
946 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
947 piUnlock(LOCK_LCD);
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
948 #endif
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
949
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
950 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
951 * Initialize logfiles for each unit
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
952 */
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
953 for (unit = Config.units; unit; unit = unit->next) {
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
954 if (unit->mode != UNITMODE_OFF) {
155
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 150
diff changeset
955 initlog(unit->name);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
956 }
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
957 }
33
2357e8636a60 Added user log with temperatures and cooler state
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
958
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
959 do {
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
960 if (my_shutdown)
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
961 run = 0;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
962
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
963 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
964 * 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
965 * 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
966 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
967 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
968 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
969 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
970 for (;;) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
971 usleep(100000);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
972 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
973 break;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
974 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
975 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
976 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
977 #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
978 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
979 * 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
980 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
981 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
982 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
983 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
984 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
985 #endif
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
986 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
987
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
988 now = time(NULL);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
989 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
990 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
991 * 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
992 */
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
993 last = now;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
994 seconds++;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
995
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
996 #ifdef HAVE_WIRINGPI_H
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
997 row = 3;
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
998 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
999 piLock(LOCK_LCD);
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1000 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
1001 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
1002 piUnlock(LOCK_LCD);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1003 #endif
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1004
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1005 if (Config.temp_address) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1006 rc = read_sensor(Config.temp_address, &temp);
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1007 if (rc == DEVPRESENT_YES) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1008 Config.temp_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1009 Config.temp_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1010 #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
1011 piLock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1012 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
1013 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1014 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1015 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1016 Config.temp_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1017 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1018 Config.temp_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1019 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1020 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1021
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1022 if (Config.hum_address) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1023 rc = read_sensor(Config.hum_address, &temp);
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1024 if (rc == DEVPRESENT_YES) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1025 Config.hum_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1026 Config.hum_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1027 #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
1028 piLock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1029 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
1030 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1031 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1032 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1033 Config.hum_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1034 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1035 Config.hum_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1036 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1037 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1038
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1039 for (unit = Config.units; unit; unit = unit->next) {
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1040 #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
1041 piLock(LOCK_LCD);
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1042 lcd_buf_write(row++, "Unit %s ", unit->name);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1043 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
1044 piUnlock(LOCK_LCD);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1045 #endif
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1046
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1047 if (unit->air_address) {
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1048 rc = read_sensor(unit->air_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1049 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1050 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1051 * It is possible to have read errors or extreme values.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1052 * This can happen with bad connections so we compare the
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1053 * value with the previous one. If the difference is too
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1054 * 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
1055 * 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
1056 * Maximum error is 40 degrees for now.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1057 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1058 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1059 if ((unit->air_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1060 (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
1061 unit->air_temperature = temp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1062 unit->air_state = 0;
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1063 #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
1064 piLock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1065 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
1066 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1067 #endif
182
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 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
1070 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1071 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
1072 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1073 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1074 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1075 unit->air_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1076 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1077 unit->air_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1078 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1079 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1080
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1081 if (unit->beer_address) {
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1082 rc = read_sensor(unit->beer_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1083 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1084 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1085 if ((unit->beer_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1086 (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
1087 unit->beer_temperature = temp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1088 unit->beer_state = 0;
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1089 #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
1090 piLock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1091 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
1092 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1093 #endif
182
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 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
1096 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1097 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
1098 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1099 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1100 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1101 unit->beer_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1102 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1103 unit->beer_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1104 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1105 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1106
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1107 if (unit->door_address) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1108 rc = read_sensor(unit->door_address, &temp);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1109 if (rc == DEVPRESENT_YES) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1110 if (temp) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1111 if (unit->door_state == 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1112 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1113 unit->door_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1114 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1115 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1116 if (unit->door_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1117 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1118 unit->door_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1119 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1120 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1121 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1122 unit->door_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1123 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1124 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1125 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1126 * No door switch, say door is closed.
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1127 */
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1128 unit->door_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1129 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1130
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1131 if (unit->psu_address) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1132 rc = read_sensor(unit->psu_address, &temp);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1133 if (rc == DEVPRESENT_YES) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1134 if (temp) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1135 if (unit->psu_state == 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1136 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1137 unit->psu_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1138 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1139 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1140 if (unit->psu_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1141 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1142 unit->psu_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1143 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1144 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1145 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1146 unit->psu_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1147 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1148 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1149 unit->psu_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1150 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1151
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1152 /*
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1153 * 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
1154 */
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1155 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
1156 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1157 * 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
1158 * 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
1159 * 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
1160 * unit->prof_target - Calculated target temperature.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1161 * unit->prof_paused - Internal pause counter.
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1162 * 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
1163 * 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
1164 * 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
1165 */
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1166 for (profile = Config.profiles; profile; profile = profile->next) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1167 if (strcmp(unit->profile, profile->uuid) == 0) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1168
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1169 switch (unit->prof_state) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1170 case PROFILE_OFF:
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1171 unit->prof_target = profile->inittemp;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1172 unit->prof_percent = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1173 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1174 case PROFILE_PAUSE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1175 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1176 * Keep current temperature, measure pause time. For
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1177 * temperature fall thru.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1178 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1179 unit->prof_paused++;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1180 case PROFILE_RUN:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1181 /*
288
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1182 * Calculate current profile step and desired temperature.
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1183 * 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
1184 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1185 previous_target = profile->inittemp;
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1186 time_until_now = current_step = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1187 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
1188 run_minutes = run_seconds / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1189 run_hours = run_minutes / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
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, "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
1192
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1193 /*
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1194 * Primary fermentation tests
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1195 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1196 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
1197 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
1198 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
1199 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
1200 if (unit->prof_primary_done == 0) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1201 if (unit->cooler_address) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1202 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1203 * 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
1204 * drops we assume the primary fermentation is done.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1205 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1206 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
1207 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1208 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
1209 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1210 } else {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1211 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1212 * 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
1213 * beer temperature to rise freely.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1214 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1215 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
1216 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1217 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
1218 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1219 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1220 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1221
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1222 /*
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1223 * See how long this profile will take
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1224 */
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1225 tot_minutes = 0;
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1226 for (step = profile->steps; step; step = step->next) {
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1227 tot_minutes += ((step->steptime + step->resttime) * 60);
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1228 }
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1229
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1230 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
1231 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
1232 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1233 * step->steptime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1234 * step->resttime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1235 * step->target
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1236 */
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1237 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
1238 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
1239 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1240 * This is our current step
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1241 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1242 valid_step = TRUE;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1243 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
1244 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
1245 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
1246 step->steptime, step->resttime, step->target);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1247 if ((run_hours - time_until_now) < step->steptime) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1248 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
1249 if (debug)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1250 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
1251 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
1252 step->steptime * 60, unit->prof_target);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1253 } else {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1254 unit->prof_target = step->target;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1255 fprintf(stdout, "resting target=%.1f ", step->target);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1256 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1257 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1258 }
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1259 time_until_now += step->steptime + step->resttime;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1260 previous_target = step->target;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1261 }
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1262 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
1263 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
1264
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
1265 if (valid_step == TRUE) {
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1266 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
1267 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
1268 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
1269 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
1270 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
1271 }
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
1272 } 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
1273 /*
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
1274 * 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
1275 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1276 unit->prof_state = PROFILE_DONE;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1277 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
1278 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
1279 }
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1280 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
1281
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1282 case PROFILE_DONE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1283 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1284 * 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
1285 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1286 previous_target = profile->inittemp;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1287 for (step = profile->steps; step; step = step->next) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1288 if (step->steptime == 0)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1289 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1290 previous_target = step->target;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1291 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1292 unit->prof_target = previous_target;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1293 unit->prof_percent = 100;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1294 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1295 } /* switch */
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1296 }
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1297 }
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1298 }
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1299
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1300 /*
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1301 * Manual switching
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1302 */
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1303 if (unit->mode == UNITMODE_NONE) {
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1304 device_out(unit->heater_address, unit->heater_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1305 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1306 device_out(unit->fan_address, unit->fan_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1307 }
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1308
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1309 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1310 * Usage counters
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1311 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1312 if (unit->heater_address && unit->heater_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1313 unit->heater_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1314 if (unit->cooler_address && unit->cooler_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1315 unit->cooler_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1316 if (unit->fan_address && unit->fan_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1317 unit->fan_usage++;
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1318 if (unit->light_address && unit->light_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1319 unit->light_usage++;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1320
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1321 #ifdef HAVE_WIRINGPI_H
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1322 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
1323 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
1324 if (unit->heater_state) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1325 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
1326 } else if (unit->cooler_state) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1327 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
1328 } else {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1329 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
1330 }
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
1331 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
1332 piLock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1333 switch (unit->mode) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1334 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
1335 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1336 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
1337 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1338 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
1339 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
1340 else
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1341 lcd_buf_write(row++, "Target not set ");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1342 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1343 default: lcd_buf_write(row++, "Target not set ");
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1344 }
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
1345 piUnlock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1346 } 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
1347 piLock(LOCK_LCD);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1348 if (unit->heater_address) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1349 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
1350 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1351 if (unit->cooler_address) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1352 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
1353 }
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
1354 piUnlock(LOCK_LCD);
188
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1355 }
4fc17ef4593f Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1356 #endif
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1357
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1358 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1359 * Interior lights
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1360 */
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1361 if (unit->light_address) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1362 if (unit->door_state && unit->light_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1363 if (unit->light_wait > 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1364 unit->light_wait--;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1365 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1366 unit->light_state = 0;
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1367 syslog(LOG_NOTICE, "Unit `%s' lights On => Off", unit->name);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1368 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1369 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1370 if (!unit->door_state && !unit->light_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1371 unit->light_wait = unit->light_delay; /* No delay to turn lights on */
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1372 unit->light_state = 1;
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1373 syslog(LOG_NOTICE, "Unit `%s' lights Off => On", unit->name);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1374 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1375 device_out(unit->light_address, unit->light_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1376 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1377
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1378 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1379 * Temperature control in this unit
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1380 */
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1381 if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE)) {
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1382
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1383 /*
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1384 * Set both PID's to their input values.
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1385 */
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1386 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1387 if (unit->mode == UNITMODE_FRIDGE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1388 unit->PID_cool->SetP = unit->PID_heat->SetP = unit->fridge_set;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1389 unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1390 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1391 } else if (unit->mode == UNITMODE_BEER) {
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1392 unit->PID_cool->SetP = unit->PID_heat->SetP = unit->beer_set;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1393 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1394 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1395 } else if (unit->mode == UNITMODE_PROFILE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1396 unit->PID_cool->SetP = unit->PID_heat->SetP = unit->prof_target;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1397 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1398 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
314
a919c6dc2100 Restored blackout window
Michiel Broek <mbroek@mbse.eu>
parents: 313
diff changeset
1399 }
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1400
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1401 /*
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1402 * PID controller compute
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1403 */
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1404 UpdatePID(unit->PID_heat);
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1405 UpdatePID(unit->PID_cool);
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1406
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1407 /*
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1408 * Logging
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1409 */
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1410 if (unit->heater_address) {
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1411 if (debug)
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1412 fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1413 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1414 if (((unit->PID_heat->OutP >= 2) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1415 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1416 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1417 }
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1418 }
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1419 if (unit->cooler_address) {
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1420 if (debug)
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1421 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1422 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1423 if (((unit->PID_cool->OutP >= 2) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1424 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1425 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1426 }
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1427 }
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1428
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1429 /*
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1430 * Deadlock
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1431 */
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1432 if (unit->PID_cool->OutP && unit->PID_heat->OutP) {
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1433 syslog(LOG_NOTICE, "Heat and Cool lockdown");
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1434 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1435 }
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1436
318
aad7789a40f2 Better protection, fixed fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 317
diff changeset
1437 if (unit->heater_address && ! unit->cooler_state) {
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1438 if (unit->PID_heat->OutP >= 2) {
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1439 if (unit->heater_wait < unit->heater_delay) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1440 unit->heater_wait++;
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
1441 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1442 int power = round(unit->PID_heat->OutP);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1443 if (unit->heater_state != power) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1444 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1445 unit->heater_state = power;
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
1446 }
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
1447 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1448 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1449 if (unit->heater_wait > 0) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1450 unit->heater_wait--;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1451 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1452 if (unit->heater_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1453 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1454 unit->heater_state = 0;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1455 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1456 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1457 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1458 if (unit->door_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1459 device_out(unit->heater_address, unit->heater_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1460 else
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1461 device_out(unit->heater_address, 0);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1462 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1463
318
aad7789a40f2 Better protection, fixed fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 317
diff changeset
1464 if (unit->cooler_address && ! unit->heater_state) {
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1465 if (unit->PID_cool->OutP >= 2) {
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1466 if (unit->cooler_wait < unit->cooler_delay) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1467 unit->cooler_wait++;
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
1468 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1469 int power = round(unit->PID_cool->OutP);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1470 if (unit->cooler_state != power) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1471 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1472 unit->cooler_state = power;
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1473 }
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
1474 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1475 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1476 if (unit->cooler_wait > 0) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1477 unit->cooler_wait--;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1478 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1479 if (unit->cooler_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1480 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1481 unit->cooler_state = 0;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1482 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1483 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1484 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1485 if (unit->door_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1486 device_out(unit->cooler_address, unit->cooler_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1487 else
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1488 device_out(unit->cooler_address, 0);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1489 }
348
ffc4b8aa824f Changed Fan switch logic.
Michiel Broek <mbroek@mbse.eu>
parents: 328
diff changeset
1490
ffc4b8aa824f Changed Fan switch logic.
Michiel Broek <mbroek@mbse.eu>
parents: 328
diff changeset
1491 if ((unit->heater_address || unit->cooler_address) && unit->fan_address) {
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1492 /*
348
ffc4b8aa824f Changed Fan switch logic.
Michiel Broek <mbroek@mbse.eu>
parents: 328
diff changeset
1493 * If there is a heater or cooler and we have a fan, turn fan on if
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1494 * cooling or heating. The Fan has a start/stop delay.
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1495 */
348
ffc4b8aa824f Changed Fan switch logic.
Michiel Broek <mbroek@mbse.eu>
parents: 328
diff changeset
1496 if ((unit->heater_address && unit->heater_state) || (unit->cooler_address && unit->cooler_state)) {
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1497 if (unit->fan_wait < unit->fan_delay) {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1498 unit->fan_wait++;
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1499 } else {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1500 if (! unit->fan_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1501 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name);
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1502 unit->fan_state = 100;
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1503 }
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1504 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1505 } else {
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1506 if (unit->fan_wait > 0) {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1507 unit->fan_wait--;
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1508 } else {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1509 if (unit->fan_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1510 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name);
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1511 unit->fan_state = 0;
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1512 }
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1513 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1514 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1515 if (unit->door_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1516 device_out(unit->fan_address, unit->fan_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1517 else
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1518 device_out(unit->fan_address, 0);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1519 }
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1520 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1521 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1522 } /* fridge beer or profile mode */
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1523 } /* for units */
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1524
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
1525 #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
1526 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
1527 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
1528 piLock(LOCK_LCD);
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1529 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
1530 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
1531 }
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
1532 piUnlock(LOCK_MENU);
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
1533 #endif
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1534
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1535 if (seconds == 60) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1536 seconds = 0;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1537
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1538 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1539 * Log temperature and status every minute if unit is active.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1540 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1541 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1542 if (unit->mode != UNITMODE_OFF) {
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
1543
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1544 snprintf(target, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1545 snprintf(heater, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1546 snprintf(cooler, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1547 snprintf(fan, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1548 snprintf(door, 39, "NA");
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1549 snprintf(use_heater, 39, "NA");
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1550 snprintf(use_cooler, 39, "NA");
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1551 snprintf(use_fan, 39, "NA");
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1552 snprintf(room_temp, 39, "NA");
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1553
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1554 if (unit->mode == UNITMODE_BEER)
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1555 snprintf(target, 39, "%.1f", unit->beer_set);
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1556 else if (unit->mode == UNITMODE_FRIDGE)
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1557 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
1558 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
1559 snprintf(target, 39, "%.1f", unit->prof_target);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1560
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
1561 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
1562 snprintf(heater, 39, "%d", unit->heater_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1563 snprintf(use_heater, 39, "%d", unit->heater_usage);
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
1564 }
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
1565 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
1566 snprintf(cooler, 39, "%d", unit->cooler_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1567 snprintf(use_cooler, 39, "%d", unit->cooler_usage);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1568 }
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
1569 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
1570 snprintf(fan, 39, "%d", unit->fan_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
1571 snprintf(use_fan, 39, "%d", unit->fan_usage);
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
1572 }
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
1573 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
1574 snprintf(door, 39, "%d", unit->door_state);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1575 }
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1576 if (Config.temp_address) {
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1577 snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0);
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1578 }
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1579
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1580 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s",
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1581 UNITMODE[unit->mode], unit->air_temperature / 1000.0,
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1582 unit->beer_temperature / 1000.0, target, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1583 filename = xstrcpy(unit->name);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1584 filename = xstrcat(filename, (char *)".log");
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1585 logger(filename, buf);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1586 free(filename);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1587 filename = NULL;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1588 }
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1589 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1590
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1591 minutes++;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1592 if (minutes == 60) {
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1593 minutes = 0;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1594 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1595 * Log usage counters every hour
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1596 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1597 for (unit = Config.units; unit; unit = unit->next) {
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1598 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
1599 }
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1600 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
1601
227
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1602 /*
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1603 * Save the configuration each half hour.
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1604 */
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
1605 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
1606 wrconfig();
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
1607 }
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1608 }
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
1609
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
1610 #ifdef HAVE_WIRINGPI_H
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
1611 key = keycheck();
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1612 if (key != KEY_NONE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1613 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
1614 #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
1615
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1616 usleep(100000);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1617
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1618 } while (run);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1619
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1620 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1621 * Stop units processing in a neat way
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1622 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1623 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1624 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1625 * Turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1626 */
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1627 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1628 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1629 device_out(unit->heater_address, unit->heater_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1630 device_out(unit->cooler_address, unit->cooler_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1631 device_out(unit->fan_address, unit->fan_state);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1632 device_out(unit->light_address, unit->light_state);
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1633 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1634 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1635
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1636 if (debug)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1637 fprintf(stdout, (char *)"Out of loop\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1638
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1639 /*
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1640 * Give threads time to cleanup
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1641 */
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1642 usleep(1500000);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1643
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1644 #ifdef HAVE_WIRINGPI_H
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1645 stopLCD();
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1646 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1647
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
1648 wrconfig();
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
1649
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
1650 ulockprog((char *)"thermferm");
34
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1651
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1652 if (debug)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
1653 fprintf(stdout, "Goodbye\n");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1654
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1655 return 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1656 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1657

mercurial