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