Grupo T / Mbed OS GRUPOT
Revision:
33:6ad0d169b154
Parent:
32:5bd3f0d073ac
Child:
34:e3090fc2e9a4
diff -r 5bd3f0d073ac -r 6ad0d169b154 main.cpp
--- a/main.cpp	Fri Jun 08 20:57:57 2018 +0000
+++ b/main.cpp	Sun Jun 10 05:00:10 2018 +0000
@@ -106,11 +106,15 @@
 
 int kill_jog;
 
+int emerg_stop = 0;
+
+int gcode_move_upload = 0;
+
 // PROTOTYPE FUNCTIONS -------------------------------------------------------------------------------
 void jog(void);
 void killJog(void);
 
-void automatic_run(int);
+void automatic_run(int, bool);
 
 void move(int pps, int x_dir, int y_dir, int z_dir, int x_step, int y_step, int z_step);
 void moveZ(int, int);
@@ -293,6 +297,12 @@
     }
     
     for(int i = 0; i < max_val; i++){
+        if(ihm.readable()){
+            readSerial();    
+        }
+        if(emerg_stop){
+            break;
+        }
         if(i >= x_step){
             stepX = 0;
         }
@@ -339,6 +349,12 @@
     }
     
     while(!x_block_min){
+        if(ihm.readable()){
+            readSerial();    
+        }
+        if(emerg_stop){
+            break;    
+        }
         stepX = 1;
         wait(time);
         stepX = 0;
@@ -362,6 +378,12 @@
     }
     
     while(!y_block_min){
+        if(ihm.readable()){
+            readSerial();    
+        }
+        if(emerg_stop){
+            break;    
+        }
         stepY = 1;
         wait(time);
         stepY = 0;
@@ -386,6 +408,12 @@
     }
     
     while(!z_block_min){
+        if(ihm.readable()){
+            readSerial();    
+        }
+        if(emerg_stop){
+            break;    
+        }
         stepZ = 1;
         wait(time);
         stepZ = 0;
@@ -468,7 +496,10 @@
     while(1){  
         if(ihm.readable()){
             readSerial();    
-        }      
+        }    
+        if(emerg_stop){
+            break;    
+        }  
         valX = joyX;
         valY = joyY;
         
@@ -602,7 +633,7 @@
     move(ppsMax, x_dir, y_dir, z_dir, 0, 0, z_dist);
 }  
             
-void automatic_run(int total_points){
+void automatic_run(int total_points, bool virtual_zero_first){
     int x_start;
     int x_end;
     int y_start;
@@ -622,7 +653,9 @@
     
     printf("\nStarting automatic routine\n\r");
     
-    virtualZero();
+    if(virtual_zero_first){
+        virtualZero();
+    }
     
     wait(1);
     // routine
@@ -630,6 +663,12 @@
     printf("Total points: %d\n\r", total_points);
     
     for(int i = 0; i <= total_points; i++){
+        if(ihm.readable()){
+            readSerial();    
+        }
+        if(emerg_stop){
+            break;    
+        }
         printf("Move n: %d\n\r", i);
         
         x_start = totalX;
@@ -751,6 +790,9 @@
     //delete
     int delete_saved = 0;
     
+    //emergencia
+    int emerg_recv = 0;
+    
     printf("\n\nReceiving...\n\r");
     
     t.reset();
@@ -770,7 +812,11 @@
                 savePoint(speed_str, mode_recv);
             } else if(begin){
                 printf("Automatic: %d\n\r", saved);
-                automatic_run(saved);    
+                if(gcode_move_upload){
+                    automatic_run(saved, false);
+                } else {
+                    automatic_run(saved, true);   
+                } 
             } else if(jog_mode){
                 if(kill_jog_mode){
                     killJog();
@@ -803,13 +849,28 @@
                 clean_glue();
             } else if(delete_saved){
                 saved = saved - 1;    
-            } else {
+            } else if(emerg_recv){
+                printf("Emergencia!\n\r");
+                killJog();
+                emerg_stop = 1;    
+            } 
+            else {
                 printf("End\n\r");
                 return;
             }
             return;
         }
         
+        if(recv == 'e'){
+            emerg_recv = 1;
+        }
+        
+        if(recv == 'm'){
+            gcode_move_upload = 1;
+            timeoutTime = 10.0;
+            upload = 1;
+        }
+        
         if(recv == 's'){
             save = 1;
         }
@@ -881,7 +942,7 @@
             last_recv = recv;    
         }
         
-        if(upload && recv != 'u'){
+        if(upload && recv != 'u' && recv != 'm'){
             upload_buffer.push_back(recv); 
         }
     }