Código simplificado, grados, funciona detencion filas, columna completo, puede recoger 4 fuguras en caracteres.

Dependencies:   mbed mbed

Fork of moggo_2 by julian alvarez

Revision:
2:eac5a192998a
Parent:
1:78d5142da831
Child:
3:990a096b8120
--- a/moggo.cpp	Mon Sep 10 20:19:56 2018 +0000
+++ b/moggo.cpp	Wed Sep 12 17:09:26 2018 +0000
@@ -9,18 +9,15 @@
 
 #define  VEL 250 //Velocidad de actualizacion de dato en el controlador.
 
-void debug_m(char *s , ... ); //depurador de errores, probador.
-
-uint8_t mat_act[8]={0,0,0,0,0,0,0,0};    //Matriz para mostrar en pantalla.
-uint8_t mat_tmp[8]={0,0,0,0,0,0,0,0}; //Matriz temporal para arrojar las fichas.
-uint8_t cont=0;
+uint8_t mat_act[11]={0,0,0,0,0,0,0,0,0,0,0};    //Matriz para mostrar en pantalla.
+uint8_t mat_tmp[8]={0,0,0,0,0,0,0,0};    //Matriz temporal para arrojar las fichas.
 uint8_t fila=0;
  
 void sendSPI(uint8_t d1, uint8_t d2)
 {
     deviceM.unlock();
     ssel=0;
-    deviceM.write(d1);
+    deviceM.write(d1); 
     deviceM.write(d2);
     ssel=1;
     deviceM.lock();
@@ -35,38 +32,11 @@
     sendSPI(0x0F,0);        //operacion normal     
 }
 
-/*void imp_mat(uint8_t*  vC)  // recibe matriz actualizada
-
-{
-    for (uint8_t i=0;i<8;i++){                      //Realiza la impresion de la matriz.
-        sendSPI(i,*(vC+i-1));
-    }
-}*/
-
-/*void baja(uint8_t*  vC)  // recibe matriz actualizada
-
-{
-    for (uint8_t i=0;i<8;i++){                      //Realiza la impresion de la matriz.
-        sendSPI(i,*(vC+i));
-        sendSPI(i+1,*(vC+(i+1)));
-        sendSPI(i+2,*(vC+(i+2)));
-        wait_ms(VEL);
-    }
-}*/
-
-
-/*void act_mat(uint8_t*  mascara)  //recibe matriz temporal
-{ 
-    for (int i=0; i<8;i++)                  //Es la matriz que tenemos como resultado de las diferentes piezas.
-        mat_act[i]=  (*(mascara+i));
-} */
- 
-void cop_mat(uint8_t a,uint8_t b,uint8_t c,uint8_t* fig)
-{
-                    //Realiza una copia de la matriz actual fila por fila.
-        mat_tmp[0]= *(fig+a);
-        mat_tmp[1]= *(fig+b);
-        mat_tmp[2]= *(fig+c);       
+void cop_mat(uint8_t a,uint8_t b,uint8_t c,uint8_t* fig,uint8_t columna)
+{                    
+        mat_tmp[0]= *(fig+a)>>columna-1; //Realiza una copia de la matriz actual fila por fila.
+        mat_tmp[1]= *(fig+b)>>columna-1;
+        mat_tmp[2]= *(fig+c)>>columna-1;       
 }
 
 void borrar() //borrar toda la matriz;
@@ -79,15 +49,28 @@
 };
 
 void buscar_fil(){
-    //uint8_t fil;
     for (uint8_t i=0;i<8;i++){                      //Realiza la impresion de la matriz.
         if(mat_act[i]==0)
         fila=i;
         if(mat_act[i]!=0){
         fila=i-2;
-        i=9;
+        i=8;
         }
     }
+    command.printf("\n buscar fila \n %d",fila);
+    command.printf("\n ******************************* \n ");
+};
+
+void buscar_col(){
+    uint8_t y;
+        y= mat_act[fila] & mat_tmp[2];
+        if(y != 0){
+            fila=0;
+            }
+        else{
+            fila++;
+        }
+        command.printf("\n fila cambiada en columna: y=%d",y);        
 };
 
 void guardar_mat(){
@@ -96,11 +79,9 @@
         mat_act[fila-1]=mat_tmp[0];
         mat_act[fila]=mat_tmp[1];
         mat_act[fila+1]=mat_tmp[2];
-        sendSPI(fila-1,mat_act[fila-1]);
-        sendSPI(fila,mat_act[fila]);
-        sendSPI(fila+1,mat_act[fila+1]);
     };
 
+
 void imp_mat(uint8_t *temp){
     uint8_t i=0;
     buscar_fil();
@@ -111,49 +92,53 @@
         sendSPI(i+2,*(temp+2));
         wait_ms(VEL);
     }
-   // if(cont==0){
-   // guardar_mat(i,mat_tmp);
-   // cont=1;
-   // }  
 }
 
-
-/*void desplazar_fila(){                      //Realiza el desplazamiento para copiar el vector
-     for (int i=0;i<11;i++)
-      mat_tmp[i]= mat_tmp[i]>>1;            //Podemos indicar en que columna caer
-    
-} */
-
 void dibujar(char type_fig,char grados,char columna)
 {
     //borrar();    
     switch (type_fig){                  //Se envia el vector que contiene la figura a la funcion copiar matriz.
-        case 1: cop_mat(5,1,1,FIG_C); break;  //1: cuadro;
-        case 2: cop_mat(0,0,0,FIG_C); break;  //2: I;
-        case 3: cop_mat(0,0,1,FIG_C); break;  //3: L;
-        case 4: cop_mat(5,2,3,FIG_C); break;  //4: T;
-        case 5: cop_mat(5,4,1,FIG_C); break;  //5: S;  
+        case 1: cop_mat(5,1,1,FIG_ALL,columna); break;  //1: cuadro;
+        
+        case 2: if(grados==1 || grados==3)              
+                cop_mat(0,0,0,FIG_ALL,columna);
+                if(grados==2 || grados==4)
+                cop_mat(5,5,2,FIG_ALL,columna);         //2: I;    
+                break;
+                  
+        case 3: if(grados==1)
+                cop_mat(0,0,1,FIG_ALL,columna);         //3: L; 
+                if(grados==2)
+                cop_mat(5,2,0,FIG_ALL,columna);
+                if(grados==3)
+                cop_mat(1,0,0,FIG_ALL,columna);
+                if(grados==4)
+                cop_mat(5,0,2,FIG_ALL,columna);
+                break;  //2: I;
+        
+        case 4: if(grados==1)
+                cop_mat(5,2,0,FIG_ALL,columna);         //4: T;
+                if(grados==2)
+                cop_mat(3,1,3,FIG_ALL,columna);
+                if(grados==3)
+                cop_mat(5,3,2,FIG_ALL,columna);
+                if(grados==4)
+                cop_mat(0,1,0,FIG_ALL,columna);
+                break;
+        
+        case 5: if(grados==1 || grados==3)
+                cop_mat(5,4,1,FIG_ALL,columna);   //5: S; 
+                if(grados==2 || grados==4)
+                cop_mat(0,1,3,FIG_ALL,columna);
+                break; 
     }  
 }
 
-/*void dibujar(char type_fig,char grados,char columna)
-{
-    //borrar();    
-    switch (type_fig){
-        case C_TYPE: cop_mat(1,1,0); break; //Se envia el vector que contiene la figura a la funcion copiar matriz.
-        case I_TYPE: cop_mat(3,1,2); break;
-        case L_TYPE: cop_mat(1,1,2); break;
-        case T_TYPE: cop_mat(1,1,2); break;
-        case S_TYPE: cop_mat(1,1,2); break;  
-    }  
-}*/
-
 int main() {
     char tipo_fig=1,ncolumna=1,grados=1,lee1=0,lee2=0;  // enviar ficha y columna
     test();
     borrar();
     while(1){
-        dibujar(1,1,1);
         lee1=command.getc();                //recive '<' para iniciar la linea de comandos.
         tipo_fig=command.getc();
         grados=command.getc();
@@ -162,19 +147,8 @@
             if(lee1==0x3c && lee2==0x3e)    //solo imprime una figura si viene bajo el parametro '<(t_fig) (Grados) (Col)>'.
             {
             dibujar(tipo_fig,grados,ncolumna);
-                //desplazar_fila();
-                //act_mat(mat_tmp);
-                imp_mat(mat_tmp);
-                guardar_mat();
-                //baja(mat_act);          
+            imp_mat(mat_tmp);
+            guardar_mat();
             }     
         }
-    }
-    
-
-    
-void debug_m(char *s , ... ){
-    #if DEBUG
-    command.printf(s);   //busca errores para depurar en el sistema datos guardados.
-    #endif  
-}
\ No newline at end of file
+    }
\ No newline at end of file