Guillermo Stedile / Mbed 2 deprecated SNOCC_V2

Dependencies:   NAVDATA RA8875 SDFileSystem VCODATA mbed

Committer:
gstedile
Date:
Fri Jun 23 03:59:11 2017 +0000
Revision:
1:30b1ca228fc7
Parent:
0:e40cf759ba9a
Child:
2:968b38c3ef49
20170622

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gstedile 0:e40cf759ba9a 1
gstedile 0:e40cf759ba9a 2 #include "mbed.h" // v112
gstedile 0:e40cf759ba9a 3 #include "RA8875.h" // v102
gstedile 0:e40cf759ba9a 4 #include "MyFont18x32.h"
gstedile 0:e40cf759ba9a 5 #include "BPG_Arial08x08.h"
gstedile 0:e40cf759ba9a 6 #include "BPG_Arial10x10.h"
gstedile 0:e40cf759ba9a 7 #include "BPG_Arial20x20.h"
gstedile 0:e40cf759ba9a 8 #include "BPG_Arial31x32.h"
gstedile 0:e40cf759ba9a 9 #include "BPG_Arial63x63.h"
gstedile 1:30b1ca228fc7 10 #include "GPS.h" // Comunicacion con el gps.
gstedile 1:30b1ca228fc7 11 #include "NAVDATA.h" // Para la clase NAVDATA que maneja los datos de navegación del último período.
gstedile 1:30b1ca228fc7 12 #include "VCODATA.h" // Para la clase VCODATA que maneja los datos de navegación más recientes parametrizados por velocidad de cada período.
gstedile 1:30b1ca228fc7 13 #include "SDFileSystem.h" // SD Card
gstedile 1:30b1ca228fc7 14 #include <sstream> // Para uso de streams
gstedile 0:e40cf759ba9a 15 #include <string>
gstedile 0:e40cf759ba9a 16
gstedile 1:30b1ca228fc7 17 int err_Store=0;
gstedile 1:30b1ca228fc7 18 int TESTING=0; // -->1:Habilita test de funcionamiento del almacenamiento de datos.
gstedile 1:30b1ca228fc7 19 int DEBUG1=1; // -->1:Habilita informacion para debug.
gstedile 1:30b1ca228fc7 20 int DEBUG2=1; // -->1:Habilita informacion para debug2.
gstedile 1:30b1ca228fc7 21 int DEBUG_GPS=0; // -->1:Habilita datos para debug de comunicacion con gps.
gstedile 1:30b1ca228fc7 22 enum sentido{DWN=0,UP,NO};
gstedile 1:30b1ca228fc7 23 enum figura{ZONA=0,SIN_DT,CIRC,FLECHA,ElIP};
gstedile 0:e40cf759ba9a 24 const char *sd_dir="/sd/snocc"; // Directorio de almacenamiento de datos.
gstedile 0:e40cf759ba9a 25 const char *sd_file="/sd/snocc/sdsnocc.csv"; // Archivo csv de almacenamiento de datos.
gstedile 1:30b1ca228fc7 26 const int V_M=54; //Velocidad Maxima
gstedile 0:e40cf759ba9a 27 float Counter=0; //Contador de pulsos del sensor de flujo.
gstedile 0:e40cf759ba9a 28 float LCounter=0; //Consumo en litros
gstedile 0:e40cf759ba9a 29
gstedile 1:30b1ca228fc7 30 NAVDATA NAVIGATION_OBJECT; //Objeto que maneja los datos de navegación del último período. (ANTERIORMENTE LLAMADO NAVIGATION_TABLE, nombre que generaba confusion)
gstedile 1:30b1ca228fc7 31 VCODATA NAVIGATION_VMATRIX(NAVIGATION_OBJECT, V_M); // Objeto que maneja la matriz de datos de navegación $
gstedile 1:30b1ca228fc7 32 VCODATA NAVIGATION_V_SMOOTH_MTRX(NAVIGATION_OBJECT, V_M); // Objeto que maneja la matriz de datos de navegación promediados $
gstedile 1:30b1ca228fc7 33 NAVDATA TestNAV; // Objeto para crear matriz default; /// DEBUG?
gstedile 0:e40cf759ba9a 34
gstedile 1:30b1ca228fc7 35 LocalFileSystem local("local"); // Para <PrintScreen>
gstedile 1:30b1ca228fc7 36 Serial pc(USBTX, USBRX);
gstedile 1:30b1ca228fc7 37 RA8875 lcd(p5, p6, p7, p8, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name // Comunicacion con Display
gstedile 1:30b1ca228fc7 38 SDFileSystem sd(p11, p12, p13, p14, "sd"); // SD CARD: mosi, miso, sclk, cs // Comunicacion con SD card
gstedile 0:e40cf759ba9a 39
gstedile 0:e40cf759ba9a 40
gstedile 0:e40cf759ba9a 41
gstedile 1:30b1ca228fc7 42 //>>>>>>>>>>>>>>>>>> SECCION TOUCH PANEL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
gstedile 0:e40cf759ba9a 43 extern "C" void mbed_reset();
gstedile 0:e40cf759ba9a 44 #define min(a,b) ((a<b)?a:b)
gstedile 0:e40cf759ba9a 45 #define max(a,b) ((a>b)?a:b)
gstedile 0:e40cf759ba9a 46 bool Intersect(rect_t rect, point_t p)
gstedile 0:e40cf759ba9a 47 {
gstedile 0:e40cf759ba9a 48 if (p.x >= min(rect.p1.x, rect.p2.x) && p.x <= max(rect.p1.x, rect.p2.x)
gstedile 0:e40cf759ba9a 49 && p.y >= min(rect.p1.y, rect.p2.y) && p.y <= max(rect.p1.y, rect.p2.y))
gstedile 0:e40cf759ba9a 50 return true;
gstedile 0:e40cf759ba9a 51 else
gstedile 0:e40cf759ba9a 52 return false;
gstedile 0:e40cf759ba9a 53 }
gstedile 0:e40cf759ba9a 54 int GetScreenCapture(void)
gstedile 0:e40cf759ba9a 55 {
gstedile 0:e40cf759ba9a 56 char fqfn[50];
gstedile 0:e40cf759ba9a 57 int i = 0;
gstedile 0:e40cf759ba9a 58 pc.printf("Screen Capture... ");
gstedile 0:e40cf759ba9a 59 for (i=1; i< 100; i++) {
gstedile 0:e40cf759ba9a 60 snprintf(fqfn, sizeof(fqfn), "/local/Screen%02d.bmp", i);
gstedile 0:e40cf759ba9a 61 FILE * fh = fopen(fqfn, "rb");
gstedile 0:e40cf759ba9a 62 if (!fh) {
gstedile 0:e40cf759ba9a 63 lcd.PrintScreen(0,0,480,272,fqfn);
gstedile 0:e40cf759ba9a 64 pc.printf(" as /local/Screen%02d.bmp\r\n", i);
gstedile 0:e40cf759ba9a 65 return i;
gstedile 0:e40cf759ba9a 66 } else {
gstedile 1:30b1ca228fc7 67 fclose(fh);
gstedile 0:e40cf759ba9a 68 }
gstedile 0:e40cf759ba9a 69 }
gstedile 0:e40cf759ba9a 70 return 0;
gstedile 0:e40cf759ba9a 71 }
gstedile 1:30b1ca228fc7 72 //>>>>>>>>>>>>>>>>>> FIN SECCION TOUCH PANEL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
gstedile 0:e40cf759ba9a 73
gstedile 0:e40cf759ba9a 74 //Función para la interrupción
gstedile 0:e40cf759ba9a 75
gstedile 0:e40cf759ba9a 76 void trigger() {
gstedile 0:e40cf759ba9a 77 Counter++;
gstedile 0:e40cf759ba9a 78 LCounter=Counter/2500;
gstedile 0:e40cf759ba9a 79 }
gstedile 0:e40cf759ba9a 80
gstedile 0:e40cf759ba9a 81
gstedile 0:e40cf759ba9a 82 /* Funcion print_VCO_curve : Imprime la curva de consumo/milla en funcion de la velocidad a partir del vector de objetos NAV_DATA de la clase VCODATA, con lineas (printline=1) o puntos (=0)
gstedile 0:e40cf759ba9a 83 Parametros: Objeto VCODATA; Interpolated: 0 -> no imprime valores interpolados o promediados; 1: interpola con puntos, 2: interpola con lineas*/
gstedile 0:e40cf759ba9a 84
gstedile 0:e40cf759ba9a 85 void print_VCO_curve(VCODATA &Matrix_VCO, int interpolated){
gstedile 0:e40cf759ba9a 86 //lcd.puts("ENTRANDO a print_VCO_curve\r\n"); // DEBUG
gstedile 1:30b1ca228fc7 87 int vcc[2];
gstedile 0:e40cf759ba9a 88 float s; // Consumo
gstedile 0:e40cf759ba9a 89 int y,x;
gstedile 1:30b1ca228fc7 90 int VCO= Matrix_VCO.get_VCO(vcc);
gstedile 0:e40cf759ba9a 91 int y_offset=250; //Para que imprima de abajo hacia arriba.
gstedile 0:e40cf759ba9a 92 int y_text_offset=15; //Para cooregir diferencia de impresion entre caracter y linea.
gstedile 0:e40cf759ba9a 93 int x_offset=30; //Posicionamiento en x
gstedile 0:e40cf759ba9a 94 int y_i=y_offset; //Punto origen y
gstedile 0:e40cf759ba9a 95 int x_i=x_offset; //Punto origen x
gstedile 1:30b1ca228fc7 96 int x_scale=8; // Escala para graficar eje x.
gstedile 0:e40cf759ba9a 97 int y_scale=90; // Escala para graficar eje y.
gstedile 0:e40cf759ba9a 98 lcd.background(RGB(255,255,255));
gstedile 0:e40cf759ba9a 99 lcd.foreground(Blue);
gstedile 0:e40cf759ba9a 100 lcd.SelectUserFont(BPG_Arial20x20);
gstedile 0:e40cf759ba9a 101 lcd.SetTextCursor(0,0); // Pongo cursor en posicion
gstedile 0:e40cf759ba9a 102 lcd.cls();
gstedile 0:e40cf759ba9a 103 lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n");
gstedile 0:e40cf759ba9a 104 lcd.roundrect( 5,20,470,270,10,8, RGB(255,255,0)); // Rectangulo para encuadre de graficos
gstedile 0:e40cf759ba9a 105 lcd.fillroundrect(10,25,465,264,5,3, Green);
gstedile 0:e40cf759ba9a 106 lcd.foreground(RGB(255,255,0));
gstedile 0:e40cf759ba9a 107 lcd.background(Green);
gstedile 0:e40cf759ba9a 108
gstedile 0:e40cf759ba9a 109 for (int n=0;n<Matrix_VCO.vel_max;n++){ // Recorre x de 0 a vel_max.
gstedile 0:e40cf759ba9a 110 s = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período
gstedile 0:e40cf759ba9a 111 y=int(y_offset-y_scale*s); // El consumo máximo es alrededor de 2 l/m => Multiplico por y_scale
gstedile 0:e40cf759ba9a 112 // para que ocupe mas pantalla.
gstedile 0:e40cf759ba9a 113 x=n*x_scale+x_offset; // para aumentar el span (eje x)
gstedile 0:e40cf759ba9a 114 switch (interpolated){
gstedile 0:e40cf759ba9a 115 case 0: if (Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]==0){ //Valores sin interpolar
gstedile 0:e40cf759ba9a 116 lcd.SetTextCursor(x,y-y_text_offset);
gstedile 0:e40cf759ba9a 117 lcd.printf(".");
gstedile 0:e40cf759ba9a 118 }
gstedile 0:e40cf759ba9a 119 break;
gstedile 0:e40cf759ba9a 120 case 1: if ((Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]==1) || (Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]==2))lcd.foreground(Orange); // interpola con puntos de otro color
gstedile 0:e40cf759ba9a 121 lcd.SetTextCursor(x,y-y_text_offset); // el offset adicional es para corregir la diferencia de ubicacion linea-caracter.
gstedile 0:e40cf759ba9a 122 lcd.printf(".");
gstedile 0:e40cf759ba9a 123 lcd.foreground(RGB(255,255,0));
gstedile 0:e40cf759ba9a 124 break;
gstedile 0:e40cf759ba9a 125 case 2: lcd.line(x_i,y_i,x,y); // Imprime linea
gstedile 0:e40cf759ba9a 126 break;
gstedile 0:e40cf759ba9a 127 default:
gstedile 0:e40cf759ba9a 128 lcd.SetTextCursor(x,y-y_text_offset);
gstedile 0:e40cf759ba9a 129 lcd.printf(".");
gstedile 0:e40cf759ba9a 130 break;
gstedile 0:e40cf759ba9a 131 }
gstedile 0:e40cf759ba9a 132
gstedile 0:e40cf759ba9a 133 x_i=x;
gstedile 0:e40cf759ba9a 134 y_i=y;
gstedile 0:e40cf759ba9a 135 }
gstedile 0:e40cf759ba9a 136
gstedile 0:e40cf759ba9a 137 x_i=x_offset;
gstedile 0:e40cf759ba9a 138 y_i=y_offset;
gstedile 0:e40cf759ba9a 139
gstedile 0:e40cf759ba9a 140 lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 141 lcd.background(Green);
gstedile 0:e40cf759ba9a 142 lcd.foreground(Blue);
gstedile 0:e40cf759ba9a 143 lcd.SetTextCursor(30,32);
gstedile 0:e40cf759ba9a 144 lcd.puts("Cons.(l/m)\r\n");
gstedile 0:e40cf759ba9a 145 lcd.SetTextCursor(420,235);
gstedile 0:e40cf759ba9a 146 lcd.puts("Vel.(kn)\r\n");
gstedile 0:e40cf759ba9a 147 lcd.line(x_i,y_i,Matrix_VCO.vel_max*x_scale+x_offset,y_i); // Imprimo eje x.
gstedile 1:30b1ca228fc7 148 for(int j=10;j<=Matrix_VCO.vel_max;j+=10){
gstedile 0:e40cf759ba9a 149 int x=j*x_scale+x_offset;
gstedile 0:e40cf759ba9a 150 lcd.line(x,y_i,x,y_i-5);
gstedile 0:e40cf759ba9a 151 lcd.SetTextCursor(x,y_i+5);
gstedile 0:e40cf759ba9a 152 lcd.printf("%d",j);
gstedile 0:e40cf759ba9a 153 }
gstedile 0:e40cf759ba9a 154 lcd.line(x_i,y_i,x_i,40); // Imprimo eje y.
gstedile 0:e40cf759ba9a 155 for(int k=1;k<=5;k++){
gstedile 0:e40cf759ba9a 156 y=y_offset-k*0.5*y_scale;
gstedile 0:e40cf759ba9a 157 lcd.line(x_i,y,x_i+10,y);
gstedile 0:e40cf759ba9a 158 lcd.SetTextCursor(x_i-15,y+5);
gstedile 0:e40cf759ba9a 159 if(y>=0)lcd.printf("%.1f",k*0.5);
gstedile 0:e40cf759ba9a 160 }
gstedile 0:e40cf759ba9a 161 if (VCO>0){
gstedile 0:e40cf759ba9a 162 s = Matrix_VCO.NAV_DATA[VCO].LAST_NAV_DATA[cons_mile_p];; // Valor de consumo para VCO.
gstedile 0:e40cf759ba9a 163 y=int(y_offset-y_scale*s); // el consumo máximo es alrededor de 2 l/m. Multiplico por y_scale para que ocupe mas pantalla.
gstedile 0:e40cf759ba9a 164 x=VCO*x_scale+x_offset; // para aumentar el span (eje x)
gstedile 0:e40cf759ba9a 165 if (interpolated==2){
gstedile 0:e40cf759ba9a 166 lcd.circle(x,y,5);
gstedile 0:e40cf759ba9a 167 }
gstedile 0:e40cf759ba9a 168 else{
gstedile 0:e40cf759ba9a 169 lcd.SetTextCursor(x,y);
gstedile 0:e40cf759ba9a 170 lcd.printf("*");
gstedile 0:e40cf759ba9a 171 }
gstedile 0:e40cf759ba9a 172 lcd.SetTextCursor(VCO*x_scale+x_offset+10,y_offset-s*y_scale+20);
gstedile 1:30b1ca228fc7 173 lcd.printf("%lf l/m",s);
gstedile 0:e40cf759ba9a 174 lcd.SetTextCursor(VCO*x_scale+x_offset+10,y_offset-s*y_scale+40);
gstedile 0:e40cf759ba9a 175 lcd.printf("VCO: %d kn",VCO);
gstedile 0:e40cf759ba9a 176
gstedile 0:e40cf759ba9a 177 }
gstedile 0:e40cf759ba9a 178 else{
gstedile 0:e40cf759ba9a 179 lcd.SetTextCursor(120,35);
gstedile 0:e40cf759ba9a 180 lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 181 lcd.printf("No hay datos suficientes para obtener la VCO");
gstedile 0:e40cf759ba9a 182 lcd.printf("%d",VCO);//DEBUG
gstedile 0:e40cf759ba9a 183 }
gstedile 0:e40cf759ba9a 184 lcd.foreground(RGB(255,255,0));
gstedile 0:e40cf759ba9a 185 lcd.background(Black);
gstedile 0:e40cf759ba9a 186 }
gstedile 0:e40cf759ba9a 187
gstedile 0:e40cf759ba9a 188
gstedile 1:30b1ca228fc7 189 /* Funcion print_VCO_data : Imprime una tabla con los datos de consumo/milla en funcion de la velocidad a partir del vector de objetos NAV_DATA de la clase VCODATA.
gstedile 0:e40cf759ba9a 190 Parametros: Objeto VCODATA; */
gstedile 0:e40cf759ba9a 191
gstedile 0:e40cf759ba9a 192 void print_VCO_data(VCODATA &Matrix_VCO){
gstedile 0:e40cf759ba9a 193 float cons, vel;
gstedile 0:e40cf759ba9a 194 lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 195 lcd.background(RGB(255,255,255));
gstedile 0:e40cf759ba9a 196 lcd.foreground(Blue);
gstedile 0:e40cf759ba9a 197 lcd.SetTextCursor(0,0); // Pongo cursor en posicion
gstedile 0:e40cf759ba9a 198 lcd.cls();
gstedile 0:e40cf759ba9a 199 lcd.puts("Velocidad-Consumo\r\n");
gstedile 0:e40cf759ba9a 200 for (int n=0;n<83;n++){ // Recorre x de 0 a 83. (Maxima cantidad que entra en una pantalla)
gstedile 0:e40cf759ba9a 201 cons = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período
gstedile 0:e40cf759ba9a 202 vel= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad del período.
gstedile 1:30b1ca228fc7 203 lcd.printf("| %d - %lf | %lf |",n,vel,cons);
gstedile 0:e40cf759ba9a 204 }
gstedile 0:e40cf759ba9a 205 wait(3);
gstedile 0:e40cf759ba9a 206 lcd.cls();
gstedile 0:e40cf759ba9a 207 for (int n=83;n<Matrix_VCO.vel_max;n++){ // Recorre x de 0 a vel_max.
gstedile 0:e40cf759ba9a 208 cons = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período
gstedile 0:e40cf759ba9a 209 vel= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad del período.
gstedile 1:30b1ca228fc7 210 lcd.printf("| %d - %lf | %lf |",n,vel,cons);
gstedile 0:e40cf759ba9a 211 }
gstedile 0:e40cf759ba9a 212 //lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 213
gstedile 0:e40cf759ba9a 214 }
gstedile 0:e40cf759ba9a 215
gstedile 0:e40cf759ba9a 216
gstedile 0:e40cf759ba9a 217 /* Funcion mtrx2sd: Guarda los datos de la matriz en un archivo de texto existente*/
gstedile 0:e40cf759ba9a 218
gstedile 0:e40cf759ba9a 219 int mtrx2sd(VCODATA &Matrix_VCO, const char *filename){
gstedile 1:30b1ca228fc7 220 double lngtd_f,lngtd_i,lttd_f,lttd_i,tm_f,tm_i,dstnc_p,spd_p,cnsmptn_i,cnsmptn_f,cnsmptn_p,cns_ml_p,cns_hr_p,cns_ntrpltd; // Variables de navegacion;
gstedile 0:e40cf759ba9a 221 FILE *fp1;
gstedile 0:e40cf759ba9a 222 fp1 = fopen(filename, "w"); //Apertura para escritura
gstedile 0:e40cf759ba9a 223 if(fp1 == NULL) {
gstedile 0:e40cf759ba9a 224 //error("Could not open file for write\n");
gstedile 0:e40cf759ba9a 225 return -1;
gstedile 0:e40cf759ba9a 226 }
gstedile 1:30b1ca228fc7 227 for (int n=0;n<=Matrix_VCO.vel_max;n++){
gstedile 0:e40cf759ba9a 228 lngtd_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_f]; // Longitud y Latitud iniciales y finales.
gstedile 0:e40cf759ba9a 229 lngtd_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_i];
gstedile 0:e40cf759ba9a 230 lttd_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_f];
gstedile 0:e40cf759ba9a 231 lttd_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_i];
gstedile 0:e40cf759ba9a 232 tm_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_f]; // El dato (timestamp al final del período en cuestion, en horas) se obtendrá luego proveniente del GPS.
gstedile 0:e40cf759ba9a 233 tm_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_i]; // Timestamp al inicio del período en horas.
gstedile 0:e40cf759ba9a 234 dstnc_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[distance_p]; // Distancia recorrida durante este período en millas nauticas.
gstedile 0:e40cf759ba9a 235 spd_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad media del período en nudos.
gstedile 0:e40cf759ba9a 236 cnsmptn_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_i]; // Consumo en litros al comienzo del período.
gstedile 0:e40cf759ba9a 237 cnsmptn_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_f]; // Consumo en litros al final del período.
gstedile 0:e40cf759ba9a 238 cnsmptn_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_p]; // Consumo en litros del período.
gstedile 0:e40cf759ba9a 239 cns_ml_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo en litros por milla nautica.
gstedile 0:e40cf759ba9a 240 cns_hr_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_hour_p]; // Consumo en litros por hora.
gstedile 0:e40cf759ba9a 241 cns_ntrpltd= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]; // Consumo interpolado?: -1-> initial padding
gstedile 1:30b1ca228fc7 242
gstedile 0:e40cf759ba9a 243 fprintf(fp1,"%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f\r\n",lngtd_f,lngtd_i,lttd_f,lttd_i,tm_f,tm_i,dstnc_p,spd_p,cnsmptn_i,cnsmptn_f,cnsmptn_p,cns_ml_p,cns_hr_p,cns_ntrpltd);
gstedile 0:e40cf759ba9a 244 }
gstedile 0:e40cf759ba9a 245 return fclose(fp1);
gstedile 0:e40cf759ba9a 246 }
gstedile 0:e40cf759ba9a 247
gstedile 0:e40cf759ba9a 248 /* Funcion sd2mtrx: Guarda los datos de un archivo de texto existente en la matriz*/
gstedile 0:e40cf759ba9a 249
gstedile 0:e40cf759ba9a 250 int sd2mtrx(VCODATA &Matrix_VCO, const char *filename){
gstedile 1:30b1ca228fc7 251 double lngtd_f,lngtd_i,lttd_f,lttd_i,tm_f,tm_i,dstnc_p,spd_p,cnsmptn_i,cnsmptn_f,cnsmptn_p,cns_ml_p,cns_hr_p,cns_ntrpltd; // Variables de navegacion;
gstedile 0:e40cf759ba9a 252 FILE *fp1;
gstedile 0:e40cf759ba9a 253 fp1 = fopen(filename, "r"); //Apertura para escritura
gstedile 0:e40cf759ba9a 254 if(fp1 == NULL) {
gstedile 0:e40cf759ba9a 255 //error("Could not open file for read\n");
gstedile 0:e40cf759ba9a 256 return -1;
gstedile 0:e40cf759ba9a 257 }
gstedile 0:e40cf759ba9a 258 for (int n=0;n<Matrix_VCO.vel_max;n++){
gstedile 1:30b1ca228fc7 259 fscanf(fp1,"%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf",&lngtd_f,&lngtd_i,&lttd_f,&lttd_i,&tm_f,&tm_i,&dstnc_p,&spd_p,&cnsmptn_i,&cnsmptn_f,&cnsmptn_p,&cns_ml_p,&cns_hr_p,&cns_ntrpltd); // Leemos un double y lo guardamos
gstedile 0:e40cf759ba9a 260 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_f]=lngtd_f;
gstedile 0:e40cf759ba9a 261 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_i]=lngtd_i;
gstedile 0:e40cf759ba9a 262 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_f]=lttd_f;
gstedile 0:e40cf759ba9a 263 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_i]=lttd_i;
gstedile 0:e40cf759ba9a 264 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_f]=tm_f;
gstedile 0:e40cf759ba9a 265 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_i]=tm_i;
gstedile 0:e40cf759ba9a 266 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[distance_p]=dstnc_p;
gstedile 0:e40cf759ba9a 267 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]=spd_p;
gstedile 0:e40cf759ba9a 268 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_i]=cnsmptn_i;
gstedile 0:e40cf759ba9a 269 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_f]=cnsmptn_f;
gstedile 0:e40cf759ba9a 270 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_p]=cnsmptn_p;
gstedile 0:e40cf759ba9a 271 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]=cns_ml_p;
gstedile 0:e40cf759ba9a 272 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_hour_p]=cns_hr_p;
gstedile 0:e40cf759ba9a 273 Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]=cns_ntrpltd;
gstedile 0:e40cf759ba9a 274
gstedile 0:e40cf759ba9a 275 }
gstedile 0:e40cf759ba9a 276 return fclose(fp1);
gstedile 0:e40cf759ba9a 277 }
gstedile 0:e40cf759ba9a 278
gstedile 0:e40cf759ba9a 279 /* Funcion build_default_Mtrx: Carga los datos (consumo/milla) del vector LAST_NAV_DATA de los objetos NAVDATA de VCODATA para testing.*/
gstedile 1:30b1ca228fc7 280 /* Si el parámetro virtual_speed es cero, se completa la matríz con valores default. Sino, se carga
gstedile 1:30b1ca228fc7 281 solamente un vector NAVDATA con valores default consistentes con los parámetros y se almacena en la matríz cuando la cantidad
gstedile 1:30b1ca228fc7 282 de períodos a vel constante es alcanzada. Este caso es utilizado para testing.*/
gstedile 0:e40cf759ba9a 283
gstedile 1:30b1ca228fc7 284 int build_default_Mtrx(VCODATA &Test_Matrix_VCO,NAVDATA &TestNDO, double virtual_speed, double virtual_timestamp){
gstedile 1:30b1ca228fc7 285 double virtual_time=0;
gstedile 1:30b1ca228fc7 286 double virtual_longitude=-58.5797; // Mantiene cte la Longitud.
gstedile 1:30b1ca228fc7 287 double virtual_latitude=-34.4251;
gstedile 1:30b1ca228fc7 288 double virtual_counter=0;
gstedile 1:30b1ca228fc7 289 if (virtual_speed==0){
gstedile 1:30b1ca228fc7 290 //virtual_timestamp=0.00000001; // en segundos
gstedile 1:30b1ca228fc7 291 for (int i=1; i< Test_Matrix_VCO.vel_max; i++){
gstedile 1:30b1ca228fc7 292 virtual_speed= i*1.0;
gstedile 1:30b1ca228fc7 293
gstedile 1:30b1ca228fc7 294 if (i<12) virtual_time=5.0*i; // Formato NMEA: hhmmss,ss
gstedile 1:30b1ca228fc7 295 else {
gstedile 1:30b1ca228fc7 296 int mnts=int(5*i/60);
gstedile 1:30b1ca228fc7 297 virtual_time = ((mnts*100) +((5*i)- (mnts*60))); // Formato NMEA: (hh)mmss,ss
gstedile 1:30b1ca228fc7 298 }
gstedile 1:30b1ca228fc7 299 TestNDO.LAST_NAV_DATA[cons_interpolated]=-1; // --> -1:Datos iniciales.
gstedile 1:30b1ca228fc7 300 TestNDO.np_concat=0; // Cantidad de periodos concatenados:-->0: Solo valores de inicio.
gstedile 1:30b1ca228fc7 301 virtual_latitude+=(virtual_speed*5/3600)/(59.99999981628485);// Tomo delta_t virtual de (virtual_speed*Delta t) y // calculo latitud recorrida en virtual_timestamp @virtual_speed y longitud cte.
gstedile 1:30b1ca228fc7 302 if (i<10) virtual_counter+=0.6*i*i; // Simulacion de consumo; modificar y probar
gstedile 1:30b1ca228fc7 303 else if (i<20) virtual_counter+=55;
gstedile 1:30b1ca228fc7 304 else if(i<30) virtual_counter+=900/i;
gstedile 1:30b1ca228fc7 305 else virtual_counter+=0.06*i*i;
gstedile 1:30b1ca228fc7 306 int err_Rot=TestNDO.rotate_data(virtual_longitude, virtual_latitude, virtual_time, virtual_counter, NAVIGATION_VMATRIX.vel_max);
gstedile 1:30b1ca228fc7 307 virtual_timestamp+=5; // en segundos, 5 segundos de período
gstedile 1:30b1ca228fc7 308 if(err_Rot==0){ // Si la rotacion fue 100% exitosa
gstedile 1:30b1ca228fc7 309 if(Test_Matrix_VCO.store_data(TestNDO,1)!=0) return -1; //Notar que no requiere validar velocidad constante para almacenar; almacena todos los periodos bien rotados.
gstedile 1:30b1ca228fc7 310 }
gstedile 1:30b1ca228fc7 311 else {
gstedile 1:30b1ca228fc7 312
gstedile 1:30b1ca228fc7 313 if(err_Rot==1) return 1; // Tiempo entre muestras demasiado grande. Períódo no válido.
gstedile 1:30b1ca228fc7 314 else return 2; // Timestamp no válido.
gstedile 1:30b1ca228fc7 315 }
gstedile 1:30b1ca228fc7 316 }
gstedile 1:30b1ca228fc7 317 }
gstedile 1:30b1ca228fc7 318 else{ // Rota valores para la velocidad indicada, seteando valores crecientes de consumo para testing
gstedile 1:30b1ca228fc7 319
gstedile 0:e40cf759ba9a 320
gstedile 1:30b1ca228fc7 321 TestNDO.np_concat=0; // Cantidad de periodos concatenados:-->0: Solo valores de inicio.
gstedile 1:30b1ca228fc7 322 float virtual_longitude=-58.5797; // Mantiene cte la Longitud.
gstedile 1:30b1ca228fc7 323 float virtual_latitude=-34.4251+((virtual_speed*virtual_timestamp)/(59.99999981628485*3600));// Tomo delta_t virtual de (virtual_speed*virtual_timestamp) y calculo
gstedile 1:30b1ca228fc7 324 // latitud navegada en virtual_timestamp @virtual_speed y longitud cte.
gstedile 1:30b1ca228fc7 325 virtual_time=virtual_timestamp; //en formato NMEA hhmmss,ss
gstedile 1:30b1ca228fc7 326 float virtual_counter=0.01*virtual_timestamp*virtual_timestamp; // Simulacion de consumo creciente; modificar y probar
gstedile 1:30b1ca228fc7 327 int err_Rot=TestNDO.rotate_data(virtual_longitude, virtual_latitude, virtual_time, virtual_counter, NAVIGATION_VMATRIX.vel_max);
gstedile 1:30b1ca228fc7 328 if(err_Rot==0){ // Si la rotacion fue 100% exitosa
gstedile 1:30b1ca228fc7 329 if(Test_Matrix_VCO.store_data(TestNDO,2)==-1) return -1; // Notar que requiere 2 períodos a igual velocidad para que se almacene definitivamente.
gstedile 1:30b1ca228fc7 330 }
gstedile 1:30b1ca228fc7 331 else {
gstedile 1:30b1ca228fc7 332 if(err_Rot==1) return 1; // Tiempo entre muestras demasiado grande. Períódo no válido.
gstedile 1:30b1ca228fc7 333 else return 2; // Timestamp no válido.
gstedile 1:30b1ca228fc7 334 }
gstedile 1:30b1ca228fc7 335 }
gstedile 1:30b1ca228fc7 336 return 0;
gstedile 1:30b1ca228fc7 337 }
gstedile 1:30b1ca228fc7 338
gstedile 1:30b1ca228fc7 339
gstedile 1:30b1ca228fc7 340 /* Function print_signal: imprime un simbolo a partir de las coordenadas de un rectangulo: signal=0-> ZONA VCO,1:Sin datos; 2:Circulo; 3:flecha; 4: elipse */
gstedile 1:30b1ca228fc7 341
gstedile 1:30b1ca228fc7 342
gstedile 1:30b1ca228fc7 343 void print_signal(int x1, int y1, int x2, int y2, int R, int G, int B, figura FIG, sentido S){
gstedile 1:30b1ca228fc7 344 int tx1,tx2,tx3,rx1,rx2,ty1,ty2,ty3,ry1,ry2, delta_ty1,delta_ty2,delta_ty3;
gstedile 1:30b1ca228fc7 345 int cex,cey,cer1,cer2;
gstedile 1:30b1ca228fc7 346 cex=(x1+x2)/2;
gstedile 1:30b1ca228fc7 347 cey=(y1+y2)/2;
gstedile 1:30b1ca228fc7 348 cer2= (y2-y1)/2;
gstedile 1:30b1ca228fc7 349 cer1= (x2-x1)/2;
gstedile 1:30b1ca228fc7 350
gstedile 1:30b1ca228fc7 351 switch (S){
gstedile 1:30b1ca228fc7 352 case 1: { // UP
gstedile 1:30b1ca228fc7 353 tx1=(x2+x1)/2;
gstedile 1:30b1ca228fc7 354 ty1=y1;
gstedile 1:30b1ca228fc7 355 tx2=x2;
gstedile 1:30b1ca228fc7 356 ty2=(y2+y1)/2;
gstedile 1:30b1ca228fc7 357 tx3=x1;
gstedile 1:30b1ca228fc7 358 ty3=(y2+y1)/2;
gstedile 1:30b1ca228fc7 359 delta_ty1=8;
gstedile 1:30b1ca228fc7 360 delta_ty2=-5;
gstedile 1:30b1ca228fc7 361 delta_ty3=-5;
gstedile 1:30b1ca228fc7 362 rx1=(x2+3*x1)/4;
gstedile 1:30b1ca228fc7 363 ry1=(y2+y1)/2;
gstedile 1:30b1ca228fc7 364 rx2=(3*x2+x1)/4;
gstedile 1:30b1ca228fc7 365 ry2=y2;
gstedile 1:30b1ca228fc7 366 }
gstedile 1:30b1ca228fc7 367 break;
gstedile 1:30b1ca228fc7 368 case 0: { // DWN
gstedile 1:30b1ca228fc7 369 tx1=(x2+x1)/2;
gstedile 1:30b1ca228fc7 370 ty1=y2;
gstedile 1:30b1ca228fc7 371 tx2=x2;
gstedile 1:30b1ca228fc7 372 ty2=(y2+y1)/2;
gstedile 1:30b1ca228fc7 373 tx3=x1;
gstedile 1:30b1ca228fc7 374 ty3=(y2+y1)/2;
gstedile 1:30b1ca228fc7 375 delta_ty1=-8;
gstedile 1:30b1ca228fc7 376 delta_ty2=5;
gstedile 1:30b1ca228fc7 377 delta_ty3=5;
gstedile 1:30b1ca228fc7 378 rx1=(x2+3*x1)/4;
gstedile 1:30b1ca228fc7 379 ry1=y1;
gstedile 1:30b1ca228fc7 380 rx2=(3*x2+x1)/4;
gstedile 1:30b1ca228fc7 381 ry2=(y2+y1)/2;
gstedile 0:e40cf759ba9a 382 }
gstedile 1:30b1ca228fc7 383 break;
gstedile 1:30b1ca228fc7 384 default:
gstedile 1:30b1ca228fc7 385 break;
gstedile 1:30b1ca228fc7 386 }
gstedile 1:30b1ca228fc7 387 switch (FIG){
gstedile 1:30b1ca228fc7 388 case 0:
gstedile 1:30b1ca228fc7 389 lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue);
gstedile 1:30b1ca228fc7 390 lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153));
gstedile 1:30b1ca228fc7 391 lcd.foreground(BrightBlue);
gstedile 1:30b1ca228fc7 392 lcd.fillroundrect( x1+2,y1+2, x2-2,y2-2, 5,4, RGB(R,G,B));
gstedile 1:30b1ca228fc7 393 lcd.SetTextCursor(x1+10,y1+(y2-y1)/5);
gstedile 1:30b1ca228fc7 394 lcd.background(BrightGreen);
gstedile 1:30b1ca228fc7 395 lcd.foreground(White);
gstedile 1:30b1ca228fc7 396 lcd.printf ("NAVEGANDO");
gstedile 1:30b1ca228fc7 397 lcd.SetTextCursor(x1+55,y1+(y2-y1)/2-10);
gstedile 1:30b1ca228fc7 398 //lcd.SetTextCursor(132,140);
gstedile 1:30b1ca228fc7 399 lcd.printf ("EN");
gstedile 1:30b1ca228fc7 400 lcd.SetTextCursor(x1+15,y1+(y2-y1)*2/3);
gstedile 1:30b1ca228fc7 401 //lcd.SetTextCursor(135,170);
gstedile 1:30b1ca228fc7 402 lcd.printf ("ZONA VCO");
gstedile 1:30b1ca228fc7 403 break;
gstedile 1:30b1ca228fc7 404 case 1:
gstedile 1:30b1ca228fc7 405 lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue);
gstedile 1:30b1ca228fc7 406 lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153));
gstedile 1:30b1ca228fc7 407 lcd.foreground(BrightBlue);
gstedile 1:30b1ca228fc7 408 lcd.SetTextCursor(x1+10,y1+28);
gstedile 1:30b1ca228fc7 409 lcd.printf ("SIN DATOS");
gstedile 1:30b1ca228fc7 410 lcd.SetTextCursor(x1+1,y1+48);
gstedile 1:30b1ca228fc7 411 lcd.printf ("SUFICIENTES\r\n");
gstedile 1:30b1ca228fc7 412 break;
gstedile 1:30b1ca228fc7 413 case 2:
gstedile 1:30b1ca228fc7 414 lcd.circle( cex,cey, cer2+10, BrightBlue);
gstedile 1:30b1ca228fc7 415 lcd.fillcircle( cex,cey,cer2+5,RGB(R,G,B));
gstedile 1:30b1ca228fc7 416
gstedile 1:30b1ca228fc7 417 break;
gstedile 1:30b1ca228fc7 418 case 3:
gstedile 1:30b1ca228fc7 419 lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue);
gstedile 1:30b1ca228fc7 420 lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153));
gstedile 1:30b1ca228fc7 421 lcd.fillroundrect(rx1,ry1, rx2,ry2, 5,3, RGB(R,G,B) );
gstedile 1:30b1ca228fc7 422 lcd.filltriangle( tx1,ty1, tx2,ty2, tx3,ty3, RGB(R,G,B));
gstedile 1:30b1ca228fc7 423 lcd.SetTextCursor(x1+(x2-x1)/2-9,y1+(y2-y1)/5);
gstedile 1:30b1ca228fc7 424 lcd.background(BrightGreen);
gstedile 1:30b1ca228fc7 425 lcd.foreground(Black);
gstedile 1:30b1ca228fc7 426 lcd.printf ("A");
gstedile 1:30b1ca228fc7 427 lcd.SetTextCursor(x1+(x2-x1)/3-6,y1+(y2-y1)/2-10);
gstedile 1:30b1ca228fc7 428 //lcd.SetTextCursor(132,140);
gstedile 1:30b1ca228fc7 429 lcd.printf ("ZONA");
gstedile 1:30b1ca228fc7 430 lcd.SetTextCursor(x1+(x2-x1)/3-3,y1+(y2-y1)*2/3);
gstedile 1:30b1ca228fc7 431 //lcd.SetTextCursor(135,170);
gstedile 1:30b1ca228fc7 432 lcd.printf ("VCO");
gstedile 1:30b1ca228fc7 433 break;
gstedile 1:30b1ca228fc7 434 case 4:
gstedile 1:30b1ca228fc7 435 lcd.ellipse( cex,cey, cer1,cer2, BrightBlue);
gstedile 1:30b1ca228fc7 436 lcd.fillellipse( cex,cey, cer1-5,cer2-5, RGB(R,G,B));
gstedile 1:30b1ca228fc7 437 default:
gstedile 1:30b1ca228fc7 438 lcd.circle( cex,cey, cer2+10, Blue);
gstedile 1:30b1ca228fc7 439 lcd.fillcircle( cex,cey,cer2+5,RGB(R,G,B));
gstedile 1:30b1ca228fc7 440 break;
gstedile 1:30b1ca228fc7 441
gstedile 1:30b1ca228fc7 442 }
gstedile 1:30b1ca228fc7 443
gstedile 1:30b1ca228fc7 444
gstedile 1:30b1ca228fc7 445 // lcd.printf("printing 3 x 2 = %d", 3*2);
gstedile 1:30b1ca228fc7 446 // lcd.circle( cex,cey, cer2+10, Blue);
gstedile 1:30b1ca228fc7 447 // lcd.fillcircle( cex,cey,cer2+5, Cyan);
gstedile 1:30b1ca228fc7 448 /// lcd.ellipse( 440,75, 35,20, BrightBlue);
gstedile 1:30b1ca228fc7 449 /// lcd.fillellipse( 440,75, 25,10, Blue);
gstedile 1:30b1ca228fc7 450 // lcd.triangle( tx1,ty1,tx2,ty2,tx3,ty3, Blue);
gstedile 1:30b1ca228fc7 451 // lcd.filltriangle( tx1,ty1+delta_ty1, tx2-5,ty2+delta_ty2, tx3+5,ty3+delta_ty3, RGB(R,G,B));
gstedile 0:e40cf759ba9a 452
gstedile 1:30b1ca228fc7 453 /// lcd.rect( 400,130, 475,155, Brown);
gstedile 1:30b1ca228fc7 454 /// lcd.fillrect( 405,135, 470,150, Pink);
gstedile 1:30b1ca228fc7 455
gstedile 1:30b1ca228fc7 456 // lcd.fillroundrect(x1-4,y1-4, x2+4,y2+4, 5,3,Blue);
gstedile 1:30b1ca228fc7 457 // lcd.roundrect( rx1,ry1,rx2,ry2, 10,8, Blue);
gstedile 1:30b1ca228fc7 458 // lcd.fillroundrect(rx1+5,ry1+5, rx2-5,ry2-5, 5,3, RGB(R,G,B) );
gstedile 1:30b1ca228fc7 459
gstedile 1:30b1ca228fc7 460 }
gstedile 1:30b1ca228fc7 461
gstedile 1:30b1ca228fc7 462
gstedile 1:30b1ca228fc7 463 //###################----------- MAIN ------------#########################
gstedile 0:e40cf759ba9a 464
gstedile 0:e40cf759ba9a 465 int main()
gstedile 1:30b1ca228fc7 466 { int VCC[2]; // Array de valores crucero críticos. VCC[0]=VCO; VCC[1]=VMC (Velocidad de Máximo Consumo)
gstedile 1:30b1ca228fc7 467 VCC[0]=-1;
gstedile 1:30b1ca228fc7 468 VCC[1]=-1;
gstedile 1:30b1ca228fc7 469 int R,G,B=0;
gstedile 1:30b1ca228fc7 470 int R1,G1,B1=0;
gstedile 1:30b1ca228fc7 471 int err_Mtrx=0;
gstedile 1:30b1ca228fc7 472 float PRFM=-1; // Performance
gstedile 1:30b1ca228fc7 473 sentido SENTIDO; // Sentido de la flecha
gstedile 1:30b1ca228fc7 474 figura FIG; //
gstedile 1:30b1ca228fc7 475 pc.baud(460800);
gstedile 0:e40cf759ba9a 476 pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
gstedile 0:e40cf759ba9a 477 lcd.init();
gstedile 1:30b1ca228fc7 478 lcd.TouchPanelCalibrate(); // Funcion modificada para fijar calibracion.
gstedile 0:e40cf759ba9a 479 lcd.cls();
gstedile 0:e40cf759ba9a 480 rect_t PrintScreenRect = { 425-65, 20, 425+65, 60}; // Rectangulo para encuadrar boton.
gstedile 0:e40cf759ba9a 481 lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras.
gstedile 0:e40cf759ba9a 482 lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 483 GPS gps(p9, p10); // Agrego para comunicacion con el GPS
gstedile 0:e40cf759ba9a 484
gstedile 0:e40cf759ba9a 485
gstedile 0:e40cf759ba9a 486 //-------------------------------------------------------------------------------------------------------------
gstedile 1:30b1ca228fc7 487 // Sensor de flujo:
gstedile 0:e40cf759ba9a 488 InterruptIn pulse_sensor(p15); // Defino pulse_sensor como una entrada de interrupción en p15 .
gstedile 0:e40cf759ba9a 489 pulse_sensor.mode(PullUp); // PullUp para esa entrada.
gstedile 0:e40cf759ba9a 490 //pulse_sensor.rise(&trigger); // Dispara interrupción con flanco ascendente. (Podría tambien ser desecendente--> fall)
gstedile 0:e40cf759ba9a 491 pulse_sensor.fall(&trigger);
gstedile 1:30b1ca228fc7 492 //--------------------------------------------------------------------------------------------------------------
gstedile 0:e40cf759ba9a 493
gstedile 0:e40cf759ba9a 494 lcd.SetTextCursor(0,0); // Posicionamiento de cursor.
gstedile 1:30b1ca228fc7 495 lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n");
gstedile 1:30b1ca228fc7 496 if (!sd2mtrx(NAVIGATION_VMATRIX, sd_file)) lcd.puts("Datos leidos de SD card\r\n"); // Cargando matriz desde SD.
gstedile 0:e40cf759ba9a 497 else{
gstedile 0:e40cf759ba9a 498 lcd.puts("Error al leer los datos.\r\n Inicio sin datos historicos.\r\n");
gstedile 1:30b1ca228fc7 499 if (TESTING){
gstedile 1:30b1ca228fc7 500 err_Mtrx=build_default_Mtrx(NAVIGATION_VMATRIX,TestNAV,0,0);
gstedile 1:30b1ca228fc7 501 if(err_Mtrx!=0) lcd.printf("Error al crear la Matriz default.%d\r\n",err_Mtrx); // Creando matriz de inicio default.
gstedile 1:30b1ca228fc7 502 else lcd.printf("Matriz default creada con exito.\r\n");
gstedile 1:30b1ca228fc7 503 }
gstedile 0:e40cf759ba9a 504 if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n");
gstedile 1:30b1ca228fc7 505 else {
gstedile 1:30b1ca228fc7 506 lcd.puts("Error al guardar los datos default.\r\nCreando directorio en SD card...\r\n");
gstedile 1:30b1ca228fc7 507 if(!mkdir(sd_dir, 0777)){ // Creando directorio si no existe.
gstedile 1:30b1ca228fc7 508 lcd.printf("Creado: %s\r\n", sd_dir);
gstedile 1:30b1ca228fc7 509 lcd.printf("Cargando datos de inicio default en SD card...\r\n");
gstedile 1:30b1ca228fc7 510 if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n");
gstedile 1:30b1ca228fc7 511 else lcd.puts("Error al guardar los datos default.\r\nNo se podran almacenar los datos.\r\n");
gstedile 1:30b1ca228fc7 512 }
gstedile 1:30b1ca228fc7 513 else lcd.puts("Error al guardar los datos default.\r\nNo se podran almacenar los datos.\r\n");
gstedile 0:e40cf759ba9a 514 }
gstedile 1:30b1ca228fc7 515 }
gstedile 0:e40cf759ba9a 516 wait(3);
gstedile 1:30b1ca228fc7 517
gstedile 1:30b1ca228fc7 518 float delta=5.0;//DEBUG
gstedile 1:30b1ca228fc7 519 float virtual_tmstmp=0.0;//DEBUG
gstedile 0:e40cf759ba9a 520
gstedile 1:30b1ca228fc7 521 int prueba=0; // BORRAR ESTO. ES SOLO PARA PROBAR <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
gstedile 0:e40cf759ba9a 522
gstedile 1:30b1ca228fc7 523 // -------------------------------- LOOP INFINITO ------------------------------------
gstedile 0:e40cf759ba9a 524 while(1) {
gstedile 0:e40cf759ba9a 525
gstedile 0:e40cf759ba9a 526 lcd.SetTextCursor(0,0); // Pongo cursor en posicion
gstedile 0:e40cf759ba9a 527 lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n");
gstedile 1:30b1ca228fc7 528 if (DEBUG_GPS) lcd.printf("M0: %s \r\n\r\n", gps.msg); //Imprimo el mensaje crudo proveniente de la uart
gstedile 0:e40cf759ba9a 529
gstedile 1:30b1ca228fc7 530 if(gps.sample()) { // Si es exitosa la obtencion de datos del gps.
gstedile 0:e40cf759ba9a 531 lcd.cls();
gstedile 1:30b1ca228fc7 532 lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras.
gstedile 1:30b1ca228fc7 533 lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 1:30b1ca228fc7 534 lcd.SetTextCursor(0,0); // Cursor en posicion
gstedile 0:e40cf759ba9a 535 lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n");
gstedile 0:e40cf759ba9a 536
gstedile 1:30b1ca228fc7 537 if (!NAVIGATION_OBJECT.rotate_data(gps.longitude, gps.latitude, gps.time, Counter,NAVIGATION_VMATRIX.vel_max )){
gstedile 1:30b1ca228fc7 538 NAVIGATION_OBJECT.LAST_NAV_DATA[cons_interpolated]=0; // Dato tipo recolectado
gstedile 1:30b1ca228fc7 539 err_Store=NAVIGATION_VMATRIX.store_data(NAVIGATION_OBJECT,2); // Luego de rotar los datos en la tabla de navegacion,
gstedile 1:30b1ca228fc7 540 // la guarda en la matriz segun criterios de la clase VCODATA
gstedile 1:30b1ca228fc7 541
gstedile 1:30b1ca228fc7 542 int i=int(NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p]);
gstedile 1:30b1ca228fc7 543 //int VCO=NAVIGATION_VMATRIX.get_VCO(&VCC[0]);
gstedile 1:30b1ca228fc7 544 NAVIGATION_V_SMOOTH_MTRX.smooth(4, NAVIGATION_VMATRIX); // Genera matriz de datos filtrados con pasabajos
gstedile 1:30b1ca228fc7 545 int VCO=NAVIGATION_V_SMOOTH_MTRX.get_VCO(&VCC[0]); // VCO OBTENIDA DE MATRIZ FILTRADA.
gstedile 1:30b1ca228fc7 546
gstedile 1:30b1ca228fc7 547
gstedile 1:30b1ca228fc7 548 if (DEBUG1) {
gstedile 1:30b1ca228fc7 549 lcd.puts("Rotacion exitosa!-->");
gstedile 1:30b1ca228fc7 550 lcd.printf("Error de rotacion:\t %d\r\n",err_Store); // DEBUG
gstedile 1:30b1ca228fc7 551 lcd.printf("Speed_f_Mtrx(%d):\t %lf kn.\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]); // DEBUG
gstedile 1:30b1ca228fc7 552 lcd.printf("Speed_f_Last(%d):\t\t %lf km/h.\r\n",i, NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p]*1.852); // DEBUG
gstedile 1:30b1ca228fc7 553 lcd.printf("Time_f_Mtrx(%d):\t %lf Hours.\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]); // DEBUG
gstedile 1:30b1ca228fc7 554 lcd.printf("Time_f_Last(%d):\t %lf Hours.\r\n",i, NAVIGATION_OBJECT.LAST_NAV_DATA[time_f]); // DEBUG
gstedile 1:30b1ca228fc7 555 lcd.printf("Dist_p_Mtrx(%d):\t %lf miles.\r\n",i,NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]); // DEBUG
gstedile 1:30b1ca228fc7 556 }
gstedile 1:30b1ca228fc7 557 lcd.printf("Posicion: Long(%d):\t %lf ; Lat: %lf\r\n",i,NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[longitude_f],NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[latitude_f]); // DEBUG
gstedile 1:30b1ca228fc7 558 lcd.printf("FlujoVCOmtrx(%d):\t %lf Litros/Hora\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_hour_p]); // DEBUG
gstedile 1:30b1ca228fc7 559 lcd.printf("FlujoVCOmtrx(%d):\t %lf Litros/Milla\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_mile_p]); // DEBUG
gstedile 1:30b1ca228fc7 560 lcd.printf("Cons. Acumulado:\t %lf l\r\n", LCounter);
gstedile 1:30b1ca228fc7 561 lcd.printf("VCO:\t %d knots\r\n", VCO);
gstedile 1:30b1ca228fc7 562
gstedile 1:30b1ca228fc7 563 NAVIGATION_VMATRIX.interpolate(); // Interpolacion.
gstedile 1:30b1ca228fc7 564 if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos guardados en SD card\r\n"); // Almacenamiento de datos en SD.
gstedile 1:30b1ca228fc7 565 else lcd.printf("Error al guardar los datos.\r\n");
gstedile 1:30b1ca228fc7 566
gstedile 1:30b1ca228fc7 567 //_____________________________________________________________________________________________________________________
gstedile 1:30b1ca228fc7 568 int signal_x=80; // REGION DE SEÑALIZACION
gstedile 1:30b1ca228fc7 569 int signal_y=60;
gstedile 1:30b1ca228fc7 570 int signal_x_sz=120;
gstedile 1:30b1ca228fc7 571 int signal_y_sz=150;
gstedile 1:30b1ca228fc7 572
gstedile 1:30b1ca228fc7 573 //PRFM=NAVIGATION_VMATRIX.performance(i);
gstedile 1:30b1ca228fc7 574 PRFM=NAVIGATION_V_SMOOTH_MTRX.performance(i); // PERFORMANCE OBTENIDA DE MATRIZ FILTRADA.
gstedile 1:30b1ca228fc7 575
gstedile 1:30b1ca228fc7 576 R1=0; // COLOR DEFAULT PARA CIRCULO DE REFERENCIA DE PERFORMANCE (VERDE)
gstedile 1:30b1ca228fc7 577 G1=255;
gstedile 1:30b1ca228fc7 578 B1=0;
gstedile 1:30b1ca228fc7 579 lcd.foreground(RGB(R1,G1,B1));
gstedile 1:30b1ca228fc7 580 lcd.SetTextCursor(200,245);
gstedile 1:30b1ca228fc7 581 lcd.printf("VCO: %d \t\t",VCC[0]);
gstedile 1:30b1ca228fc7 582 lcd.printf("VMC: %d \r\n",VCC[1]);
gstedile 1:30b1ca228fc7 583 if (PRFM!=-1 && VCC[0]!=-1){
gstedile 1:30b1ca228fc7 584 if (PRFM>0.98) {
gstedile 1:30b1ca228fc7 585 R=0;
gstedile 1:30b1ca228fc7 586 G=255;
gstedile 1:30b1ca228fc7 587 B=0;
gstedile 1:30b1ca228fc7 588 }
gstedile 1:30b1ca228fc7 589 else {
gstedile 1:30b1ca228fc7 590 if (PRFM<0.75){
gstedile 1:30b1ca228fc7 591 R=255;
gstedile 1:30b1ca228fc7 592 G=255*4*PRFM/3;
gstedile 1:30b1ca228fc7 593 B=0;
gstedile 1:30b1ca228fc7 594 }
gstedile 1:30b1ca228fc7 595 else {
gstedile 1:30b1ca228fc7 596 R=255*4*(1-PRFM);
gstedile 1:30b1ca228fc7 597 G=255;
gstedile 1:30b1ca228fc7 598 B=0;
gstedile 1:30b1ca228fc7 599 }
gstedile 1:30b1ca228fc7 600 }
gstedile 1:30b1ca228fc7 601 float delta_vel= NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]-VCC[0]; // ES IGUAL QUE EN MTRX FILTRADA
gstedile 1:30b1ca228fc7 602 if (fabs(delta_vel)<2){
gstedile 1:30b1ca228fc7 603 FIG=ZONA;
gstedile 1:30b1ca228fc7 604 signal_x=60; // REGION DE SEÑALIZACION
gstedile 1:30b1ca228fc7 605 signal_y=80;
gstedile 1:30b1ca228fc7 606 signal_x_sz=150;
gstedile 1:30b1ca228fc7 607 signal_y_sz=120;
gstedile 1:30b1ca228fc7 608 }
gstedile 1:30b1ca228fc7 609 else FIG=FLECHA;
gstedile 1:30b1ca228fc7 610 if (delta_vel<0) SENTIDO=UP;
gstedile 1:30b1ca228fc7 611 else SENTIDO=DWN;
gstedile 1:30b1ca228fc7 612
gstedile 1:30b1ca228fc7 613
gstedile 1:30b1ca228fc7 614 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, 0, 255, 0,FIG,SENTIDO); // SI ESTA EN ENTORNO DE VCO--> IMPRIMIR "ZONA VCO".
gstedile 1:30b1ca228fc7 615
gstedile 1:30b1ca228fc7 616 }
gstedile 1:30b1ca228fc7 617 else {
gstedile 1:30b1ca228fc7 618 int signal_x=80; //CAMBIO ZONA DE SEÑALIZACION (PARA TEXTO "SIN DATOS..")
gstedile 1:30b1ca228fc7 619 int signal_y=85;
gstedile 1:30b1ca228fc7 620 signal_y_sz=100;
gstedile 1:30b1ca228fc7 621 signal_x_sz=130;
gstedile 1:30b1ca228fc7 622 R1=190;
gstedile 1:30b1ca228fc7 623 G1=190;
gstedile 1:30b1ca228fc7 624 B1=190;
gstedile 1:30b1ca228fc7 625 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz,R,G,B,SIN_DT,NO); // SIN DATOS: SOLO RECUADRO PARA TEXTO
gstedile 1:30b1ca228fc7 626
gstedile 1:30b1ca228fc7 627 }
gstedile 1:30b1ca228fc7 628 signal_x=265; // ZONA PERFORMANCE
gstedile 1:30b1ca228fc7 629 signal_y=85;
gstedile 1:30b1ca228fc7 630 signal_x_sz=90;
gstedile 1:30b1ca228fc7 631 signal_y_sz=90;
gstedile 1:30b1ca228fc7 632 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, R1, G1, B1,CIRC,NO); // CIRCULO VERDE
gstedile 1:30b1ca228fc7 633
gstedile 1:30b1ca228fc7 634 if (PRFM >= 0){
gstedile 1:30b1ca228fc7 635 if (SENTIDO==DWN) {
gstedile 1:30b1ca228fc7 636 print_signal(signal_x+5, (signal_y+5)-(signal_y_sz*(1-PRFM)), signal_x+signal_x_sz-5, (signal_y+signal_y_sz-5)-(signal_y_sz*(1-PRFM)), R, G, B,CIRC,NO);
gstedile 1:30b1ca228fc7 637 lcd.SetTextCursor(signal_x+20,(signal_y+5)-(signal_y_sz*(1-PRFM))+ 25);
gstedile 1:30b1ca228fc7 638 lcd.foreground(RGB(0,0,0));
gstedile 1:30b1ca228fc7 639 lcd.background(RGB(R,G,B));
gstedile 1:30b1ca228fc7 640 lcd.SelectUserFont(BPG_Arial31x32);
gstedile 1:30b1ca228fc7 641 lcd.printf ("%.2f\r\n",PRFM);
gstedile 1:30b1ca228fc7 642 }
gstedile 1:30b1ca228fc7 643 else {
gstedile 1:30b1ca228fc7 644 print_signal(signal_x+5, (signal_y+5)+(signal_y_sz*(1-PRFM)), signal_x+signal_x_sz-5, (signal_y+signal_y_sz-5)+(signal_y_sz*(1-PRFM)), R, G, B,CIRC,NO);
gstedile 1:30b1ca228fc7 645 lcd.SetTextCursor(signal_x+20,(signal_y+5)+(signal_y_sz*(1-PRFM))+ 25);
gstedile 1:30b1ca228fc7 646 lcd.foreground(RGB(0,0,0));
gstedile 1:30b1ca228fc7 647 lcd.background(RGB(R,G,B));
gstedile 1:30b1ca228fc7 648 lcd.SelectUserFont(BPG_Arial31x32);
gstedile 1:30b1ca228fc7 649 lcd.printf ("%.2f\r\n",PRFM);
gstedile 1:30b1ca228fc7 650 }
gstedile 1:30b1ca228fc7 651 }
gstedile 1:30b1ca228fc7 652 lcd.background(Black);
gstedile 1:30b1ca228fc7 653 lcd.foreground(RGB(0,255,0));
gstedile 1:30b1ca228fc7 654 lcd.SetTextCursor(20,245);
gstedile 1:30b1ca228fc7 655 lcd.SelectUserFont(BPG_Arial20x20);
gstedile 1:30b1ca228fc7 656 lcd.printf("VEL: %.1f \r\n",NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p]); // VELOCIDAD ACTUAL.
gstedile 0:e40cf759ba9a 657
gstedile 1:30b1ca228fc7 658 //____________________________________________________________________________________________________________________________________________________________
gstedile 0:e40cf759ba9a 659 }
gstedile 0:e40cf759ba9a 660 else lcd.puts("Periodo no valido!\r\n");
gstedile 0:e40cf759ba9a 661
gstedile 1:30b1ca228fc7 662 }
gstedile 1:30b1ca228fc7 663 else { // No hay datos gps
gstedile 0:e40cf759ba9a 664 lcd.background(Black);
gstedile 0:e40cf759ba9a 665 lcd.cls();
gstedile 1:30b1ca228fc7 666 lcd.foreground(RGB(0,255,0)); // Seteo del color de las letras.
gstedile 0:e40cf759ba9a 667 lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 0:e40cf759ba9a 668 lcd.SetTextCursor(0,0); // Posicionamiento de cursor.
gstedile 0:e40cf759ba9a 669 lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n");
gstedile 1:30b1ca228fc7 670 lcd.SetTextCursor(0,20);
gstedile 0:e40cf759ba9a 671
gstedile 1:30b1ca228fc7 672 if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n"); //DEBUG
gstedile 1:30b1ca228fc7 673 else lcd.printf("Error al guardar los datos default.\r\n"); //DEBUG
gstedile 1:30b1ca228fc7 674
gstedile 1:30b1ca228fc7 675 lcd.printf("Aun no hay datos gps disponibles. Usando historicos.\r\n");
gstedile 0:e40cf759ba9a 676
gstedile 1:30b1ca228fc7 677 //lcd.printf("Timetick %lf h\r\n", NAVIGATION_OBJECT.LAST_NAV_DATA[time_f]);
gstedile 1:30b1ca228fc7 678
gstedile 1:30b1ca228fc7 679 //_____________________________________________________________________________________________________________________
gstedile 1:30b1ca228fc7 680 int signal_x=80; // REGION DE SEÑALIZACION
gstedile 1:30b1ca228fc7 681 int signal_y=60;
gstedile 1:30b1ca228fc7 682 int signal_x_sz=120;
gstedile 1:30b1ca228fc7 683 int signal_y_sz=150;
gstedile 1:30b1ca228fc7 684
gstedile 1:30b1ca228fc7 685 if (prueba >= NAVIGATION_VMATRIX.vel_max) prueba=prueba-NAVIGATION_VMATRIX.vel_max;
gstedile 1:30b1ca228fc7 686 PRFM=NAVIGATION_VMATRIX.performance(prueba);
gstedile 1:30b1ca228fc7 687 R1=0; // COLOR DEFAULT PARA CIRCULO DE REFERENCIA DE PERFORMANCE (VERDE)
gstedile 1:30b1ca228fc7 688 G1=255;
gstedile 1:30b1ca228fc7 689 B1=0;
gstedile 1:30b1ca228fc7 690 lcd.foreground(RGB(R1,G1,B1));
gstedile 1:30b1ca228fc7 691 //lcd.printf("Indice: %d \r\n",prueba);
gstedile 1:30b1ca228fc7 692 //lcd.printf("Perf.: %f \r\n",PRFM);
gstedile 1:30b1ca228fc7 693 lcd.SetTextCursor(200,245);
gstedile 1:30b1ca228fc7 694 lcd.printf("VCO: %d \t\t",NAVIGATION_VMATRIX.get_VCO(&VCC[0]));
gstedile 1:30b1ca228fc7 695 lcd.printf("VMC: %d \r\n",VCC[1]);
gstedile 1:30b1ca228fc7 696 if (PRFM!=-1 && VCC[0]!=-1){
gstedile 1:30b1ca228fc7 697 if (PRFM>0.98) {
gstedile 1:30b1ca228fc7 698 R=0;
gstedile 1:30b1ca228fc7 699 G=255;
gstedile 1:30b1ca228fc7 700 B=0;
gstedile 1:30b1ca228fc7 701 }
gstedile 1:30b1ca228fc7 702 else {
gstedile 1:30b1ca228fc7 703 if (PRFM<0.75){
gstedile 1:30b1ca228fc7 704 R=255;
gstedile 1:30b1ca228fc7 705 G=255*4*PRFM/3;
gstedile 1:30b1ca228fc7 706 B=0;
gstedile 1:30b1ca228fc7 707 }
gstedile 1:30b1ca228fc7 708 else {
gstedile 1:30b1ca228fc7 709 R=255*4*(1-PRFM);
gstedile 1:30b1ca228fc7 710 G=255;
gstedile 1:30b1ca228fc7 711 B=0;
gstedile 1:30b1ca228fc7 712 }
gstedile 1:30b1ca228fc7 713 }
gstedile 1:30b1ca228fc7 714 float delta_vel= NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[speed_p]-VCC[0];
gstedile 1:30b1ca228fc7 715
gstedile 1:30b1ca228fc7 716 //float delta_vel=int(NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p])-VCC[0];
gstedile 1:30b1ca228fc7 717
gstedile 1:30b1ca228fc7 718 if (fabs(delta_vel)<2){
gstedile 1:30b1ca228fc7 719 FIG=ZONA;
gstedile 1:30b1ca228fc7 720 signal_x=60; // REGION DE SEÑALIZACION
gstedile 1:30b1ca228fc7 721 signal_y=80;
gstedile 1:30b1ca228fc7 722 signal_x_sz=150;
gstedile 1:30b1ca228fc7 723 signal_y_sz=120;
gstedile 1:30b1ca228fc7 724 }
gstedile 1:30b1ca228fc7 725 else FIG=FLECHA;
gstedile 1:30b1ca228fc7 726 if (delta_vel<0) SENTIDO=UP;
gstedile 1:30b1ca228fc7 727 else SENTIDO=DWN;
gstedile 1:30b1ca228fc7 728
gstedile 1:30b1ca228fc7 729
gstedile 1:30b1ca228fc7 730 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, 0, 255, 0,FIG,SENTIDO); // SI ESTA EN ENTORNO DE VCO--> IMPRIMIR "ZONA VCO".
gstedile 1:30b1ca228fc7 731
gstedile 1:30b1ca228fc7 732 /*
gstedile 1:30b1ca228fc7 733 lcd.SetTextCursor(signal_x+signal_x_sz/2-6,signal_y+signal_y_sz/4);
gstedile 1:30b1ca228fc7 734 lcd.background(RGB(0,255,0));
gstedile 1:30b1ca228fc7 735 lcd.foreground(RGB(0,0,255));
gstedile 1:30b1ca228fc7 736 lcd.printf ("A");
gstedile 1:30b1ca228fc7 737 lcd.SetTextCursor(signal_x+signal_x_sz/3-3,signal_y+signal_y_sz/2-10);
gstedile 1:30b1ca228fc7 738 //lcd.SetTextCursor(132,140);
gstedile 1:30b1ca228fc7 739 lcd.printf ("ZONA");
gstedile 1:30b1ca228fc7 740 lcd.SetTextCursor(signal_x+signal_x_sz/3,signal_y+2*signal_y_sz/3);
gstedile 1:30b1ca228fc7 741 //lcd.SetTextCursor(135,170);
gstedile 1:30b1ca228fc7 742 lcd.printf ("VCO");
gstedile 1:30b1ca228fc7 743 */
gstedile 1:30b1ca228fc7 744
gstedile 0:e40cf759ba9a 745
gstedile 1:30b1ca228fc7 746 //lcd.printf("Delta_v: %.0f \r\n",delta_vel);
gstedile 1:30b1ca228fc7 747 }
gstedile 1:30b1ca228fc7 748 else {
gstedile 1:30b1ca228fc7 749 int signal_x=80; //CAMBIO ZONA DE SEÑALIZACION (PARA TEXTO "SIN DATOS..")
gstedile 1:30b1ca228fc7 750 int signal_y=85;
gstedile 1:30b1ca228fc7 751 signal_y_sz=100;
gstedile 1:30b1ca228fc7 752 signal_x_sz=130;
gstedile 1:30b1ca228fc7 753 R1=190;
gstedile 1:30b1ca228fc7 754 G1=190;
gstedile 1:30b1ca228fc7 755 B1=190;
gstedile 1:30b1ca228fc7 756 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz,R,G,B,SIN_DT,NO); // SIN DATOS: SOLO RECUADRO PARA TEXTO
gstedile 1:30b1ca228fc7 757
gstedile 1:30b1ca228fc7 758 }
gstedile 1:30b1ca228fc7 759 signal_x=265; // ZONA PERFORMANCE
gstedile 1:30b1ca228fc7 760 signal_y=85;
gstedile 1:30b1ca228fc7 761 signal_x_sz=90;
gstedile 1:30b1ca228fc7 762 signal_y_sz=90;
gstedile 1:30b1ca228fc7 763 print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, R1, G1, B1,CIRC,NO); // CIRCULO VERDE
gstedile 1:30b1ca228fc7 764
gstedile 1:30b1ca228fc7 765 if (SENTIDO==DWN){
gstedile 1:30b1ca228fc7 766 print_signal(signal_x+5, (signal_y+5)-(signal_y_sz*(1-PRFM)), signal_x+signal_x_sz-5, (signal_y+signal_y_sz-5)-(signal_y_sz*(1-PRFM)), R, G, B,CIRC,NO);
gstedile 1:30b1ca228fc7 767 lcd.SetTextCursor(signal_x+20,(signal_y+5)-(signal_y_sz*(1-PRFM))+ 25);
gstedile 1:30b1ca228fc7 768 lcd.foreground(RGB(0,0,0));
gstedile 1:30b1ca228fc7 769 lcd.background(RGB(R,G,B));
gstedile 1:30b1ca228fc7 770 lcd.SelectUserFont(BPG_Arial31x32);
gstedile 1:30b1ca228fc7 771 if (PRFM >= 0) lcd.printf ("%.2f\r\n",PRFM);
gstedile 1:30b1ca228fc7 772 }
gstedile 1:30b1ca228fc7 773 else {
gstedile 1:30b1ca228fc7 774 print_signal(signal_x+5, (signal_y+5)+(signal_y_sz*(1-PRFM)), signal_x+signal_x_sz-5, (signal_y+signal_y_sz-5)+(signal_y_sz*(1-PRFM)), R, G, B,CIRC,NO);
gstedile 1:30b1ca228fc7 775 lcd.SetTextCursor(signal_x+20,(signal_y+5)+(signal_y_sz*(1-PRFM))+ 25);
gstedile 1:30b1ca228fc7 776 lcd.foreground(RGB(0,0,0));
gstedile 1:30b1ca228fc7 777 lcd.background(RGB(R,G,B));
gstedile 1:30b1ca228fc7 778 lcd.SelectUserFont(BPG_Arial31x32);
gstedile 1:30b1ca228fc7 779 lcd.printf ("%.2f\r\n",PRFM);
gstedile 1:30b1ca228fc7 780 }
gstedile 1:30b1ca228fc7 781 lcd.background(Black);
gstedile 1:30b1ca228fc7 782 lcd.foreground(RGB(0,255,0));
gstedile 1:30b1ca228fc7 783 lcd.SetTextCursor(20,235);
gstedile 1:30b1ca228fc7 784 lcd.printf("Flujo Acum: %.1f \r\n",LCounter);
gstedile 1:30b1ca228fc7 785 lcd.SetTextCursor(20,245);
gstedile 1:30b1ca228fc7 786 lcd.SelectUserFont(BPG_Arial20x20);
gstedile 1:30b1ca228fc7 787 lcd.printf("Speed_p: %.1f \r\n",NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[speed_p]);
gstedile 1:30b1ca228fc7 788 prueba++;
gstedile 1:30b1ca228fc7 789 //______________________________________________________________________________________________________________________
gstedile 1:30b1ca228fc7 790
gstedile 1:30b1ca228fc7 791 if (TESTING){ //DEBUG
gstedile 1:30b1ca228fc7 792
gstedile 1:30b1ca228fc7 793 // ESTA PARTE ES PARA PROBAR EL FUNCIONAMIENTO DE LA ROTACION Y ALMACENAMIENTO DE DATOS......DEBUG.
gstedile 1:30b1ca228fc7 794 //lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras
gstedile 1:30b1ca228fc7 795
gstedile 1:30b1ca228fc7 796 float vrtl_speed=12; // pruebo cargar datos para velocidad 12.
gstedile 1:30b1ca228fc7 797 TestNAV.LAST_NAV_DATA[cons_interpolated]=0; // --> -1:Datos iniciales. 0--> recolectado (setear para testing)
gstedile 1:30b1ca228fc7 798 err_Mtrx=build_default_Mtrx(NAVIGATION_VMATRIX, TestNAV, vrtl_speed, virtual_tmstmp);
gstedile 1:30b1ca228fc7 799 if(err_Mtrx!=0){
gstedile 1:30b1ca228fc7 800 lcd.printf("Error al cargar datos en la Matriz default.%d..\r\n", err_Mtrx); // DEBUG; ya se crea la matriz en el arranque, si no hay archivo.
gstedile 1:30b1ca228fc7 801 }
gstedile 1:30b1ca228fc7 802 else lcd.printf("Datos para virtual_speed= %.1f cargado con exito.\r\n",vrtl_speed);
gstedile 1:30b1ca228fc7 803 lcd.printf("Virtual_Timestamp=%.2f.\t",virtual_tmstmp);//DEBUG
gstedile 1:30b1ca228fc7 804 virtual_tmstmp+=delta; // DEBUG Esta en formato NMEA(hhmmss.ss): no son validos los valores de segundos mayores a 59, por lo tanto
gstedile 1:30b1ca228fc7 805 // cuando se ingrese 100,00 despues de 95,00 se espera que el sistema no valide la ronda pues en ese
gstedile 1:30b1ca228fc7 806 // formato 100,00 < 95,00 (1m < 95s); seria un valor entrante menor que el anterior.
gstedile 1:30b1ca228fc7 807
gstedile 1:30b1ca228fc7 808 lcd.printf("V_time(h):%lf\r\n",TestNAV.time_NMEA2hours(virtual_tmstmp));
gstedile 1:30b1ca228fc7 809
gstedile 1:30b1ca228fc7 810 // FIN DE LA PARTE PARA PROBAR EL FUNCIONAMIENTO DE LA ROTACION Y ALMACENAMIENTO DE DATOS......DEBUG.
gstedile 1:30b1ca228fc7 811
gstedile 1:30b1ca228fc7 812 }
gstedile 1:30b1ca228fc7 813 if (DEBUG2){
gstedile 1:30b1ca228fc7 814 int buff_indx=int(NAVIGATION_VMATRIX.NAV_DATA[NAVIGATION_VMATRIX.vel_max].LAST_NAV_DATA[speed_p]+0.5); // DEBUG
gstedile 1:30b1ca228fc7 815 lcd.printf("Cons_m_p[%d]= %.3f l/ml\t",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[cons_mile_p]);
gstedile 1:30b1ca228fc7 816 lcd.printf("Dist_p[%d]= %lf ml\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[distance_p]);
gstedile 1:30b1ca228fc7 817 lcd.printf("Tiempo_f[%d]= %lf h\t",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[time_f]);
gstedile 1:30b1ca228fc7 818 lcd.printf("Tiempo_i[%d]= %lf h\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[time_i]);
gstedile 1:30b1ca228fc7 819 lcd.printf("Buff_INDX = %d \t", buff_indx);
gstedile 1:30b1ca228fc7 820 lcd.printf("Speed_p[%d]= %.2f knots\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[speed_p]);
gstedile 1:30b1ca228fc7 821 lcd.printf("Per_con[vel_max]= %d \t", NAVIGATION_VMATRIX.NAV_DATA[NAVIGATION_VMATRIX.vel_max].np_concat);
gstedile 1:30b1ca228fc7 822 lcd.printf("V_buff[%d]= %.2f\t", NAVIGATION_VMATRIX.vel_max,NAVIGATION_VMATRIX.NAV_DATA[NAVIGATION_VMATRIX.vel_max].LAST_NAV_DATA[speed_p]);
gstedile 1:30b1ca228fc7 823 lcd.printf("TestNAV-time_f = %lf \t", TestNAV.LAST_NAV_DATA[time_f]);
gstedile 1:30b1ca228fc7 824 lcd.printf("TestNAV-time_i = %lf \r\n", TestNAV.LAST_NAV_DATA[time_i]);
gstedile 1:30b1ca228fc7 825 lcd.printf("TestNAV-max_per_t = %lf \t", TestNAV.max_period_time);
gstedile 1:30b1ca228fc7 826 lcd.printf("TestNAV-time_p = %lf \r\n", TestNAV.LAST_NAV_DATA[time_f]-TestNAV.LAST_NAV_DATA[time_i]);
gstedile 1:30b1ca228fc7 827 lcd.printf("TestNAV-cons_m_p = %lf \t", TestNAV.LAST_NAV_DATA[cons_mile_p]);
gstedile 1:30b1ca228fc7 828 lcd.printf("TestNAV-cons_h_p = %lf \r\n", TestNAV.LAST_NAV_DATA[cons_hour_p]);
gstedile 1:30b1ca228fc7 829 //lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 1:30b1ca228fc7 830 }// FIN DEBUG
gstedile 1:30b1ca228fc7 831 }
gstedile 0:e40cf759ba9a 832
gstedile 1:30b1ca228fc7 833 for (int i=0;i<200;i++) { // Barrido para el touch
gstedile 0:e40cf759ba9a 834 point_t p;
gstedile 1:30b1ca228fc7 835 lcd.fillroundrect(PrintScreenRect,5,2, Green);
gstedile 1:30b1ca228fc7 836 lcd.roundrect(PrintScreenRect, 5,2, BrightBlue);
gstedile 1:30b1ca228fc7 837 lcd.foreground(BrightBlue);
gstedile 0:e40cf759ba9a 838 lcd.background(Green);
gstedile 0:e40cf759ba9a 839 lcd.puts(425-60, 22, "GET CURVE");
gstedile 0:e40cf759ba9a 840 lcd.background(Black);
gstedile 0:e40cf759ba9a 841 //wait_us(1);
gstedile 0:e40cf759ba9a 842 if (lcd.TouchPanelReadable(&p)) {
gstedile 0:e40cf759ba9a 843 //lcd.foreground(Blue);
gstedile 0:e40cf759ba9a 844 //lcd.SetTextCursor(10, 15);
gstedile 0:e40cf759ba9a 845 //lcd.printf("(%3d,%3d)", p.x, p.y);
gstedile 0:e40cf759ba9a 846 //lcd.foreground(RGB(255,255,0));
gstedile 0:e40cf759ba9a 847
gstedile 0:e40cf759ba9a 848 if (Intersect(PrintScreenRect, p)) {
gstedile 0:e40cf759ba9a 849 lcd.foreground(Red);
gstedile 0:e40cf759ba9a 850 lcd.puts(400-38, 20, "GET CURVE");
gstedile 1:30b1ca228fc7 851 //if(build_default_Mtrx(NAVIGATION_VMATRIX)==-1) lcd.printf("Error al crear la Matriz default...\r\n"); // DEBUG Curve
gstedile 0:e40cf759ba9a 852 NAVIGATION_V_SMOOTH_MTRX.smooth(4, NAVIGATION_VMATRIX); // Genera matriz de datos filtrados con pasabajos
gstedile 0:e40cf759ba9a 853 //lcd.puts(425-120, 22, "ANTES de PRINT"); //DEBUG
gstedile 0:e40cf759ba9a 854 print_VCO_curve(NAVIGATION_VMATRIX,0); // Valores recolectados
gstedile 0:e40cf759ba9a 855 wait(2);
gstedile 0:e40cf759ba9a 856 print_VCO_curve(NAVIGATION_VMATRIX,1); // Interpolados (puntos)
gstedile 0:e40cf759ba9a 857 wait(3);
gstedile 0:e40cf759ba9a 858 print_VCO_curve(NAVIGATION_V_SMOOTH_MTRX,1); // Suavizado (puntos)
gstedile 0:e40cf759ba9a 859 wait(3);
gstedile 0:e40cf759ba9a 860
gstedile 0:e40cf759ba9a 861 print_VCO_curve(NAVIGATION_VMATRIX,2); // Interpolados (lineas)
gstedile 0:e40cf759ba9a 862 wait(3);
gstedile 0:e40cf759ba9a 863 print_VCO_curve(NAVIGATION_V_SMOOTH_MTRX,2); // Suavizados (lineas)
gstedile 0:e40cf759ba9a 864 wait(3);
gstedile 1:30b1ca228fc7 865 if (DEBUG2){
gstedile 1:30b1ca228fc7 866 print_VCO_data(NAVIGATION_VMATRIX); // Volcado de datos
gstedile 1:30b1ca228fc7 867 wait(4);
gstedile 1:30b1ca228fc7 868 }
gstedile 1:30b1ca228fc7 869 //GetScreenCapture();
gstedile 0:e40cf759ba9a 870 break;
gstedile 1:30b1ca228fc7 871
gstedile 0:e40cf759ba9a 872 }
gstedile 0:e40cf759ba9a 873
gstedile 0:e40cf759ba9a 874 }
gstedile 0:e40cf759ba9a 875 lcd.foreground(RGB(255,255,0));
gstedile 0:e40cf759ba9a 876 }
gstedile 0:e40cf759ba9a 877 }
gstedile 0:e40cf759ba9a 878 }
gstedile 0:e40cf759ba9a 879
gstedile 0:e40cf759ba9a 880
gstedile 0:e40cf759ba9a 881