Read GCODE from a laptop and parse it into usable structures.

Dependencies:   MODSERIAL mbed

Dependents:   DrawBot

Fork of gCodeParser by Alejandro Jimenez

Revision:
1:7818b02dde4b
Parent:
0:fa0891ea897b
--- a/gparser.cpp	Mon Apr 14 05:03:29 2014 +0000
+++ b/gparser.cpp	Tue Apr 29 21:51:12 2014 +0000
@@ -5,18 +5,13 @@
 #include "gparser.h"
 #include "mbed.h"
 #include "MODSERIAL.h"
+#include "uLCD_4DGL.h"
 #include <ctype.h>
 
-#define TEST
-
-#ifdef TEST
-#include "uLCD_4DGL.h"
-uLCD_4DGL uLCD(p9,p10,p11);
-#endif
-
 #define FEEDME 10
 #define END_OF_TRANSMISSION 23
 extern MODSERIAL gpc;
+//uLCD_4DGL uLCD(p9, p10, p11);
 
 /************VARS*******************************/
 DigitalOut led1(LED1);
@@ -25,6 +20,7 @@
 DigitalOut led4(LED4);
 
 G_cmd gcmd_list[CMD_LIST_SIZE]; // buffer to be filled with commands, main program retrieves commands from here
+//extern G_cmd* gcmd_list;
 
 // buffer used to transfer the serial buffer contents and parse them into cmd structure
 char rx_buff[CMD_BUFFER_SIZE];
@@ -55,10 +51,8 @@
  * to the pc to request another gcode line
  * returns a pointer to the allocated list of commands.
  */
-G_cmd* fillInCmdList()
+int fillInCmdList()
 {
-    //list_position = 0;      // incremented by parseGcode at the end
-
     // end_flag_received should be detected in parseGcode()
     while(endTransmission == false) {
         // Light up LED1 to indicate the mbed is ready to receive Serial commands
@@ -75,12 +69,14 @@
             led2 = 0;                   // parsing stage is over
         }
     }
+    /*
     uLCD.printf("Commands copied %d\n", list_position);
-    
-    for(int i = (list_position - 4); i < list_position; i++) {
-        uLCD.printf("%d X:%f Y:%f Z:%f F:%f.\r\n", gcmd_list[i].G, gcmd_list[i].X, gcmd_list[i].Y, gcmd_list[i].Z, gcmd_list[i].F);       
+    for(int i = 0; i < list_position; i++) {
+        uLCD.printf("G:%d X:%.2f Y:%.2f Z:%.2f I:%.2f J:%.2f F:%.2f\r\n", gcmd_list[i].G, gcmd_list[i].X, gcmd_list[i].Y, gcmd_list[i].Z, gcmd_list[i].I, gcmd_list[i].J, gcmd_list[i].F);
+    wait(10);
+    uLCD.cls();
     }
-    
+    */
     led1 = 1;
     wait(0.5);
     led1 = 0;
@@ -94,7 +90,7 @@
     wait(0.5);
     led3 = 1;
     led2 = 1;
-    return gcmd_list;
+    return (list_position);
 }
 
 //interrupt routine called when the null terminator is received
@@ -118,8 +114,6 @@
     // in case there are leading spaces
     char* cmdP = strtok(rx_buff, " G");
 
-    //uLCD.printf("cmdP is pointing now to %s\n", cmdP);
-
     char coord_label[2];
 
     //int g = atoi(cmdP);
@@ -128,6 +122,12 @@
 
     //fill out the command number field
     gcmd_list[list_position].G = atoi(cmdP);
+    gcmd_list[list_position].X = -1;
+    gcmd_list[list_position].Y = -1;
+    gcmd_list[list_position].Z = -1;
+    gcmd_list[list_position].F = -1;
+    gcmd_list[list_position].I = -1;
+    gcmd_list[list_position].J = -1;
 
     //uLCD.printf("%d: ", gcmd_list[list_position].G);
 
@@ -145,6 +145,14 @@
 
         // now print the number
         //uLCD.printf("%s ", cmdP);
+        /*
+        gcmd_list[list_position].X = -1;
+        gcmd_list[list_position].Y = -1;
+        gcmd_list[list_position].Z = -2;
+        gcmd_list[list_position].F = -1;
+        gcmd_list[list_position].I = -1;
+        gcmd_list[list_position].J = -1;
+        */
         switch(coord_label[0]) {
             case 'X':
                 gcmd_list[list_position].X = atof(cmdP);
@@ -165,7 +173,7 @@
                 gcmd_list[list_position].J = atof(cmdP);
                 break;
             default:
-        
+
                 break;
         }// switch
     } // while