comparison tempctrl.c @ 73:56165caf744b

Missed some USB related crud + copyright updates.
author darius@Inchoate
date Wed, 21 Jan 2009 18:01:17 +1030
parents 553c061fda7c
children ca5fc59ec4f0
comparison
equal deleted inserted replaced
72:13f8e6eb5c01 73:56165caf744b
1 /* 1 /*
2 * Temperature control logic 2 * Temperature control logic
3 * 3 *
4 * Copyright (c) 2008 4 * Copyright (c) 2009
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. 5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
79 79
80 /* Check/stale times */ 80 /* Check/stale times */
81 int16_t check_interval; 81 int16_t check_interval;
82 int16_t stale_factor; 82 int16_t stale_factor;
83 83
84 #ifndef WITHUSB
85 /* Beep if stale */ 84 /* Beep if stale */
86 int8_t dobeep; 85 int8_t dobeep;
87 #endif
88 } __attribute__((packed)) settings_t; 86 } __attribute__((packed)) settings_t;
89 87
90 /* Current settings in RAM */ 88 /* Current settings in RAM */
91 static settings_t settings; 89 static settings_t settings;
92 90
113 .coolbits = _BV(6), 111 .coolbits = _BV(6),
114 .heatbits = _BV(7), 112 .heatbits = _BV(7),
115 .idlebits = 0x00, 113 .idlebits = 0x00,
116 .check_interval = 10, 114 .check_interval = 10,
117 .stale_factor = 3, 115 .stale_factor = 3,
118 #ifndef WITHUSB
119 .dobeep = 0 116 .dobeep = 0
120 #endif
121 }; 117 };
122 118
123 /* Local variable declarations */ 119 /* Local variable declarations */
124 volatile static time_t now; 120 volatile static time_t now;
125 #ifndef WITHUSB
126 volatile static uint8_t beeping = 0; 121 volatile static uint8_t beeping = 0;
127 volatile static uint8_t lasttoggle = 0; 122 volatile static uint8_t lasttoggle = 0;
128 #endif
129 123
130 /* Local function prototypes */ 124 /* Local function prototypes */
131 static void tempctrl_load_or_init_settings(void); 125 static void tempctrl_load_or_init_settings(void);
132 static void tempctrl_default_settings(void); 126 static void tempctrl_default_settings(void);
133 static void tempctrl_write_settings(void); 127 static void tempctrl_write_settings(void);
174 while (now.usec > 1000000) { 168 while (now.usec > 1000000) {
175 now.usec -= 1000000; 169 now.usec -= 1000000;
176 now.sec++; 170 now.sec++;
177 } 171 }
178 172
179 #ifndef WITHUSB
180 if (beeping) { 173 if (beeping) {
181 lasttoggle++; 174 lasttoggle++;
182 // 63 * 8ms = ~0.5s 175 // 63 * 8ms = ~0.5s
183 if (lasttoggle > 63) { 176 if (lasttoggle > 63) {
184 DDRB ^= _BV(PB3); 177 DDRB ^= _BV(PB3);
186 } 179 }
187 } else { 180 } else {
188 DDRB &= ~_BV(PB3); 181 DDRB &= ~_BV(PB3);
189 lasttoggle = 0; 182 lasttoggle = 0;
190 } 183 }
191 #endif
192 } 184 }
193 185
194 /* 186 /*
195 * tempctrl_update 187 * tempctrl_update
196 * 188 *
294 286
295 /* Override if we have stale data */ 287 /* Override if we have stale data */
296 if (stale) 288 if (stale)
297 nextstate = 'i'; 289 nextstate = 'i';
298 290
299 #ifndef WITHUSB
300 /* Handle beeping */ 291 /* Handle beeping */
301 if (settings.dobeep && stale) 292 if (settings.dobeep && stale)
302 beeping = 1; 293 beeping = 1;
303 else 294 else
304 beeping = 0; 295 beeping = 0;
305 #endif
306 296
307 /* Handle state forcing */ 297 /* Handle state forcing */
308 if (settings.mode != TC_MODE_AUTO) 298 if (settings.mode != TC_MODE_AUTO)
309 forced = 1; 299 forced = 1;
310 else 300 else
480 " a Auto\r\n" 470 " a Auto\r\n"
481 " c Always cool\r\n" 471 " c Always cool\r\n"
482 " h Always heat\r\n" 472 " h Always heat\r\n"
483 " i Always idle\r\n" 473 " i Always idle\r\n"
484 " n Like idle but don't log anything\r\n" 474 " n Like idle but don't log anything\r\n"
485 #ifndef WITHUSB
486 "tc beep [01] Enable/disable beeping when data is stale\r\n" 475 "tc beep [01] Enable/disable beeping when data is stale\r\n"
487 #endif
488 "tc X Y Set X to Y where X is one of\r\n" 476 "tc X Y Set X to Y where X is one of\r\n"
489 " targ Target temperature\r\n" 477 " targ Target temperature\r\n"
490 " hys Hysteresis range\r\n" 478 " hys Hysteresis range\r\n"
491 " mhov Minimum heat overshoot\r\n" 479 " mhov Minimum heat overshoot\r\n"
492 " mcov Minimum cool overshoot\r\n" 480 " mcov Minimum cool overshoot\r\n"
522 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" 510 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n"
523 "Mode - %c, Target - %d, Hystersis - %d\r\n" 511 "Mode - %c, Target - %d, Hystersis - %d\r\n"
524 "Min heat overshoot - %d, Min cool overshoot - %d\r\n" 512 "Min heat overshoot - %d, Min cool overshoot - %d\r\n"
525 "Min cool on time - %d, Min cool off time - %d\r\n" 513 "Min cool on time - %d, Min cool off time - %d\r\n"
526 "Min heat on time - %d, Min heat off time - %d\r\n" 514 "Min heat on time - %d, Min heat off time - %d\r\n"
527 #ifndef WITHUSB
528 "Beep on stale - %S\r\n" 515 "Beep on stale - %S\r\n"
529 #endif
530 ), 516 ),
531 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3], 517 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3],
532 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], 518 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7],
533 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3], 519 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3],
534 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], 520 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7],
536 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7], 522 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7],
537 settings.mode, settings.target_temp, settings.hysteresis, 523 settings.mode, settings.target_temp, settings.hysteresis,
538 settings.minheatovershoot, settings.mincoolovershoot, 524 settings.minheatovershoot, settings.mincoolovershoot,
539 settings.mincoolontime, settings.minheatontime, 525 settings.mincoolontime, settings.minheatontime,
540 settings.minheatontime, settings.minheatofftime, 526 settings.minheatontime, settings.minheatofftime,
541 #ifndef WITHUSB
542 settings.dobeep ? PSTR("yes") : PSTR("no") 527 settings.dobeep ? PSTR("yes") : PSTR("no")
543 #endif
544 ); 528 );
545 return; 529 return;
546 } 530 }
547 if (!strcasecmp_P(cmd, PSTR("mode"))) { 531 if (!strcasecmp_P(cmd, PSTR("mode"))) {
548 switch (buf[8]) { 532 switch (buf[8]) {
558 printf_P(PSTR("Unknown mode character '%c'\r\n"), buf[8]); 542 printf_P(PSTR("Unknown mode character '%c'\r\n"), buf[8]);
559 break; 543 break;
560 } 544 }
561 return; 545 return;
562 } 546 }
563 #ifndef WITHUSB
564 if (!strcasecmp_P(cmd, PSTR("beep"))) { 547 if (!strcasecmp_P(cmd, PSTR("beep"))) {
565 if (buf[8] == '1' || buf[8] == 'y') 548 if (buf[8] == '1' || buf[8] == 'y')
566 settings.dobeep = 1; 549 settings.dobeep = 1;
567 else if (buf[8] == '0' || buf[8] == 'n') 550 else if (buf[8] == '0' || buf[8] == 'n')
568 settings.dobeep = 0; 551 settings.dobeep = 0;
569 else 552 else
570 printf_P(PSTR("Expected a y/1 or n/0\r\n")); 553 printf_P(PSTR("Expected a y/1 or n/0\r\n"));
571 return; 554 return;
572 } 555 }
573 #endif
574 if (!strcasecmp_P(cmd, PSTR("ferm")) || 556 if (!strcasecmp_P(cmd, PSTR("ferm")) ||
575 !strcasecmp_P(cmd, PSTR("frg")) || 557 !strcasecmp_P(cmd, PSTR("frg")) ||
576 !strcasecmp_P(cmd, PSTR("amb"))) { 558 !strcasecmp_P(cmd, PSTR("amb"))) {
577 559
578 if (sscanf_P(buf, PSTR("tc %5s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), cmd, 560 if (sscanf_P(buf, PSTR("tc %5s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx"), cmd,