20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 #include "thermferm.h" |
23 #include "thermferm.h" |
24 |
24 |
25 #ifdef HAVE_WIRINGPI_H |
|
26 |
25 |
27 bool debug = FALSE; |
26 bool debug = FALSE; |
28 static char *mypath; |
27 static char *mypath; |
29 static char *k, *v; |
28 static char *k, *v; |
30 static int linecnt = 0; |
29 static int linecnt = 0; |
31 sys_config Config; /* System configuration */ |
30 sys_config Config; /* System configuration */ |
32 |
31 |
33 |
32 |
34 |
33 |
35 static int getstr(char **); |
34 //static int getstr(char **); |
36 static int getint(char **); |
35 //static int getint(char **); |
37 static int getw1(char **); |
36 static int getw1(char **); |
|
37 #ifdef HAVE_WIRINGPI_H |
38 static int getrcs(char **); |
38 static int getrcs(char **); |
|
39 #endif |
39 static int getuch(char **); |
40 static int getuch(char **); |
40 static int getfloat(char **); |
41 static int getfloat(char **); |
41 //static int getbyt(char **); |
42 //static int getbyt(char **); |
42 //static int gethex(char **); |
43 //static int gethex(char **); |
43 |
44 |
47 /* |
48 /* |
48 * System configuration table |
49 * System configuration table |
49 */ |
50 */ |
50 key_list keytab[] = { |
51 key_list keytab[] = { |
51 {(char *)"w1therm", getw1, (char **)&Config.w1therms}, |
52 {(char *)"w1therm", getw1, (char **)&Config.w1therms}, |
|
53 #ifdef HAVE_WIRINGPI_H |
52 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, |
54 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, |
53 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, |
55 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, |
54 {(char *)"tx433", getint, (char **)&Config.tx433}, |
56 {(char *)"tx433", getint, (char **)&Config.tx433}, |
55 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
57 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
|
58 #endif |
56 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode}, |
59 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode}, |
57 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet}, |
60 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet}, |
58 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet}, |
61 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet}, |
59 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator}, |
62 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator}, |
60 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator}, |
63 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator}, |
136 } |
145 } |
137 |
146 |
138 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION); |
147 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION); |
139 fprintf(fp, "\n"); |
148 fprintf(fp, "\n"); |
140 |
149 |
|
150 #ifdef HAVE_WIRINGPI_H |
141 fprintf(fp, "# Radio controllers 433 MHz.\n"); |
151 fprintf(fp, "# Radio controllers 433 MHz.\n"); |
142 fprintf(fp, "#\n"); |
152 fprintf(fp, "#\n"); |
143 fprintf(fp, "tx433 %d\n", Config.tx433); |
153 fprintf(fp, "tx433 %d\n", Config.tx433); |
144 fprintf(fp, "\n"); |
154 fprintf(fp, "\n"); |
145 |
155 |
146 fprintf(fp, "# LCD display\n"); |
156 fprintf(fp, "# LCD display\n"); |
147 fprintf(fp, "#\n"); |
157 fprintf(fp, "#\n"); |
148 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols); |
158 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols); |
149 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows); |
159 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows); |
150 fprintf(fp, "\n"); |
160 fprintf(fp, "\n"); |
|
161 #endif |
151 |
162 |
152 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n"); |
163 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n"); |
153 fprintf(fp, "#\n"); |
164 fprintf(fp, "#\n"); |
154 fprintf(fp, "# kwd master bus name alias\n"); |
165 fprintf(fp, "# kwd master bus name alias\n"); |
155 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { |
166 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { |
156 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias); |
167 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias); |
157 } |
168 } |
158 fprintf(fp, "\n"); |
169 fprintf(fp, "\n"); |
159 |
170 |
|
171 #ifdef HAVE_WIRINGPI_H |
160 fprintf(fp, "# RC switches that we want to control.\n"); |
172 fprintf(fp, "# RC switches that we want to control.\n"); |
161 fprintf(fp, "#\n"); |
173 fprintf(fp, "#\n"); |
162 fprintf(fp, "# kwd address alias\n"); |
174 fprintf(fp, "# kwd address alias\n"); |
163 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { |
175 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { |
164 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); |
176 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); |
165 } |
177 } |
166 fprintf(fp, "\n"); |
178 fprintf(fp, "\n"); |
|
179 #endif |
167 |
180 |
168 fprintf(fp, "# Control Settings.\n"); |
181 fprintf(fp, "# Control Settings.\n"); |
169 fprintf(fp, "#\n"); |
182 fprintf(fp, "#\n"); |
170 fprintf(fp, "cs_mode %c\n", Config.cs_mode); |
183 fprintf(fp, "cs_mode %c\n", Config.cs_mode); |
171 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet); |
184 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet); |
284 return rc; |
297 return rc; |
285 } |
298 } |
286 |
299 |
287 |
300 |
288 |
301 |
|
302 /* |
289 static int getstr(char **dest) |
303 static int getstr(char **dest) |
290 { |
304 { |
291 if (debug) |
305 if (debug) |
292 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
306 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
293 |
307 |
294 *dest = xstrcpy(v); |
308 *dest = xstrcpy(v); |
295 return 0; |
309 return 0; |
296 } |
310 } |
297 |
311 */ |
298 |
312 |
299 |
313 |
|
314 |
|
315 /* |
300 static int getint(char **dest) |
316 static int getint(char **dest) |
301 { |
317 { |
302 if (debug) |
318 if (debug) |
303 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
319 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
304 |
320 |