Mercurial > ~darius > hgwebdir.cgi > tempctrl
annotate tempctrl.c @ 50:a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
is printed in one hit.
author | darius@Inchoate |
---|---|
date | Wed, 29 Oct 2008 16:06:42 +1030 |
parents | 91e06007fe23 |
children | cb184206344d |
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, | |
49
91e06007fe23
Default to idle mode (saves on compressor stress when testing)
darius@Inchoate
parents:
46
diff
changeset
|
106 .mode = TC_MODE_IDLE, |
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 */ | |
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); | |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
123 static void printtemp(char *name, int tmp, char *trailer); |
41 | 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 */ | |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
212 fermenter_temp = OWGetTemp(settings.fermenter_ROM); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
213 fridge_temp = OWGetTemp(settings.fridge_ROM); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
214 ambient_temp = OWGetTemp(settings.ambient_ROM); |
41 | 215 |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
216 if (fermenter_temp > OW_TEMP_BADVAL) |
41 | 217 lastdata = t; |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
218 |
41 | 219 /* Check for stale data */ |
220 if (lastdata + (settings.check_interval * settings.stale_factor) < t) | |
221 stale = 1; | |
222 else | |
223 stale = 0; | |
224 | |
225 /* Default to remaining as we are */ | |
226 nextstate = '-'; | |
227 | |
228 /* Temperature diff, -ve => too cold, +ve => too warm */ | |
229 diff = fermenter_temp - settings.target_temp; | |
230 | |
231 switch (currstate) { | |
232 case 'i': | |
233 /* If we're idle then only heat or cool if the temperate difference is out of the | |
234 * hysteresis band | |
235 */ | |
236 if (abs(diff) > settings.hysteresis) { | |
237 if (diff < 0 && settings.minheatofftime + lastheatoff < t) | |
238 nextstate = 'h'; | |
239 else if (diff > 0 && settings.mincoolofftime + lastcooloff < t) | |
240 nextstate = 'c'; | |
241 } | |
242 break; | |
243 | |
244 case 'c': | |
245 /* Work out if we should go idle (based on min on time & overshoot) */ | |
246 if (diff + settings.mincoolovershoot < 0 && | |
247 settings.mincoolontime + lastcoolon < t) | |
248 nextstate = 'i'; | |
249 break; | |
250 | |
251 case 'h': | |
252 if (diff - settings.minheatovershoot > 0 && | |
253 settings.minheatontime + lastheaton < t) | |
254 nextstate = 'i'; | |
255 break; | |
256 | |
257 default: | |
258 printf_P(PSTR("\r\nUnknown state %c, going to idle\n"), currstate); | |
259 nextstate = 'i'; | |
260 break; | |
261 } | |
262 | |
263 /* Override if we have stale data */ | |
264 if (stale) | |
265 nextstate = 'i'; | |
266 | |
267 /* Handle state forcing */ | |
268 if (settings.mode != TC_MODE_AUTO) | |
269 forced = 1; | |
270 else | |
271 forced = 0; | |
272 | |
273 if (settings.mode == TC_MODE_IDLE) | |
274 nextstate = 'i'; | |
275 else if (settings.mode == TC_MODE_HEAT) | |
276 nextstate = 'h'; | |
277 else if (settings.mode == TC_MODE_COOL) | |
278 nextstate = 'c'; | |
279 | |
42
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
280 // 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
|
281 switch (nextstate) { |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
282 case 'c': |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
283 if (currstate == 'h') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
284 lastheatoff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
285 lastcoolon = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
286 break; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
287 |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
288 case 'h': |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
289 if (currstate == 'c') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
290 lastcooloff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
291 lastheaton = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
292 break; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
293 |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
294 default: |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
295 if (currstate == 'c') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
296 lastcooloff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
297 if (currstate == 'h') |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
298 lastheatoff = t; |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
299 } |
97ae82023d5b
Actually keep track of when the heater & cooler go on/off..
darius@inchoate.localdomain
parents:
41
diff
changeset
|
300 |
41 | 301 if (nextstate != '-') |
302 currstate = nextstate; | |
303 | |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
304 printf_P(PSTR("Time: %10ld, "), t); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
305 printtemp(PSTR("Target"), settings.target_temp, PSTR(", ")); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
306 printtemp(PSTR("Fermenter"), fermenter_temp, PSTR(", ")); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
307 printtemp(PSTR("Fridge"), fridge_temp, PSTR(", ")); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
308 printtemp(PSTR("Ambient"), ambient_temp, PSTR(", ")); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
309 printf_P(PSTR("State: %S, Flags: %S%S\r\n"), state2long(currstate), |
41 | 310 forced ? PSTR("F") : PSTR(""), |
311 stale ? PSTR("S") : PSTR("")); | |
312 | |
313 setstate: | |
314 setstate(currstate); | |
315 } | |
316 | |
317 /* Return 'time of day' (really uptime) */ | |
318 int32_t | |
319 gettod(void) { | |
320 int32_t t; | |
321 | |
322 cli(); | |
323 t = now.sec; | |
324 sei(); | |
325 | |
326 return(t); | |
327 } | |
328 | |
50
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
329 /* |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
330 * Print out temperature (or NA + error code) with specified trailer |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
331 */ |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
332 static void |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
333 printtemp(char *name, int tmp, char *trailer) { |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
334 if (tmp > OW_TEMP_BADVAL) |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
335 printf_P(PSTR("%S: %d.%02d%S"), name, GETWHOLE(tmp), GETFRAC(tmp), trailer); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
336 else |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
337 printf_P(PSTR("%S: NA (%d)%S"), name, tmp, trailer); |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
338 } |
a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
darius@Inchoate
parents:
49
diff
changeset
|
339 |
41 | 340 /* Read the settings from EEPROM |
341 * If the CRC fails then reload from flash | |
342 */ | |
343 static void | |
344 tempctrl_load_or_init_settings(void) { | |
345 uint8_t *dptr; | |
346 uint16_t crc, strcrc; | |
347 int i; | |
348 | |
349 crc = 0; | |
350 eeprom_busy_wait(); | |
351 eeprom_read_block(&settings, &ee_area.settings, sizeof(settings_t)); | |
352 strcrc = eeprom_read_word(&ee_area.crc); | |
353 | |
354 dptr = (uint8_t *)&settings; | |
355 | |
356 for (i = 0; i < sizeof(settings_t); i++) | |
357 crc = _crc16_update(crc, dptr[i]); | |
358 | |
359 /* All OK? */ | |
360 if (crc == strcrc) | |
361 return; | |
362 | |
363 printf_P(PSTR("CRC mismatch got 0x%04x vs 0x%04x, setting defaults\r\n"), crc, strcrc); | |
364 tempctrl_default_settings(); | |
365 tempctrl_write_settings(); | |
366 } | |
367 | |
368 /* Load in the defaults from flash */ | |
369 static void | |
370 tempctrl_default_settings(void) { | |
371 memcpy_P(&settings, &default_settings, sizeof(settings_t)); | |
372 } | |
373 | |
374 /* Write the current settings out to EEPROM */ | |
375 static void | |
376 tempctrl_write_settings(void) { | |
377 uint16_t crc; | |
378 uint8_t *dptr; | |
379 int i; | |
380 | |
381 eeprom_busy_wait(); | |
382 eeprom_write_block(&settings, &ee_area.settings, sizeof(settings_t)); | |
383 | |
384 dptr = (uint8_t *)&settings; | |
385 crc = 0; | |
386 for (i = 0; i < sizeof(settings_t); i++) | |
387 crc = _crc16_update(crc, dptr[i]); | |
388 | |
389 eeprom_write_word(&ee_area.crc, crc); | |
390 } | |
391 | |
392 /* Set the relays to match the desired state */ | |
393 static void | |
394 setstate(char state) { | |
395 switch (state) { | |
396 case 'c': | |
397 PORTC = settings.coolbits; | |
398 break; | |
399 | |
400 case 'h': | |
401 PORTC = settings.heatbits; | |
402 break; | |
403 | |
404 default: | |
405 printf_P(PSTR("Unknown state %c, setting idle\r\n"), state); | |
406 /* fallthrough */ | |
407 | |
408 case 'i': | |
409 PORTC = settings.idlebits; | |
410 break; | |
411 } | |
412 } | |
413 | |
414 /* Handle user command | |
415 * | |
416 */ | |
417 void | |
418 tempctrl_cmd(char *buf) { | |
419 char cmd[6]; | |
420 int16_t data; | |
421 int i; | |
422 | |
423 i = sscanf_P(buf, PSTR("tc %5s %d"), cmd, &data); | |
424 | |
425 if (i == 1) { | |
426 if (!strcasecmp_P(cmd, PSTR("help"))) { | |
427 printf_P(PSTR( | |
428 "tc help This help\r\n" | |
429 "tc save Save settings to EEPROM\r\n" | |
430 "tc load Load or default settings from EEPROM\r\n" | |
431 "tc dflt Load defaults from flash\r\n" | |
432 "tc list List current settings\r\n" | |
433 "tc mode [achin] Change control mode, must be one of\r\n" | |
434 " a Auto\r\n" | |
435 " c Always cool\r\n" | |
436 " h Always heat\r\n" | |
437 " i Always idle\r\n" | |
438 " n Like idle but don't log anything\r\n" | |
439 "\r\n" | |
440 "tc X Y Set X to Y where X is one of\r\n" | |
441 " targ Target temperature\r\n" | |
442 " hys Hysteresis range\r\n" | |
443 " mhov Minimum heat overshoot\r\n" | |
444 " mcov Minimum cool overshoot\r\n" | |
445 " mcon Minimum cool on time\r\n" | |
446 " mcoff Minimum cool off time\r\n" | |
447 " mhin Minimum heat on time\r\n" | |
448 " mhoff Minimum heat off time\r\n" | |
449 " Times are in seconds\r\n" | |
450 " Temperatures are in hundredths of degrees Celcius\r\n" | |
451 )); | |
452 return; | |
453 } | |
454 | |
455 if (!strcasecmp_P(cmd, PSTR("save"))) { | |
456 tempctrl_write_settings(); | |
457 return; | |
458 } | |
459 if (!strcasecmp_P(cmd, PSTR("load"))) { | |
460 tempctrl_load_or_init_settings(); | |
461 return; | |
462 } | |
463 if (!strcasecmp_P(cmd, PSTR("dflt"))) { | |
464 tempctrl_default_settings(); | |
465 return; | |
466 } | |
467 if (!strcasecmp_P(cmd, PSTR("list"))) { | |
468 printf_P(PSTR("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
469 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
470 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | |
46 | 471 "Mode - %c, Target - %d, Hystersis - %d\r\n" |
41 | 472 "Min heat overshoot - %d, Min cool overshoot - %d\r\n" |
473 "Min cool on time - %d, Min cool off time - %d\r\n" | |
44 | 474 "Min heat on time - %d, Min heat off time - %d\r\n"), |
41 | 475 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3], |
476 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], | |
477 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3], | |
478 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], | |
479 settings.ambient_ROM[0], settings.ambient_ROM[1], settings.ambient_ROM[2], settings.ambient_ROM[3], | |
480 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7], | |
46 | 481 settings.mode, settings.target_temp, settings.hysteresis, |
41 | 482 settings.minheatovershoot, settings.mincoolovershoot, |
483 settings.mincoolontime, settings.minheatontime, | |
484 settings.minheatontime, settings.minheatofftime); | |
485 return; | |
486 } | |
487 if (!strcasecmp_P(cmd, PSTR("mode"))) { | |
488 switch (buf[8]) { | |
489 case TC_MODE_AUTO: | |
490 case TC_MODE_HEAT: | |
491 case TC_MODE_COOL: | |
492 case TC_MODE_IDLE: | |
493 case TC_MODE_NOTHING: | |
494 settings.mode = buf[8]; | |
495 break; | |
496 | |
497 default: | |
498 printf_P(PSTR("Unknown mode character '%c'\r\n"), buf[8]); | |
499 break; | |
500 } | |
501 return; | |
502 } | |
503 | |
504 } | |
505 | |
506 if (i != 2) { | |
507 printf_P(PSTR("Unable to parse command\r\n")); | |
508 return; | |
509 } | |
510 | |
511 if (!strcasecmp_P(cmd, PSTR("targ"))) { | |
512 settings.target_temp = data; | |
513 } else if (!strcasecmp_P(cmd, PSTR("hys"))) { | |
514 settings.hysteresis = data; | |
515 } else if (!strcasecmp_P(cmd, PSTR("mhov"))) { | |
516 settings.minheatovershoot = data; | |
517 } else if (!strcasecmp_P(cmd, PSTR("mcov"))) { | |
518 settings.mincoolovershoot = data; | |
519 } else if (!strcasecmp_P(cmd, PSTR("mcon"))) { | |
520 settings.mincoolontime = data; | |
521 } else if (!strcasecmp_P(cmd, PSTR("mcoff"))) { | |
522 settings.mincoolofftime = data; | |
523 } else if (!strcasecmp_P(cmd, PSTR("mhon"))) { | |
524 settings.minheatontime = data; | |
525 } else if (!strcasecmp_P(cmd, PSTR("mhoff"))) { | |
526 settings.minheatofftime = data; | |
527 } else { | |
528 printf_P(PSTR("Unknown setting\r\n")); | |
529 return; | |
530 } | |
531 } | |
532 | |
533 static const PROGMEM char* | |
534 state2long(char s) { | |
535 switch (s) { | |
536 case 'i': | |
537 return PSTR("idle"); | |
538 break; | |
539 | |
540 case 'c': | |
541 return PSTR("cool"); | |
542 break; | |
543 | |
544 case 'h': | |
545 return PSTR("heat"); | |
546 break; | |
547 | |
548 case '-': | |
549 return PSTR("-"); | |
550 break; | |
551 | |
552 default: | |
553 return PSTR("unknown"); | |
554 break; | |
555 } | |
556 } | |
557 |