Mercurial > ~darius > hgwebdir.cgi > tempctrl
changeset 50:a13e0ccc1d2d
Rejig how temperatures are logged. Print out the final line at the end so it
is printed in one hit.
author | darius@Inchoate |
---|---|
date | Wed, 29 Oct 2008 16:06:42 +1030 |
parents | 91e06007fe23 |
children | cb184206344d |
files | tempctrl.c |
diffstat | 1 files changed, 23 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- 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 */