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