comparison water.c @ 5:951277329ee6

Use splitargv instead of rolling our own. Fix WDT tripping continuously on self reset (disable WDT on startup). Pretty up startup message.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 15 Feb 2015 16:16:54 +1030
parents e75ecd162da3
children c32b5792683a
comparison
equal deleted inserted replaced
4:1188042ddc2f 5:951277329ee6
34 #include <avr/pgmspace.h> 34 #include <avr/pgmspace.h>
35 #include <avr/eeprom.h> 35 #include <avr/eeprom.h>
36 #include <util/crc16.h> 36 #include <util/crc16.h>
37 37
38 #include "ds1307.h" 38 #include "ds1307.h"
39 #include "splitargv.h"
39 #include "water.h" 40 #include "water.h"
40 41
41 struct tm { 42 struct tm {
42 int32_t sec; 43 int32_t sec;
43 int32_t usec; 44 int32_t usec;
121 nowtm.usec -= 1000000; 122 nowtm.usec -= 1000000;
122 nowtm.sec++; 123 nowtm.sec++;
123 } 124 }
124 } 125 }
125 126
126 #define MAXARGS 10
127
128 /* Parse water related command */ 127 /* Parse water related command */
129 void 128 void
130 water_cmd(char *buf) { 129 water_cmd(int argc, char **argv) {
131 char *e, **btmp; 130 char *e;
132 uint16_t delay; 131 uint16_t delay;
133 uint16_t time; 132 uint16_t time;
134 long tmp; 133 long tmp;
135 int i, argc, skip; 134 int i;
136 char *argv[MAXARGS]; 135
137 136 if (!strcmp_P(argv[0], PSTR("all"))) {
138 /* Split command string on space/tab boundaries into argv/argc */
139 argc = 0;
140 btmp = &buf;
141 skip = 1;
142 while (1) {
143 argv[argc] = strsep(btmp, " \t");
144 if (argv[argc] == '\0')
145 break;
146 /* Skip first arg (ie 'wa') */
147 if (skip) {
148 skip = 0;
149 continue;
150 }
151 argc++;
152 if (argc == MAXARGS)
153 break;
154 }
155
156 if (!strcmp(argv[0], "all")) {
157 if (argc != 3) { 137 if (argc != 3) {
158 puts_P(PSTR("Wrong number of arguments, usage: wa all delay time\r\n")); 138 puts_P(PSTR("Wrong number of arguments, usage: wa all delay time\r\n"));
159 return; 139 return;
160 } 140 }
161 141