diff 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
line wrap: on
line diff
--- a/water.c	Tue Jan 27 23:40:50 2015 +1030
+++ b/water.c	Sun Feb 15 16:16:54 2015 +1030
@@ -36,6 +36,7 @@
 #include <util/crc16.h>
 
 #include "ds1307.h"
+#include "splitargv.h"
 #include "water.h"
 
 struct tm {
@@ -123,37 +124,16 @@
     }
 }
 
-#define MAXARGS 10
-
 /* Parse water related command */
 void
-water_cmd(char *buf) {
-    char	*e, **btmp;
+water_cmd(int argc, char **argv) {
+    char	*e;
     uint16_t	delay;
     uint16_t	time;
     long	tmp;
-    int		i, argc, skip;
-    char	*argv[MAXARGS];
+    int		i;
 
-    /* Split command string on space/tab boundaries into argv/argc */
-    argc = 0;
-    btmp = &buf;
-    skip = 1;
-    while (1) {
-	    argv[argc] = strsep(btmp, " \t");
-	    if (argv[argc] == '\0')
-		    break;
-	    /* Skip first arg (ie 'wa') */
-	    if (skip) {
-		    skip = 0;
-		    continue;
-	    }
-	    argc++;
-	    if (argc == MAXARGS)
-		    break;
-    }
-
-    if (!strcmp(argv[0], "all")) {
+    if (!strcmp_P(argv[0], PSTR("all"))) {
 	    if (argc != 3) {
 		    puts_P(PSTR("Wrong number of arguments, usage: wa all delay time\r\n"));
 		    return;