pausa

Dependencies:   mbed

Fork of primercorte by edson antonio vargas villarreal

Revision:
2:c457572a9bb2
Parent:
1:6ed951d975cc
Child:
4:244a242e0428
--- a/main.cpp	Fri Apr 20 00:56:27 2018 +0000
+++ b/main.cpp	Tue Jun 05 23:01:22 2018 +0000
@@ -1,17 +1,21 @@
 #include "mbed.h" 
 #include "main.h" 
 #include "stepmotor.h" 
+
+
   
 Serial command(USBTX, USBRX);
 stepmotor smotor1(D9,D10,D11,D12);
+stepmotor smotor2(D2,D3,D14,D15);
 
- 
+void Rx_interrupt();
  
- 
-int main() {
+int main()  {
+
     init_servo();
     init_serial();
     draw();
+    Rx_interrupt ();
     nodraw();
     home();
     debug_m("inicio \n");
@@ -22,7 +26,9 @@
         switch (read_cc) {
             case  CM_DRAWING: drawing(); break;
             case  CM_SAVING: saving(); break;
-            default: debug_m("error de comando. \nSe espera  0xFEF0 o 0xFFF0 \n");break ;      
+            case CM_PAUSA:  Rx_interrupt(); break;
+            
+            default: debug_m("error de comando. \nSe espera  0xFEF0 o 0xfff0   \n");break ;      
         }
     }
 }
@@ -31,14 +37,7 @@
  
 uint32_t read_command()
 {
-   // retorna los byte recibidos concatenados en un entero, se reciben maximo 4 bytes,
-   // recibe hasta que encuetra  un fin de comando "CM_END".
-   // Ejemplo: para el comando drawing se 
-   // espera un byte,  por lo que al recibir 0xFF y 0xF0 la funcióm  retorna el 0xff
-   // siempre y cuando se reciba el fin de dato  F0 de lo contrario retorna un cero
-   // para el caso del comando vertex2d se espera  recibir 3 bytes, 1 del comando 
-   // y dos bytes para x y y, se retorna la concatenación de los tres bytes  siempre y
-   // cuando el cuarto byte sea CM_END de lo contrario retorna un cero 
+  
    
     uint32_t val=0;
     uint8_t  cnt=0;
@@ -53,17 +52,19 @@
     }   
     if(endc==CM_END)   
         return val;
-    return 0;   //al retornar 0 indica que  no se recibe el comando  
+    return 0;   
 }
-void init_serial()
-{
-    command.baud(9600);    
+void init_serial(){
+
+    command.baud(9600);  
+    
 }
+
+
  
  
 void drawing(){
-    // la funcion se ejecuta siemrpe y cuando exista datos validos para leer de 
-    // memoria 
+
     debug_m("se esta ejecutando el dibujo... \n");       
      
     uint8_t error=0;
@@ -73,9 +74,12 @@
  
     while(error==0){
         error = mem_get(&dato);
+        
+        
         if (error==0) {
             
-            switch (dato) {
+            switch (dato) {   
+          
             case  CM_DRAW: 
                     debug_m("-> Baja Z\n");
                     draw();
@@ -91,8 +95,12 @@
                 int y  = (uint8_t)(dato);
                 int x  = (uint8_t)(dato>>8);
                 char ncomm  = (uint8_t)(dato>>16);
-                               
-                if (ncomm == CM_VERTEX2D) {
+                
+                if (ncomm == CM_PAUSA){
+                    debug_m("-pausa");
+                command.attach(&Rx_interrupt, Serial::RxIrq); 
+                    }               
+                else if (ncomm == CM_VERTEX2D) {
                     debug_m("-> Mover piccolo x a %d y y a %d \n",x,x, y);
                     vertex2d(x,y);
                     
@@ -126,6 +134,32 @@
     debug_m("fin del comado guardar..\n");    
     
 }
+void Rx_interrupt() {
+       debug_m(" dibujo en pausa ... \n"); 
+ 
+     uint8_t error=0;
+    MEM_TYPE dato;
+    tail_reset();
+       while(error==0){
+        error = mem_get(&dato);
+         if (error==0) {
+            
+            switch (dato) {   
+          
+            case  CM_PAUSA: 
+                     debug_m("-> pausa \n");
+                      Rx_interrupt();
+                        break ;  
+                
+                
+                          
+               
+    }  
+    command.attach(&Rx_interrupt, Serial::RxIrq); 
+    
+}
+    }
+ }     
  
 void debug_m(char *s , ... ){
     #if DEBUG