# HG changeset patch # User darius@inchoate.localdomain # Date 1215349101 -34200 # Node ID 97ae82023d5badd1e116846d0bb62d1ec6dc83fc # Parent 5898fba6593c918bb7d7b7650cbae97bd471ef77 Actually keep track of when the heater & cooler go on/off.. diff -r 5898fba6593c -r 97ae82023d5b tempctrl.c --- a/tempctrl.c Sun Jul 06 22:19:53 2008 +0930 +++ b/tempctrl.c Sun Jul 06 22:28:21 2008 +0930 @@ -38,10 +38,6 @@ #include "1wire.h" #include "tempctrl.h" -/* Helpers for our number system */ -#define GETWHOLE(x) ((x) / 100) -#define GETFRAC(x) ((x) - (GETWHOLE(x) * 100)) - typedef struct { int32_t sec; int32_t usec; @@ -280,6 +276,27 @@ else if (settings.mode == TC_MODE_COOL) nextstate = 'c'; + // Keep track of when we last turned things on or off + switch (nextstate) { + case 'c': + if (currstate == 'h') + lastheatoff = t; + lastcoolon = t; + break; + + case 'h': + if (currstate == 'c') + lastcooloff = t; + lastheaton = t; + break; + + default: + if (currstate == 'c') + lastcooloff = t; + if (currstate == 'h') + lastheatoff = t; + } + if (nextstate != '-') currstate = nextstate;