# HG changeset patch # User darius@Inchoate # Date 1225258602 -37800 # Node ID a13e0ccc1d2da6a05320f2cfcf6510d08f61bad2 # Parent 91e06007fe234130f90840ce4f9cf0df3e224128 Rejig how temperatures are logged. Print out the final line at the end so it is printed in one hit. diff -r 91e06007fe23 -r a13e0ccc1d2d tempctrl.c --- a/tempctrl.c Wed Oct 29 16:04:20 2008 +1030 +++ b/tempctrl.c Wed Oct 29 16:06:42 2008 +1030 @@ -115,12 +115,12 @@ volatile static time_t now; /* Local function prototypes */ -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); static void setstate(char state); static const PROGMEM char*state2long(char s); +static void printtemp(char *name, int tmp, char *trailer); /* * tempctrl_init @@ -209,21 +209,19 @@ } /* Update our temperatures */ - printf_P(PSTR("Time: %ld, Target: %d.%02d, "), now.sec, GETWHOLE(settings.target_temp), - GETFRAC(settings.target_temp)); + fermenter_temp = OWGetTemp(settings.fermenter_ROM); + fridge_temp = OWGetTemp(settings.fridge_ROM); + ambient_temp = OWGetTemp(settings.ambient_ROM); - if (gettemp(PSTR("Fermenter"), settings.fermenter_ROM, &fermenter_temp, 0)) + if (fermenter_temp > OW_TEMP_BADVAL) lastdata = t; - + /* Check for stale data */ if (lastdata + (settings.check_interval * settings.stale_factor) < t) stale = 1; else stale = 0; - gettemp(PSTR("Fridge"), settings.fridge_ROM, &fridge_temp, 0); - gettemp(PSTR("Ambient"), settings.ambient_ROM, &ambient_temp, 1); - /* Default to remaining as we are */ nextstate = '-'; @@ -303,7 +301,12 @@ if (nextstate != '-') currstate = nextstate; - printf_P(PSTR(", State: %S, Flags: %S%S\r\n"), state2long(currstate), + printf_P(PSTR("Time: %10ld, "), t); + printtemp(PSTR("Target"), settings.target_temp, PSTR(", ")); + printtemp(PSTR("Fermenter"), fermenter_temp, PSTR(", ")); + printtemp(PSTR("Fridge"), fridge_temp, PSTR(", ")); + printtemp(PSTR("Ambient"), ambient_temp, PSTR(", ")); + printf_P(PSTR("State: %S, Flags: %S%S\r\n"), state2long(currstate), forced ? PSTR("F") : PSTR(""), stale ? PSTR("S") : PSTR("")); @@ -311,27 +314,6 @@ setstate(currstate); } -/* - * Log a temperature & store it if valid - * - * Returns 1 if it was valid, 0 otherwise - */ -static int -gettemp(const char *name, uint8_t *ROM, int16_t *temp, uint8_t last) { - int16_t tmp; - - tmp = OWGetTemp(ROM); - printf_P(PSTR("%S: "), name); - if (tmp > OW_TEMP_BADVAL) { - printf_P(PSTR("%d.%02d%S"), GETWHOLE(tmp), GETFRAC(tmp), last ? PSTR("") : PSTR(", ")); - *temp = tmp; - return(1); - } else { - printf_P(PSTR("NA (%d)%S"), tmp, last ? PSTR("") : PSTR(", ")); - return(0); - } -} - /* Return 'time of day' (really uptime) */ int32_t gettod(void) { @@ -344,6 +326,17 @@ return(t); } +/* + * Print out temperature (or NA + error code) with specified trailer + */ +static void +printtemp(char *name, int tmp, char *trailer) { + if (tmp > OW_TEMP_BADVAL) + printf_P(PSTR("%S: %d.%02d%S"), name, GETWHOLE(tmp), GETFRAC(tmp), trailer); + else + printf_P(PSTR("%S: NA (%d)%S"), name, tmp, trailer); +} + /* Read the settings from EEPROM * If the CRC fails then reload from flash */