Diego Coll / Mbed 2 deprecated Praxis

Dependencies:   mbed BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG

Revision:
1:6e255a933812
Parent:
0:9cac1b16cf93
Child:
2:997b65c65e65
--- a/main.cpp	Tue Jun 06 19:26:15 2017 +0000
+++ b/main.cpp	Thu Jun 08 00:17:30 2017 +0000
@@ -1,5 +1,7 @@
 #include<string>
 #include "mbed.h"
+#include "TS_DISCO_F746NG.h"
+#include "LCD_DISCO_F746NG.h"
 
 //-------------------------------------------- definicion de uarts
 
@@ -11,21 +13,61 @@
 
 //-------------------------------------------- definicion de etiquetas
 
+LCD_DISCO_F746NG lcd;
+TS_DISCO_F746NG ts;
 InterruptIn button(BUTTON1);
 DigitalOut myled(LED1);
 
 //-------------------------------------------- definicion de variables globales
 
-string ID="C1",ST="OK",AC="";
+string ID="C1",ST="OK",AC="",AK="";
 //char IDs[]="",STs[]="",ACs[]="",AKs[]="";
 
 char buffer[32]="";
-char* aux[8];
+char* aux[10];
+//char* acc[4]={"CN","DT","OK","ER"};
 int SP=1;
 int OP=1;
+int x=0;
+int yx=72, yy=142, yz=212;
+int gx=72, gy=142, gz=212;
+int mx=72, my=142, mz=212;
+
 
 //-------------------------------------------- definicion de funciones
 
+void encabezado_lcd(){
+    
+    //------------------------------ programa
+    
+    lcd.Clear(LCD_COLOR_BLACK);
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"PRAXIS", CENTER_MODE);
+    wait(3); // 3s
+    lcd.Clear(LCD_COLOR_BLACK);
+    };
+
+void refrescar_lcd(){
+    
+    //------------------------------ programa
+    
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"PRAXIS", CENTER_MODE);
+    
+    x++;
+    if(x==480){
+        x=0;
+        lcd.Clear(LCD_COLOR_BLACK);
+        }
+    
+    lcd.DrawPixel(x, yx, LCD_COLOR_ORANGE);
+    lcd.DrawPixel(x, yy, LCD_COLOR_YELLOW);
+    lcd.DrawPixel(x, yz, LCD_COLOR_RED);
+    
+    wait(0.01); // 10 ms
+    };
+
 void blinkled(){
     myled = 1; // LED is ON
     wait(0.2); // 200 ms
@@ -49,8 +91,6 @@
         }
     };
 
-
-
 void borrar_buffer(char *cadena){
     
     //------------ variables locales
@@ -68,6 +108,7 @@
     
     //------------ variables locales
     
+    char chksm=0;
     char c;
     int i=0;
     
@@ -78,18 +119,56 @@
         while(c!='>'){
             c=uart.getc();
             if(c!='>'){
-                buffer[i++]=c;
+                buffer[i++]=c;              //------------ carga buffer
                 }
             }
+        
+        for(i=0;i<strlen(buffer)-2;i++){    //------------ calculo checksum
+            chksm ^= buffer[i];
+            }
+        
+        //uart.printf("%x",chksm);
+        
         i=0;
-        aux[i]=strtok(buffer,";");
+
+        aux[i]=strtok(buffer,";");          //------------ separa la cadena
+
         do{
             i++;
             aux[i]=strtok(NULL, ";");
             }while(aux[i]!=NULL);
-        if(strcmp(aux[2],"CN") == 0){
-            uart.printf("<%s;%s;YE;2F>",ID,ST);
-            } 
+                     
+        
+        //if(strcmp(aux[??],chksm) == 0){       //------------ comparar checksum (FALTA)
+        //    uart.printf("checksum igual");
+        //    }
+        
+        
+        if(strcmp(aux[2],"CN") == 0){       //------------ toma de decision
+        
+            uart.printf("<%s;%s;YE;51>",ID,ST);
+            }
+        if(strcmp(aux[2],"D1") == 0){
+            yx= 120 - *aux[3];
+            yy= 190 - *aux[4];
+            yz= 260 - *aux[5];
+            //uart.putc(yx);
+            //uart.putc(yy);
+            //uart.putc(yz);
+            //uart.printf("<%s;%s;DT;2F>",ID,ST);
+            }
+        if(strcmp(aux[2],"D2") == 0){
+            gx=*aux[3];
+            gy=*aux[4];
+            gz=*aux[5];
+            //uart.printf("<%s;%s;DT;2F>",ID,ST);
+            }
+        if(strcmp(aux[2],"D3") == 0){
+            mx=*aux[3];
+            my=*aux[4];
+            mz=*aux[5];
+            //uart.printf("<%s;%s;DT;2F>",ID,ST);
+            }        
         }
     borrar_buffer(buffer);
     };
@@ -98,7 +177,9 @@
 
 int main() {
     
-    uart.printf("Inicio de programa\n");     //cambiar uart de destino al final
+    //pc.printf("Inicio de programa\n");     //cambiar uart de destino al final
+    uart.printf("Inicio de programa\n");     
+    encabezado_lcd();
     
     //------------------------------ Interrupciones
     
@@ -108,6 +189,8 @@
     //------------------------------ programa
     
     while(1) {
-        blinkled();
+        
+        refrescar_lcd();
+        //blinkled();
     }
 }