# HG changeset patch # User Matt Johnston # Date 1349265876 0 # Node ID cfd32449b48586d8d7299d17fac6d68d328a3c45 # Parent a4d6030db09ecc59279e11389b71f01fbd312335 start of fridge bits diff -r a4d6030db09e -r cfd32449b485 main.c --- a/main.c Fri Sep 07 22:59:26 2012 +0800 +++ b/main.c Wed Oct 03 12:04:36 2012 +0000 @@ -68,10 +68,13 @@ static uint16_t comms_wake = 3600; static uint8_t wake_secs = 30; + // ---- Atomic guards required accessing these variables static uint32_t clock_epoch; static uint16_t comms_count; static uint16_t measure_count; +// decidegrees +static uint16_t fridge_temp = 175; // ---- End atomic guards required static uint16_t n_measurements; @@ -129,11 +132,14 @@ #define EXPECT_MAGIC 0x67c9 struct __attribute__ ((__packed__)) __eeprom_data { - // XXX eeprom unused at present uint16_t magic; uint16_t measure_wake; uint16_t comms_wake; uint8_t wake_secs; + + uint16_t fridge_temp; + + }; static void deep_sleep(); @@ -481,6 +487,32 @@ printf_P(PSTR("measure %hu comms %hu wake %hhu\n"), new_measure_wake, new_comms_wake, new_wake_secs); } +}static void +cmd_set_fridge(const char *params) +{ + uint16_t new_measure_wake; + uint16_t new_comms_wake; + uint8_t new_wake_secs; + int ret = sscanf_P(params, PSTR("%hu %hu %hhu"), + &new_measure_wake, &new_comms_wake, &new_wake_secs); + + if (ret != 3) + { + printf_P(PSTR("Bad values\n")); + } + else + { + cli(); + eeprom_write(new_measure_wake, measure_wake); + eeprom_write(new_comms_wake, comms_wake); + eeprom_write(new_wake_secs, wake_secs); + uint16_t magic = EXPECT_MAGIC; + eeprom_write(magic, magic); + sei(); + printf_P(PSTR("set_params for next boot\n")); + printf_P(PSTR("measure %hu comms %hu wake %hhu\n"), + new_measure_wake, new_comms_wake, new_wake_secs); + } } static void @@ -521,6 +553,10 @@ { cmd_set_params(&readbuf[11]); } + else if (strncmp_P(readbuf, PSTR("set_fridge "), 11) == 0) + { + cmd_set_fridge(&readbuf[11]); + } else if (strcmp_P(readbuf, PSTR("awake")) == 0) { cmd_awake();