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