# HG changeset patch # User darius@Inchoate # Date 1224503481 -37800 # Node ID fb272cb82bcbacdde948ded919272ebeae19777f # Parent efd44dc4093481d63d15f302fcc535a11504785a Add watchdog reset to timer IRQ. Swap heat and cool bits by default. Init to INT32_MIN so we don't get odd behaviour at startup. Print out mode in tc list. Silence compiler warning regarding PROGMEM pointers. diff -r efd44dc40934 -r fb272cb82bcb tempctrl.c --- a/tempctrl.c Mon Oct 20 22:11:18 2008 +1030 +++ b/tempctrl.c Mon Oct 20 22:21:21 2008 +1030 @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "cons.h" @@ -103,8 +104,8 @@ .minheatontime = 60, .minheatofftime = 60, .mode = TC_MODE_AUTO, - .coolbits = _BV(7), - .heatbits = _BV(6), + .coolbits = _BV(6), + .heatbits = _BV(7), .idlebits = 0x00, .check_interval = 10, .stale_factor = 3 @@ -114,7 +115,7 @@ volatile static time_t now; /* Local function prototypes */ -static int gettemp(const PROGMEM char *name, uint8_t *ROM, int16_t *temp, uint8_t last); +static int gettemp(const char *name, uint8_t *ROM, int16_t *temp, uint8_t last); static void tempctrl_load_or_init_settings(void); static void tempctrl_default_settings(void); static void tempctrl_write_settings(void); @@ -154,6 +155,8 @@ */ ISR(TIMER0_COMP_vect) { + wdt_reset(); + now.usec += 8000; /* 1000000 * 1 / F_CPU / 1024 / 125 */ while (now.usec > 1000000) { now.usec -= 1000000; @@ -172,18 +175,18 @@ tempctrl_update(void) { /* State variables */ static int32_t checktime = 0; // Time of next check - static int32_t lastdata = -100000; // Last time we got data + static int32_t lastdata = INT32_MIN; // Last time we got data static int16_t fermenter_temp = 0; // Fermenter temperature static int16_t fridge_temp = 0; // Fridge temperature static int16_t ambient_temp = 0; // Ambient temperature - // These are inited like this so we will still heat/cool when - // now < settings.minheatofftime - static int32_t lastheaton = -100000; // Last time the heater was on - static int32_t lastheatoff = -100000; // Last time the heater was off - static int32_t lastcoolon = -100000; // Last time the cooler was on - static int32_t lastcooloff = -100000; // Last time the cooler was off + static int32_t lastheaton = INT32_MIN; // Last time the heater was on + static int32_t lastheatoff = INT32_MIN;// Last time the heater was off + static int32_t lastcoolon = INT32_MIN; // Last time the cooler was on + static int32_t lastcooloff = INT32_MIN;// Last time the cooler was off static char currstate = 'i'; // Current state + /* We init to times to INT32_MIN so that things function properly when + * now < settings.minheat/cool/on/offtime */ /* Temporary variables */ int32_t t; @@ -314,7 +317,7 @@ * Returns 1 if it was valid, 0 otherwise */ static int -gettemp(const PROGMEM char *name, uint8_t *ROM, int16_t *temp, uint8_t last) { +gettemp(const char *name, uint8_t *ROM, int16_t *temp, uint8_t last) { int16_t tmp; tmp = OWGetTemp(ROM); @@ -472,7 +475,7 @@ printf_P(PSTR("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" - "Target - %d, Hystersis - %d\r\n" + "Mode - %c, Target - %d, Hystersis - %d\r\n" "Min heat overshoot - %d, Min cool overshoot - %d\r\n" "Min cool on time - %d, Min cool off time - %d\r\n" "Min heat on time - %d, Min heat off time - %d\r\n"), @@ -482,7 +485,7 @@ settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], settings.ambient_ROM[0], settings.ambient_ROM[1], settings.ambient_ROM[2], settings.ambient_ROM[3], settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7], - settings.target_temp, settings.hysteresis, + settings.mode, settings.target_temp, settings.hysteresis, settings.minheatovershoot, settings.mincoolovershoot, settings.mincoolontime, settings.minheatontime, settings.minheatontime, settings.minheatofftime);