pausa

Dependencies:   mbed

Fork of primercorte by edson antonio vargas villarreal

Revision:
4:244a242e0428
Parent:
2:c457572a9bb2
Child:
5:9187685429b3
--- a/main.cpp	Tue Jun 05 23:01:22 2018 +0000
+++ b/main.cpp	Wed Jun 06 18:02:21 2018 +0000
@@ -8,14 +8,12 @@
 stepmotor smotor1(D9,D10,D11,D12);
 stepmotor smotor2(D2,D3,D14,D15);
 
-void Rx_interrupt();
- 
+   
 int main()  {
-
+     
     init_servo();
     init_serial();
     draw();
-    Rx_interrupt ();
     nodraw();
     home();
     debug_m("inicio \n");
@@ -26,8 +24,6 @@
         switch (read_cc) {
             case  CM_DRAWING: drawing(); break;
             case  CM_SAVING: saving(); break;
-            case CM_PAUSA:  Rx_interrupt(); break;
-            
             default: debug_m("error de comando. \nSe espera  0xFEF0 o 0xfff0   \n");break ;      
         }
     }
@@ -71,10 +67,12 @@
     MEM_TYPE dato;
  
     tail_reset();
+
+
  
     while(error==0){
         error = mem_get(&dato);
-        
+
         
         if (error==0) {
             
@@ -88,19 +86,14 @@
                     debug_m("-> Sube Z\n");
                     nodraw();
                     break ;     
-            
-              
-                
+                            
              default:  
                 int y  = (uint8_t)(dato);
                 int x  = (uint8_t)(dato>>8);
                 char ncomm  = (uint8_t)(dato>>16);
                 
-                if (ncomm == CM_PAUSA){
-                    debug_m("-pausa");
-                command.attach(&Rx_interrupt, Serial::RxIrq); 
-                    }               
-                else if (ncomm == CM_VERTEX2D) {
+                            
+            if (ncomm == CM_VERTEX2D) {
                     debug_m("-> Mover piccolo x a %d y y a %d \n",x,x, y);
                     vertex2d(x,y);
                     
@@ -109,9 +102,14 @@
                     
                     smotor1.step(x*4096,(bool) y);
                     }
-                    
+                   else if(ncomn == CM_PAUSA) {
+                        debug_m("didujo en pausa\n");
+                        pause();
+                        
+                        }      
+                        
                     debug_m("-> ERROR DE COMMANDO: %d %d %d \n " ,ncomm,x,y,y);
-                break;   
+               
              }
          }        
     }  
@@ -119,8 +117,9 @@
     debug_m("fin del comando dibujar..\n");    
     
 }
+
  
- 
+
 void saving(){
     debug_m("se inicia el comando guardar..\n");    
     
@@ -130,37 +129,29 @@
         dato = read_command();
         if (dato !=CM_STOP)
                mem_put(dato);
-    }  
-    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); 
     
+    debug_m("fin del comado guardar..\n");    
+
 }
-    }
- }     
+
+
+
+void pause(){
+          
+        char d=command.getc();
+        if(d==CM_PAUSA){
+        
+        command.attach(0,Serial::RxIrq);
+        debug_m("interrumpe\n");
+        while(command.getc()!=CM_PLAY){}
+        command.attach(&pause,Serial::RxIrq);
+            return;}
+ }
  
+        
 void debug_m(char *s , ... ){
     #if DEBUG
     command.printf(s);