this appears to work well enough for now.
authorDarron Broad <darron@kewl.org>
Tue, 03 Feb 2015 06:35:18 +0000
changeset 6 a59fcc1a55a5
parent 5 3798eabee36b
child 7 4eb51cb4c176
this appears to work well enough for now.

can be made more robust later perhaps but good enough for web demo?

eg.

> ./helloworld.esp
for variable = 0, 10, 2 do
>> print ( "hello world" )
>> print ( variable )
>> end
hello world
0
hello world
2
hello world
4
hello world
6
hello world
8
hello world
10
>
espy.c
helloworld.esp
--- a/espy.c	Tue Feb 03 06:28:33 2015 +0000
+++ b/espy.c	Tue Feb 03 06:35:18 2015 +0000
@@ -424,11 +424,11 @@
 
 /*******************************************************************************
  *
- * Send a string for LUA processing
+ * Send a line for LUA processing
  *
  ******************************************************************************/
 int
-LuaSend(int fd, char *line)
+LuaLine(int fd, char *line)
 {
 	uint8_t buffer[BUFLEN];
 	int len;
@@ -449,29 +449,26 @@
 
 	printf("%s", buffer);
 
-	/* LUA DELAY */
+	/* INITIAL LUA LINE DELAY */
 	if (strstr(line, "node.restart") == line) {
 		usleep(LONGDELAY * 1000);
 	} else {
 		usleep(SHORTDELAY * 1000);
 	}
 
-	return 0;
-}
-
-void
-LuaRecv(int fd)
-{
-	uint8_t buffer[BUFLEN];
-	int len;
-
 	ioctl(fd, FIONREAD, &len);
 	while (len) {
 		len = fdio(fd, buffer, len, TIMEOUT, IN);
 		buffer[len] = '\0';
 		printf("%s", buffer);
+
+		/* LUA LINE DELAY */
+		usleep(SHORTDELAY * 1000);
+
 		ioctl(fd, FIONREAD, &len);
 	}
+
+	return 0;
 }
 
 /*******************************************************************************
@@ -520,8 +517,7 @@
 		if (line[0] == '\0')
 			continue;
 
-		LuaSend(fd, line);
-		LuaRecv(fd);
+		LuaLine(fd, line);
 	}
 
 	close(fd);
--- a/helloworld.esp	Tue Feb 03 06:28:33 2015 +0000
+++ b/helloworld.esp	Tue Feb 03 06:35:18 2015 +0000
@@ -1,5 +1,6 @@
 #!espy /dev/ttyUSB0 9600
 
-node.restart()
-
-print ("hello world")
+for variable = 0, 10, 2 do
+	print ( "hello world" )
+	print ( variable )
+end