Para Juan

Dependencies:   NAVDATA RA8875 mbed VCODATA

Committer:
gstedile
Date:
Tue Apr 04 06:17:17 2017 +0000
Revision:
3:0c9ee19fb976
Parent:
0:d92271b032c7
Child:
4:9901f6da64b7
Compilado y corrido sin errores. Hasta aqui carga los datos en un objeto NAVDATA y los rota. Falta cargar un objeto VCODATA con la matriz y calcular la VCO.

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 0:d92271b032c7 12 #include "GPS.h"
gstedile 0:d92271b032c7 13
gstedile 3:0c9ee19fb976 14 // Agrego includes para la clase NAVDATA que maneja los datos de navegación del último período.
gstedile 3:0c9ee19fb976 15 #include "NAVDATA.h"
gstedile 3:0c9ee19fb976 16
gstedile 3:0c9ee19fb976 17 // 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 18 #include "VCODATA.h"
gstedile 3:0c9ee19fb976 19
gstedile 0:d92271b032c7 20
gstedile 0:d92271b032c7 21 #include <sstream> //include this to use string streams
gstedile 0:d92271b032c7 22 #include <string>
gstedile 0:d92271b032c7 23
gstedile 3:0c9ee19fb976 24 float Counter=0; //Contador de pulsos del sensor de flujo.
gstedile 3:0c9ee19fb976 25 float LCounter=0; //Consumo en litros
gstedile 3:0c9ee19fb976 26 float Consumo_km=0; //Consumo en litros/km.
gstedile 3:0c9ee19fb976 27 NAVDATA NAVIGATION_TABLE; //Objeto que maneja los datos de navegación del último período. $
gstedile 3:0c9ee19fb976 28 VCODATA NAVIGATION_VMATRIX(NAVIGATION_TABLE); // Objeto que maneja la matriz de datos de navegación $
gstedile 0:d92271b032c7 29
gstedile 0:d92271b032c7 30
gstedile 0:d92271b032c7 31
gstedile 0:d92271b032c7 32 LocalFileSystem local("local"); // Because I want <PrintScreen>
gstedile 0:d92271b032c7 33 Serial pc(USBTX, USBRX); // And a little feedback
gstedile 0:d92271b032c7 34
gstedile 0:d92271b032c7 35 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name
gstedile 0:d92271b032c7 36
gstedile 0:d92271b032c7 37 void trigger() { //Función para la interrupción
gstedile 0:d92271b032c7 38 Counter++;
gstedile 0:d92271b032c7 39 LCounter=Counter/2500;
gstedile 0:d92271b032c7 40 //point_t p_cursor = lcd.GetTextCursor();
gstedile 0:d92271b032c7 41 //lcd.SetTextCursor(0,200);
gstedile 0:d92271b032c7 42 //lcd.printf("Flujo %d pulsos", Counter);
gstedile 0:d92271b032c7 43 //lcd.SetTextCursor(p_cursor);
gstedile 0:d92271b032c7 44 }
gstedile 0:d92271b032c7 45 // float getConsumo(int , int velocidad){
gstedile 0:d92271b032c7 46
gstedile 0:d92271b032c7 47 int main()
gstedile 0:d92271b032c7 48 {
gstedile 0:d92271b032c7 49
gstedile 0:d92271b032c7 50
gstedile 0:d92271b032c7 51 pc.baud(460800); // I like a snappy terminal, so crank it up!
gstedile 0:d92271b032c7 52 pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
gstedile 0:d92271b032c7 53
gstedile 0:d92271b032c7 54 lcd.init();
gstedile 0:d92271b032c7 55
gstedile 0:d92271b032c7 56
gstedile 0:d92271b032c7 57
gstedile 0:d92271b032c7 58
gstedile 0:d92271b032c7 59
gstedile 0:d92271b032c7 60
gstedile 0:d92271b032c7 61
gstedile 0:d92271b032c7 62 // **************************
gstedile 0:d92271b032c7 63 //RunTestSet(lcd, pc); // If the library was compiled for test mode...
gstedile 0:d92271b032c7 64
gstedile 0:d92271b032c7 65 lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras.
gstedile 0:d92271b032c7 66
gstedile 0:d92271b032c7 67
gstedile 0:d92271b032c7 68
gstedile 0:d92271b032c7 69 //lcd.puts(0,0, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
gstedile 0:d92271b032c7 70
gstedile 0:d92271b032c7 71 //lcd.SelectUserFont(Dave_Smart18x32);
gstedile 0:d92271b032c7 72 //lcd.puts("**** ! Soft Fonts ! **** 0123456789\r\n");
gstedile 0:d92271b032c7 73 //lcd.puts("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
gstedile 0:d92271b032c7 74 //lcd.puts("abcdefghijklmnopqrstuvwxyz\r\n");
gstedile 0:d92271b032c7 75 //lcd.SelectUserFont();
gstedile 0:d92271b032c7 76 //lcd.puts("Back to normal\r\n");
gstedile 0:d92271b032c7 77 //lcd.SelectUserFont(BPG_Arial08x08);
gstedile 0:d92271b032c7 78 //lcd.puts("BPG_Arial08x08 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
gstedile 0:d92271b032c7 79 //lcd.puts("BPG_Arial08x08 abcdefghijklmnopqrstuvwxyz\r\n");
gstedile 0:d92271b032c7 80 //lcd.SelectUserFont(BPG_Arial10x10);
gstedile 0:d92271b032c7 81 //lcd.puts("BPG_Arial10x10 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
gstedile 0:d92271b032c7 82 //lcd.puts("BPG_Arial10x10 abcdefghijklmnopqrstuvwxyz\r\n");
gstedile 0:d92271b032c7 83 //lcd.SelectUserFont(BPG_Arial20x20);
gstedile 0:d92271b032c7 84 //lcd.puts("BPG_Arial20x20 ");
gstedile 0:d92271b032c7 85 //lcd.SelectUserFont(BPG_Arial31x32);
gstedile 0:d92271b032c7 86 //lcd.puts("BPG_Arial31x32\r\n");
gstedile 0:d92271b032c7 87
gstedile 0:d92271b032c7 88 // lcd.init();
gstedile 0:d92271b032c7 89 //lcd.printf("printing 3 x 2 = %d", 3*2);
gstedile 0:d92271b032c7 90 /*lcd.circle( 400,25, 25, BrightRed);
gstedile 0:d92271b032c7 91 lcd.fillcircle( 400,25, 15, RGB(128,255,128));
gstedile 0:d92271b032c7 92 lcd.ellipse( 440,75, 35,20, BrightBlue);
gstedile 0:d92271b032c7 93 lcd.fillellipse( 440,75, 25,10, Blue);
gstedile 0:d92271b032c7 94 */
gstedile 0:d92271b032c7 95
gstedile 0:d92271b032c7 96 /*
gstedile 0:d92271b032c7 97 lcd.SelectUserFont(BPG_Arial63x63);
gstedile 0:d92271b032c7 98 //lcd.puts("BPG_Arial63x63");
gstedile 0:d92271b032c7 99 lcd.puts(" FIUBA\r\n");
gstedile 0:d92271b032c7 100
gstedile 0:d92271b032c7 101 lcd.puts("------------------------\r\n");
gstedile 0:d92271b032c7 102 lcd.puts("Proyecto SNOCC\r\n");
gstedile 0:d92271b032c7 103 */
gstedile 0:d92271b032c7 104
gstedile 0:d92271b032c7 105 /*lcd.triangle( 440,100, 475,110, 450,125, Magenta);
gstedile 0:d92271b032c7 106 lcd.filltriangle( 445,105, 467,111, 452,120, Cyan);
gstedile 0:d92271b032c7 107 //lcd.rect( 400,130, 475,155, Brown);
gstedile 0:d92271b032c7 108 lcd.rect( 170,210, 55,235, Brown);
gstedile 0:d92271b032c7 109 //lcd.fillrect( 405,135, 470,150, Pink);
gstedile 0:d92271b032c7 110 lcd.fillrect( 165,215, 60,230, Pink);
gstedile 0:d92271b032c7 111 //lcd.roundrect( 410,160, 475,190, 10,8, Yellow);
gstedile 0:d92271b032c7 112 lcd.roundrect( 210,200, 275,230, 10,8, Green);
gstedile 0:d92271b032c7 113 //lcd.fillroundrect(415,165, 470,185, 5,3, Orange);
gstedile 0:d92271b032c7 114 lcd.fillroundrect(215,205, 270,225, 5,3, Yellow);
gstedile 0:d92271b032c7 115 lcd.line( 330,200, 360,230, RGB(0,255,255));
gstedile 0:d92271b032c7 116 for (int i=0; i<=30; i+=5)
gstedile 0:d92271b032c7 117 lcd.pixel(335+i,200+i, White);
gstedile 0:d92271b032c7 118 */
gstedile 0:d92271b032c7 119
gstedile 0:d92271b032c7 120
gstedile 0:d92271b032c7 121
gstedile 0:d92271b032c7 122
gstedile 0:d92271b032c7 123
gstedile 0:d92271b032c7 124
gstedile 0:d92271b032c7 125
gstedile 0:d92271b032c7 126 lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras
gstedile 0:d92271b032c7 127 //lcd.puts("BPG_Arial63x63");
gstedile 0:d92271b032c7 128 /* lcd.puts("\t\tFIUBA\r\n");
gstedile 0:d92271b032c7 129 lcd.puts("---------------------\r\n");
gstedile 0:d92271b032c7 130 lcd.printf("Contador = %d", Counter);
gstedile 0:d92271b032c7 131 lcd.puts("Proyecto SNOCC");
gstedile 0:d92271b032c7 132
gstedile 0:d92271b032c7 133 pc.printf("PrintScreen activated ...\r\n");
gstedile 0:d92271b032c7 134 RetCode_t r = lcd.PrintScreen(0,0,480,272,"/sd/file.bmp");
gstedile 0:d92271b032c7 135 pc.printf(" PrintScreen returned %d\r\n", r);
gstedile 0:d92271b032c7 136 */
gstedile 0:d92271b032c7 137
gstedile 0:d92271b032c7 138 GPS gps(p9, p10); // Agrego para comunicacion con el GPS
gstedile 0:d92271b032c7 139
gstedile 0:d92271b032c7 140 //Inicializo variables para el sensor de flujo
gstedile 0:d92271b032c7 141 //----------------------------------------------------
gstedile 0:d92271b032c7 142 DigitalOut myled(LED1);
gstedile 0:d92271b032c7 143 DigitalOut myled2(LED2);
gstedile 0:d92271b032c7 144 DigitalOut myled3(LED3);
gstedile 0:d92271b032c7 145 DigitalOut myled4(LED4);
gstedile 0:d92271b032c7 146
gstedile 0:d92271b032c7 147
gstedile 0:d92271b032c7 148 //DebounceIn pb(p8);
gstedile 0:d92271b032c7 149 /*DigitalIn pb(p11);
gstedile 0:d92271b032c7 150 int count=0; //Comento esto porque voy a usar interrupciones
gstedile 0:d92271b032c7 151 int old_pb=0;
gstedile 0:d92271b032c7 152 int new_pb;
gstedile 0:d92271b032c7 153 // Use internal pullup for pushbutton
gstedile 0:d92271b032c7 154 pb.mode(PullUp);
gstedile 0:d92271b032c7 155 //pb.mode(PullNone);
gstedile 0:d92271b032c7 156 // Delay for initial pullup to take effect
gstedile 0:d92271b032c7 157 wait(.001);*/
gstedile 0:d92271b032c7 158
gstedile 0:d92271b032c7 159 //----------------------------------------------------
gstedile 0:d92271b032c7 160
gstedile 0:d92271b032c7 161
gstedile 0:d92271b032c7 162 // Sensor de flujo:
gstedile 0:d92271b032c7 163 //-----------------------------------------------------
gstedile 0:d92271b032c7 164 InterruptIn pulse_sensor(p11); // Defino pulse_sensor como una entrada de interrupción en p11.
gstedile 0:d92271b032c7 165 pulse_sensor.mode(PullUp); // PullUp para esa entrada.
gstedile 0:d92271b032c7 166 //DigitalOut led(LED1);
gstedile 0:d92271b032c7 167 pulse_sensor.rise(&trigger); // Dispara interrupción con flanco ascendente. (Podría tambien ser desecendente--> fall)
gstedile 0:d92271b032c7 168
gstedile 0:d92271b032c7 169 while(1) {
gstedile 0:d92271b032c7 170
gstedile 0:d92271b032c7 171
gstedile 3:0c9ee19fb976 172 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 173 lcd.puts("Proyecto SNOCC\r\n");
gstedile 0:d92271b032c7 174
gstedile 0:d92271b032c7 175
gstedile 0:d92271b032c7 176
gstedile 0:d92271b032c7 177 //int main() {
gstedile 0:d92271b032c7 178
gstedile 0:d92271b032c7 179 // }
gstedile 0:d92271b032c7 180
gstedile 0:d92271b032c7 181
gstedile 0:d92271b032c7 182
gstedile 0:d92271b032c7 183
gstedile 0:d92271b032c7 184
gstedile 0:d92271b032c7 185
gstedile 0:d92271b032c7 186
gstedile 0:d92271b032c7 187
gstedile 0:d92271b032c7 188 //new_pb = pb;
gstedile 0:d92271b032c7 189 /* new_pb = pb.read();
gstedile 0:d92271b032c7 190 //if ((new_pb==0) && (old_pb==1)) count++;
gstedile 0:d92271b032c7 191 if ((!new_pb) && (old_pb)) Counter++;
gstedile 0:d92271b032c7 192 //myled4 = count & 0x01;
gstedile 0:d92271b032c7 193 //myled3 = (count & 0x02)>>1;
gstedile 0:d92271b032c7 194 //myled2 = (count & 0x04)>>2;
gstedile 0:d92271b032c7 195 //myled = (count & 0x08)>>3;
gstedile 0:d92271b032c7 196 old_pb = new_pb;
gstedile 0:d92271b032c7 197 lcd.SetTextCursor(0,200);
gstedile 0:d92271b032c7 198 lcd.printf("Flujo %d pulsos", Counter);
gstedile 0:d92271b032c7 199 */
gstedile 0:d92271b032c7 200 //-----------------------------------------------------
gstedile 0:d92271b032c7 201
gstedile 3:0c9ee19fb976 202 //lcd.SetTextCursor(0,20);
gstedile 0:d92271b032c7 203 //lcd.printf("M0: %s \r\n\r\n", gps.msg); //Imprimo el mensaje crudo proveniente de la uart
gstedile 0:d92271b032c7 204 //lcd.printf("M1: %s \r\n", gps.mensaje1);
gstedile 0:d92271b032c7 205 //lcd.printf("M2: %s \r\n", gps.mensaje2);
gstedile 0:d92271b032c7 206 //lcd.printf("M3: %s \r\n", gps.mensaje3);
gstedile 0:d92271b032c7 207 //lcd.printf("M4: %s \r\n", gps.mensaje4);
gstedile 0:d92271b032c7 208 //lcd.printf("Posicion actual_0: %f, %f \r\n", gps.longitude, gps.latitude);
gstedile 0:d92271b032c7 209 //lcd.printf("Contador = %d", Counter);
gstedile 0:d92271b032c7 210
gstedile 0:d92271b032c7 211 if(gps.sample()) { // Si es exitosa la obtencion de datos del gps.
gstedile 3:0c9ee19fb976 212 lcd.cls();
gstedile 3:0c9ee19fb976 213
gstedile 3:0c9ee19fb976 214
gstedile 3:0c9ee19fb976 215 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 216 lcd.puts("Proyecto SNOCC\r\n");
gstedile 3:0c9ee19fb976 217
gstedile 3:0c9ee19fb976 218 if (NAVIGATION_TABLE.rotate_data(gps.longitude, gps.latitude, gps.time, Counter))
gstedile 3:0c9ee19fb976 219 lcd.puts("Rotacion exitosa!\r\n");
gstedile 3:0c9ee19fb976 220 else
gstedile 3:0c9ee19fb976 221 lcd.puts("Periodo no valido!\r\n");
gstedile 3:0c9ee19fb976 222
gstedile 3:0c9ee19fb976 223 lcd.SetTextCursor(0,50);
gstedile 3:0c9ee19fb976 224 //lcd.printf("Posicion: %f, %f\r\n", gps.longitude, gps.latitude);
gstedile 3:0c9ee19fb976 225 lcd.printf("Posicion: %f, %f\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[longitude_f], gps.latitude); // $
gstedile 3:0c9ee19fb976 226 //lcd.printf("Velocidad %f km/h", gps.speed);
gstedile 3:0c9ee19fb976 227 lcd.printf("Distancia_p %f km\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[distance_p]);
gstedile 3:0c9ee19fb976 228 lcd.printf("Velocidad %f km/h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[speed_p]);
gstedile 3:0c9ee19fb976 229 lcd.printf("Timetick_i %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_i]);
gstedile 3:0c9ee19fb976 230 lcd.printf("Timetick_f %f h\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]);
gstedile 3:0c9ee19fb976 231 lcd.printf("Timetick_gps %f NMEA\r\n", gps.time);
gstedile 0:d92271b032c7 232 // lcd.printf("Consumo %f l/km", getConsumo(Count; gps.speed);
gstedile 0:d92271b032c7 233 lcd.SetTextCursor(0,200);
gstedile 3:0c9ee19fb976 234 lcd.printf("Flujo %f Litros/Hora\r\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]);
gstedile 3:0c9ee19fb976 235 lcd.printf("Flujo %f Litros\r\n", LCounter);
gstedile 0:d92271b032c7 236
gstedile 0:d92271b032c7 237 } else {
gstedile 0:d92271b032c7 238 lcd.cls();
gstedile 3:0c9ee19fb976 239 lcd.SetTextCursor(20,0); // Pongo cursor en posicion
gstedile 0:d92271b032c7 240 lcd.puts("Proyecto SNOCC\r\n");
gstedile 0:d92271b032c7 241 lcd.SetTextCursor(0,100);
gstedile 0:d92271b032c7 242 lcd.printf("No hay datos disponibles :(\n");
gstedile 3:0c9ee19fb976 243 lcd.SetTextCursor(0,180);
gstedile 3:0c9ee19fb976 244 lcd.printf("Timestick %f km/h", NAVIGATION_TABLE.LAST_NAV_DATA[time_f]);
gstedile 3:0c9ee19fb976 245 lcd.printf("Flujo %f Litros/Hora\n", NAVIGATION_TABLE.LAST_NAV_DATA[cons_hour_p]);
gstedile 0:d92271b032c7 246 lcd.printf("Flujo %f Litros", LCounter);
gstedile 0:d92271b032c7 247 }
gstedile 0:d92271b032c7 248
gstedile 0:d92271b032c7 249 }
gstedile 0:d92271b032c7 250
gstedile 0:d92271b032c7 251
gstedile 0:d92271b032c7 252
gstedile 0:d92271b032c7 253
gstedile 0:d92271b032c7 254 /*
gstedile 0:d92271b032c7 255 while(1) {
gstedile 0:d92271b032c7 256 ; // end
gstedile 0:d92271b032c7 257 }
gstedile 0:d92271b032c7 258 */
gstedile 0:d92271b032c7 259
gstedile 0:d92271b032c7 260 }