Para Juan

Dependencies:   NAVDATA RA8875 mbed VCODATA

Committer:
gstedile
Date:
Sat Apr 08 18:39:29 2017 +0000
Revision:
4:9901f6da64b7
Parent:
3:0c9ee19fb976
Child:
5:56d63eaa8415
Matriz de VCO carga y muestra datos con subindice "int(speed)"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gstedile 0:d92271b032c7 1
gstedile 0:d92271b032c7 2 #include "mbed.h" // v112
gstedile 0:d92271b032c7 3 #include "RA8875.h" // v102
gstedile 0:d92271b032c7 4 #include "MyFont18x32.h"
gstedile 0:d92271b032c7 5 #include "BPG_Arial08x08.h"
gstedile 0:d92271b032c7 6 #include "BPG_Arial10x10.h"
gstedile 0:d92271b032c7 7 #include "BPG_Arial20x20.h"
gstedile 0:d92271b032c7 8 #include "BPG_Arial31x32.h"
gstedile 0:d92271b032c7 9 #include "BPG_Arial63x63.h"
gstedile 0:d92271b032c7 10
gstedile 0:d92271b032c7 11 // Agrego includes para uso en la comunicacion con el gps.
gstedile 4:9901f6da64b7 12 #include "GPS.h"
gstedile 4:9901f6da64b7 13 // Agrego includes para la clase NAVDATA que maneja los datos de navegación del último período.
gstedile 4:9901f6da64b7 14 #include "NAVDATA.h"
gstedile 4:9901f6da64b7 15 // Agrego includes para la clase VCODATA que maneja los datos de navegación más recientes parametrizados por velocidad de cada período.
gstedile 3:0c9ee19fb976 16 #include "VCODATA.h"
gstedile 3:0c9ee19fb976 17
gstedile 4:9901f6da64b7 18 #include <sstream> //include this to use string streams
gstedile 4:9901f6da64b7 19 #include <string>
gstedile 0:d92271b032c7 20
gstedile 3:0c9ee19fb976 21 float Counter=0; //Contador de pulsos del sensor de flujo.
gstedile 3:0c9ee19fb976 22 float LCounter=0; //Consumo en litros
gstedile 3:0c9ee19fb976 23 float Consumo_km=0; //Consumo en litros/km.
gstedile 3:0c9ee19fb976 24 NAVDATA NAVIGATION_TABLE; //Objeto que maneja los datos de navegación del último período. $
gstedile 3:0c9ee19fb976 25 VCODATA NAVIGATION_VMATRIX(NAVIGATION_TABLE); // Objeto que maneja la matriz de datos de navegación $
gstedile 0:d92271b032c7 26
gstedile 0:d92271b032c7 27
gstedile 0:d92271b032c7 28
gstedile 4:9901f6da64b7 29 LocalFileSystem local("local"); // Because I want <PrintScreen>
gstedile 4:9901f6da64b7 30 Serial pc(USBTX, USBRX); // And a little feedback
gstedile 0:d92271b032c7 31
gstedile 4:9901f6da64b7 32 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name
gstedile 0:d92271b032c7 33
gstedile 4:9901f6da64b7 34 void trigger() { //Función para la interrupción
gstedile 0:d92271b032c7 35 Counter++;
gstedile 0:d92271b032c7 36 LCounter=Counter/2500;
gstedile 0:d92271b032c7 37 //point_t p_cursor = lcd.GetTextCursor();
gstedile 0:d92271b032c7 38 //lcd.SetTextCursor(0,200);
gstedile 0:d92271b032c7 39 //lcd.printf("Flujo %d pulsos", Counter);
gstedile 0:d92271b032c7 40 //lcd.SetTextCursor(p_cursor);
gstedile 0:d92271b032c7 41 }
gstedile 0:d92271b032c7 42 // float getConsumo(int , int velocidad){
gstedile 0:d92271b032c7 43
gstedile 0:d92271b032c7 44 int main()
gstedile 0:d92271b032c7 45 {
gstedile 0:d92271b032c7 46 pc.baud(460800); // I like a snappy terminal, so crank it up!
gstedile 0:d92271b032c7 47 pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
gstedile 0:d92271b032c7 48
gstedile 0:d92271b032c7 49 lcd.init();
gstedile 4:9901f6da64b7 50
gstedile 4:9901f6da64b7 51 // **************************
gstedile 0:d92271b032c7 52 //RunTestSet(lcd, pc); // If the library was compiled for test mode...
gstedile 0:d92271b032c7 53
gstedile 0:d92271b032c7 54 lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras.
gstedile 0:d92271b032c7 55 lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 0:d92271b032c7 56 //lcd.puts("BPG_Arial63x63");
gstedile 4:9901f6da64b7 57
gstedile 0:d92271b032c7 58
gstedile 0:d92271b032c7 59 GPS gps(p9, p10); // Agrego para comunicacion con el GPS
gstedile 0:d92271b032c7 60
gstedile 0:d92271b032c7 61 //Inicializo variables para el sensor de flujo
gstedile 0:d92271b032c7 62 //----------------------------------------------------
gstedile 0:d92271b032c7 63 DigitalOut myled(LED1);
gstedile 0:d92271b032c7 64 DigitalOut myled2(LED2);
gstedile 0:d92271b032c7 65 DigitalOut myled3(LED3);
gstedile 0:d92271b032c7 66 DigitalOut myled4(LED4);
gstedile 0:d92271b032c7 67
gstedile 0:d92271b032c7 68
gstedile 0:d92271b032c7 69 //DebounceIn pb(p8);
gstedile 0:d92271b032c7 70 /*DigitalIn pb(p11);
gstedile 0:d92271b032c7 71 int count=0; //Comento esto porque voy a usar interrupciones
gstedile 0:d92271b032c7 72 int old_pb=0;
gstedile 0:d92271b032c7 73 int new_pb;
gstedile 0:d92271b032c7 74 // Use internal pullup for pushbutton
gstedile 0:d92271b032c7 75 pb.mode(PullUp);
gstedile 0:d92271b032c7 76 //pb.mode(PullNone);
gstedile 0:d92271b032c7 77 // Delay for initial pullup to take effect
gstedile 0:d92271b032c7 78 wait(.001);*/
gstedile 0:d92271b032c7 79
gstedile 4:9901f6da64b7 80 //----------------------------------------------------
gstedile 4:9901f6da64b7 81 // Sensor de flujo:
gstedile 0:d92271b032c7 82 //-----------------------------------------------------
gstedile 0:d92271b032c7 83 InterruptIn pulse_sensor(p11); // Defino pulse_sensor como una entrada de interrupción en p11.
gstedile 0:d92271b032c7 84 pulse_sensor.mode(PullUp); // PullUp para esa entrada.
gstedile 0:d92271b032c7 85 //DigitalOut led(LED1);
gstedile 0:d92271b032c7 86 pulse_sensor.rise(&trigger); // Dispara interrupción con flanco ascendente. (Podría tambien ser desecendente--> fall)
gstedile 0:d92271b032c7 87
gstedile 4:9901f6da64b7 88
gstedile 4:9901f6da64b7 89
gstedile 4:9901f6da64b7 90
gstedile 4:9901f6da64b7 91 while(1) {
gstedile 4:9901f6da64b7 92
gstedile 3:0c9ee19fb976 93 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 94 lcd.puts("Proyecto SNOCC\r\n");
gstedile 4:9901f6da64b7 95
gstedile 0:d92271b032c7 96
gstedile 0:d92271b032c7 97 //-----------------------------------------------------
gstedile 0:d92271b032c7 98
gstedile 3:0c9ee19fb976 99 //lcd.SetTextCursor(0,20);
gstedile 0:d92271b032c7 100 //lcd.printf("M0: %s \r\n\r\n", gps.msg); //Imprimo el mensaje crudo proveniente de la uart
gstedile 0:d92271b032c7 101 //lcd.printf("M1: %s \r\n", gps.mensaje1);
gstedile 0:d92271b032c7 102 //lcd.printf("M2: %s \r\n", gps.mensaje2);
gstedile 0:d92271b032c7 103 //lcd.printf("M3: %s \r\n", gps.mensaje3);
gstedile 0:d92271b032c7 104 //lcd.printf("M4: %s \r\n", gps.mensaje4);
gstedile 0:d92271b032c7 105 //lcd.printf("Posicion actual_0: %f, %f \r\n", gps.longitude, gps.latitude);
gstedile 0:d92271b032c7 106 //lcd.printf("Contador = %d", Counter);
gstedile 0:d92271b032c7 107
gstedile 0:d92271b032c7 108 if(gps.sample()) { // Si es exitosa la obtencion de datos del gps.
gstedile 4:9901f6da64b7 109
gstedile 3:0c9ee19fb976 110 lcd.cls();
gstedile 4:9901f6da64b7 111
gstedile 3:0c9ee19fb976 112 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 113 lcd.puts("Proyecto SNOCC\r\n");
gstedile 3:0c9ee19fb976 114
gstedile 4:9901f6da64b7 115 if (NAVIGATION_TABLE.rotate_data(gps.longitude, gps.latitude, gps.time, Counter)){
gstedile 4:9901f6da64b7 116 NAVIGATION_VMATRIX.store_data(NAVIGATION_TABLE);// Luego de rotar los datos en la tabla de navegacion, la guarda en la matriz,
gstedile 4:9901f6da64b7 117 // en el lugar correspondiente a la velocidad del preiodo (por ahora reemplaza...ver otras opciones)
gstedile 4:9901f6da64b7 118 lcd.puts("Rotacion exitosa!\r\n");
gstedile 4:9901f6da64b7 119 int i=int(NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]);
gstedile 4:9901f6da64b7 120 float timetick_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]; // DEBUG
gstedile 4:9901f6da64b7 121 float distance_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]; // DEBUG
gstedile 4:9901f6da64b7 122 float speed_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]; // DEBUG
gstedile 4:9901f6da64b7 123 float longitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[longitude_f]; // DEBUG
gstedile 4:9901f6da64b7 124 float latitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[latitude_f]; // DEBUG
gstedile 4:9901f6da64b7 125 float cons_hour_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_hour_p];
gstedile 4:9901f6da64b7 126 lcd.printf("Algunos datos guardados en la Matriz: \r\n"); // DEBUG
gstedile 4:9901f6da64b7 127 lcd.printf("INDICE_Mtrx: %d (Parte entera de speed)\r\n", i); // DEBUG
gstedile 4:9901f6da64b7 128 lcd.printf("Speed_f_Mtrx: %f kn.\r\n", speed_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 129 lcd.printf("Time_f_Mtrx: %f Hours.\r\n", timetick_f_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 130 lcd.printf("Distance_p_Mtrx: %f miles.\r\n",distance_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 131 lcd.printf("Posicion: Long: %f, Lat: %f\r\n",longitude_f_Mtrx,latitude_f_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 132 lcd.printf("FlujoVCOmtrx %f Litros/Hora\r\n", cons_hour_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 133 }
gstedile 3:0c9ee19fb976 134 else
gstedile 4:9901f6da64b7 135 {
gstedile 3:0c9ee19fb976 136 lcd.puts("Periodo no valido!\r\n");
gstedile 4:9901f6da64b7 137 int i=int(NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]);
gstedile 4:9901f6da64b7 138 float timetick_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]; // DEBUG
gstedile 4:9901f6da64b7 139 float distance_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]; // DEBUG
gstedile 4:9901f6da64b7 140 float speed_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]; // DEBUG
gstedile 4:9901f6da64b7 141 float longitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[longitude_f]; // DEBUG
gstedile 4:9901f6da64b7 142 float latitude_f_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[latitude_f]; // DEBUG
gstedile 4:9901f6da64b7 143 float cons_hour_p_Mtrx = NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[cons_hour_p]; // DEBUG
gstedile 4:9901f6da64b7 144 lcd.printf("Algunos datos guardados en la Matriz: \r\n"); // DEBUG
gstedile 4:9901f6da64b7 145 lcd.printf("INDICE_Mtrx: %d (Parte entera de speed)\r\n", i); // DEBUG
gstedile 4:9901f6da64b7 146 lcd.printf("Speed_f_Mtrx: %f kn.\r\n", speed_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 147 lcd.printf("Time_f_Mtrx: %f Hours.\r\n", timetick_f_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 148 lcd.printf("Distance_p_Mtrx: %f miles.\r\n",distance_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 149 lcd.printf("Posicion: Long: %f, Lat: %f\r\n",longitude_f_Mtrx,latitude_f_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 150 lcd.printf("FlujoVCOmtrx %f Litros/Hora\r\n", cons_hour_p_Mtrx); // DEBUG
gstedile 4:9901f6da64b7 151 }
gstedile 4:9901f6da64b7 152 /* lcd.SetTextCursor(0,80);
gstedile 3:0c9ee19fb976 153 //lcd.printf("Posicion: %f, %f\r\n", gps.longitude, gps.latitude);
gstedile 4:9901f6da64b7 154 lcd.printf("Posicion: %f, %f\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[longitude_f], NAVIGATION_TABLE.LAST_NAV_DATA[latitude_f]); // $
gstedile 3:0c9ee19fb976 155 //lcd.printf("Velocidad %f km/h", gps.speed);
gstedile 3:0c9ee19fb976 156 lcd.printf("Distancia_p %f km\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[distance_p]);
gstedile 3:0c9ee19fb976 157 lcd.printf("Velocidad %f km/h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]);
gstedile 3:0c9ee19fb976 158 lcd.printf("Timetick_i %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_i]);
gstedile 3:0c9ee19fb976 159 lcd.printf("Timetick_f %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]);
gstedile 3:0c9ee19fb976 160 lcd.printf("Timetick_gps %f NMEA\r\n", gps.time);
gstedile 4:9901f6da64b7 161 // lcd.printf("Consumo %f l/km", getConsumo(Count; gps.speed); */
gstedile 0:d92271b032c7 162 lcd.SetTextCursor(0,200);
gstedile 4:9901f6da64b7 163 //lcd.printf("Flujo %f Litros/Hora\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]);
gstedile 4:9901f6da64b7 164 //lcd.printf("FlujoVCOmtrx %f Litros/Hora\r\n", cons_hour_p_Mtrx);
gstedile 4:9901f6da64b7 165 lcd.printf("Flujo acumulado (Tomado directamente del contador):%f Litros\r\n", LCounter);
gstedile 0:d92271b032c7 166
gstedile 4:9901f6da64b7 167 }
gstedile 4:9901f6da64b7 168 else {
gstedile 0:d92271b032c7 169 lcd.cls();
gstedile 3:0c9ee19fb976 170 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 171 lcd.puts("Proyecto SNOCC\r\n");
gstedile 0:d92271b032c7 172 lcd.SetTextCursor(0,100);
gstedile 4:9901f6da64b7 173 lcd.printf("No hay datos disponibles :(\r\n");
gstedile 3:0c9ee19fb976 174 lcd.SetTextCursor(0,180);
gstedile 4:9901f6da64b7 175 lcd.printf("Timestick %f km/h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]);
gstedile 4:9901f6da64b7 176 lcd.printf("Flujo %f Litros/Hora\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]);
gstedile 4:9901f6da64b7 177 lcd.printf("Flujo %f Litros\r\n", LCounter);
gstedile 0:d92271b032c7 178 }
gstedile 4:9901f6da64b7 179 }
gstedile 0:d92271b032c7 180 }