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