Para Juan

Dependencies:   NAVDATA RA8875 mbed VCODATA

Committer:
gstedile
Date:
Sun Mar 19 21:09:11 2017 +0000
Revision:
0:d92271b032c7
Child:
3:0c9ee19fb976
Para Juan

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