Mercurial > ~darius > hgwebdir.cgi > avr
annotate tempctrl.c @ 45:efd44dc40934
Add macros for number system used for temperatures.
Add error strings and improve comments for ROM programming.
author | darius@Inchoate |
---|---|
date | Mon, 20 Oct 2008 22:11:18 +1030 |
parents | f219538d6ea7 |
children | fb272cb82bcb |
rev | line source |
---|---|
41 | 1 /* |
2 * Temperature control logic | |
3 * | |
4 * Copyright (c) 2008 | |
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. | |
6 * | |
7 * Redistribution and use in source and binary forms, with or without | |
8 * modification, are permitted provided that the following conditions | |
9 * are met: | |
10 * 1. Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 * SUCH DAMAGE. | |
27 */ | |
28 | |
29 #include <stdio.h> | |
30 #include <stdint.h> | |
31 #include <stdlib.h> | |
32 #include <avr/interrupt.h> | |
33 #include <avr/pgmspace.h> | |
34 #include <avr/eeprom.h> | |
35 #include <util/crc16.h> | |
36 | |
37 #include "cons.h" | |
38 #include "1wire.h" | |
39 #include "tempctrl.h" | |
40 | |
41 typedef struct { | |
42 int32_t sec; | |
43 int32_t usec; | |
44 } time_t; | |
45 | |
46 /* Holds all the settings needed */ | |
47 typedef struct { | |
48 uint8_t fermenter_ROM[8]; | |
49 uint8_t fridge_ROM[8]; | |
50 uint8_t ambient_ROM[8]; | |
51 int16_t target_temp; | |
52 uint16_t hysteresis; | |
53 | |
54 /* How much to under/overshoot on heating/cooling */ | |
55 int16_t minheatovershoot; | |
56 int16_t mincoolovershoot; | |
57 | |
58 /* Minimum time the cooler can be on/off */ | |
59 int16_t mincoolontime; | |
60 int16_t mincoolofftime; | |
61 | |
62 /* Minimum time the heater can be on/off */ | |
63 int16_t minheatontime; | |
64 int16_t minheatofftime; | |
65 | |
66 #define TC_MODE_AUTO 'a' /* Automatic control */ | |
67 #define TC_MODE_HEAT 'h' /* Force heating */ | |
68 #define TC_MODE_COOL 'c' /* Force cooling */ | |
69 #define TC_MODE_IDLE 'i' /* Force idle */ | |
70 #define TC_MODE_NOTHING 'n' /* Do nothing (like idle but log nothing) */ | |
71 char mode; | |
72 | |
73 /* Bit patterns for various modes */ | |
74 uint8_t coolbits; | |
75 uint8_t heatbits; | |
76 uint8_t idlebits; | |
77 | |
78 /* Check/stale times */ | |
79 int16_t check_interval; | |
80 int16_t stale_factor; | |
81 } __attribute__((packed)) settings_t; | |
82 | |
83 /* Current settings in RAM */ | |
84 static settings_t settings; | |
85 | |
86 /* Our map of EEPROM */ | |
87 struct { | |
88 settings_t settings; | |
89 uint16_t crc; | |
90 } ee_area __attribute__((section(".eeprom"))); | |
91 | |
92 /* Defaults that are shoved into EEPROM if it isn't inited */ | |
93 const PROGMEM settings_t default_settings = { | |
94 .fermenter_ROM = { 0x10, 0xeb, 0x48, 0x21, 0x01, 0x08, 0x00, 0xdf }, | |
95 .fridge_ROM = { 0x10, 0xa6, 0x2a, 0xc4, 0x00, 0x08, 0x00, 0x11 }, | |
96 .ambient_ROM = { 0x10, 0x97, 0x1b, 0xfe, 0x00, 0x08, 0x00, 0xd1 }, | |
97 .target_temp = 1400, | |
98 .hysteresis = 100, | |
99 .minheatovershoot = 50, | |
100 .mincoolovershoot = -50, | |
101 .mincoolontime = 300, | |
102 .mincoolofftime = 600, | |
103 .minheatontime = 60, | |
104 .minheatofftime = 60, | |
105 .mode = TC_MODE_AUTO, | |
106 .coolbits = _BV(7), | |
107 .heatbits = _BV(6), | |
108 .idlebits = 0x00, | |
109 .check_interval = 10, | |
110 .stale_factor = 3 | |
111 }; | |
112 | |
113 /* Local variable declarations */ | |
114 volatile static time_t now; | |
115 | |
116 /* Local function prototypes */ | |
117 static int gettemp(const PROGMEM char *name, uint8_t *ROM, int16_t *temp, uint8_t last); | |
118 static void tempctrl_load_or_init_settings(void); | |
119 static void tempctrl_default_settings(void); | |
120 static void tempctrl_write_settings(void); | |
121 static void setstate(char state); | |
122 static const PROGMEM char*state2long(char s); | |
123 | |
124 /* | |
125 * tempctrl_init | |
126 * | |
127 * Setup timer, should be called with interrupts disabled. | |
128 * | |
129 */ | |
130 void | |
131 tempctrl_init(void) { | |
132 /* Setup timer */ | |
133 /* 16Mhz / 1024 = 15625 Hz / 125 = 125 Hz = IRQ every 8 ms */ | |
134 | |
135 /* CTC mode, no output on pin, Divide clock by 1024 */ | |
136 TCCR0 = _BV(WGM01)| _BV(CS02) | _BV(CS00); | |
137 | |
138 /* Compare with ... */ | |
139 OCR0 = 125; | |
140 | |
141 /* Enable interrupt for match on A */ | |
142 TIMSK = _BV(OCIE0); | |
143 | |
144 now.sec = 0; | |
145 now.usec = 0; | |
146 | |
147 tempctrl_load_or_init_settings(); | |
148 } | |
149 | |
150 /* | |
151 * Timer 0 Compare IRQ | |
152 * | |
153 * Update time counter | |
154 */ | |
155 | |
156 ISR(TIMER0_COMP_vect) { | |
157 now.usec += 8000; /* 1000000 * 1 / F_CPU / 1024 / 125 */ | |
158 while (now.usec > 1000000) { | |
159 now.usec -= 1000000; | |
160 now.sec++; | |
161 } | |
162 } | |
163 | |
164 /* | |
165 * tempctrl_update | |
166 * | |
167 * Should be called in a normal context, could run things that take a long time. | |
168 * (ie 1wire bus stuff) | |
169 * | |
170 */ | |
171 void | |
172 tempctrl_update(void) { | |
173 /* State variables */ | |
174 static int32_t checktime = 0; // Time of next check | |
43
51e7458d2e76
Init lastdata same as lastheat/coolon/off otherwise we won't handle thing
darius@inchoate.localdomain
parents:
42
diff
changeset
|
175 static int32_t lastdata = -100000; // Last time we got data |
41 | 176 |
177 static int16_t fermenter_temp = 0; // Fermenter temperature | |
178 static int16_t fridge_temp = 0; // Fridge temperature | |
179 static int16_t ambient_temp = 0; // Ambient temperature | |
180 // These are inited like this so we will still heat/cool when | |
181 // now < settings.minheatofftime | |
182 static int32_t lastheaton = -100000; // Last time the heater was on | |
183 static int32_t lastheatoff = -100000; // Last time the heater was off | |
184 static int32_t lastcoolon = -100000; // Last time the cooler was on | |
185 static int32_t lastcooloff = -100000; // Last time the cooler was off | |
186 static char currstate = 'i'; // Current state | |
187 | |
188 /* Temporary variables */ | |
189 int32_t t; | |
190 int16_t diff; | |
191 char nextstate; | |
192 int forced; | |
193 int stale; | |
194 | |
195 t = gettod(); | |
196 /* Time to check temperatures? */ | |
197 if (t < checktime) | |
198 return; | |
199 | |
200 checktime = t + settings.check_interval; | |
201 | |
202 /* Don't do any logging, just force idle and leave */ | |
203 if (settings.mode == TC_MODE_NOTHING) { | |
204 nextstate = 'i'; | |
205 goto setstate; | |
206 } | |
207 | |
208 /* Update our temperatures */ | |
209 printf_P(PSTR("Time: %ld, Target: %d.%02d, "), now.sec, GETWHOLE(settings.target_temp), | |
210 GETFRAC(settings.target_temp)); | |
211 | |
212 if (gettemp(PSTR("Fermenter"), settings.fermenter_ROM, &fermenter_temp, 0)) | |
213 lastdata = t; | |
214 | |
215 /* Check for stale data */ | |
216 if (lastdata + (settings.check_interval * settings.stale_factor) < t) | |
217 stale = 1; | |
218 else | |
219 stale = 0; | |
220 | |
221 gettemp(PSTR("Fridge"), settings.fridge_ROM, &fridge_temp, 0); | |
222 gettemp(PSTR("Ambient"), settings.ambient_ROM, &ambient_temp, 1); | |
223 | |
224 /* Default to remaining as we are */ | |
225 nextstate = '-'; | |
226 | |
227 /* Temperature diff, -ve => too cold, +ve => too warm */ | |
228 diff = fermenter_temp - settings.target_temp; | |
229 | |
230 switch (currstate) { | |
231 case 'i': | |
232 /* If we're idle then only heat or cool if the temperate difference is out of the | |
233 * hysteresis band | |
234 */ | |
235 if (abs(diff) > settings.hysteresis) { | |
236 if (diff < 0 && settings.minheatofftime + lastheatoff < t) | |
237 nextstate = 'h'; | |
238 else if (diff > 0 && settings.mincoolofftime + lastcooloff < t) | |
239 nextstate = 'c'; | |
240 } | |
241 break; | |
242 | |
243 case 'c': | |
244 /* Work out if we should go idle (based on min on time & overshoot) */ | |
245 if (diff + settings.mincoolovershoot < 0 && | |
246 settings.mincoolontime + lastcoolon < t) | |
247 nextstate = 'i'; | |
248 break; | |
249 | |
250 case 'h': | |
251 if (diff - settings.minheatovershoot > 0 && | |
252 settings.minheatontime + lastheaton < t) | |
253 nextstate = 'i'; | |
254 break; | |
255 | |
256 default: | |
257 printf_P(PSTR("\r\nUnknown state %c, going to idle\n"), currstate); | |
258 nextstate = 'i'; | |
259 break; | |
260 } | |
261 | |
262 /* Override if we have stale data */ | |
263 if (stale) | |
264 nextstate = 'i'; | |
265 | |
266 /* Handle state forcing */ | |
267 if (settings.mode != TC_MODE_AUTO) | |
268 forced = 1; | |
269 else | |
270 forced = 0; | |
271 | |
272 if (settings.mode == TC_MODE_IDLE) | |
273 nextstate = 'i'; | |
274 else if (settings.mode == TC_MODE_HEAT) | |
275 nextstate = 'h'; | |
276 else if (settings.mode == TC_MODE_COOL) | |
277 nextstate = 'c'; | |
278 | |
42
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
279 // Keep track of when we last turned things on or off |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
280 switch (nextstate) { |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
281 case 'c': |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
282 if (currstate == 'h') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
283 lastheatoff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
284 lastcoolon = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
285 break; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
286 |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
287 case 'h': |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
288 if (currstate == 'c') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
289 lastcooloff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
290 lastheaton = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
291 break; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
292 |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
293 default: |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
294 if (currstate == 'c') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
295 lastcooloff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
296 if (currstate == 'h') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
297 lastheatoff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
298 } |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
299 |
41 | 300 if (nextstate != '-') |
301 currstate = nextstate; | |
302 | |
303 printf_P(PSTR(", State: %S, Flags: %S%S\r\n"), state2long(currstate), | |
304 forced ? PSTR("F") : PSTR(""), | |
305 stale ? PSTR("S") : PSTR("")); | |
306 | |
307 setstate: | |
308 setstate(currstate); | |
309 } | |
310 | |
311 /* | |
312 * Log a temperature & store it if valid | |
313 * | |
314 * Returns 1 if it was valid, 0 otherwise | |
315 */ | |
316 static int | |
317 gettemp(const PROGMEM char *name, uint8_t *ROM, int16_t *temp, uint8_t last) { | |
318 int16_t tmp; | |
319 | |
320 tmp = OWGetTemp(ROM); | |
321 printf_P(PSTR("%S: "), name); | |
322 if (tmp > OW_TEMP_BADVAL) { | |
323 printf_P(PSTR("%d.%02d%S"), GETWHOLE(tmp), GETFRAC(tmp), last ? PSTR("") : PSTR(", ")); | |
324 *temp = tmp; | |
325 return(1); | |
326 } else { | |
327 printf_P(PSTR("NA (%d)%S"), tmp, last ? PSTR("") : PSTR(", ")); | |
328 return(0); | |
329 } | |
330 } | |
331 | |
332 /* Return 'time of day' (really uptime) */ | |
333 int32_t | |
334 gettod(void) { | |
335 int32_t t; | |
336 | |
337 cli(); | |
338 t = now.sec; | |
339 sei(); | |
340 | |
341 return(t); | |
342 } | |
343 | |
344 /* Read the settings from EEPROM | |
345 * If the CRC fails then reload from flash | |
346 */ | |
347 static void | |
348 tempctrl_load_or_init_settings(void) { | |
349 uint8_t *dptr; | |
350 uint16_t crc, strcrc; | |
351 int i; | |
352 | |
353 crc = 0; | |
354 eeprom_busy_wait(); | |
355 eeprom_read_block(&settings, &ee_area.settings, sizeof(settings_t)); | |
356 strcrc = eeprom_read_word(&ee_area.crc); | |
357 | |
358 dptr = (uint8_t *)&settings; | |
359 | |
360 for (i = 0; i < sizeof(settings_t); i++) | |
361 crc = _crc16_update(crc, dptr[i]); | |
362 | |
363 /* All OK? */ | |
364 if (crc == strcrc) | |
365 return; | |
366 | |
367 printf_P(PSTR("CRC mismatch got 0x%04x vs 0x%04x, setting defaults\r\n"), crc, strcrc); | |
368 tempctrl_default_settings(); | |
369 tempctrl_write_settings(); | |
370 } | |
371 | |
372 /* Load in the defaults from flash */ | |
373 static void | |
374 tempctrl_default_settings(void) { | |
375 memcpy_P(&settings, &default_settings, sizeof(settings_t)); | |
376 } | |
377 | |
378 /* Write the current settings out to EEPROM */ | |
379 static void | |
380 tempctrl_write_settings(void) { | |
381 uint16_t crc; | |
382 uint8_t *dptr; | |
383 int i; | |
384 | |
385 eeprom_busy_wait(); | |
386 eeprom_write_block(&settings, &ee_area.settings, sizeof(settings_t)); | |
387 | |
388 dptr = (uint8_t *)&settings; | |
389 crc = 0; | |
390 for (i = 0; i < sizeof(settings_t); i++) | |
391 crc = _crc16_update(crc, dptr[i]); | |
392 | |
393 eeprom_write_word(&ee_area.crc, crc); | |
394 } | |
395 | |
396 /* Set the relays to match the desired state */ | |
397 static void | |
398 setstate(char state) { | |
399 switch (state) { | |
400 case 'c': | |
401 PORTC = settings.coolbits; | |
402 break; | |
403 | |
404 case 'h': | |
405 PORTC = settings.heatbits; | |
406 break; | |
407 | |
408 default: | |
409 printf_P(PSTR("Unknown state %c, setting idle\r\n"), state); | |
410 /* fallthrough */ | |
411 | |
412 case 'i': | |
413 PORTC = settings.idlebits; | |
414 break; | |
415 } | |
416 } | |
417 | |
418 /* Handle user command | |
419 * | |
420 */ | |
421 void | |
422 tempctrl_cmd(char *buf) { | |
423 char cmd[6]; | |
424 int16_t data; | |
425 int i; | |
426 | |
427 i = sscanf_P(buf, PSTR("tc %5s %d"), cmd, &data); | |
428 | |
429 if (i == 1) { | |
430 if (!strcasecmp_P(cmd, PSTR("help"))) { | |
431 printf_P(PSTR( | |
432 "tc help This help\r\n" | |
433 "tc save Save settings to EEPROM\r\n" | |
434 "tc load Load or default settings from EEPROM\r\n" | |
435 "tc dflt Load defaults from flash\r\n" | |
436 "tc list List current settings\r\n" | |
437 "tc mode [achin] Change control mode, must be one of\r\n" | |
438 " a Auto\r\n" | |
439 " c Always cool\r\n" | |
440 " h Always heat\r\n" | |
441 " i Always idle\r\n" | |
442 " n Like idle but don't log anything\r\n" | |
443 "\r\n" | |
444 "tc X Y Set X to Y where X is one of\r\n" | |
445 " targ Target temperature\r\n" | |
446 " hys Hysteresis range\r\n" | |
447 " mhov Minimum heat overshoot\r\n" | |
448 " mcov Minimum cool overshoot\r\n" | |
449 " mcon Minimum cool on time\r\n" | |
450 " mcoff Minimum cool off time\r\n" | |
451 " mhin Minimum heat on time\r\n" | |
452 " mhoff Minimum heat off time\r\n" | |
453 " Times are in seconds\r\n" | |
454 " Temperatures are in hundredths of degrees Celcius\r\n" | |
455 )); | |
456 return; | |
457 } | |
458 | |
459 if (!strcasecmp_P(cmd, PSTR("save"))) { | |
460 tempctrl_write_settings(); | |
461 return; | |
462 } | |
463 if (!strcasecmp_P(cmd, PSTR("load"))) { | |
464 tempctrl_load_or_init_settings(); | |
465 return; | |
466 } | |
467 if (!strcasecmp_P(cmd, PSTR("dflt"))) { | |
468 tempctrl_default_settings(); | |
469 return; | |
470 } | |
471 if (!strcasecmp_P(cmd, PSTR("list"))) { | |
472 printf_P(PSTR("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
473 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
474 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
475 "Target - %d, Hystersis - %d\r\n" | |
476 "Min heat overshoot - %d, Min cool overshoot - %d\r\n" | |
477 "Min cool on time - %d, Min cool off time - %d\r\n" | |
44 | 478 "Min heat on time - %d, Min heat off time - %d\r\n"), |
41 | 479 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3], |
480 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], | |
481 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3], | |
482 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], | |
483 settings.ambient_ROM[0], settings.ambient_ROM[1], settings.ambient_ROM[2], settings.ambient_ROM[3], | |
484 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7], | |
485 settings.target_temp, settings.hysteresis, | |
486 settings.minheatovershoot, settings.mincoolovershoot, | |
487 settings.mincoolontime, settings.minheatontime, | |
488 settings.minheatontime, settings.minheatofftime); | |
489 return; | |
490 } | |
491 if (!strcasecmp_P(cmd, PSTR("mode"))) { | |
492 switch (buf[8]) { | |
493 case TC_MODE_AUTO: | |
494 case TC_MODE_HEAT: | |
495 case TC_MODE_COOL: | |
496 case TC_MODE_IDLE: | |
497 case TC_MODE_NOTHING: | |
498 settings.mode = buf[8]; | |
499 break; | |
500 | |
501 default: | |
502 printf_P(PSTR("Unknown mode character '%c'\r\n"), buf[8]); | |
503 break; | |
504 } | |
505 return; | |
506 } | |
507 | |
508 } | |
509 | |
510 if (i != 2) { | |
511 printf_P(PSTR("Unable to parse command\r\n")); | |
512 return; | |
513 } | |
514 | |
515 if (!strcasecmp_P(cmd, PSTR("targ"))) { | |
516 settings.target_temp = data; | |
517 } else if (!strcasecmp_P(cmd, PSTR("hys"))) { | |
518 settings.hysteresis = data; | |
519 } else if (!strcasecmp_P(cmd, PSTR("mhov"))) { | |
520 settings.minheatovershoot = data; | |
521 } else if (!strcasecmp_P(cmd, PSTR("mcov"))) { | |
522 settings.mincoolovershoot = data; | |
523 } else if (!strcasecmp_P(cmd, PSTR("mcon"))) { | |
524 settings.mincoolontime = data; | |
525 } else if (!strcasecmp_P(cmd, PSTR("mcoff"))) { | |
526 settings.mincoolofftime = data; | |
527 } else if (!strcasecmp_P(cmd, PSTR("mhon"))) { | |
528 settings.minheatontime = data; | |
529 } else if (!strcasecmp_P(cmd, PSTR("mhoff"))) { | |
530 settings.minheatofftime = data; | |
531 } else { | |
532 printf_P(PSTR("Unknown setting\r\n")); | |
533 return; | |
534 } | |
535 } | |
536 | |
537 static const PROGMEM char* | |
538 state2long(char s) { | |
539 switch (s) { | |
540 case 'i': | |
541 return PSTR("idle"); | |
542 break; | |
543 | |
544 case 'c': | |
545 return PSTR("cool"); | |
546 break; | |
547 | |
548 case 'h': | |
549 return PSTR("heat"); | |
550 break; | |
551 | |
552 case '-': | |
553 return PSTR("-"); | |
554 break; | |
555 | |
556 default: | |
557 return PSTR("unknown"); | |
558 break; | |
559 } | |
560 } | |
561 |