comparison tempctrl.c @ 42:97ae82023d5b

Actually keep track of when the heater & cooler go on/off..
author darius@inchoate.localdomain
date Sun, 06 Jul 2008 22:28:21 +0930
parents 5898fba6593c
children 51e7458d2e76
comparison
equal deleted inserted replaced
41:5898fba6593c 42:97ae82023d5b
35 #include <util/crc16.h> 35 #include <util/crc16.h>
36 36
37 #include "cons.h" 37 #include "cons.h"
38 #include "1wire.h" 38 #include "1wire.h"
39 #include "tempctrl.h" 39 #include "tempctrl.h"
40
41 /* Helpers for our number system */
42 #define GETWHOLE(x) ((x) / 100)
43 #define GETFRAC(x) ((x) - (GETWHOLE(x) * 100))
44 40
45 typedef struct { 41 typedef struct {
46 int32_t sec; 42 int32_t sec;
47 int32_t usec; 43 int32_t usec;
48 } time_t; 44 } time_t;
278 else if (settings.mode == TC_MODE_HEAT) 274 else if (settings.mode == TC_MODE_HEAT)
279 nextstate = 'h'; 275 nextstate = 'h';
280 else if (settings.mode == TC_MODE_COOL) 276 else if (settings.mode == TC_MODE_COOL)
281 nextstate = 'c'; 277 nextstate = 'c';
282 278
279 // Keep track of when we last turned things on or off
280 switch (nextstate) {
281 case 'c':
282 if (currstate == 'h')
283 lastheatoff = t;
284 lastcoolon = t;
285 break;
286
287 case 'h':
288 if (currstate == 'c')
289 lastcooloff = t;
290 lastheaton = t;
291 break;
292
293 default:
294 if (currstate == 'c')
295 lastcooloff = t;
296 if (currstate == 'h')
297 lastheatoff = t;
298 }
299
283 if (nextstate != '-') 300 if (nextstate != '-')
284 currstate = nextstate; 301 currstate = nextstate;
285 302
286 printf_P(PSTR(", State: %S, Flags: %S%S\r\n"), state2long(currstate), 303 printf_P(PSTR(", State: %S, Flags: %S%S\r\n"), state2long(currstate),
287 forced ? PSTR("F") : PSTR(""), 304 forced ? PSTR("F") : PSTR(""),