Thu, 14 Aug 2014 21:50:38 +0200
Added more panel menus
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2014 |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
209
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
106 | 23 | #include "lock.h" |
24 | #include "logger.h" | |
25 | #include "rdconfig.h" | |
160 | 26 | #include "devices.h" |
106 | 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" |
106 | 29 | #include "lcd-pcf8574.h" |
30 | #include "lcd-buffer.h" | |
198
20716bcff2b0
Added dependencies for panel
Michiel Broek <mbroek@mbse.eu>
parents:
195
diff
changeset
|
31 | #include "panel.h" |
106 | 32 | #include "futil.h" |
33 | #include "xutil.h" | |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
36 | int my_shutdown = FALSE; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | static pid_t pgrp, mypid; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
39 | extern int debug; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | extern sys_config Config; |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
41 | #ifdef HAVE_WIRINGPI_H |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | extern int lcdHandle; |
205 | 43 | int setupmenu = MENU_NONE; |
238 | 44 | units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ |
205 | 45 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
46 | #endif |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | int lcdupdate; |
74 | 48 | #ifndef HAVE_WIRINGPI_H |
164
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
49 | pthread_t threads[4]; |
74 | 50 | #endif |
104 | 51 | 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
|
52 | extern const char PROFSTATE[4][6]; |
104 | 53 | |
40
dafbbd5e9922
Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents:
34
diff
changeset
|
54 | |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
55 | int server(void); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | void help(void); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | void die(int); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
58 | #ifdef HAVE_WIRINGPI_H |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
59 | void sendRCswitch(char *, int); |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
60 | void stopLCD(void); |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
61 | void stopRCswitch(void); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
62 | #endif |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
63 | |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | void help(void) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | { |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
68 | 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
|
69 | fprintf(stdout, "Usage: thermferm [-d] [-h]\n"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | fprintf(stdout, " -d --debug Debug and run in foreground\n"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | fprintf(stdout, " -h --help Display this help\n"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | void die(int onsig) |
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 | switch (onsig) { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
79 | case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
88 | my_shutdown = TRUE; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | |
238 | 92 | |
93 | void show_mode(void) | |
94 | { | |
95 | char buf[21]; | |
96 | ||
97 | snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]); | |
98 | lcdPuts(lcdHandle, buf); | |
99 | lcdPosition(lcdHandle, 0, 1); | |
100 | } | |
101 | ||
102 | ||
103 | ||
215
5ad534c79a22
Do not use 100% cpu on a system without devices
Michiel Broek <mbroek@mbse.eu>
parents:
214
diff
changeset
|
104 | #ifdef HAVE_WIRINGPI_H |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
105 | void go_menu(int menu) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
106 | { |
238 | 107 | char buf[21]; |
108 | ||
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
109 | lcdClear(lcdHandle); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
110 | lcdPosition(lcdHandle, 0, 0); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
111 | setupmenu = menu; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
112 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
113 | switch (menu) { |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
114 | case MENU_NONE: lcd_buf_show(); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
115 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
116 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
117 | 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
|
118 | lcdPosition(lcdHandle, 0, 1); |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
119 | lcdPuts(lcdHandle, "Up&Down = Escape"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
120 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
121 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
122 | 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
|
123 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
124 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
125 | case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:"); |
238 | 126 | if ((current_unit == NULL) && Config.units) { |
127 | /* | |
128 | * First time in this menu, select the first unit. | |
129 | */ | |
130 | current_unit = Config.units; | |
131 | lcdPosition(lcdHandle, 0, 1); | |
132 | lcdPuts(lcdHandle, Config.units->name); | |
133 | } | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
134 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
135 | |
238 | 136 | case MENU_MODE_OFF: show_mode(); |
137 | lcdPuts(lcdHandle, "New mode OFF"); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
138 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
139 | |
238 | 140 | case MENU_MODE_NONE: show_mode(); |
141 | lcdPuts(lcdHandle, "New mode NONE"); | |
142 | break; | |
143 | ||
144 | case MENU_NONE_HEAT: snprintf(buf, 20, "Set heater %s", current_unit->heater_state ? "OFF":"ON"); | |
145 | lcdPuts(lcdHandle, buf); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
146 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
147 | |
238 | 148 | case MENU_NONE_COOL: snprintf(buf, 20, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON"); |
149 | lcdPuts(lcdHandle, buf); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
150 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
151 | |
238 | 152 | case MENU_NONE_FAN: snprintf(buf, 20, "Set fan %s", current_unit->fan_state ? "OFF":"ON"); |
153 | lcdPuts(lcdHandle, buf); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
154 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
155 | |
238 | 156 | case MENU_MODE_BEER: show_mode(); |
157 | lcdPuts(lcdHandle, "New mode BEER"); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
158 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
159 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
160 | case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
161 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
162 | |
238 | 163 | case MENU_MODE_FRIDGE: show_mode(); |
164 | lcdPuts(lcdHandle, "New mode FRIDGE"); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
165 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
166 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
167 | case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
168 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
169 | |
238 | 170 | case MENU_MODE_PROFILE: show_mode(); |
171 | lcdPuts(lcdHandle, "New mode PROFILE"); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
172 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
173 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
174 | case MENU_PROFILE_SELECT: lcdPuts(lcdHandle, "Select profile"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
175 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
176 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
177 | case MENU_PROFILE_START: lcdPuts(lcdHandle, "Start profile"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
178 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
179 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
180 | case MENU_PROFILE_PAUSE: lcdPuts(lcdHandle, "Pause profile"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
181 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
182 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
183 | case MENU_PROFILE_ABORT: lcdPuts(lcdHandle, "Abort 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 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
186 | case MENU_PROFILE_RESUME: lcdPuts(lcdHandle, "Resume profile"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
187 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
188 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
189 | case MENU_PROFILE_GOOFF: lcdPuts(lcdHandle, "Set profile OFF"); |
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 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
192 | 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
|
193 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
194 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
195 | 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
|
196 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
197 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
198 | 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
|
199 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
200 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
201 | case MENU_SYS_MASH: lcdPuts(lcdHandle, "Start Mash program"); |
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 | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
204 | case MENU_SYS_THERMS: lcdPuts(lcdHandle, "Start Thermometers"); |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
205 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
206 | } |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
207 | } |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
208 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
209 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
210 | |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | void stopLCD(void) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | { |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
221
diff
changeset
|
213 | lcdClear(lcdHandle); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
214 | setBacklight(0); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
215 | } |
238 | 216 | |
217 | ||
218 | ||
219 | /* | |
220 | * Change mode of current_unit | |
221 | */ | |
222 | void change_mode(int mode) | |
223 | { | |
224 | if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) | |
225 | initlog(current_unit->name); | |
226 | syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); | |
227 | current_unit->mode = mode; | |
228 | /* Allways turn everything off after a mode change */ | |
229 | current_unit->PID_I_err = current_unit->PID_err_old = 0.0; | |
230 | current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; | |
231 | device_out(current_unit->heater_address, current_unit->heater_state); | |
232 | device_out(current_unit->cooler_address, current_unit->cooler_state); | |
233 | device_out(current_unit->fan_address, current_unit->fan_state); | |
234 | if (current_unit->mode == UNITMODE_PROFILE) { | |
235 | /* | |
236 | * Set a sane default until it will be overruled by the | |
237 | * main processing loop. | |
238 | */ | |
239 | current_unit->prof_target = 20.0; | |
240 | } | |
241 | } | |
242 | ||
243 | ||
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
244 | #endif |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
245 | |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
246 | |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
247 | |
207 | 248 | int read_sensor(char *address, int *val) |
182 | 249 | { |
250 | devices_list *device; | |
251 | int tmp; | |
252 | ||
253 | for (device = Config.devices; device; device = device->next) { | |
254 | if (strcmp(address, device->uuid) == 0) { | |
209
c5b1dfd83e81
Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents:
207
diff
changeset
|
255 | tmp = device->value + device->offset; |
182 | 256 | *val = tmp; |
257 | return device->present; | |
258 | } | |
259 | } | |
260 | ||
261 | return DEVPRESENT_NO; | |
262 | } | |
263 | ||
264 | ||
265 | ||
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | int main(int argc, char *argv[]) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | int rc, c, i; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | pid_t frk; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | while (1) { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | int option_index = 0; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | static struct option long_options[] = { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | {"debug", 0, 0, 'c'}, |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | {"help", 0, 0, 'h'}, |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | {0, 0, 0, 0} |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | }; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | c = getopt_long(argc, argv, "dh", long_options, &option_index); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | if (c == -1) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
283 | 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
|
284 | case 'd': debug = TRUE; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | case 'h': help(); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | return 1; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
291 | 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
|
292 | 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
|
293 | if (debug) |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
294 | 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
|
295 | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
83
diff
changeset
|
296 | if (rdconfig()) { |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | fprintf(stderr, "Error reading configuration\n"); |
235 | 298 | syslog(LOG_WARNING, "Error reading configuration: halted"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
299 | return 1; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | /* |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | * 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
|
304 | * 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
|
305 | * Don't catch SIGCHLD. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | for (i = 0; i < NSIG; i++) { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | signal(i, (void (*))die); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
312 | #ifdef HAVE_WIRINGPI_H |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
313 | if (wiringPiSetup () ) |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
314 | return 1; |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
315 | |
108 | 316 | if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) { |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | return 1; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | } |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
320 | #endif |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
321 | |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | if (debug) { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | /* |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
324 | * For debugging run in foreground. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
325 | */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | rc = server(); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
327 | } else { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | /* |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | * Server initialization is complete. Now we can fork the |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | * 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
|
331 | * 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
|
332 | * users control terminal. This is done before the fork, so |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
333 | * 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
|
334 | * 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
|
335 | * associated with that terminal as its control terminal. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | if ((pgrp = setpgid(0, 0)) == -1) { |
235 | 338 | syslog(LOG_WARNING, "setpgpid failed"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | frk = fork(); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
342 | switch (frk) { |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
343 | case -1: |
235 | 344 | syslog(LOG_WARNING, "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
|
345 | #ifdef HAVE_WIRINGPI_H |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 | stopLCD(); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
347 | #endif |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | exit(1); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
349 | case 0: /* |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
350 | * Run the daemon |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
352 | fclose(stdin); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
353 | if (open("/dev/null", O_RDONLY) != 0) { |
235 | 354 | syslog(LOG_WARNING, "Reopen of stdin to /dev/null failed"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
355 | _exit(2); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | fclose(stdout); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { |
235 | 359 | syslog(LOG_WARNING, "Reopen of stdout to /dev/null failed"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
360 | _exit(2); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
361 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | fclose(stderr); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { |
235 | 364 | syslog(LOG_WARNING, "Reopen of stderr to /dev/null failed"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | _exit(2); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
366 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
367 | mypid = getpid(); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
368 | rc = server(); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | break; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | /* Not reached */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | default: |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | /* |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | * Here we detach this process and let the child |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | * run the deamon process. |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
375 | */ |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
376 | syslog(LOG_NOTICE, "Starting daemon with pid %d", frk); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
377 | exit(0); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
378 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
380 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
381 | syslog(LOG_NOTICE, "Finished, rc=%d", rc); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
382 | return rc; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
383 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
384 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
385 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
386 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
387 | int server(void) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
388 | { |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
389 | char buf[1024], *filename, target[40], heater[40], cooler[40], fan[40], door[40]; |
64
2431965e8a8c
Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents:
63
diff
changeset
|
390 | time_t now, last = (time_t)0; |
104 | 391 | units_list *unit; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
392 | profiles_list *profile; |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
393 | prof_step *step; |
182 | 394 | int rc, run = 1, seconds = 0, minutes = 0, piddelay = 0, temp, deviation; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
395 | int run_seconds, run_minutes, run_hours; |
185 | 396 | float err = 0.0, sp, pv, P_err, D_err, Out; |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
397 | #ifdef HAVE_WIRINGPI_H |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
398 | struct tm *tm; |
205 | 399 | int row, key; |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
400 | #else |
74 | 401 | long t = 0; |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
402 | #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
|
403 | 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
|
404 | float previous_target; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
405 | |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
406 | if (lockprog((char *)"thermferm")) { |
235 | 407 | syslog(LOG_WARNING, "Can't lock"); |
34 | 408 | return 1; |
409 | } | |
410 | ||
158 | 411 | rc = devices_detect(); |
412 | if (rc) { | |
413 | syslog(LOG_NOTICE, "Detected %d new devices", rc); | |
414 | wrconfig(); | |
415 | } | |
416 | ||
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
417 | #ifdef HAVE_WIRINGPI_H |
164
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
418 | rc = piThreadCreate(my_devices_loop); |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
419 | #else |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
420 | 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
|
421 | #endif |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
422 | if (rc) { |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
423 | fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc); |
235 | 424 | syslog(LOG_WARNING, "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
|
425 | #ifndef HAVE_WIRINGPI_H |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
426 | } else { |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
427 | t++; |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
428 | #endif |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
429 | } |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
430 | |
f16def8472ba
Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents:
160
diff
changeset
|
431 | #ifdef HAVE_WIRINGPI_H |
43 | 432 | rc = piThreadCreate(my_server_loop); |
74 | 433 | #else |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
434 | rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); |
74 | 435 | #endif |
43 | 436 | if (rc) { |
437 | fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); | |
235 | 438 | syslog(LOG_WARNING, "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
|
439 | #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
|
440 | } else { |
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
441 | t++; |
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
442 | #endif |
43 | 443 | } |
444 | ||
199 | 445 | #ifdef HAVE_WIRINGPI_H |
446 | rc = piThreadCreate(my_panel_loop); | |
447 | if (rc) { | |
448 | fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); | |
235 | 449 | syslog(LOG_WARNING, "my_panel_loop thread didn't start rc=%d", rc); |
199 | 450 | } |
451 | #endif | |
452 | ||
182 | 453 | /* |
454 | * Initialize units for processing | |
455 | */ | |
456 | for (unit = Config.units; unit; unit = unit->next) { | |
457 | /* | |
458 | * Safety, turn everything off | |
459 | */ | |
460 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 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
|
461 | if (unit->mode == UNITMODE_PROFILE) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
462 | if (!unit->profile) |
195
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
463 | syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name); |
b34a1b2421fb
Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents:
194
diff
changeset
|
464 | else |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
465 | syslog(LOG_NOTICE, "Starting unit %s in profile state %s.", unit->name, PROFSTATE[unit->prof_state]); |
182 | 466 | } else if (unit->mode == UNITMODE_BEER) { |
467 | syslog(LOG_NOTICE, "Starting unit %s beer cooler at %.1f degrees", unit->name, unit->beer_set); | |
468 | } else if (unit->mode == UNITMODE_FRIDGE) { | |
469 | syslog(LOG_NOTICE, "Starting unit %s as refridgerator at %.1f degrees", unit->name, unit->fridge_set); | |
470 | } else if (unit->mode == UNITMODE_NONE) { | |
471 | syslog(LOG_NOTICE, "Starting unit %s in inactive state", unit->name); | |
472 | } else { | |
473 | syslog(LOG_NOTICE, "Starting unit %s in off state", unit->name); | |
474 | } | |
475 | } | |
476 | ||
93
b759f814469d
Added units processing thread
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
477 | |
111 | 478 | #ifdef HAVE_WIRINGPI_H |
238 | 479 | lcd_buf_write(1, (char *)" ThermFerm "); |
108 | 480 | lcd_buf_write(2, (char *)" Version %s ", VERSION); |
111 | 481 | #endif |
108 | 482 | |
104 | 483 | for (unit = Config.units; unit; unit = unit->next) { |
484 | if (unit->mode != UNITMODE_OFF) { | |
155
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
150
diff
changeset
|
485 | initlog(unit->name); |
104 | 486 | } |
487 | } | |
33
2357e8636a60
Added user log with temperatures and cooler state
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
488 | |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
489 | do { |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
490 | if (my_shutdown) |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
491 | run = 0; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
492 | |
64
2431965e8a8c
Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents:
63
diff
changeset
|
493 | now = time(NULL); |
104 | 494 | 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
|
495 | /* |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
496 | * 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
|
497 | */ |
64
2431965e8a8c
Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents:
63
diff
changeset
|
498 | last = now; |
104 | 499 | seconds++; |
500 | ||
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
501 | #ifdef HAVE_WIRINGPI_H |
108 | 502 | row = 3; |
503 | tm = localtime(&now); | |
504 | lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); | |
505 | lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); | |
182 | 506 | #endif |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
507 | |
207 | 508 | if (Config.temp_address) { |
509 | rc = read_sensor(Config.temp_address, &temp); | |
510 | if (rc == DEVPRESENT_YES) { | |
511 | Config.temp_value = temp; | |
512 | Config.temp_state = 0; | |
513 | #ifdef HAVE_WIRINGPI_H | |
514 | lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); | |
515 | #endif | |
516 | } else if (rc == DEVPRESENT_ERROR) { | |
517 | Config.temp_state = 1; | |
518 | } else { | |
519 | Config.temp_state = 2; | |
520 | } | |
521 | } | |
522 | ||
523 | if (Config.hum_address) { | |
524 | rc = read_sensor(Config.hum_address, &temp); | |
525 | if (rc == DEVPRESENT_YES) { | |
526 | Config.hum_value = temp; | |
527 | Config.hum_state = 0; | |
528 | #ifdef HAVE_WIRINGPI_H | |
529 | lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); | |
530 | #endif | |
531 | } else if (rc == DEVPRESENT_ERROR) { | |
532 | Config.hum_state = 1; | |
533 | } else { | |
534 | Config.hum_state = 2; | |
535 | } | |
536 | } | |
537 | ||
108 | 538 | for (unit = Config.units; unit; unit = unit->next) { |
182 | 539 | #ifdef HAVE_WIRINGPI_H |
184 | 540 | lcd_buf_write(row++, "Unit %s ", unit->name); |
541 | lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); | |
182 | 542 | #endif |
543 | ||
544 | if (unit->air_address) { | |
207 | 545 | rc = read_sensor(unit->air_address, &temp); |
182 | 546 | if (rc == DEVPRESENT_YES) { |
547 | /* | |
548 | * It is possible to have read errors or extreme values. | |
549 | * This can happen with bad connections so we compare the | |
550 | * value with the previous one. If the difference is too | |
551 | * much, we don't send that value. That also means that if | |
552 | * the next value is ok again, it will be marked invalid too. | |
553 | * Maximum error is 40 degrees for now. | |
554 | */ | |
555 | deviation = 40000; | |
556 | if ((unit->air_temperature == 0) || | |
557 | (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { | |
558 | unit->air_temperature = temp; | |
559 | unit->air_state = 0; | |
188
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
560 | #ifdef HAVE_WIRINGPI_H |
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
561 | lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); |
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
562 | #endif |
182 | 563 | } else { |
564 | syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); | |
565 | if (debug) { | |
566 | fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); | |
567 | } | |
568 | } | |
569 | } else if (rc == DEVPRESENT_ERROR) { | |
570 | unit->air_state = 1; | |
571 | } else { | |
572 | unit->air_state = 2; | |
573 | } | |
574 | } | |
575 | ||
576 | if (unit->beer_address) { | |
207 | 577 | rc = read_sensor(unit->beer_address, &temp); |
182 | 578 | if (rc == DEVPRESENT_YES) { |
579 | deviation = 40000; | |
580 | if ((unit->beer_temperature == 0) || | |
581 | (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { | |
582 | unit->beer_temperature = temp; | |
583 | unit->beer_state = 0; | |
188
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
584 | #ifdef HAVE_WIRINGPI_H |
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
585 | lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); |
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
586 | #endif |
182 | 587 | } else { |
588 | syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); | |
589 | if (debug) { | |
590 | fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); | |
591 | } | |
592 | } | |
593 | } else if (rc == DEVPRESENT_ERROR) { | |
594 | unit->beer_state = 1; | |
595 | } else { | |
596 | unit->beer_state = 2; | |
597 | } | |
598 | } | |
184 | 599 | |
600 | /* | |
189
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
601 | * 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
|
602 | */ |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
603 | 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
|
604 | /* |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
605 | * 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
|
606 | * 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
|
607 | * 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
|
608 | * unit->prof_target - Calculated target temperature. |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
609 | * unit->prof_paused - Internal pause counter. |
189
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
610 | */ |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
611 | for (profile = Config.profiles; profile; profile = profile->next) { |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
612 | if (strcmp(unit->profile, profile->uuid) == 0) { |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
613 | |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
614 | switch (unit->prof_state) { |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
615 | case PROFILE_OFF: |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
616 | unit->prof_target = profile->inittemp; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
617 | break; |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
618 | case PROFILE_PAUSE: |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
619 | /* |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
620 | * Keep current temperature, measure pause time. For |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
621 | * temperature fall thru. |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
622 | */ |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
623 | unit->prof_paused++; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
624 | case PROFILE_RUN: |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
625 | /* |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
626 | * Calculate current profile step en desired temperature. |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
627 | * When all done, set state to PROFILE_DONE. |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
628 | */ |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
629 | previous_target = profile->inittemp; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
630 | time_until_now = 0; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
631 | current_step = 0; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
632 | 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
|
633 | run_minutes = run_seconds / 60; |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
634 | run_hours = run_minutes / 60; |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
635 | 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
|
636 | 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
|
637 | |
221
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
638 | 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
|
639 | 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
|
640 | /* |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
641 | * step->steptime |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
642 | * step->resttime |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
643 | * step->target |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
644 | */ |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
645 | 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
|
646 | 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
|
647 | /* |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
648 | * This is our current step |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
649 | */ |
221
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
650 | valid_step = TRUE; |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
651 | 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
|
652 | 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
|
653 | 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
|
654 | step->steptime, step->resttime, step->target); |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
655 | if ((run_hours - time_until_now) < step->steptime) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
656 | 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
|
657 | if (debug) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
658 | 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
|
659 | 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
|
660 | step->steptime * 60, unit->prof_target); |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
661 | } else { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
662 | unit->prof_target = step->target; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
663 | fprintf(stdout, "resting target=%.1f ", step->target); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
664 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
665 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
666 | } |
221
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
667 | time_until_now += step->steptime + step->resttime; |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
668 | previous_target = step->target; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
669 | } |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
670 | 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
|
671 | fprintf(stdout, " %s\n", valid_step ? "TRUE":"FALSE"); |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
672 | |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
673 | /* |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
674 | * No more steps to do |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
675 | */ |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
676 | if (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
|
677 | unit->prof_state = PROFILE_DONE; |
91a5e7281c35
Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents:
219
diff
changeset
|
678 | 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
|
679 | } |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
680 | 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
|
681 | |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
682 | case PROFILE_DONE: |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
683 | /* |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
684 | * 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
|
685 | */ |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
686 | previous_target = profile->inittemp; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
687 | for (step = profile->steps; step; step = step->next) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
688 | if (step->steptime == 0) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
689 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
690 | previous_target = step->target; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
691 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
692 | unit->prof_target = previous_target; |
194
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
693 | break; |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
694 | } /* switch */ |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
695 | } |
9eaaba49450f
Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents:
189
diff
changeset
|
696 | } |
189
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
697 | } |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
698 | |
cc2b04d4db99
Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents:
188
diff
changeset
|
699 | /* |
184 | 700 | * Manual switching |
701 | */ | |
702 | if (unit->mode == UNITMODE_NONE) { | |
703 | device_out(unit->heater_address, unit->heater_state); | |
704 | device_out(unit->cooler_address, unit->cooler_state); | |
705 | device_out(unit->fan_address, unit->fan_state); | |
706 | } | |
188
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
707 | #ifdef HAVE_WIRINGPI_H |
219
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
708 | if (unit->heater_address && unit->cooler_address) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
709 | if (unit->heater_state) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
710 | lcd_buf_write(row++, "Heater On "); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
711 | else if (unit->cooler_state) |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
712 | lcd_buf_write(row++, "Cooler On "); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
713 | else |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
714 | lcd_buf_write(row++, "Standby "); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
715 | switch (unit->mode) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
716 | 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
|
717 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
718 | 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
|
719 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
720 | 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
|
721 | 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
|
722 | else |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
723 | lcd_buf_write(row++, "Target not set "); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
724 | break; |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
725 | default: lcd_buf_write(row++, "Target not set "); |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
726 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
727 | } else { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
728 | if (unit->heater_address) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
729 | 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
|
730 | } |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
731 | if (unit->cooler_address) { |
ae720212accc
Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents:
215
diff
changeset
|
732 | 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
|
733 | } |
188
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
734 | } |
4fc17ef4593f
Added heat/cool state to the LCD display
Michiel Broek <mbroek@mbse.eu>
parents:
185
diff
changeset
|
735 | #endif |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
736 | } |
108 | 737 | |
182 | 738 | piddelay++; |
739 | if (piddelay == 15) { | |
740 | piddelay = 0; | |
104 | 741 | |
742 | for (unit = Config.units; unit; unit = unit->next) { | |
184 | 743 | if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE)) { |
744 | /* | |
745 | * PID controller | |
746 | */ | |
747 | sp = unit->beer_set; | |
748 | pv = unit->beer_temperature / 1000.0; | |
749 | if (unit->mode == UNITMODE_FRIDGE) { | |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
750 | sp = unit->fridge_set; |
179
417ee898fb02
Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents:
177
diff
changeset
|
751 | pv = unit->air_temperature / 1000.0; |
184 | 752 | } else if (unit->mode == UNITMODE_PROFILE) { |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
753 | sp = unit->prof_target; |
184 | 754 | } |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
755 | |
184 | 756 | unit->PID_err_old = err; |
757 | err = sp - pv; | |
185 | 758 | if (err < unit->idle_rangeH && err > unit->idle_rangeL) { |
184 | 759 | err = 0; |
185 | 760 | unit->PID_I_err -= unit->PID_err_old; |
761 | } else { | |
762 | unit->PID_I_err += unit->PID_err_old; | |
763 | } | |
764 | /* Limit intergral error */ | |
765 | if (unit->PID_I_err < -10.0) | |
766 | unit->PID_I_err = -10.0; | |
767 | if (unit->PID_I_err > 10.0) | |
768 | unit->PID_I_err = 10.0; | |
184 | 769 | P_err = err; |
770 | D_err = err - unit->PID_err_old; | |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
771 | |
184 | 772 | /* |
773 | * A postive value means heating, a negative value cooling. | |
774 | */ | |
185 | 775 | Out = (10.0*P_err) + (0.1*unit->PID_I_err) + (5*D_err); |
776 | // Kp 0.1 Ki 0.3 Kd 0.02 | |
184 | 777 | if (debug) |
778 | fprintf(stdout, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f\n", | |
185 | 779 | sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); |
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
|
780 | syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f", |
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
|
781 | sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); |
184 | 782 | if (unit->heater_address) { |
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
|
783 | if (Out >= 2) { |
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
|
784 | if (! unit->heater_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
785 | syslog(LOG_NOTICE, "Heater Off => On"); |
184 | 786 | unit->heater_state = 100; |
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
|
787 | } else { |
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
|
788 | if (unit->heater_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
789 | syslog(LOG_NOTICE, "Heater On => Off"); |
184 | 790 | unit->heater_state = 0; |
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
|
791 | } |
184 | 792 | device_out(unit->heater_address, unit->heater_state); |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
793 | } |
184 | 794 | if (unit->cooler_address) { |
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
|
795 | if (Out <= -2) { |
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
|
796 | if (! unit->cooler_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
797 | syslog(LOG_NOTICE, "Cooler Off => On"); |
184 | 798 | unit->cooler_state = 100; |
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
|
799 | } else { |
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
|
800 | if (unit->cooler_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
801 | syslog(LOG_NOTICE, "Cooler On => Off"); |
184 | 802 | unit->cooler_state = 0; |
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
|
803 | } |
184 | 804 | device_out(unit->cooler_address, unit->cooler_state); |
805 | } | |
233
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
806 | if (unit->heater_address && unit->cooler_address && unit->fan_address) { |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
807 | /* |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
808 | * If the temperature difference between air and beer is more then |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
809 | * xxx degrees, turn the fan on to make an airflow. |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
810 | * Maybe, run the fan too if the heater is on because the heater in |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
811 | * most cases will be some sort of radiating heat device. |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
812 | * For cooling ??? dunno yet. |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
813 | */ |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
814 | if (((unit->air_temperature - unit->beer_temperature) > 1000) || |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
815 | ((unit->air_temperature - unit->beer_temperature) < -1000)) { |
234
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
816 | if (! unit->fan_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
817 | syslog(LOG_NOTICE, "Fan Off => On"); |
233
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
818 | unit->fan_state = 100; |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
819 | } else { |
234
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
820 | if (unit->fan_state) |
b69438db19ec
Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents:
233
diff
changeset
|
821 | syslog(LOG_NOTICE, "Fan On => Off"); |
233
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
822 | unit->fan_state = 0; |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
823 | } |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
824 | device_out(unit->fan_address, unit->fan_state); |
5874a6480322
Added code to control the Fan.
Michiel Broek <mbroek@mbse.eu>
parents:
227
diff
changeset
|
825 | } |
184 | 826 | } else { |
827 | err = 0.0; | |
185 | 828 | unit->PID_I_err = 0.0; |
184 | 829 | unit->PID_err_old = 0.0; |
182 | 830 | } |
831 | } | |
832 | } | |
833 | ||
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
834 | #ifdef HAVE_WIRINGPI_H |
205 | 835 | if (setupmenu == MENU_NONE) |
836 | lcd_buf_show(); | |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
837 | #endif |
205 | 838 | |
182 | 839 | if (seconds == 60) { |
840 | seconds = 0; | |
841 | ||
842 | /* | |
843 | * Log temperature and status every minute if unit is active. | |
844 | */ | |
845 | for (unit = Config.units; unit; unit = unit->next) { | |
846 | if (unit->mode != UNITMODE_OFF) { | |
176
8c7d87a2c094
Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents:
175
diff
changeset
|
847 | |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
848 | snprintf(target, 39, "NA"); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
849 | snprintf(heater, 39, "NA"); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
850 | snprintf(cooler, 39, "NA"); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
851 | snprintf(fan, 39, "NA"); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
852 | snprintf(door, 39, "NA"); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
853 | |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
854 | if (unit->mode == UNITMODE_BEER) |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
855 | snprintf(target, 39, "%.1f", unit->beer_set); |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
856 | else if (unit->mode == UNITMODE_FRIDGE) |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
857 | 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
|
858 | 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
|
859 | snprintf(target, 39, "%.1f", unit->prof_target); |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
860 | |
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
|
861 | 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
|
862 | snprintf(heater, 39, "%d", unit->heater_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
863 | } |
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
|
864 | 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
|
865 | snprintf(cooler, 39, "%d", unit->cooler_state); |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
866 | } |
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
|
867 | 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
|
868 | snprintf(fan, 39, "%d", unit->fan_state); |
b73490398368
Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents:
174
diff
changeset
|
869 | } |
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
|
870 | 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
|
871 | snprintf(door, 39, "%d", unit->door_state); |
105
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
872 | } |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
873 | |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
874 | snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s", |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
875 | UNITMODE[unit->mode], unit->air_temperature / 1000.0, |
a5a964148e34
Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents:
104
diff
changeset
|
876 | unit->beer_temperature / 1000.0, target, heater, cooler, fan, door); |
104 | 877 | filename = xstrcpy(unit->name); |
878 | filename = xstrcat(filename, (char *)".log"); | |
879 | logger(filename, buf); | |
880 | free(filename); | |
881 | filename = NULL; | |
882 | } | |
883 | } | |
167
56b008563db8
Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
165
diff
changeset
|
884 | |
56b008563db8
Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
165
diff
changeset
|
885 | minutes++; |
56b008563db8
Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
165
diff
changeset
|
886 | if (minutes == 60) |
56b008563db8
Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
165
diff
changeset
|
887 | minutes = 0; |
56b008563db8
Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents:
165
diff
changeset
|
888 | |
227
1cb55ea51f76
Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
889 | /* |
1cb55ea51f76
Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
890 | * Save the configuration each half hour. |
1cb55ea51f76
Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
891 | */ |
1cb55ea51f76
Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
892 | 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
|
893 | wrconfig(); |
64
2431965e8a8c
Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents:
63
diff
changeset
|
894 | } |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
895 | } |
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
|
896 | |
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
|
897 | #ifdef HAVE_WIRINGPI_H |
205 | 898 | /* |
899 | * Handle panel key events. | |
900 | */ | |
901 | key = keycheck(); | |
902 | ||
903 | switch (setupmenu) { | |
904 | case MENU_NONE: | |
905 | if ((key == KEY_DOWN) || (key == KEY_UP)) | |
906 | lcd_buf_step(key); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
907 | if ((key == KEY_CONFIRM) && (setupmenu == MENU_NONE)) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
908 | go_menu(MENU_TOP_DEFAULT); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
909 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
910 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
911 | case MENU_TOP_DEFAULT: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
912 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
913 | go_menu(MENU_NONE); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
914 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
915 | go_menu(MENU_TOP_UNITS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
916 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
917 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
918 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
919 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
920 | case MENU_TOP_UNITS: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
921 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
922 | go_menu(MENU_NONE); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
923 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
924 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
925 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
926 | go_menu(MENU_TOP_DEFAULT); |
238 | 927 | if (key == KEY_ENTER) |
928 | go_menu(MENU_UNITS); | |
929 | break; | |
930 | ||
931 | case MENU_UNITS: | |
932 | if (key == KEY_ESCAPE) | |
933 | go_menu(MENU_TOP_UNITS); | |
934 | if (key == KEY_DOWN) { | |
935 | for (unit = Config.units; unit; unit = unit->next) { | |
936 | if (strcmp(unit->uuid, current_unit->uuid) == 0) { /* Current unit */ | |
937 | if (unit->next) { /* Is there a next */ | |
938 | unit = unit->next; /* Select that */ | |
939 | lcdPosition(lcdHandle, 0, 1); | |
940 | lcdPuts(lcdHandle, Config.units->name); | |
941 | } | |
942 | } | |
943 | } | |
944 | } | |
945 | if (key == KEY_ENTER) { | |
946 | for (unit = Config.units; unit; unit = unit->next) { | |
947 | if (strcmp(unit->uuid, current_unit->uuid) == 0) { | |
948 | if (unit->mode == UNITMODE_OFF) | |
949 | go_menu(MENU_MODE_NONE); | |
950 | else | |
951 | go_menu(MENU_MODE_OFF); | |
952 | } | |
953 | } | |
954 | } | |
955 | break; | |
956 | ||
957 | case MENU_MODE_OFF: | |
958 | if (key == KEY_ESCAPE) | |
959 | go_menu(MENU_UNITS); | |
960 | if (key == KEY_DOWN) | |
961 | go_menu(MENU_MODE_NONE); | |
962 | if (key == KEY_UP) | |
963 | go_menu(MENU_MODE_PROFILE); | |
964 | if (key == KEY_ENTER) { | |
965 | change_mode(UNITMODE_OFF); | |
966 | go_menu(MENU_MODE_OFF); | |
967 | } | |
968 | break; | |
969 | ||
970 | case MENU_MODE_NONE: | |
971 | if (key == KEY_ESCAPE) | |
972 | go_menu(MENU_UNITS); | |
973 | if (key == KEY_DOWN) | |
974 | go_menu(MENU_MODE_FRIDGE); | |
975 | if (key == KEY_UP) | |
976 | go_menu(MENU_MODE_OFF); | |
977 | if (key == KEY_ENTER) { | |
978 | if (current_unit->mode == UNITMODE_NONE) | |
979 | go_menu(MENU_NONE_HEAT); | |
980 | else { | |
981 | change_mode(UNITMODE_NONE); | |
982 | go_menu(MENU_MODE_NONE); | |
983 | } | |
984 | } | |
985 | break; | |
986 | ||
987 | case MENU_NONE_HEAT: | |
988 | if (key == KEY_ESCAPE) | |
989 | go_menu(MENU_MODE_NONE); | |
990 | if (key == KEY_DOWN) | |
991 | go_menu(MENU_NONE_COOL); | |
992 | if (key == KEY_UP) | |
993 | go_menu(MENU_NONE_FAN); | |
994 | if (key == KEY_ENTER) { | |
995 | if (current_unit->heater_state) | |
996 | current_unit->heater_state = 0; | |
997 | else | |
998 | current_unit->heater_state = 100; | |
999 | go_menu(MENU_NONE_HEAT); | |
1000 | } | |
1001 | break; | |
1002 | ||
1003 | case MENU_NONE_COOL: | |
1004 | if (key == KEY_ESCAPE) | |
1005 | go_menu(MENU_MODE_NONE); | |
1006 | if (key == KEY_DOWN) | |
1007 | go_menu(MENU_NONE_FAN); | |
1008 | if (key == KEY_UP) | |
1009 | go_menu(MENU_NONE_HEAT); | |
1010 | if (key == KEY_ENTER) { | |
1011 | if (current_unit->cooler_state) | |
1012 | current_unit->cooler_state = 0; | |
1013 | else | |
1014 | current_unit->cooler_state = 100; | |
1015 | go_menu(MENU_NONE_COOL); | |
1016 | } | |
1017 | break; | |
1018 | ||
1019 | case MENU_NONE_FAN: | |
1020 | if (key == KEY_ESCAPE) | |
1021 | go_menu(MENU_MODE_NONE); | |
1022 | if (key == KEY_DOWN) | |
1023 | go_menu(MENU_NONE_HEAT); | |
1024 | if (key == KEY_UP) | |
1025 | go_menu(MENU_NONE_COOL); | |
1026 | if (key == KEY_ENTER) { | |
1027 | if (current_unit->fan_state) | |
1028 | current_unit->fan_state = 0; | |
1029 | else | |
1030 | current_unit->fan_state = 100; | |
1031 | go_menu(MENU_NONE_FAN); | |
1032 | } | |
1033 | break; | |
1034 | ||
1035 | case MENU_MODE_FRIDGE: | |
1036 | if (key == KEY_ESCAPE) | |
1037 | go_menu(MENU_UNITS); | |
1038 | if (key == KEY_DOWN) | |
1039 | go_menu(MENU_MODE_BEER); | |
1040 | if (key == KEY_UP) | |
1041 | go_menu(MENU_MODE_NONE); | |
1042 | if (key == KEY_ENTER) { | |
1043 | change_mode(UNITMODE_FRIDGE); | |
1044 | go_menu(MENU_MODE_FRIDGE); | |
1045 | } | |
1046 | break; | |
1047 | ||
1048 | case MENU_FRIDGE_TEMP: | |
1049 | break; | |
1050 | ||
1051 | case MENU_MODE_BEER: | |
1052 | if (key == KEY_ESCAPE) | |
1053 | go_menu(MENU_UNITS); | |
1054 | if (key == KEY_DOWN) | |
1055 | go_menu(MENU_MODE_PROFILE); | |
1056 | if (key == KEY_UP) | |
1057 | go_menu(MENU_MODE_FRIDGE); | |
1058 | if (key == KEY_ENTER) { | |
1059 | change_mode(UNITMODE_BEER); | |
1060 | go_menu(MENU_MODE_BEER); | |
1061 | } | |
1062 | break; | |
1063 | ||
1064 | case MENU_BEER_TEMP: | |
1065 | break; | |
1066 | ||
1067 | case MENU_MODE_PROFILE: | |
1068 | if (key == KEY_ESCAPE) | |
1069 | go_menu(MENU_UNITS); | |
1070 | if (key == KEY_DOWN) | |
1071 | go_menu(MENU_MODE_OFF); | |
1072 | if (key == KEY_UP) | |
1073 | go_menu(MENU_MODE_BEER); | |
1074 | if (key == KEY_ENTER) { | |
1075 | change_mode(UNITMODE_PROFILE); | |
1076 | go_menu(MENU_MODE_PROFILE); | |
1077 | } | |
1078 | break; | |
1079 | ||
1080 | case MENU_PROFILE_SELECT: | |
1081 | break; | |
1082 | ||
1083 | case MENU_PROFILE_START: | |
1084 | break; | |
1085 | ||
1086 | case MENU_PROFILE_PAUSE: | |
1087 | break; | |
1088 | ||
1089 | case MENU_PROFILE_ABORT: | |
1090 | break; | |
1091 | ||
1092 | case MENU_PROFILE_RESUME: | |
1093 | break; | |
1094 | ||
1095 | case MENU_PROFILE_GOOFF: | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1096 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1097 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1098 | case MENU_TOP_SYS: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1099 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1100 | go_menu(MENU_NONE); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1101 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1102 | go_menu(MENU_TOP_DEFAULT); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1103 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1104 | go_menu(MENU_TOP_UNITS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1105 | if (key == KEY_ENTER) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1106 | go_menu(MENU_SYS_HALT); |
205 | 1107 | break; |
1108 | ||
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1109 | case MENU_SYS_HALT: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1110 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1111 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1112 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1113 | go_menu(MENU_SYS_REBOOT); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1114 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1115 | go_menu(MENU_SYS_THERMS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1116 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1117 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1118 | case MENU_SYS_REBOOT: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1119 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1120 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1121 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1122 | go_menu(MENU_SYS_MASH); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1123 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1124 | go_menu(MENU_SYS_HALT); |
205 | 1125 | break; |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1126 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1127 | case MENU_SYS_MASH: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1128 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1129 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1130 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1131 | go_menu(MENU_SYS_THERMS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1132 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1133 | go_menu(MENU_SYS_REBOOT); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1134 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1135 | |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1136 | case MENU_SYS_THERMS: |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1137 | if (key == KEY_ESCAPE) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1138 | go_menu(MENU_TOP_SYS); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1139 | if (key == KEY_DOWN) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1140 | go_menu(MENU_SYS_HALT); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1141 | if (key == KEY_UP) |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1142 | go_menu(MENU_SYS_MASH); |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1143 | break; |
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
1144 | |
205 | 1145 | } |
1146 | ||
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
|
1147 | #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
|
1148 | |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1149 | usleep(100000); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1150 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1151 | } while (run); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1152 | |
182 | 1153 | /* |
1154 | * Stop units processing in a neat way | |
1155 | */ | |
1156 | for (unit = Config.units; unit; unit = unit->next) { | |
1157 | /* | |
1158 | * Turn everything off | |
1159 | */ | |
1160 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; | |
1161 | device_out(unit->heater_address, unit->heater_state); | |
1162 | device_out(unit->cooler_address, unit->cooler_state); | |
1163 | device_out(unit->fan_address, unit->fan_state); | |
1164 | syslog(LOG_NOTICE, "Stopped unit %s mode %s", unit->name, UNITMODE[unit->mode]); | |
1165 | } | |
1166 | ||
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1167 | if (debug) |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1168 | fprintf(stdout, (char *)"Out of loop\n"); |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1169 | |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1170 | /* |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1171 | * Give threads time to cleanup |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1172 | */ |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1173 | usleep(1500000); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1174 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
1175 | #ifdef HAVE_WIRINGPI_H |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1176 | stopLCD(); |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
1177 | #endif |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1178 | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
83
diff
changeset
|
1179 | wrconfig(); |
53 | 1180 | |
41
f534ace74eea
Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents:
40
diff
changeset
|
1181 | ulockprog((char *)"thermferm"); |
34 | 1182 | |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1183 | if (debug) |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
1184 | fprintf(stdout, "Goodbye\n"); |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1185 | |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1186 | return 0; |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1187 | } |
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1188 |