Mercurial > ~darius > hgwebdir.cgi > sprink
diff sprink.c @ 1:be930b34fcd3
Make it compile, no testing yet.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 26 Jan 2015 23:04:09 +1030 |
parents | 93d4ddff7dd0 |
children | 1188042ddc2f |
line wrap: on
line diff
--- a/sprink.c Wed Jan 04 23:19:12 2012 +1030 +++ b/sprink.c Mon Jan 26 23:04:09 2015 +1030 @@ -40,6 +40,7 @@ #include "cons.h" #include "ds1307.h" #include "1wire.h" +#include "water.h" /* ** Fuse bits should be set as follows @@ -58,40 +59,6 @@ ** LFUSE - 0x62 - 01100010 - CLKDIV8, no CKOUT, long SUT, CKSEL3/2/0 (internal 8Mhz) */ -#define NUMSPRINKS 6 - -/* Holds all the settings needed */ -typedef struct { - bitstr_t bit_decl(mon[NUMSPRINKS], 24); - bitstr_t bit_decl(tue[NUMSPRINKS], 24); - bitstr_t bit_decl(wed[NUMSPRINKS], 24); - bitstr_t bit_decl(thu[NUMSPRINKS], 24); - bitstr_t bit_decl(fri[NUMSPRINKS], 24); - bitstr_t bit_decl(sat[NUMSPRINKS], 24); - bitstr_t bit_decl(sun[NUMSPRINKS], 24); - -} __attribute__((packed)) settings_t; - -/* Current settings in RAM */ -static settings_t settings; - -/* Our map of EEPROM */ -struct { - settings_t settings; - uint16_t crc; -} ee_area __attribute__((section(".eeprom"))); - -/* Defaults that are shoved into EEPROM if it fails checksum */ -const PROGMEM settings_t default_settings = { - /* XXX: no handy macro for this */ - .mon[0] = {0, 0, 0}, - .mon[1] = {0, 0, 0}, - .mon[2] = {0, 0, 0}, - .mon[3] = {0, 0, 0}, - .mon[4] = {0, 0, 0}, - .mon[5] = {0, 0, 0} -}; - /* * Mirror of the MCUCSR register, taken early during startup. */ @@ -132,12 +99,15 @@ /* Set up the one wire stuff */ OWInit(); + /* Init water control state machine */ + water_init(); + /* Analogue input is PA0:7 */ DDRA = 0x00; PORTA = 0x00; DIDR0 = 0xff; /* Disable digital input buffers */ #ifdef PRR - PRR &= ~_BV(PRADC); /* Power ADV on - note that the + PRR &= ~_BV(PRADC); /* Power ADC on - note that the * datasheet says this is already 0 at * power on.. */ #endif @@ -193,6 +163,8 @@ while (1) { wdt_reset(); + water_update(); + if (cmd.state == 255) { process_cmd(); printf_P(PSTR("> ")); @@ -210,24 +182,27 @@ if (!strcasecmp_P((char *)cmd.buf, PSTR("?")) || !strcasecmp_P((char *)cmd.buf, PSTR("help"))) { - printf_P(PSTR("help This help\r\n" - "gc Get time of day\r\n" - "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" - "in port Read from a port\r\n" - "ou port val Write to a port (val in hex)\r\n" - "dd port val Set DDR on port\r\n" - "an pin Sample from pin\r\n" - "sr Search for 1-wire devices\r\n" - "te ID Sample temperature from ID\r\n" - "re Reset 1-wire bus\r\n" - "rb Read bit from 1-wire bus\r\n" - "rc Read byte from 1-wire bus\r\n" - "wb bit Write bit to 1-wire bus\r\n" - "wc byte Write byte to 1-wire bus\r\n" - "zz Reset micro\r\n")); + puts_P(PSTR("help This help\r\n" + "wa dly time Water for time minutes after dly minutes\r\n" + "gc Get time of day\r\n" + "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" + "in port Read from a port\r\n" + "ou port val Write to a port (val in hex)\r\n" + "dd port val Set DDR on port\r\n" + "an pin Sample from pin\r\n" + "sr Search for 1-wire devices\r\n" + "te ID Sample temperature from ID\r\n" + "re Reset 1-wire bus\r\n" + "rb Read bit from 1-wire bus\r\n" + "rc Read byte from 1-wire bus\r\n" + "wb bit Write bit to 1-wire bus\r\n" + "wc byte Write byte to 1-wire bus\r\n" + "zz Reset micro\r\n")); return; + } else if (!strncasecmp_P((char *)cmd.buf, PSTR("wa"), 2)) { + water_cmd((char *)cmd.buf); } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) { - ds1307_printtime(PSTR(""), PSTR("\r\n")); + ds1307_printnow(PSTR(""), PSTR("\r\n")); } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) { if (cmd.len < 17) { printf_P(PSTR("Invalid TOD\r\n")); @@ -273,9 +248,9 @@ return; } - /* Select desired pin, use VCC reference */ - ADMUX = _BV(REFS0) | pin; - + /* Select desired pin, use AVREF */ + ADMUX = _BV(pin); + /* Enable ADC, start conversion, set divisor to 64 * (8e6 / 64 => 125kHz (max is 200kHz) */