With SD Card
Dependencies: NAVDATA RA8875 SDFileSystem VCODATA mbed
main.cpp@2:968b38c3ef49, 2017-07-30 (annotated)
- Committer:
- gstedile
- Date:
- Sun Jul 30 15:39:01 2017 +0000
- Revision:
- 2:968b38c3ef49
- Parent:
- 1:30b1ca228fc7
V9_UI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gstedile | 2:968b38c3ef49 | 1 | #include <time.h> |
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 | 2:968b38c3ef49 | 19 | int DEBUG1=0; // -->1:Habilita informacion para debug. |
gstedile | 2:968b38c3ef49 | 20 | int DEBUG2=0; // -->1:Habilita informacion para debug2. |
gstedile | 1:30b1ca228fc7 | 21 | int DEBUG_GPS=0; // -->1:Habilita datos para debug de comunicacion con gps. |
gstedile | 2:968b38c3ef49 | 22 | int SIMULATION=1; // -->1: Habilita simulacion cuando no hay datos gps. |
gstedile | 1:30b1ca228fc7 | 23 | enum sentido{DWN=0,UP,NO}; |
gstedile | 2:968b38c3ef49 | 24 | enum figura{ZONA=0,SIN_DT,CIRC,FLECHA,ElIP,GAUGE}; |
gstedile | 0:e40cf759ba9a | 25 | const char *sd_dir="/sd/snocc"; // Directorio de almacenamiento de datos. |
gstedile | 0:e40cf759ba9a | 26 | const char *sd_file="/sd/snocc/sdsnocc.csv"; // Archivo csv de almacenamiento de datos. |
gstedile | 2:968b38c3ef49 | 27 | const int V_M=40; //Velocidad Maxima |
gstedile | 0:e40cf759ba9a | 28 | float Counter=0; //Contador de pulsos del sensor de flujo. |
gstedile | 0:e40cf759ba9a | 29 | float LCounter=0; //Consumo en litros |
gstedile | 0:e40cf759ba9a | 30 | |
gstedile | 2:968b38c3ef49 | 31 | int sepx= 105; // Separacion x entre recuadros |
gstedile | 2:968b38c3ef49 | 32 | int sepy= 66; // Separacion x entre recuadros |
gstedile | 2:968b38c3ef49 | 33 | int sizex1=100; // Tamaño cuadro para valores |
gstedile | 2:968b38c3ef49 | 34 | int sizey1=40; |
gstedile | 2:968b38c3ef49 | 35 | int xr1=10; // Posicion de recuadros para exhibir datos |
gstedile | 2:968b38c3ef49 | 36 | int yr1=10; |
gstedile | 2:968b38c3ef49 | 37 | int xr2=xr1+sepx; |
gstedile | 2:968b38c3ef49 | 38 | int yr2=yr1; |
gstedile | 2:968b38c3ef49 | 39 | int xr3=xr1; |
gstedile | 2:968b38c3ef49 | 40 | int yr3=yr1+sepy; |
gstedile | 2:968b38c3ef49 | 41 | int xr4=xr1; |
gstedile | 2:968b38c3ef49 | 42 | int yr4=yr3+sepy; |
gstedile | 2:968b38c3ef49 | 43 | int xr5=xr1; |
gstedile | 2:968b38c3ef49 | 44 | int yr5=yr4+sepy; |
gstedile | 2:968b38c3ef49 | 45 | int xr6=xr2; |
gstedile | 2:968b38c3ef49 | 46 | int yr6=yr5; |
gstedile | 2:968b38c3ef49 | 47 | |
gstedile | 2:968b38c3ef49 | 48 | int signal_x=xr2; // REGION DE SEÑALIZACION |
gstedile | 2:968b38c3ef49 | 49 | int signal_y=yr3; |
gstedile | 2:968b38c3ef49 | 50 | int signal_x_sz=99; |
gstedile | 2:968b38c3ef49 | 51 | int signal_y_sz= 2*sepy-10; |
gstedile | 2:968b38c3ef49 | 52 | |
gstedile | 1:30b1ca228fc7 | 53 | 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 | 54 | VCODATA NAVIGATION_VMATRIX(NAVIGATION_OBJECT, V_M); // Objeto que maneja la matriz de datos de navegación $ |
gstedile | 1:30b1ca228fc7 | 55 | VCODATA NAVIGATION_V_SMOOTH_MTRX(NAVIGATION_OBJECT, V_M); // Objeto que maneja la matriz de datos de navegación promediados $ |
gstedile | 1:30b1ca228fc7 | 56 | NAVDATA TestNAV; // Objeto para crear matriz default; /// DEBUG? |
gstedile | 0:e40cf759ba9a | 57 | |
gstedile | 1:30b1ca228fc7 | 58 | LocalFileSystem local("local"); // Para <PrintScreen> |
gstedile | 1:30b1ca228fc7 | 59 | Serial pc(USBTX, USBRX); |
gstedile | 2:968b38c3ef49 | 60 | RA8875 lcd(p5, p6, p7, p8, NC, "lcd"); // MOSI, MISO, SCK, /ChipSelect, /reset, name // Comunicacion con Display |
gstedile | 1:30b1ca228fc7 | 61 | SDFileSystem sd(p11, p12, p13, p14, "sd"); // SD CARD: mosi, miso, sclk, cs // Comunicacion con SD card |
gstedile | 0:e40cf759ba9a | 62 | |
gstedile | 0:e40cf759ba9a | 63 | |
gstedile | 1:30b1ca228fc7 | 64 | //>>>>>>>>>>>>>>>>>> SECCION TOUCH PANEL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 0:e40cf759ba9a | 65 | extern "C" void mbed_reset(); |
gstedile | 0:e40cf759ba9a | 66 | #define min(a,b) ((a<b)?a:b) |
gstedile | 0:e40cf759ba9a | 67 | #define max(a,b) ((a>b)?a:b) |
gstedile | 0:e40cf759ba9a | 68 | bool Intersect(rect_t rect, point_t p) |
gstedile | 0:e40cf759ba9a | 69 | { |
gstedile | 0:e40cf759ba9a | 70 | if (p.x >= min(rect.p1.x, rect.p2.x) && p.x <= max(rect.p1.x, rect.p2.x) |
gstedile | 0:e40cf759ba9a | 71 | && p.y >= min(rect.p1.y, rect.p2.y) && p.y <= max(rect.p1.y, rect.p2.y)) |
gstedile | 0:e40cf759ba9a | 72 | return true; |
gstedile | 0:e40cf759ba9a | 73 | else |
gstedile | 0:e40cf759ba9a | 74 | return false; |
gstedile | 0:e40cf759ba9a | 75 | } |
gstedile | 2:968b38c3ef49 | 76 | |
gstedile | 1:30b1ca228fc7 | 77 | //>>>>>>>>>>>>>>>>>> FIN SECCION TOUCH PANEL <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 0:e40cf759ba9a | 78 | |
gstedile | 0:e40cf759ba9a | 79 | //Función para la interrupción |
gstedile | 0:e40cf759ba9a | 80 | |
gstedile | 0:e40cf759ba9a | 81 | void trigger() { |
gstedile | 0:e40cf759ba9a | 82 | Counter++; |
gstedile | 0:e40cf759ba9a | 83 | LCounter=Counter/2500; |
gstedile | 0:e40cf759ba9a | 84 | } |
gstedile | 2:968b38c3ef49 | 85 | |
gstedile | 2:968b38c3ef49 | 86 | |
gstedile | 2:968b38c3ef49 | 87 | //##################### GAUGE - CLOCK ################################################################## |
gstedile | 2:968b38c3ef49 | 88 | |
gstedile | 2:968b38c3ef49 | 89 | uint16_t ccenterx=100, ccentery=100; //center x,y of the clock |
gstedile | 2:968b38c3ef49 | 90 | const uint16_t cradius = 110;//radius of the clock |
gstedile | 2:968b38c3ef49 | 91 | const float scosConst = 0.0174532925; |
gstedile | 2:968b38c3ef49 | 92 | float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0, vx = 0, vy = 0; |
gstedile | 2:968b38c3ef49 | 93 | float sdeg = 0, mdeg = 0, hdeg = 0, vdeg=0; |
gstedile | 2:968b38c3ef49 | 94 | uint16_t osx, osy, omx, omy, ohx, ohy,ovx, ovy; |
gstedile | 2:968b38c3ef49 | 95 | uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0; |
gstedile | 2:968b38c3ef49 | 96 | uint32_t targetTime = 0;// for next 1 second timeout |
gstedile | 2:968b38c3ef49 | 97 | uint8_t hh, mm, ss; //containers for current time |
gstedile | 2:968b38c3ef49 | 98 | |
gstedile | 0:e40cf759ba9a | 99 | |
gstedile | 2:968b38c3ef49 | 100 | void drawClockFace() { |
gstedile | 2:968b38c3ef49 | 101 | lcd.fillcircle(ccenterx, ccentery, cradius, Blue); |
gstedile | 2:968b38c3ef49 | 102 | lcd.fillcircle(ccenterx, ccentery, cradius - 4, Black); |
gstedile | 2:968b38c3ef49 | 103 | uint16_t span_angle=180; // Grados de span en el reloj. |
gstedile | 2:968b38c3ef49 | 104 | int j=0, RD=255,GN=255, BL=255; |
gstedile | 2:968b38c3ef49 | 105 | for (int i = 0; i <= span_angle; i += 2) { |
gstedile | 2:968b38c3ef49 | 106 | sx = cos((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 107 | sy = sin((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 108 | x0 = sx * (cradius - 4) + ccenterx; |
gstedile | 2:968b38c3ef49 | 109 | yy0 = sy * (cradius - 4) + ccentery; |
gstedile | 2:968b38c3ef49 | 110 | x1 = sx * (cradius - 40) + ccenterx; |
gstedile | 2:968b38c3ef49 | 111 | yy1 = sy * (cradius - 40) + ccentery; |
gstedile | 2:968b38c3ef49 | 112 | if (i < span_angle/2)j=i; |
gstedile | 2:968b38c3ef49 | 113 | else j=(span_angle-i) ; |
gstedile | 2:968b38c3ef49 | 114 | |
gstedile | 2:968b38c3ef49 | 115 | if (2*j/span_angle>0.9) { |
gstedile | 2:968b38c3ef49 | 116 | RD=0; |
gstedile | 2:968b38c3ef49 | 117 | GN=255; |
gstedile | 2:968b38c3ef49 | 118 | BL=0; |
gstedile | 2:968b38c3ef49 | 119 | } |
gstedile | 2:968b38c3ef49 | 120 | else if (2*j/span_angle<0.75){ |
gstedile | 2:968b38c3ef49 | 121 | RD=255; |
gstedile | 2:968b38c3ef49 | 122 | GN=255*4*(2*j/span_angle)/3; |
gstedile | 2:968b38c3ef49 | 123 | BL=0; |
gstedile | 2:968b38c3ef49 | 124 | } |
gstedile | 2:968b38c3ef49 | 125 | else { |
gstedile | 2:968b38c3ef49 | 126 | RD=255*4*(1-(2*j/span_angle)); |
gstedile | 2:968b38c3ef49 | 127 | GN=255; |
gstedile | 2:968b38c3ef49 | 128 | BL=0; |
gstedile | 2:968b38c3ef49 | 129 | } |
gstedile | 0:e40cf759ba9a | 130 | |
gstedile | 2:968b38c3ef49 | 131 | if (i<10 || i>170) lcd.line(x0, yy0, x1, yy1, RGB(255,0,0)); |
gstedile | 2:968b38c3ef49 | 132 | else if (i<20 || i>160) lcd.line(x0, yy0, x1, yy1,RGB(255,50,0)); |
gstedile | 2:968b38c3ef49 | 133 | else if (i<30 || i>150) lcd.line(x0, yy0, x1, yy1, RGB(255,120,0)); |
gstedile | 2:968b38c3ef49 | 134 | else if (i<40 || i>140) lcd.line(x0, yy0, x1, yy1, RGB(255,200,0)); |
gstedile | 2:968b38c3ef49 | 135 | else if (i<50 || i>130) lcd.line(x0, yy0, x1, yy1, RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 136 | else if (i<60 || i>120) lcd.line(x0, yy0, x1, yy1, RGB(200,255,0)); |
gstedile | 2:968b38c3ef49 | 137 | else if (i<70 || i>110) lcd.line(x0, yy0, x1, yy1, RGB(120,255,0)); |
gstedile | 2:968b38c3ef49 | 138 | else if (i<80 || i>100) lcd.line(x0, yy0, x1, yy1, RGB(50,255,0)); |
gstedile | 2:968b38c3ef49 | 139 | else lcd.line(x0, yy0, x1, yy1, RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 140 | } |
gstedile | 2:968b38c3ef49 | 141 | |
gstedile | 2:968b38c3ef49 | 142 | for (int i = 0; i <= span_angle; i +=5 ) { // DIBUJO ESCALA 1 |
gstedile | 2:968b38c3ef49 | 143 | //sx = cos((i - 90) * scosConst); |
gstedile | 2:968b38c3ef49 | 144 | sx = cos((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 145 | //sy = sin((i - 90) * scosConst); |
gstedile | 2:968b38c3ef49 | 146 | sy = sin((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 147 | x0 = sx * (cradius - 4) + ccenterx; |
gstedile | 2:968b38c3ef49 | 148 | yy0 = sy * (cradius - 4) + ccentery; |
gstedile | 2:968b38c3ef49 | 149 | x1 = sx * (cradius - 10) + ccenterx; |
gstedile | 2:968b38c3ef49 | 150 | yy1 = sy * (cradius - 10) + ccentery; |
gstedile | 2:968b38c3ef49 | 151 | lcd.line(x0, yy0, x1, yy1, White); |
gstedile | 0:e40cf759ba9a | 152 | } |
gstedile | 2:968b38c3ef49 | 153 | for (int i = 0; i <= span_angle; i +=15 ) { // DIBUJO ESCALA 2 |
gstedile | 2:968b38c3ef49 | 154 | sx = cos((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 155 | sy = sin((i - 180) * scosConst); |
gstedile | 2:968b38c3ef49 | 156 | x0 = sx * (cradius - 4) + ccenterx; |
gstedile | 2:968b38c3ef49 | 157 | yy0 = sy * (cradius - 4) + ccentery; |
gstedile | 2:968b38c3ef49 | 158 | x1 = sx * (cradius - 20) + ccenterx; |
gstedile | 2:968b38c3ef49 | 159 | yy1 = sy * (cradius - 20) + ccentery; |
gstedile | 2:968b38c3ef49 | 160 | lcd.line(x0, yy0, x1, yy1, White); |
gstedile | 2:968b38c3ef49 | 161 | } |
gstedile | 2:968b38c3ef49 | 162 | lcd.SetTextCursor(ccenterx-35, ccentery-25); |
gstedile | 2:968b38c3ef49 | 163 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 2:968b38c3ef49 | 164 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 165 | lcd.foreground(RGB(0,0,255)); |
gstedile | 2:968b38c3ef49 | 166 | lcd.printf("SNOCC"); |
gstedile | 2:968b38c3ef49 | 167 | lcd.SetTextCursor(ccenterx-35, ccentery+15); |
gstedile | 2:968b38c3ef49 | 168 | lcd.printf("METER"); |
gstedile | 2:968b38c3ef49 | 169 | lcd.SetTextCursor(ccenterx-18, (ccentery - cradius +20)); |
gstedile | 2:968b38c3ef49 | 170 | lcd.background(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 171 | lcd.foreground(Black); |
gstedile | 2:968b38c3ef49 | 172 | lcd.printf("VCO"); |
gstedile | 2:968b38c3ef49 | 173 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 174 | } |
gstedile | 0:e40cf759ba9a | 175 | |
gstedile | 2:968b38c3ef49 | 176 | void setup(void) { |
gstedile | 2:968b38c3ef49 | 177 | lcd.foreground(White); |
gstedile | 2:968b38c3ef49 | 178 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 179 | //ccenterx = lcd.width() / 2; |
gstedile | 2:968b38c3ef49 | 180 | //ccentery = lcd.height() / 2; |
gstedile | 2:968b38c3ef49 | 181 | osx = ccenterx; |
gstedile | 2:968b38c3ef49 | 182 | osy = ccentery; |
gstedile | 2:968b38c3ef49 | 183 | omx = ccenterx; |
gstedile | 2:968b38c3ef49 | 184 | omy = ccentery; |
gstedile | 2:968b38c3ef49 | 185 | ohx = ccenterx; |
gstedile | 2:968b38c3ef49 | 186 | ohy = ccentery; |
gstedile | 2:968b38c3ef49 | 187 | } |
gstedile | 2:968b38c3ef49 | 188 | |
gstedile | 2:968b38c3ef49 | 189 | void drawClockGauge(float value, float fullscl ) { // Ej. fullscl 2 => -1 a 1 |
gstedile | 2:968b38c3ef49 | 190 | |
gstedile | 2:968b38c3ef49 | 191 | vdeg=180 * value/fullscl; |
gstedile | 2:968b38c3ef49 | 192 | vx = cos((vdeg - 90) * scosConst); |
gstedile | 2:968b38c3ef49 | 193 | vy = sin((vdeg - 90) * scosConst); |
gstedile | 0:e40cf759ba9a | 194 | |
gstedile | 2:968b38c3ef49 | 195 | lcd.filltriangle(vx * (cradius - 14) + ccenterx + 1, vy * (cradius - 14) + ccentery + 1, (ccenterx + 1)-(vy * (cradius - 14))*0.1, (ccentery + 1)+vx * (cradius - 14)*0.1,(ccenterx + 1)+(vy * (cradius - 14))*0.1, (ccentery + 1)-vx * (cradius - 14)*0.1, RGB(200,255,0), FILL); |
gstedile | 2:968b38c3ef49 | 196 | lcd.line(vx * (cradius - 14) + ccenterx + 1, vy * (cradius - 14) + ccentery + 1, ccenterx + 1, ccentery + 1, Red); |
gstedile | 2:968b38c3ef49 | 197 | lcd.fillcircle(ccenterx + 1, ccentery + 1, 3, Red); |
gstedile | 2:968b38c3ef49 | 198 | } |
gstedile | 2:968b38c3ef49 | 199 | |
gstedile | 2:968b38c3ef49 | 200 | void drawPrintPrfm( int x, int y, float val){// ubicacion x,y, valor |
gstedile | 2:968b38c3ef49 | 201 | |
gstedile | 2:968b38c3ef49 | 202 | lcd.roundrect( x,y,x+82,y+36,6,4, RGB(0,0,255)); |
gstedile | 2:968b38c3ef49 | 203 | lcd.SelectUserFont(BPG_Arial31x32); |
gstedile | 2:968b38c3ef49 | 204 | if (val==0) lcd.SetTextCursor(x+15,y+3); // 100-val=100 ---> print 100 |
gstedile | 2:968b38c3ef49 | 205 | else lcd.SetTextCursor(x+21,y+3); |
gstedile | 2:968b38c3ef49 | 206 | lcd.foreground(RGB(200,255,0)); |
gstedile | 2:968b38c3ef49 | 207 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 208 | if ( val<=100) { |
gstedile | 2:968b38c3ef49 | 209 | lcd.printf ("%2.0f \r\n",100-val); // Valor porcentual del complemento |
gstedile | 2:968b38c3ef49 | 210 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 2:968b38c3ef49 | 211 | lcd.SetTextCursor(x+62,y+11); |
gstedile | 2:968b38c3ef49 | 212 | lcd.printf("%%"); |
gstedile | 2:968b38c3ef49 | 213 | } |
gstedile | 2:968b38c3ef49 | 214 | else lcd.printf ("---\r\n"); |
gstedile | 2:968b38c3ef49 | 215 | } |
gstedile | 2:968b38c3ef49 | 216 | |
gstedile | 0:e40cf759ba9a | 217 | |
gstedile | 2:968b38c3ef49 | 218 | void drawPrintTime(uint16_t x, uint16_t y, uint8_t h, uint8_t m, uint8_t s) { |
gstedile | 2:968b38c3ef49 | 219 | lcd.SetTextCursor (x, y); |
gstedile | 2:968b38c3ef49 | 220 | lcd.printf(__DATE__); |
gstedile | 2:968b38c3ef49 | 221 | lcd.SetTextCursor (x, y - 13); |
gstedile | 2:968b38c3ef49 | 222 | if (hh > 12) { |
gstedile | 2:968b38c3ef49 | 223 | if (hh < 22) lcd.printf("0"); |
gstedile | 2:968b38c3ef49 | 224 | lcd.printf ("%d",hh - 12); |
gstedile | 2:968b38c3ef49 | 225 | } |
gstedile | 2:968b38c3ef49 | 226 | else { |
gstedile | 2:968b38c3ef49 | 227 | if (hh < 10) lcd.printf("0"); |
gstedile | 2:968b38c3ef49 | 228 | lcd.printf ("%d",hh); |
gstedile | 2:968b38c3ef49 | 229 | } |
gstedile | 2:968b38c3ef49 | 230 | lcd.printf (":"); |
gstedile | 2:968b38c3ef49 | 231 | if (mm < 10) lcd.printf("0"); |
gstedile | 2:968b38c3ef49 | 232 | lcd.printf ("%d",mm); |
gstedile | 2:968b38c3ef49 | 233 | lcd.printf (":"); |
gstedile | 2:968b38c3ef49 | 234 | if (ss < 10) lcd.printf("0"); |
gstedile | 2:968b38c3ef49 | 235 | lcd.printf ("%d",ss); |
gstedile | 2:968b38c3ef49 | 236 | if (hh > 12) { |
gstedile | 2:968b38c3ef49 | 237 | lcd.printf(" pm"); |
gstedile | 2:968b38c3ef49 | 238 | } |
gstedile | 2:968b38c3ef49 | 239 | else { |
gstedile | 2:968b38c3ef49 | 240 | lcd.printf (" am"); |
gstedile | 2:968b38c3ef49 | 241 | } |
gstedile | 2:968b38c3ef49 | 242 | } |
gstedile | 2:968b38c3ef49 | 243 | |
gstedile | 2:968b38c3ef49 | 244 | void reloj(uint16_t cx,uint16_t cy,sentido sent,float gauge, float fullscale){ // coord x, coord y, valor, fondo de escala; |
gstedile | 2:968b38c3ef49 | 245 | ccenterx = cx; |
gstedile | 2:968b38c3ef49 | 246 | ccentery = cy; |
gstedile | 2:968b38c3ef49 | 247 | osx = ccenterx; |
gstedile | 2:968b38c3ef49 | 248 | osy = ccentery; |
gstedile | 2:968b38c3ef49 | 249 | omx = ccenterx; |
gstedile | 2:968b38c3ef49 | 250 | omy = ccentery; |
gstedile | 2:968b38c3ef49 | 251 | ohx = ccenterx; |
gstedile | 2:968b38c3ef49 | 252 | ohy = ccentery; |
gstedile | 2:968b38c3ef49 | 253 | drawClockFace(); |
gstedile | 2:968b38c3ef49 | 254 | drawClockGauge(gauge, fullscale ); |
gstedile | 2:968b38c3ef49 | 255 | drawPrintPrfm(ccenterx - 40, ccentery +40, abs(gauge*100)); |
gstedile | 2:968b38c3ef49 | 256 | } |
gstedile | 2:968b38c3ef49 | 257 | |
gstedile | 0:e40cf759ba9a | 258 | |
gstedile | 0:e40cf759ba9a | 259 | /* 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 | 260 | /* Si el parámetro virtual_speed es cero, se completa la matríz con valores default. Sino, se carga |
gstedile | 1:30b1ca228fc7 | 261 | 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 | 262 | de períodos a vel constante es alcanzada. Este caso es utilizado para testing.*/ |
gstedile | 0:e40cf759ba9a | 263 | |
gstedile | 1:30b1ca228fc7 | 264 | int build_default_Mtrx(VCODATA &Test_Matrix_VCO,NAVDATA &TestNDO, double virtual_speed, double virtual_timestamp){ |
gstedile | 1:30b1ca228fc7 | 265 | double virtual_time=0; |
gstedile | 1:30b1ca228fc7 | 266 | double virtual_longitude=-58.5797; // Mantiene cte la Longitud. |
gstedile | 1:30b1ca228fc7 | 267 | double virtual_latitude=-34.4251; |
gstedile | 1:30b1ca228fc7 | 268 | double virtual_counter=0; |
gstedile | 1:30b1ca228fc7 | 269 | if (virtual_speed==0){ |
gstedile | 1:30b1ca228fc7 | 270 | //virtual_timestamp=0.00000001; // en segundos |
gstedile | 1:30b1ca228fc7 | 271 | for (int i=1; i< Test_Matrix_VCO.vel_max; i++){ |
gstedile | 1:30b1ca228fc7 | 272 | virtual_speed= i*1.0; |
gstedile | 1:30b1ca228fc7 | 273 | |
gstedile | 1:30b1ca228fc7 | 274 | if (i<12) virtual_time=5.0*i; // Formato NMEA: hhmmss,ss |
gstedile | 1:30b1ca228fc7 | 275 | else { |
gstedile | 1:30b1ca228fc7 | 276 | int mnts=int(5*i/60); |
gstedile | 1:30b1ca228fc7 | 277 | virtual_time = ((mnts*100) +((5*i)- (mnts*60))); // Formato NMEA: (hh)mmss,ss |
gstedile | 1:30b1ca228fc7 | 278 | } |
gstedile | 1:30b1ca228fc7 | 279 | TestNDO.LAST_NAV_DATA[cons_interpolated]=-1; // --> -1:Datos iniciales. |
gstedile | 1:30b1ca228fc7 | 280 | TestNDO.np_concat=0; // Cantidad de periodos concatenados:-->0: Solo valores de inicio. |
gstedile | 1:30b1ca228fc7 | 281 | 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 | 282 | if (i<10) virtual_counter+=0.6*i*i; // Simulacion de consumo; modificar y probar |
gstedile | 1:30b1ca228fc7 | 283 | else if (i<20) virtual_counter+=55; |
gstedile | 1:30b1ca228fc7 | 284 | else if(i<30) virtual_counter+=900/i; |
gstedile | 1:30b1ca228fc7 | 285 | else virtual_counter+=0.06*i*i; |
gstedile | 1:30b1ca228fc7 | 286 | int err_Rot=TestNDO.rotate_data(virtual_longitude, virtual_latitude, virtual_time, virtual_counter, NAVIGATION_VMATRIX.vel_max); |
gstedile | 1:30b1ca228fc7 | 287 | virtual_timestamp+=5; // en segundos, 5 segundos de período |
gstedile | 1:30b1ca228fc7 | 288 | if(err_Rot==0){ // Si la rotacion fue 100% exitosa |
gstedile | 1:30b1ca228fc7 | 289 | 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 | 290 | } |
gstedile | 1:30b1ca228fc7 | 291 | else { |
gstedile | 1:30b1ca228fc7 | 292 | |
gstedile | 1:30b1ca228fc7 | 293 | if(err_Rot==1) return 1; // Tiempo entre muestras demasiado grande. Períódo no válido. |
gstedile | 1:30b1ca228fc7 | 294 | else return 2; // Timestamp no válido. |
gstedile | 1:30b1ca228fc7 | 295 | } |
gstedile | 1:30b1ca228fc7 | 296 | } |
gstedile | 1:30b1ca228fc7 | 297 | } |
gstedile | 1:30b1ca228fc7 | 298 | else{ // Rota valores para la velocidad indicada, seteando valores crecientes de consumo para testing |
gstedile | 1:30b1ca228fc7 | 299 | |
gstedile | 0:e40cf759ba9a | 300 | |
gstedile | 1:30b1ca228fc7 | 301 | TestNDO.np_concat=0; // Cantidad de periodos concatenados:-->0: Solo valores de inicio. |
gstedile | 1:30b1ca228fc7 | 302 | float virtual_longitude=-58.5797; // Mantiene cte la Longitud. |
gstedile | 1:30b1ca228fc7 | 303 | 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 | 304 | // latitud navegada en virtual_timestamp @virtual_speed y longitud cte. |
gstedile | 1:30b1ca228fc7 | 305 | virtual_time=virtual_timestamp; //en formato NMEA hhmmss,ss |
gstedile | 1:30b1ca228fc7 | 306 | float virtual_counter=0.01*virtual_timestamp*virtual_timestamp; // Simulacion de consumo creciente; modificar y probar |
gstedile | 1:30b1ca228fc7 | 307 | int err_Rot=TestNDO.rotate_data(virtual_longitude, virtual_latitude, virtual_time, virtual_counter, NAVIGATION_VMATRIX.vel_max); |
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,2)==-1) return -1; // Notar que requiere 2 períodos a igual velocidad para que se almacene definitivamente. |
gstedile | 1:30b1ca228fc7 | 310 | } |
gstedile | 1:30b1ca228fc7 | 311 | else { |
gstedile | 1:30b1ca228fc7 | 312 | if(err_Rot==1) return 1; // Tiempo entre muestras demasiado grande. Períódo no válido. |
gstedile | 1:30b1ca228fc7 | 313 | else return 2; // Timestamp no válido. |
gstedile | 1:30b1ca228fc7 | 314 | } |
gstedile | 1:30b1ca228fc7 | 315 | } |
gstedile | 1:30b1ca228fc7 | 316 | return 0; |
gstedile | 1:30b1ca228fc7 | 317 | } |
gstedile | 1:30b1ca228fc7 | 318 | |
gstedile | 2:968b38c3ef49 | 319 | |
gstedile | 2:968b38c3ef49 | 320 | /* 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 | 2:968b38c3ef49 | 321 | Parametros: Objeto VCODATA; Interpolated: 0 -> no imprime valores interpolados o promediados; 1: interpola con puntos, 2: interpola con lineas*/ |
gstedile | 2:968b38c3ef49 | 322 | |
gstedile | 2:968b38c3ef49 | 323 | void print_VCO_curve(VCODATA &Matrix_VCO, int interpolated){ |
gstedile | 2:968b38c3ef49 | 324 | //lcd.puts("ENTRANDO a print_VCO_curve\r\n"); // DEBUG |
gstedile | 2:968b38c3ef49 | 325 | int vcc[2]; |
gstedile | 2:968b38c3ef49 | 326 | float r,s; // Consumo |
gstedile | 2:968b38c3ef49 | 327 | int y,x; |
gstedile | 2:968b38c3ef49 | 328 | int VCO= Matrix_VCO.get_VCO(vcc); |
gstedile | 2:968b38c3ef49 | 329 | int y_offset=250; //Para que imprima de abajo hacia arriba. |
gstedile | 2:968b38c3ef49 | 330 | int y_text_offset=15; //Para cooregir diferencia de impresion entre caracter y linea. |
gstedile | 2:968b38c3ef49 | 331 | int x_offset=30; //Posicionamiento en x |
gstedile | 2:968b38c3ef49 | 332 | int y_i=y_offset; //Punto origen y |
gstedile | 2:968b38c3ef49 | 333 | int x_i=x_offset; //Punto origen x |
gstedile | 2:968b38c3ef49 | 334 | int x_scale=10; // Escala para graficar eje x. |
gstedile | 2:968b38c3ef49 | 335 | int y_scale=90; // Escala para graficar eje y. |
gstedile | 2:968b38c3ef49 | 336 | lcd.background(RGB(255,255,255)); |
gstedile | 2:968b38c3ef49 | 337 | lcd.foreground(Blue); |
gstedile | 2:968b38c3ef49 | 338 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 2:968b38c3ef49 | 339 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 2:968b38c3ef49 | 340 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 341 | lcd.roundrect( 5,20,470,270,10,8, RGB(255,255,0)); // Rectangulo para encuadre de graficos |
gstedile | 2:968b38c3ef49 | 342 | lcd.fillroundrect(10,25,465,264,5,3,Green); |
gstedile | 2:968b38c3ef49 | 343 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 344 | lcd.background(Green); |
gstedile | 2:968b38c3ef49 | 345 | |
gstedile | 2:968b38c3ef49 | 346 | for (int n=0;n<Matrix_VCO.vel_max;n++){ // Recorre x de 0 a vel_max. |
gstedile | 2:968b38c3ef49 | 347 | s = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período |
gstedile | 2:968b38c3ef49 | 348 | y=int(y_offset-y_scale*s); // El consumo máximo es alrededor de 2 l/m => Multiplico por y_scale |
gstedile | 2:968b38c3ef49 | 349 | // para que ocupe mas pantalla. |
gstedile | 2:968b38c3ef49 | 350 | x=n*x_scale+x_offset; // para aumentar el span (eje x) |
gstedile | 2:968b38c3ef49 | 351 | switch (interpolated){ |
gstedile | 2:968b38c3ef49 | 352 | case 0: if (Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]==0){ //Valores sin interpolar |
gstedile | 2:968b38c3ef49 | 353 | lcd.SetTextCursor(x,y-y_text_offset); |
gstedile | 2:968b38c3ef49 | 354 | lcd.printf("."); |
gstedile | 2:968b38c3ef49 | 355 | } |
gstedile | 2:968b38c3ef49 | 356 | break; |
gstedile | 2:968b38c3ef49 | 357 | 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 | 2:968b38c3ef49 | 358 | lcd.SetTextCursor(x,y-y_text_offset); // el offset adicional es para corregir la diferencia de ubicacion linea-caracter. |
gstedile | 2:968b38c3ef49 | 359 | lcd.printf("."); |
gstedile | 2:968b38c3ef49 | 360 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 361 | break; |
gstedile | 2:968b38c3ef49 | 362 | case 2: lcd.line(x_i,y_i,x,y); // Imprime linea |
gstedile | 2:968b38c3ef49 | 363 | break; |
gstedile | 2:968b38c3ef49 | 364 | default: |
gstedile | 2:968b38c3ef49 | 365 | lcd.SetTextCursor(x,y-y_text_offset); |
gstedile | 2:968b38c3ef49 | 366 | lcd.printf("."); |
gstedile | 2:968b38c3ef49 | 367 | break; |
gstedile | 2:968b38c3ef49 | 368 | } |
gstedile | 2:968b38c3ef49 | 369 | |
gstedile | 2:968b38c3ef49 | 370 | x_i=x; |
gstedile | 2:968b38c3ef49 | 371 | y_i=y; |
gstedile | 2:968b38c3ef49 | 372 | } |
gstedile | 2:968b38c3ef49 | 373 | |
gstedile | 2:968b38c3ef49 | 374 | x_i=x_offset; |
gstedile | 2:968b38c3ef49 | 375 | y_i=y_offset; |
gstedile | 2:968b38c3ef49 | 376 | |
gstedile | 2:968b38c3ef49 | 377 | lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 378 | lcd.background(Green); |
gstedile | 2:968b38c3ef49 | 379 | lcd.foreground(Blue); |
gstedile | 2:968b38c3ef49 | 380 | lcd.SetTextCursor(30,32); |
gstedile | 2:968b38c3ef49 | 381 | lcd.puts("Cons.(l/mn)\r\n"); |
gstedile | 2:968b38c3ef49 | 382 | lcd.SetTextCursor(420,235); |
gstedile | 2:968b38c3ef49 | 383 | lcd.puts("Vel.(kn)\r\n"); |
gstedile | 2:968b38c3ef49 | 384 | lcd.line(x_i,y_i,Matrix_VCO.vel_max*x_scale+x_offset,y_i); // Imprimo eje x. |
gstedile | 2:968b38c3ef49 | 385 | for(int j=10;j<=Matrix_VCO.vel_max;j+=10){ |
gstedile | 2:968b38c3ef49 | 386 | int x=j*x_scale+x_offset; |
gstedile | 2:968b38c3ef49 | 387 | lcd.line(x,y_i,x,y_i-5); |
gstedile | 2:968b38c3ef49 | 388 | lcd.SetTextCursor(x,y_i+5); |
gstedile | 2:968b38c3ef49 | 389 | lcd.printf("%d",j); |
gstedile | 2:968b38c3ef49 | 390 | } |
gstedile | 2:968b38c3ef49 | 391 | lcd.line(x_i,y_i,x_i,40); // Imprimo eje y. |
gstedile | 2:968b38c3ef49 | 392 | for(int k=1;k<=5;k++){ |
gstedile | 2:968b38c3ef49 | 393 | y=y_offset-k*0.5*y_scale; |
gstedile | 2:968b38c3ef49 | 394 | lcd.line(x_i,y,x_i+10,y); |
gstedile | 2:968b38c3ef49 | 395 | lcd.SetTextCursor(x_i-15,y+5); |
gstedile | 2:968b38c3ef49 | 396 | if(y>=0)lcd.printf("%.1f",k*0.5); |
gstedile | 2:968b38c3ef49 | 397 | } |
gstedile | 2:968b38c3ef49 | 398 | if (VCO>0){ |
gstedile | 2:968b38c3ef49 | 399 | r = Matrix_VCO.NAV_DATA[vcc[1]].LAST_NAV_DATA[cons_mile_p]; // Valor de consumo para VMC. |
gstedile | 2:968b38c3ef49 | 400 | s = Matrix_VCO.NAV_DATA[vcc[0]].LAST_NAV_DATA[cons_mile_p]; // Valor de consumo para VCO. |
gstedile | 2:968b38c3ef49 | 401 | 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 | 2:968b38c3ef49 | 402 | x=vcc[0]*x_scale+x_offset; // para aumentar el span (eje x) |
gstedile | 2:968b38c3ef49 | 403 | if (interpolated==2){ |
gstedile | 2:968b38c3ef49 | 404 | lcd.circle(x,y,5); |
gstedile | 2:968b38c3ef49 | 405 | } |
gstedile | 2:968b38c3ef49 | 406 | else{ |
gstedile | 2:968b38c3ef49 | 407 | lcd.SetTextCursor(x,y); |
gstedile | 2:968b38c3ef49 | 408 | lcd.printf("*"); |
gstedile | 2:968b38c3ef49 | 409 | } |
gstedile | 2:968b38c3ef49 | 410 | lcd.SetTextCursor(vcc[0]*x_scale+x_offset+10,y_offset-s*y_scale+20); |
gstedile | 2:968b38c3ef49 | 411 | lcd.printf("%.2lf l/m",s); |
gstedile | 2:968b38c3ef49 | 412 | lcd.SetTextCursor(vcc[0]*x_scale+x_offset+10,y_offset-s*y_scale+10); |
gstedile | 2:968b38c3ef49 | 413 | lcd.printf("VCO: %d kn",vcc[0]); |
gstedile | 2:968b38c3ef49 | 414 | |
gstedile | 2:968b38c3ef49 | 415 | y=int(y_offset-y_scale*r); // el consumo máximo es alrededor de 2 l/m. Multiplico por y_scale para que ocupe mas pantalla. |
gstedile | 2:968b38c3ef49 | 416 | x=vcc[1]*x_scale+x_offset; // para aumentar el span (eje x) |
gstedile | 2:968b38c3ef49 | 417 | if (interpolated==2){ |
gstedile | 2:968b38c3ef49 | 418 | lcd.circle(x,y,5); |
gstedile | 2:968b38c3ef49 | 419 | } |
gstedile | 2:968b38c3ef49 | 420 | else{ |
gstedile | 2:968b38c3ef49 | 421 | lcd.SetTextCursor(x,y); |
gstedile | 2:968b38c3ef49 | 422 | lcd.printf("*"); |
gstedile | 2:968b38c3ef49 | 423 | } |
gstedile | 2:968b38c3ef49 | 424 | lcd.SetTextCursor(vcc[1]*x_scale+x_offset+10,y_offset-r*y_scale-20); |
gstedile | 2:968b38c3ef49 | 425 | lcd.printf("%.2lf l/m",r); |
gstedile | 2:968b38c3ef49 | 426 | lcd.SetTextCursor(vcc[1]*x_scale+x_offset+10,y_offset-r*y_scale-30); |
gstedile | 2:968b38c3ef49 | 427 | lcd.printf("VMC: %d kn",vcc[1]); |
gstedile | 2:968b38c3ef49 | 428 | |
gstedile | 2:968b38c3ef49 | 429 | |
gstedile | 2:968b38c3ef49 | 430 | } |
gstedile | 2:968b38c3ef49 | 431 | else{ |
gstedile | 2:968b38c3ef49 | 432 | lcd.SetTextCursor(120,35); |
gstedile | 2:968b38c3ef49 | 433 | lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 434 | lcd.printf("No hay datos suficientes para obtener la VCO"); |
gstedile | 2:968b38c3ef49 | 435 | lcd.printf("%d",VCO);//DEBUG |
gstedile | 2:968b38c3ef49 | 436 | } |
gstedile | 2:968b38c3ef49 | 437 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 438 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 439 | } |
gstedile | 2:968b38c3ef49 | 440 | |
gstedile | 2:968b38c3ef49 | 441 | |
gstedile | 2:968b38c3ef49 | 442 | /* 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 | 2:968b38c3ef49 | 443 | Parametros: Objeto VCODATA; */ |
gstedile | 2:968b38c3ef49 | 444 | |
gstedile | 2:968b38c3ef49 | 445 | void print_VCO_data(VCODATA &Matrix_VCO){ |
gstedile | 2:968b38c3ef49 | 446 | float cons, vel; |
gstedile | 2:968b38c3ef49 | 447 | lcd.SelectUserFont(BPG_Arial10x10); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 448 | lcd.background(RGB(255,255,255)); |
gstedile | 2:968b38c3ef49 | 449 | lcd.foreground(Blue); |
gstedile | 2:968b38c3ef49 | 450 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 2:968b38c3ef49 | 451 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 452 | lcd.puts("Velocidad-Consumo\r\n"); |
gstedile | 2:968b38c3ef49 | 453 | for (int n=0;n<83;n++){ // Recorre x de 0 a 83. (Maxima cantidad que entra en una pantalla) |
gstedile | 2:968b38c3ef49 | 454 | cons = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período |
gstedile | 2:968b38c3ef49 | 455 | vel= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad del período. |
gstedile | 2:968b38c3ef49 | 456 | lcd.printf("| %d - %lf | %lf |",n,vel,cons); |
gstedile | 2:968b38c3ef49 | 457 | } |
gstedile | 2:968b38c3ef49 | 458 | wait(3); |
gstedile | 2:968b38c3ef49 | 459 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 460 | for (int n=83;n<Matrix_VCO.vel_max;n++){ // Recorre x de 0 a vel_max. |
gstedile | 2:968b38c3ef49 | 461 | cons = Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo por milla del período |
gstedile | 2:968b38c3ef49 | 462 | vel= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad del período. |
gstedile | 2:968b38c3ef49 | 463 | lcd.printf("| %d - %lf | %lf |",n,vel,cons); |
gstedile | 2:968b38c3ef49 | 464 | } |
gstedile | 2:968b38c3ef49 | 465 | //lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 466 | |
gstedile | 2:968b38c3ef49 | 467 | } |
gstedile | 2:968b38c3ef49 | 468 | |
gstedile | 2:968b38c3ef49 | 469 | |
gstedile | 2:968b38c3ef49 | 470 | /* Funcion mtrx2sd: Guarda los datos de la matriz en un archivo de texto existente*/ |
gstedile | 2:968b38c3ef49 | 471 | |
gstedile | 2:968b38c3ef49 | 472 | int mtrx2sd(VCODATA &Matrix_VCO, const char *filename){ |
gstedile | 2:968b38c3ef49 | 473 | 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 | 2:968b38c3ef49 | 474 | FILE *fp1; |
gstedile | 2:968b38c3ef49 | 475 | fp1 = fopen(filename, "w"); //Apertura para escritura |
gstedile | 2:968b38c3ef49 | 476 | if(fp1 == NULL) { |
gstedile | 2:968b38c3ef49 | 477 | return -1; |
gstedile | 2:968b38c3ef49 | 478 | } |
gstedile | 2:968b38c3ef49 | 479 | for (int n=0;n<=Matrix_VCO.vel_max;n++){ |
gstedile | 2:968b38c3ef49 | 480 | lngtd_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_f]; // Longitud y Latitud iniciales y finales. |
gstedile | 2:968b38c3ef49 | 481 | lngtd_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_i]; |
gstedile | 2:968b38c3ef49 | 482 | lttd_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_f]; |
gstedile | 2:968b38c3ef49 | 483 | lttd_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_i]; |
gstedile | 2:968b38c3ef49 | 484 | 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 | 2:968b38c3ef49 | 485 | tm_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_i]; // Timestamp al inicio del período en horas. |
gstedile | 2:968b38c3ef49 | 486 | dstnc_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[distance_p]; // Distancia recorrida durante este período en millas nauticas. |
gstedile | 2:968b38c3ef49 | 487 | spd_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]; // Velocidad media del período en nudos. |
gstedile | 2:968b38c3ef49 | 488 | cnsmptn_i= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_i]; // Consumo en litros al comienzo del período. |
gstedile | 2:968b38c3ef49 | 489 | cnsmptn_f= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_f]; // Consumo en litros al final del período. |
gstedile | 2:968b38c3ef49 | 490 | cnsmptn_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_p]; // Consumo en litros del período. |
gstedile | 2:968b38c3ef49 | 491 | cns_ml_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]; // Consumo en litros por milla nautica. |
gstedile | 2:968b38c3ef49 | 492 | cns_hr_p= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_hour_p]; // Consumo en litros por hora. |
gstedile | 2:968b38c3ef49 | 493 | cns_ntrpltd= Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]; // Consumo interpolado?: -1-> initial padding |
gstedile | 2:968b38c3ef49 | 494 | |
gstedile | 2:968b38c3ef49 | 495 | 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 | 2:968b38c3ef49 | 496 | } |
gstedile | 2:968b38c3ef49 | 497 | return fclose(fp1); |
gstedile | 2:968b38c3ef49 | 498 | } |
gstedile | 2:968b38c3ef49 | 499 | |
gstedile | 2:968b38c3ef49 | 500 | /* Funcion sd2mtrx: Guarda los datos de un archivo de texto existente en la matriz*/ |
gstedile | 2:968b38c3ef49 | 501 | |
gstedile | 2:968b38c3ef49 | 502 | int sd2mtrx(VCODATA &Matrix_VCO, const char *filename){ |
gstedile | 2:968b38c3ef49 | 503 | 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 | 2:968b38c3ef49 | 504 | FILE *fp1; |
gstedile | 2:968b38c3ef49 | 505 | fp1 = fopen(filename, "r"); //Apertura para escritura |
gstedile | 2:968b38c3ef49 | 506 | if(fp1 == NULL) { |
gstedile | 2:968b38c3ef49 | 507 | return -1; |
gstedile | 2:968b38c3ef49 | 508 | } |
gstedile | 2:968b38c3ef49 | 509 | for (int n=0;n<Matrix_VCO.vel_max;n++){ |
gstedile | 2:968b38c3ef49 | 510 | fscanf(fp1,"%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf",&lngtd_f,&lngtd_i,<td_f,<td_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 | 2:968b38c3ef49 | 511 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_f]=lngtd_f; |
gstedile | 2:968b38c3ef49 | 512 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[longitude_i]=lngtd_i; |
gstedile | 2:968b38c3ef49 | 513 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_f]=lttd_f; |
gstedile | 2:968b38c3ef49 | 514 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[latitude_i]=lttd_i; |
gstedile | 2:968b38c3ef49 | 515 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_f]=tm_f; |
gstedile | 2:968b38c3ef49 | 516 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[time_i]=tm_i; |
gstedile | 2:968b38c3ef49 | 517 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[distance_p]=dstnc_p; |
gstedile | 2:968b38c3ef49 | 518 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[speed_p]=spd_p; |
gstedile | 2:968b38c3ef49 | 519 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_i]=cnsmptn_i; |
gstedile | 2:968b38c3ef49 | 520 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_f]=cnsmptn_f; |
gstedile | 2:968b38c3ef49 | 521 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[consumption_p]=cnsmptn_p; |
gstedile | 2:968b38c3ef49 | 522 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_mile_p]=cns_ml_p; |
gstedile | 2:968b38c3ef49 | 523 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_hour_p]=cns_hr_p; |
gstedile | 2:968b38c3ef49 | 524 | Matrix_VCO.NAV_DATA[n].LAST_NAV_DATA[cons_interpolated]=cns_ntrpltd; |
gstedile | 2:968b38c3ef49 | 525 | |
gstedile | 2:968b38c3ef49 | 526 | } |
gstedile | 2:968b38c3ef49 | 527 | return fclose(fp1); |
gstedile | 2:968b38c3ef49 | 528 | } |
gstedile | 2:968b38c3ef49 | 529 | |
gstedile | 2:968b38c3ef49 | 530 | |
gstedile | 1:30b1ca228fc7 | 531 | |
gstedile | 1:30b1ca228fc7 | 532 | /* 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 | 533 | |
gstedile | 2:968b38c3ef49 | 534 | void print_signal(int x1, int y1, int x2, int y2, int R, int G, int B, figura FIG, sentido S, float prfm){ |
gstedile | 1:30b1ca228fc7 | 535 | int tx1,tx2,tx3,rx1,rx2,ty1,ty2,ty3,ry1,ry2, delta_ty1,delta_ty2,delta_ty3; |
gstedile | 2:968b38c3ef49 | 536 | uint16_t cex,cey,cer1,cer2; |
gstedile | 2:968b38c3ef49 | 537 | int delta=6; // Redimensiono para ajstar la figura dentro del rectangulo |
gstedile | 2:968b38c3ef49 | 538 | x1+=delta; |
gstedile | 2:968b38c3ef49 | 539 | y1+=delta; |
gstedile | 2:968b38c3ef49 | 540 | x2-=delta; |
gstedile | 2:968b38c3ef49 | 541 | y2-=delta; |
gstedile | 2:968b38c3ef49 | 542 | |
gstedile | 1:30b1ca228fc7 | 543 | cex=(x1+x2)/2; |
gstedile | 1:30b1ca228fc7 | 544 | cey=(y1+y2)/2; |
gstedile | 1:30b1ca228fc7 | 545 | cer2= (y2-y1)/2; |
gstedile | 1:30b1ca228fc7 | 546 | cer1= (x2-x1)/2; |
gstedile | 1:30b1ca228fc7 | 547 | |
gstedile | 1:30b1ca228fc7 | 548 | switch (S){ |
gstedile | 1:30b1ca228fc7 | 549 | case 1: { // UP |
gstedile | 2:968b38c3ef49 | 550 | tx1=(x2+x1)/2; //Dimensiones para flecha |
gstedile | 2:968b38c3ef49 | 551 | ty1=y1+4; |
gstedile | 2:968b38c3ef49 | 552 | tx2=x2-2; |
gstedile | 1:30b1ca228fc7 | 553 | ty2=(y2+y1)/2; |
gstedile | 2:968b38c3ef49 | 554 | tx3=x1+2; |
gstedile | 1:30b1ca228fc7 | 555 | ty3=(y2+y1)/2; |
gstedile | 1:30b1ca228fc7 | 556 | delta_ty1=8; |
gstedile | 1:30b1ca228fc7 | 557 | delta_ty2=-5; |
gstedile | 1:30b1ca228fc7 | 558 | delta_ty3=-5; |
gstedile | 1:30b1ca228fc7 | 559 | rx1=(x2+3*x1)/4; |
gstedile | 1:30b1ca228fc7 | 560 | ry1=(y2+y1)/2; |
gstedile | 1:30b1ca228fc7 | 561 | rx2=(3*x2+x1)/4; |
gstedile | 2:968b38c3ef49 | 562 | ry2=y2-4; |
gstedile | 1:30b1ca228fc7 | 563 | } |
gstedile | 1:30b1ca228fc7 | 564 | break; |
gstedile | 1:30b1ca228fc7 | 565 | case 0: { // DWN |
gstedile | 1:30b1ca228fc7 | 566 | tx1=(x2+x1)/2; |
gstedile | 2:968b38c3ef49 | 567 | ty1=y2-4; |
gstedile | 2:968b38c3ef49 | 568 | tx2=x2-2; |
gstedile | 1:30b1ca228fc7 | 569 | ty2=(y2+y1)/2; |
gstedile | 2:968b38c3ef49 | 570 | tx3=x1+3; |
gstedile | 1:30b1ca228fc7 | 571 | ty3=(y2+y1)/2; |
gstedile | 1:30b1ca228fc7 | 572 | delta_ty1=-8; |
gstedile | 1:30b1ca228fc7 | 573 | delta_ty2=5; |
gstedile | 1:30b1ca228fc7 | 574 | delta_ty3=5; |
gstedile | 1:30b1ca228fc7 | 575 | rx1=(x2+3*x1)/4; |
gstedile | 2:968b38c3ef49 | 576 | ry1=y1+4; |
gstedile | 1:30b1ca228fc7 | 577 | rx2=(3*x2+x1)/4; |
gstedile | 1:30b1ca228fc7 | 578 | ry2=(y2+y1)/2; |
gstedile | 0:e40cf759ba9a | 579 | } |
gstedile | 1:30b1ca228fc7 | 580 | break; |
gstedile | 1:30b1ca228fc7 | 581 | default: |
gstedile | 1:30b1ca228fc7 | 582 | break; |
gstedile | 1:30b1ca228fc7 | 583 | } |
gstedile | 1:30b1ca228fc7 | 584 | switch (FIG){ |
gstedile | 2:968b38c3ef49 | 585 | case 0: // ZONA VCO |
gstedile | 2:968b38c3ef49 | 586 | // lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue); |
gstedile | 2:968b38c3ef49 | 587 | //lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153)); |
gstedile | 2:968b38c3ef49 | 588 | //lcd.foreground(BrightBlue); |
gstedile | 2:968b38c3ef49 | 589 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 590 | lcd.fillroundrect( x1+3,y1+3, x2-3,y2-3, 5,4, RGB(R,G,B)); |
gstedile | 2:968b38c3ef49 | 591 | lcd.SetTextCursor(x1+14,y1-10+(y2-y1)/5); |
gstedile | 2:968b38c3ef49 | 592 | lcd.background(RGB(R,G,B)); |
gstedile | 1:30b1ca228fc7 | 593 | lcd.foreground(White); |
gstedile | 1:30b1ca228fc7 | 594 | lcd.printf ("NAVEGANDO"); |
gstedile | 2:968b38c3ef49 | 595 | lcd.SetTextCursor(x1+29,y1-18+(y2-y1)/2-10); |
gstedile | 1:30b1ca228fc7 | 596 | //lcd.SetTextCursor(132,140); |
gstedile | 2:968b38c3ef49 | 597 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 1:30b1ca228fc7 | 598 | lcd.printf ("EN"); |
gstedile | 2:968b38c3ef49 | 599 | lcd.SetTextCursor(x1+19,y1-18+(y2-y1)*2/3); |
gstedile | 1:30b1ca228fc7 | 600 | //lcd.SetTextCursor(135,170); |
gstedile | 2:968b38c3ef49 | 601 | lcd.printf ("ZONA"); |
gstedile | 2:968b38c3ef49 | 602 | |
gstedile | 2:968b38c3ef49 | 603 | lcd.SetTextCursor(x1+24,y1-18+(y2-y1)*9/10); |
gstedile | 2:968b38c3ef49 | 604 | //lcd.SetTextCursor(135,170); |
gstedile | 2:968b38c3ef49 | 605 | lcd.printf ("VCO"); |
gstedile | 1:30b1ca228fc7 | 606 | break; |
gstedile | 2:968b38c3ef49 | 607 | case 1: // SIN DATOS |
gstedile | 2:968b38c3ef49 | 608 | //lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue); |
gstedile | 2:968b38c3ef49 | 609 | //lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153)); |
gstedile | 2:968b38c3ef49 | 610 | lcd.fillroundrect( x1+3,y1+3, x2-3,y2-3, 5,4, RGB(0,0,0)); // Limpia el rectangulo |
gstedile | 1:30b1ca228fc7 | 611 | lcd.foreground(BrightBlue); |
gstedile | 2:968b38c3ef49 | 612 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 613 | lcd.SetTextCursor(x1+18,y1+38); |
gstedile | 1:30b1ca228fc7 | 614 | lcd.printf ("SIN DATOS"); |
gstedile | 2:968b38c3ef49 | 615 | lcd.SetTextCursor(x1+14,y1+68); |
gstedile | 1:30b1ca228fc7 | 616 | lcd.printf ("SUFICIENTES\r\n"); |
gstedile | 1:30b1ca228fc7 | 617 | break; |
gstedile | 2:968b38c3ef49 | 618 | case 2: // CIRCULO |
gstedile | 2:968b38c3ef49 | 619 | lcd.fillroundrect( x1+3,y1+3, x2-3,y2-3, 5,4, RGB(0,0,0)); //Limpia el rectangulo |
gstedile | 2:968b38c3ef49 | 620 | lcd.circle( cex,cey, cer2+10, BrightBlue); |
gstedile | 2:968b38c3ef49 | 621 | lcd.fillcircle(cex,cey,cer2+5,RGB(R,G,B)); |
gstedile | 1:30b1ca228fc7 | 622 | |
gstedile | 1:30b1ca228fc7 | 623 | break; |
gstedile | 2:968b38c3ef49 | 624 | case 3: // FLECHA |
gstedile | 2:968b38c3ef49 | 625 | //lcd.roundrect( x1-8,y1-8,x2+8,y2+8, 10,8, BrightBlue); |
gstedile | 2:968b38c3ef49 | 626 | //lcd.roundrect( x1-4,y1-4, x2+4,y2+4, 10,8, RGB(153,0,153)); |
gstedile | 2:968b38c3ef49 | 627 | lcd.fillroundrect( x1+3,y1+3, x2-3,y2-3, 5,4, RGB(0,0,0)); //Limpia el rectangulo |
gstedile | 1:30b1ca228fc7 | 628 | lcd.fillroundrect(rx1,ry1, rx2,ry2, 5,3, RGB(R,G,B) ); |
gstedile | 1:30b1ca228fc7 | 629 | lcd.filltriangle( tx1,ty1, tx2,ty2, tx3,ty3, RGB(R,G,B)); |
gstedile | 2:968b38c3ef49 | 630 | lcd.SetTextCursor(x1+(x2-x1)/2-3,y1+(y2-y1)/5); |
gstedile | 1:30b1ca228fc7 | 631 | lcd.background(BrightGreen); |
gstedile | 1:30b1ca228fc7 | 632 | lcd.foreground(Black); |
gstedile | 2:968b38c3ef49 | 633 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 1:30b1ca228fc7 | 634 | lcd.printf ("A"); |
gstedile | 2:968b38c3ef49 | 635 | lcd.SetTextCursor(x1+(x2-x1)/3,y1+(y2-y1)/2-10); |
gstedile | 1:30b1ca228fc7 | 636 | //lcd.SetTextCursor(132,140); |
gstedile | 1:30b1ca228fc7 | 637 | lcd.printf ("ZONA"); |
gstedile | 2:968b38c3ef49 | 638 | lcd.SetTextCursor(x1+(x2-x1)/3+2,y1+(y2-y1)*2/3); |
gstedile | 1:30b1ca228fc7 | 639 | //lcd.SetTextCursor(135,170); |
gstedile | 1:30b1ca228fc7 | 640 | lcd.printf ("VCO"); |
gstedile | 1:30b1ca228fc7 | 641 | break; |
gstedile | 2:968b38c3ef49 | 642 | case 4: // ELIPSE |
gstedile | 2:968b38c3ef49 | 643 | lcd.fillroundrect( x1+3,y1+3, x2-3,y2-3, 5,4, RGB(0,0,0)); //Limpia el rectangulo |
gstedile | 2:968b38c3ef49 | 644 | lcd.ellipse( cex,cey,cer1,cer2, BrightBlue); |
gstedile | 2:968b38c3ef49 | 645 | lcd.fillellipse( cex,cey, cer1-5,cer2-5, RGB(R,G,B)); |
gstedile | 2:968b38c3ef49 | 646 | break; |
gstedile | 2:968b38c3ef49 | 647 | case 5: // RELOJ |
gstedile | 2:968b38c3ef49 | 648 | if (S==UP)reloj(cex,cey,S,prfm-1,2); |
gstedile | 2:968b38c3ef49 | 649 | else reloj(cex,cey,S,1-prfm,2); // coord x, coord y, sentido, valor, fondo de escala; |
gstedile | 2:968b38c3ef49 | 650 | break; |
gstedile | 1:30b1ca228fc7 | 651 | default: |
gstedile | 2:968b38c3ef49 | 652 | reloj(cex,cey,S,prfm-1,2); |
gstedile | 1:30b1ca228fc7 | 653 | break; |
gstedile | 1:30b1ca228fc7 | 654 | |
gstedile | 2:968b38c3ef49 | 655 | } |
gstedile | 1:30b1ca228fc7 | 656 | } |
gstedile | 1:30b1ca228fc7 | 657 | |
gstedile | 2:968b38c3ef49 | 658 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>FUNCION print_fondo1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 1:30b1ca228fc7 | 659 | |
gstedile | 2:968b38c3ef49 | 660 | void print_fondo1(uint8_t r, uint8_t g,uint8_t b,uint8_t r1, uint8_t g1,uint8_t b1){ |
gstedile | 2:968b38c3ef49 | 661 | int y_offset=250; //Para que imprima de abajo hacia arriba. |
gstedile | 2:968b38c3ef49 | 662 | int x_offset=30; //Posicionamiento en x |
gstedile | 2:968b38c3ef49 | 663 | |
gstedile | 2:968b38c3ef49 | 664 | lcd.background(RGB(0,0,0)); |
gstedile | 2:968b38c3ef49 | 665 | lcd.foreground(RGB(r1,g1,b1)); |
gstedile | 2:968b38c3ef49 | 666 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 2:968b38c3ef49 | 667 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 2:968b38c3ef49 | 668 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 669 | lcd.roundrect( 2,2,475,270,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de graficos |
gstedile | 2:968b38c3ef49 | 670 | lcd.fillroundrect(7,7,470,264,5,3, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 671 | lcd.foreground(RGB(r1,g1,b1)); |
gstedile | 2:968b38c3ef49 | 672 | lcd.background(RGB(r,g,b)); // Para escribir sobre este fondo |
gstedile | 2:968b38c3ef49 | 673 | |
gstedile | 2:968b38c3ef49 | 674 | } |
gstedile | 2:968b38c3ef49 | 675 | |
gstedile | 2:968b38c3ef49 | 676 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> fin FUNCION print_fondo1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 677 | |
gstedile | 2:968b38c3ef49 | 678 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>FUNCION print_fondo2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 679 | |
gstedile | 2:968b38c3ef49 | 680 | void print_fondo2(uint8_t r, uint8_t g,uint8_t b,uint8_t r1, uint8_t g1,uint8_t b1){ |
gstedile | 2:968b38c3ef49 | 681 | /* Declaradas |
gstedile | 2:968b38c3ef49 | 682 | int sepx= 105; // Separacion x entre recuadros |
gstedile | 2:968b38c3ef49 | 683 | int sepy= 66; // Separacion x entre recuadros |
gstedile | 2:968b38c3ef49 | 684 | int sizex1=100; // Tamaño cuadro para valores |
gstedile | 2:968b38c3ef49 | 685 | int sizey1=40; |
gstedile | 2:968b38c3ef49 | 686 | int xr1=10; // Posicion de recuadros para exhibir datos |
gstedile | 2:968b38c3ef49 | 687 | int yr1=10; |
gstedile | 2:968b38c3ef49 | 688 | int xr2=xr1+sepx; |
gstedile | 2:968b38c3ef49 | 689 | int yr2=yr1; |
gstedile | 2:968b38c3ef49 | 690 | int xr3=xr1; |
gstedile | 2:968b38c3ef49 | 691 | int yr3=yr1+sepy; |
gstedile | 2:968b38c3ef49 | 692 | int xr4=xr1; |
gstedile | 2:968b38c3ef49 | 693 | int yr4=yr3+sepy; |
gstedile | 2:968b38c3ef49 | 694 | int xr5=xr1; |
gstedile | 2:968b38c3ef49 | 695 | int yr5=yr4+sepy; |
gstedile | 2:968b38c3ef49 | 696 | int xr6=xr1; |
gstedile | 2:968b38c3ef49 | 697 | int yr6=yr5+sepy; |
gstedile | 2:968b38c3ef49 | 698 | */ |
gstedile | 2:968b38c3ef49 | 699 | lcd.background(RGB(0,0,0)); |
gstedile | 2:968b38c3ef49 | 700 | lcd.foreground(RGB(r1,g1,b1)); |
gstedile | 2:968b38c3ef49 | 701 | lcd.SelectUserFont(BPG_Arial20x20); |
gstedile | 2:968b38c3ef49 | 702 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 2:968b38c3ef49 | 703 | |
gstedile | 2:968b38c3ef49 | 704 | lcd.roundrect( xr1,yr1,xr1+sizex1,yr1+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 705 | //lcd.fillroundrect(xr1+3,yr1+4,xr1+95,yr1+sizey1,8,5, Black); //RGB(r,g,b)); // Rectangulo interior lleno |
gstedile | 2:968b38c3ef49 | 706 | lcd.roundrect(xr1+3,yr1+4,xr1+95,yr1+sizey1,8,5, RGB(r,g,b)); // Vacio |
gstedile | 2:968b38c3ef49 | 707 | lcd.roundrect( xr2,yr2,xr2+sizex1,yr2+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 708 | //lcd.fillroundrect(xr2+4,yr2+4,xr2+95,yr2+sizey1,8,5, Black); //RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 709 | lcd.roundrect(xr2+4,yr2+4,xr2+95,yr2+sizey1,8,5, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 710 | lcd.roundrect( xr3,yr3,xr3+sizex1,yr3+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 711 | //lcd.fillroundrect(xr3+4,yr3+4,xr3+95,yr3+sizey1,8,5, Black); //RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 712 | lcd.roundrect(xr3+4,yr3+4,xr3+95,yr3+sizey1,8,5, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 713 | lcd.roundrect( xr4,yr4,xr4+sizex1,yr4+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 714 | //lcd.fillroundrect(xr4+4,yr4+4,xr4+95,yr4+sizey1,8,5, Black); //RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 715 | lcd.roundrect(xr4+4,yr4+4,xr4+95,yr4+sizey1,8,5, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 716 | lcd.roundrect( xr5,yr5,xr5+sizex1,yr5+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 717 | //lcd.fillroundrect(xr5+4,yr5+4,xr5+95,yr5+sizey1,8,5, Black); //RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 718 | lcd.roundrect(xr5+4,yr5+4,xr5+95,yr5+sizey1,8,5, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 719 | lcd.roundrect( xr6,yr6,xr6+sizex1,yr6+sepy-8,10,8, RGB(r1,g1,b1)); // Rectangulo para encuadre de valores |
gstedile | 2:968b38c3ef49 | 720 | //lcd.fillroundrect(xr6+4,yr6+4,xr6+95,yr6+sizey1,8,5, Black); //RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 721 | lcd.roundrect(xr6+4,yr6+4,xr6+95,yr6+sizey1,8,5, RGB(r,g,b)); |
gstedile | 2:968b38c3ef49 | 722 | |
gstedile | 2:968b38c3ef49 | 723 | lcd.roundrect( signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz+3, 10,8, BrightBlue); //Rectangulo para encuadre de grafico de señalizacion (Flecha) |
gstedile | 2:968b38c3ef49 | 724 | //lcd.roundrect( signal_x+4, signal_y-4, signal_x+signal_x_sz+4,signal_y + signal_y_sz+4, 10,8, RGB(153,0,153)); |
gstedile | 2:968b38c3ef49 | 725 | |
gstedile | 2:968b38c3ef49 | 726 | lcd.foreground(RGB(r1,g1,b1)); |
gstedile | 2:968b38c3ef49 | 727 | //lcd.background(RGB(r,g,b)); // Si se usa lleno, para escribir sobre este fondo |
gstedile | 2:968b38c3ef49 | 728 | lcd.background(Black); // Para rectangulo vacio |
gstedile | 2:968b38c3ef49 | 729 | } |
gstedile | 2:968b38c3ef49 | 730 | |
gstedile | 2:968b38c3ef49 | 731 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FIN FUNCION print_fondo2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 732 | |
gstedile | 2:968b38c3ef49 | 733 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCION print_values <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 734 | |
gstedile | 2:968b38c3ef49 | 735 | |
gstedile | 2:968b38c3ef49 | 736 | void print_values(int vel, int vco, int vmc, double cons_m, double cons_h, float lcount){ |
gstedile | 2:968b38c3ef49 | 737 | |
gstedile | 2:968b38c3ef49 | 738 | int offset_x=30, offset_y=8; // Para ubicar los valores dentro de los recuadros del fondo2. |
gstedile | 2:968b38c3ef49 | 739 | print_fondo2(255,255,255,0,0,255); // ya deja el background correcto |
gstedile | 2:968b38c3ef49 | 740 | //lcd.background(Black); // |
gstedile | 2:968b38c3ef49 | 741 | int foregndcolor=RGB(0,255,0); |
gstedile | 2:968b38c3ef49 | 742 | int despx=7,despy=7; |
gstedile | 2:968b38c3ef49 | 743 | lcd.SelectUserFont(BPG_Arial31x32); |
gstedile | 2:968b38c3ef49 | 744 | lcd.SetTextCursor(xr1+offset_x,yr1+offset_y); |
gstedile | 2:968b38c3ef49 | 745 | lcd.fillroundrect(xr1+despx,yr1+despy,xr1+sizex1-despx,yr1+sizey1-3,8,5,Black); |
gstedile | 2:968b38c3ef49 | 746 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 747 | lcd.printf("%2d ",vel); |
gstedile | 2:968b38c3ef49 | 748 | lcd.SetTextCursor(xr2+ offset_x,yr2+offset_y); |
gstedile | 2:968b38c3ef49 | 749 | lcd.fillroundrect(xr2+despx,yr2+despy,xr2+sizex1-despx,yr2+sizey1-3,8,5, Black); |
gstedile | 2:968b38c3ef49 | 750 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 751 | lcd.printf("%2d",vco); |
gstedile | 2:968b38c3ef49 | 752 | lcd.SetTextCursor(xr3+offset_x,yr3+offset_y); |
gstedile | 2:968b38c3ef49 | 753 | lcd.fillroundrect(xr3+despx,yr3+despy,xr3+sizex1-despx,yr3+sizey1-3,8,5, Black); |
gstedile | 2:968b38c3ef49 | 754 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 755 | lcd.printf("%2d", vmc); |
gstedile | 2:968b38c3ef49 | 756 | lcd.SetTextCursor(xr4+offset_x-10,yr4+offset_y); |
gstedile | 2:968b38c3ef49 | 757 | lcd.fillroundrect(xr4+despx,yr4+despy,xr4+sizex1-despx,yr4+sizey1-3,8,5, Black); |
gstedile | 2:968b38c3ef49 | 758 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 759 | lcd.printf("%.2lf", cons_m); |
gstedile | 2:968b38c3ef49 | 760 | lcd.SetTextCursor(xr5+offset_x-10,yr5+offset_y); |
gstedile | 2:968b38c3ef49 | 761 | lcd.fillroundrect(xr5+despx,yr5+despy,xr5+sizex1-despx,yr5+sizey1-3,8,5, Black); |
gstedile | 2:968b38c3ef49 | 762 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 763 | lcd.printf("%.2lf", cons_h); |
gstedile | 2:968b38c3ef49 | 764 | lcd.SetTextCursor(xr6+offset_x-10,yr6+offset_y); |
gstedile | 2:968b38c3ef49 | 765 | lcd.fillroundrect(xr6+despx,yr6+despy,xr6+sizex1-despx,yr6+sizey1-3,8,5, Black); |
gstedile | 2:968b38c3ef49 | 766 | lcd.foreground(foregndcolor); |
gstedile | 2:968b38c3ef49 | 767 | if (lcount<100)lcd.printf("%.2lf", lcount); |
gstedile | 2:968b38c3ef49 | 768 | else lcd.printf("%.1lf", lcount); |
gstedile | 2:968b38c3ef49 | 769 | |
gstedile | 2:968b38c3ef49 | 770 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 771 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 772 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 773 | lcd.SetTextCursor(xr1+offset_x-12,yr1+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 774 | lcd.printf("VEL.GPS(kt)"); |
gstedile | 2:968b38c3ef49 | 775 | lcd.SetTextCursor(xr2+offset_x-5,yr2+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 776 | lcd.printf("VCO (kt)"); |
gstedile | 2:968b38c3ef49 | 777 | lcd.SetTextCursor(xr3+offset_x-5,yr3+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 778 | lcd.printf("VMC (kt)"); |
gstedile | 2:968b38c3ef49 | 779 | lcd.SetTextCursor(xr4+offset_x-7,yr4+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 780 | lcd.printf("Cons.(L/M)"); |
gstedile | 2:968b38c3ef49 | 781 | lcd.SetTextCursor(xr5+offset_x-5,yr5+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 782 | lcd.printf("Cons(L/H)"); |
gstedile | 2:968b38c3ef49 | 783 | lcd.SetTextCursor(xr6+offset_x-15,yr6+sepy-28+offset_y); |
gstedile | 2:968b38c3ef49 | 784 | lcd.printf("Cons.Ac(L/M)"); |
gstedile | 2:968b38c3ef49 | 785 | } |
gstedile | 2:968b38c3ef49 | 786 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FIN FUNCION print_values <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 787 | |
gstedile | 2:968b38c3ef49 | 788 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCION bienvenida <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 789 | void bienvenida(){ |
gstedile | 2:968b38c3ef49 | 790 | // Prueba de gauge |
gstedile | 2:968b38c3ef49 | 791 | |
gstedile | 2:968b38c3ef49 | 792 | |
gstedile | 2:968b38c3ef49 | 793 | print_fondo1(0,0,0,0,0,255); |
gstedile | 2:968b38c3ef49 | 794 | lcd.SelectUserFont(BPG_Arial63x63); |
gstedile | 2:968b38c3ef49 | 795 | lcd.SetTextCursor(135,34); |
gstedile | 2:968b38c3ef49 | 796 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 797 | lcd.puts("SNOCC"); |
gstedile | 2:968b38c3ef49 | 798 | lcd.SelectUserFont(BPG_Arial31x32); |
gstedile | 2:968b38c3ef49 | 799 | lcd.SetTextCursor(20,130); |
gstedile | 2:968b38c3ef49 | 800 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 801 | lcd.puts("S"); |
gstedile | 2:968b38c3ef49 | 802 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 803 | lcd.puts("istema\t"); |
gstedile | 2:968b38c3ef49 | 804 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 805 | lcd.puts(" N"); |
gstedile | 2:968b38c3ef49 | 806 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 807 | lcd.puts("autico de "); |
gstedile | 2:968b38c3ef49 | 808 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 809 | lcd.puts(" O"); |
gstedile | 2:968b38c3ef49 | 810 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 811 | lcd.puts("ptimizacion "); |
gstedile | 2:968b38c3ef49 | 812 | lcd.SetTextCursor(40,200); |
gstedile | 2:968b38c3ef49 | 813 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 814 | lcd.puts("de "); |
gstedile | 2:968b38c3ef49 | 815 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 816 | lcd.puts("C"); |
gstedile | 2:968b38c3ef49 | 817 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 818 | lcd.puts("onsumo "); |
gstedile | 2:968b38c3ef49 | 819 | lcd.puts("de "); |
gstedile | 2:968b38c3ef49 | 820 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 821 | lcd.puts("C"); |
gstedile | 2:968b38c3ef49 | 822 | lcd.foreground(RGB(255,255,0)); |
gstedile | 2:968b38c3ef49 | 823 | lcd.puts("ombustible"); |
gstedile | 2:968b38c3ef49 | 824 | wait(5); |
gstedile | 2:968b38c3ef49 | 825 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 826 | print_fondo1(0,225,0,0,255,0); |
gstedile | 2:968b38c3ef49 | 827 | lcd.SelectUserFont(BPG_Arial63x63); |
gstedile | 2:968b38c3ef49 | 828 | lcd.background(RGB(0,220,0)); |
gstedile | 2:968b38c3ef49 | 829 | lcd.foreground(RGB(220,255,0)); |
gstedile | 2:968b38c3ef49 | 830 | lcd.SetTextCursor(95,20); |
gstedile | 2:968b38c3ef49 | 831 | lcd.puts("Bienvenido"); |
gstedile | 2:968b38c3ef49 | 832 | lcd.SetTextCursor(220,100); |
gstedile | 2:968b38c3ef49 | 833 | lcd.puts("a"); |
gstedile | 2:968b38c3ef49 | 834 | lcd.SetTextCursor(160,190); |
gstedile | 2:968b38c3ef49 | 835 | lcd.puts("Bordo"); |
gstedile | 2:968b38c3ef49 | 836 | |
gstedile | 2:968b38c3ef49 | 837 | |
gstedile | 2:968b38c3ef49 | 838 | wait(5); |
gstedile | 2:968b38c3ef49 | 839 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 840 | print_fondo1(0,0,0,0,0,255); |
gstedile | 2:968b38c3ef49 | 841 | print_fondo2(255,255,255,0,0,255); |
gstedile | 2:968b38c3ef49 | 842 | reloj(345,135,UP,-1,2); |
gstedile | 2:968b38c3ef49 | 843 | wait(1); |
gstedile | 2:968b38c3ef49 | 844 | reloj(345,132,UP,1,2); |
gstedile | 2:968b38c3ef49 | 845 | wait(1); |
gstedile | 2:968b38c3ef49 | 846 | reloj(345,132,UP,0,2); |
gstedile | 2:968b38c3ef49 | 847 | wait(3); |
gstedile | 2:968b38c3ef49 | 848 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 849 | print_fondo1(0,0,0,0,0,255); |
gstedile | 2:968b38c3ef49 | 850 | } |
gstedile | 2:968b38c3ef49 | 851 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FIN FUNCION bienvenida <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 852 | |
gstedile | 2:968b38c3ef49 | 853 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FUNCION despedida <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 854 | void despedida(){ |
gstedile | 2:968b38c3ef49 | 855 | |
gstedile | 2:968b38c3ef49 | 856 | |
gstedile | 2:968b38c3ef49 | 857 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 858 | print_fondo1(0,225,0,0,255,0); |
gstedile | 2:968b38c3ef49 | 859 | lcd.SelectUserFont(BPG_Arial63x63); |
gstedile | 2:968b38c3ef49 | 860 | lcd.background(RGB(0,225,0)); |
gstedile | 2:968b38c3ef49 | 861 | lcd.foreground(RGB(220,255,0)); |
gstedile | 2:968b38c3ef49 | 862 | lcd.SetTextCursor(170,20); |
gstedile | 2:968b38c3ef49 | 863 | lcd.puts("Hasta"); |
gstedile | 2:968b38c3ef49 | 864 | lcd.SetTextCursor(100,100); |
gstedile | 2:968b38c3ef49 | 865 | lcd.puts(" el proximo"); |
gstedile | 2:968b38c3ef49 | 866 | lcd.SetTextCursor(170,180); |
gstedile | 2:968b38c3ef49 | 867 | lcd.puts("viaje..."); |
gstedile | 2:968b38c3ef49 | 868 | wait(2); |
gstedile | 2:968b38c3ef49 | 869 | lcd.background(RGB(0,100,0)); |
gstedile | 2:968b38c3ef49 | 870 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 871 | lcd.SetTextCursor(112,100); |
gstedile | 2:968b38c3ef49 | 872 | lcd.puts("SNOCC"); |
gstedile | 2:968b38c3ef49 | 873 | wait(2); |
gstedile | 2:968b38c3ef49 | 874 | |
gstedile | 2:968b38c3ef49 | 875 | for (int i=0; i<273;i++){ |
gstedile | 2:968b38c3ef49 | 876 | lcd.foreground(RGB(0,225,0)); |
gstedile | 2:968b38c3ef49 | 877 | lcd.line(0,i,480,i); |
gstedile | 2:968b38c3ef49 | 878 | wait_ms(15); |
gstedile | 2:968b38c3ef49 | 879 | lcd.foreground(RGB(200,200,255)); |
gstedile | 2:968b38c3ef49 | 880 | lcd.line(0,i+2,480,i+2); |
gstedile | 2:968b38c3ef49 | 881 | lcd.foreground(RGB(0,0,200)); |
gstedile | 2:968b38c3ef49 | 882 | lcd.line(0,i,480,i); |
gstedile | 2:968b38c3ef49 | 883 | wait_ms(15); |
gstedile | 2:968b38c3ef49 | 884 | lcd.foreground(RGB(0,0,200)); |
gstedile | 2:968b38c3ef49 | 885 | lcd.line(0,i+2,480,i+2); |
gstedile | 2:968b38c3ef49 | 886 | } |
gstedile | 2:968b38c3ef49 | 887 | lcd.background(RGB(0,0,0)); |
gstedile | 2:968b38c3ef49 | 888 | lcd.cls(); |
gstedile | 2:968b38c3ef49 | 889 | while(1); |
gstedile | 2:968b38c3ef49 | 890 | } |
gstedile | 2:968b38c3ef49 | 891 | //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> FIN FUNCION despedida <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
gstedile | 2:968b38c3ef49 | 892 | |
gstedile | 2:968b38c3ef49 | 893 | |
gstedile | 2:968b38c3ef49 | 894 | |
gstedile | 2:968b38c3ef49 | 895 | |
gstedile | 2:968b38c3ef49 | 896 | |
gstedile | 2:968b38c3ef49 | 897 | |
gstedile | 2:968b38c3ef49 | 898 | //################################################### MAIN ################################################### |
gstedile | 0:e40cf759ba9a | 899 | |
gstedile | 0:e40cf759ba9a | 900 | int main() |
gstedile | 1:30b1ca228fc7 | 901 | { int VCC[2]; // Array de valores crucero críticos. VCC[0]=VCO; VCC[1]=VMC (Velocidad de Máximo Consumo) |
gstedile | 1:30b1ca228fc7 | 902 | VCC[0]=-1; |
gstedile | 1:30b1ca228fc7 | 903 | VCC[1]=-1; |
gstedile | 2:968b38c3ef49 | 904 | bool menu_flag1=0; // Flags para touch |
gstedile | 2:968b38c3ef49 | 905 | bool menu_flag2=1; |
gstedile | 2:968b38c3ef49 | 906 | bool menu_flag3=0; // 1--> Apagar |
gstedile | 1:30b1ca228fc7 | 907 | int R,G,B=0; |
gstedile | 1:30b1ca228fc7 | 908 | int R1,G1,B1=0; |
gstedile | 1:30b1ca228fc7 | 909 | int err_Mtrx=0; |
gstedile | 1:30b1ca228fc7 | 910 | float PRFM=-1; // Performance |
gstedile | 1:30b1ca228fc7 | 911 | sentido SENTIDO; // Sentido de la flecha |
gstedile | 2:968b38c3ef49 | 912 | figura FIG; |
gstedile | 2:968b38c3ef49 | 913 | loc_t butt_x1=450; // Posicion boton1 |
gstedile | 2:968b38c3ef49 | 914 | loc_t butt_y1=240; |
gstedile | 2:968b38c3ef49 | 915 | loc_t butt_x2=405; // Posicion boton2 |
gstedile | 2:968b38c3ef49 | 916 | loc_t butt_y2=40; |
gstedile | 2:968b38c3ef49 | 917 | loc_t butt_x3=450; // Posicion boton3 |
gstedile | 2:968b38c3ef49 | 918 | loc_t butt_y3=12; |
gstedile | 2:968b38c3ef49 | 919 | rect_t PrintScreenRectB1 = { butt_x1-20, butt_y1, butt_x1+20, butt_y1+25}; // Rectangulo para encuadrar boton 1. |
gstedile | 2:968b38c3ef49 | 920 | rect_t PrintScreenFillRectB1 = { butt_x1-18, butt_y1+2, butt_x1+18, butt_y1+23 }; // Rectangulo relleno para encuadrar boton 1 |
gstedile | 2:968b38c3ef49 | 921 | rect_t PrintScreenRectB2 = { butt_x2-25, butt_y2, butt_x2+25, butt_y2+25}; // Rectangulo para encuadrar boton 2. |
gstedile | 2:968b38c3ef49 | 922 | rect_t PrintScreenFillRectB2 = { butt_x2-23, butt_y2+2, butt_x2+24, butt_y2+23 }; // Rectangulo relleno para encuadrar boton 2 |
gstedile | 2:968b38c3ef49 | 923 | rect_t PrintScreenRectB3 = { butt_x3-18, butt_y3, butt_x3+18, butt_y3+25}; // Rectangulo para encuadrar boton 3. |
gstedile | 2:968b38c3ef49 | 924 | rect_t PrintScreenFillRectB3 = { butt_x3-16, butt_y3+2, butt_x3+16, butt_y3+23 }; // Rectangulo relleno para encuadrar boton 3. |
gstedile | 1:30b1ca228fc7 | 925 | pc.baud(460800); |
gstedile | 0:e40cf759ba9a | 926 | lcd.init(); |
gstedile | 2:968b38c3ef49 | 927 | lcd.TouchPanelCalibrate(); // Esta funcion fue modificada para fijar calibracion. |
gstedile | 0:e40cf759ba9a | 928 | lcd.cls(); |
gstedile | 0:e40cf759ba9a | 929 | lcd.foreground(RGB(255,255,0)); // Seteo del color de las letras. |
gstedile | 0:e40cf759ba9a | 930 | lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 0:e40cf759ba9a | 931 | GPS gps(p9, p10); // Agrego para comunicacion con el GPS |
gstedile | 0:e40cf759ba9a | 932 | |
gstedile | 0:e40cf759ba9a | 933 | |
gstedile | 0:e40cf759ba9a | 934 | //------------------------------------------------------------------------------------------------------------- |
gstedile | 1:30b1ca228fc7 | 935 | // Sensor de flujo: |
gstedile | 0:e40cf759ba9a | 936 | InterruptIn pulse_sensor(p15); // Defino pulse_sensor como una entrada de interrupción en p15 . |
gstedile | 0:e40cf759ba9a | 937 | pulse_sensor.mode(PullUp); // PullUp para esa entrada. |
gstedile | 0:e40cf759ba9a | 938 | //pulse_sensor.rise(&trigger); // Dispara interrupción con flanco ascendente. (Podría tambien ser desecendente--> fall) |
gstedile | 0:e40cf759ba9a | 939 | pulse_sensor.fall(&trigger); |
gstedile | 1:30b1ca228fc7 | 940 | //-------------------------------------------------------------------------------------------------------------- |
gstedile | 0:e40cf759ba9a | 941 | |
gstedile | 0:e40cf759ba9a | 942 | lcd.SetTextCursor(0,0); // Posicionamiento de cursor. |
gstedile | 1:30b1ca228fc7 | 943 | lcd.puts(">>>>>>>>>>>>>< Proyecto SNOCC ><<<<<<<<<<<<<<\r\n"); |
gstedile | 2:968b38c3ef49 | 944 | if (!sd2mtrx(NAVIGATION_VMATRIX, sd_file)) lcd.puts("Datos leidos de SD card\r\n"); // Cargando matriz desde SD. |
gstedile | 0:e40cf759ba9a | 945 | else{ |
gstedile | 0:e40cf759ba9a | 946 | lcd.puts("Error al leer los datos.\r\n Inicio sin datos historicos.\r\n"); |
gstedile | 1:30b1ca228fc7 | 947 | if (TESTING){ |
gstedile | 1:30b1ca228fc7 | 948 | err_Mtrx=build_default_Mtrx(NAVIGATION_VMATRIX,TestNAV,0,0); |
gstedile | 1:30b1ca228fc7 | 949 | 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 | 950 | else lcd.printf("Matriz default creada con exito.\r\n"); |
gstedile | 1:30b1ca228fc7 | 951 | } |
gstedile | 0:e40cf759ba9a | 952 | if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n"); |
gstedile | 1:30b1ca228fc7 | 953 | else { |
gstedile | 1:30b1ca228fc7 | 954 | lcd.puts("Error al guardar los datos default.\r\nCreando directorio en SD card...\r\n"); |
gstedile | 2:968b38c3ef49 | 955 | if(!mkdir(sd_dir, 0777)){ // Creando directorio si no existe. |
gstedile | 1:30b1ca228fc7 | 956 | lcd.printf("Creado: %s\r\n", sd_dir); |
gstedile | 1:30b1ca228fc7 | 957 | lcd.printf("Cargando datos de inicio default en SD card...\r\n"); |
gstedile | 1:30b1ca228fc7 | 958 | if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n"); |
gstedile | 1:30b1ca228fc7 | 959 | else lcd.puts("Error al guardar los datos default.\r\nNo se podran almacenar los datos.\r\n"); |
gstedile | 1:30b1ca228fc7 | 960 | } |
gstedile | 1:30b1ca228fc7 | 961 | else lcd.puts("Error al guardar los datos default.\r\nNo se podran almacenar los datos.\r\n"); |
gstedile | 0:e40cf759ba9a | 962 | } |
gstedile | 2:968b38c3ef49 | 963 | } |
gstedile | 2:968b38c3ef49 | 964 | |
gstedile | 2:968b38c3ef49 | 965 | bienvenida(); // Bienvenida |
gstedile | 2:968b38c3ef49 | 966 | |
gstedile | 2:968b38c3ef49 | 967 | float delta=5.0;//DEBUG |
gstedile | 2:968b38c3ef49 | 968 | float virtual_tmstmp=0.0;//DEBUG |
gstedile | 2:968b38c3ef49 | 969 | int prueba=0; // Variable indice para simulacion. |
gstedile | 0:e40cf759ba9a | 970 | |
gstedile | 2:968b38c3ef49 | 971 | ///////////////////////////////////////////////// LOOP INFINITO //////////////////////////////////////////////////// |
gstedile | 0:e40cf759ba9a | 972 | while(1) { |
gstedile | 0:e40cf759ba9a | 973 | |
gstedile | 0:e40cf759ba9a | 974 | lcd.SetTextCursor(0,0); // Pongo cursor en posicion |
gstedile | 2:968b38c3ef49 | 975 | |
gstedile | 2:968b38c3ef49 | 976 | if (DEBUG_GPS)lcd.printf("M0: %s \r\n\r\n", gps.msg); //Imprimo el mensaje crudo proveniente de la uart |
gstedile | 2:968b38c3ef49 | 977 | |
gstedile | 2:968b38c3ef49 | 978 | if(!menu_flag1){ //Boton 1 no presionado |
gstedile | 2:968b38c3ef49 | 979 | |
gstedile | 2:968b38c3ef49 | 980 | if(gps.sample()) { // Si es exitosa la obtencion de datos del gps. |
gstedile | 2:968b38c3ef49 | 981 | lcd.foreground(RGB(0,255,0)); // Seteo del color de las letras. |
gstedile | 2:968b38c3ef49 | 982 | lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 983 | lcd.SetTextCursor(0,0); // Cursor en posicion |
gstedile | 2:968b38c3ef49 | 984 | |
gstedile | 2:968b38c3ef49 | 985 | if (!NAVIGATION_OBJECT.rotate_data(gps.longitude, gps.latitude, gps.time, Counter,NAVIGATION_VMATRIX.vel_max )){ |
gstedile | 2:968b38c3ef49 | 986 | NAVIGATION_OBJECT.LAST_NAV_DATA[cons_interpolated]=0; // Dato tipo recolectado |
gstedile | 2:968b38c3ef49 | 987 | err_Store=NAVIGATION_VMATRIX.store_data(NAVIGATION_OBJECT,3); // Luego de rotar los datos en la tabla de navegacion, |
gstedile | 2:968b38c3ef49 | 988 | // la guarda en la matriz segun criterios de la clase VCODATA |
gstedile | 2:968b38c3ef49 | 989 | // Deben registrarse 3 periodos de velocidad quasi constante para |
gstedile | 2:968b38c3ef49 | 990 | // que se almacene definitivamente el dato consolidado de los mismos. |
gstedile | 2:968b38c3ef49 | 991 | |
gstedile | 2:968b38c3ef49 | 992 | int i=int(NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p]); |
gstedile | 2:968b38c3ef49 | 993 | NAVIGATION_V_SMOOTH_MTRX.smooth(4, NAVIGATION_VMATRIX); // Genera matriz de datos filtrados con pasabajos |
gstedile | 2:968b38c3ef49 | 994 | int VCO=NAVIGATION_V_SMOOTH_MTRX.get_VCO(&VCC[0]); // VCO OBTENIDA DE MATRIZ FILTRADA. |
gstedile | 2:968b38c3ef49 | 995 | |
gstedile | 2:968b38c3ef49 | 996 | print_values(NAVIGATION_OBJECT.LAST_NAV_DATA[speed_p], VCC[0],VCC[1], NAVIGATION_OBJECT.LAST_NAV_DATA[cons_mile_p], NAVIGATION_OBJECT.LAST_NAV_DATA[cons_hour_p], LCounter); |
gstedile | 0:e40cf759ba9a | 997 | |
gstedile | 2:968b38c3ef49 | 998 | if (DEBUG1) { |
gstedile | 2:968b38c3ef49 | 999 | lcd.SetTextCursor(0,60); |
gstedile | 2:968b38c3ef49 | 1000 | lcd.puts("Rotacion exitosa!-->"); |
gstedile | 2:968b38c3ef49 | 1001 | lcd.printf("Error de rotacion:\t %d\r\n",err_Store); // DEBUG |
gstedile | 2:968b38c3ef49 | 1002 | lcd.printf("Speed_f_Mtrx(%d):\t %lf kn.\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]); // DEBUG |
gstedile | 2:968b38c3ef49 | 1003 | 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 | 2:968b38c3ef49 | 1004 | lcd.printf("Time_f_Mtrx(%d):\t %lf Hours.\r\n",i, NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[time_f]); // DEBUG |
gstedile | 2:968b38c3ef49 | 1005 | lcd.printf("Time_f_Last(%d):\t %lf Hours.\r\n",i, NAVIGATION_OBJECT.LAST_NAV_DATA[time_f]); // DEBUG |
gstedile | 2:968b38c3ef49 | 1006 | lcd.printf("Dist_p_Mtrx(%d):\t %lf miles.\r\n",i,NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[distance_p]); // DEBUG |
gstedile | 2:968b38c3ef49 | 1007 | } |
gstedile | 2:968b38c3ef49 | 1008 | NAVIGATION_VMATRIX.interpolate(); // Interpolacion. |
gstedile | 2:968b38c3ef49 | 1009 | if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos guardados en SD card\r\n"); // Almacenamiento de datos en SD. |
gstedile | 2:968b38c3ef49 | 1010 | else lcd.printf("Error al guardar los datos.\r\n"); |
gstedile | 2:968b38c3ef49 | 1011 | |
gstedile | 2:968b38c3ef49 | 1012 | //______ _______________________________________________________________________________________________________________ |
gstedile | 2:968b38c3ef49 | 1013 | /*int signal_x=100; // REGION DE SEÑALIZACION |
gstedile | 2:968b38c3ef49 | 1014 | int signal_y=75; |
gstedile | 2:968b38c3ef49 | 1015 | int signal_x_sz=110; |
gstedile | 2:968b38c3ef49 | 1016 | int signal_y_sz=120;*/ |
gstedile | 2:968b38c3ef49 | 1017 | |
gstedile | 2:968b38c3ef49 | 1018 | //PRFM=NAVIGATION_VMATRIX.performance(i); |
gstedile | 2:968b38c3ef49 | 1019 | PRFM=NAVIGATION_V_SMOOTH_MTRX.performance(i); // PERFORMANCE OBTENIDA DE MATRIZ FILTRADA. |
gstedile | 2:968b38c3ef49 | 1020 | |
gstedile | 2:968b38c3ef49 | 1021 | R1=0; // COLOR DEFAULT PARA CIRCULO DE REFERENCIA DE PERFORMANCE (,PRFM) |
gstedile | 2:968b38c3ef49 | 1022 | G1=255; |
gstedile | 2:968b38c3ef49 | 1023 | B1=0; |
gstedile | 2:968b38c3ef49 | 1024 | lcd.foreground(RGB(R1,G1,B1)); |
gstedile | 2:968b38c3ef49 | 1025 | /*lcd.SetTextCursor(0,245); |
gstedile | 2:968b38c3ef49 | 1026 | lcd.printf("VCO: %d \t\t",VCC[0]); |
gstedile | 2:968b38c3ef49 | 1027 | lcd.printf("VMC: %d \r\n",VCC[1]); |
gstedile | 2:968b38c3ef49 | 1028 | */ |
gstedile | 2:968b38c3ef49 | 1029 | if (PRFM!=-1 && VCC[0]!=-1){ |
gstedile | 2:968b38c3ef49 | 1030 | if (PRFM>0.98) { |
gstedile | 2:968b38c3ef49 | 1031 | R=0; |
gstedile | 2:968b38c3ef49 | 1032 | G=255; |
gstedile | 2:968b38c3ef49 | 1033 | B=0; |
gstedile | 2:968b38c3ef49 | 1034 | } |
gstedile | 2:968b38c3ef49 | 1035 | else { |
gstedile | 2:968b38c3ef49 | 1036 | if (PRFM<0.75){ |
gstedile | 2:968b38c3ef49 | 1037 | R=255; |
gstedile | 2:968b38c3ef49 | 1038 | G=255*4*PRFM/3; |
gstedile | 2:968b38c3ef49 | 1039 | B=0; |
gstedile | 2:968b38c3ef49 | 1040 | } |
gstedile | 2:968b38c3ef49 | 1041 | else { |
gstedile | 2:968b38c3ef49 | 1042 | R=255*4*(1-PRFM); |
gstedile | 2:968b38c3ef49 | 1043 | G=255; |
gstedile | 2:968b38c3ef49 | 1044 | B=0; |
gstedile | 2:968b38c3ef49 | 1045 | } |
gstedile | 2:968b38c3ef49 | 1046 | } |
gstedile | 2:968b38c3ef49 | 1047 | float delta_vel= NAVIGATION_VMATRIX.NAV_DATA[i].LAST_NAV_DATA[speed_p]-VCC[0]; // ES IGUAL QUE EN MTRX FILTRADA |
gstedile | 2:968b38c3ef49 | 1048 | if (fabs(delta_vel)<2){ |
gstedile | 2:968b38c3ef49 | 1049 | FIG=ZONA; |
gstedile | 2:968b38c3ef49 | 1050 | } |
gstedile | 2:968b38c3ef49 | 1051 | else FIG=FLECHA; |
gstedile | 2:968b38c3ef49 | 1052 | |
gstedile | 2:968b38c3ef49 | 1053 | if (delta_vel<0) SENTIDO=UP; |
gstedile | 2:968b38c3ef49 | 1054 | else SENTIDO=DWN; |
gstedile | 2:968b38c3ef49 | 1055 | |
gstedile | 2:968b38c3ef49 | 1056 | |
gstedile | 2:968b38c3ef49 | 1057 | print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, 0, 255, 0,FIG,SENTIDO,PRFM); // SI ESTA EN ENTORNO DE VCO--> IMPRIMIR "ZONA VCO". |
gstedile | 2:968b38c3ef49 | 1058 | |
gstedile | 2:968b38c3ef49 | 1059 | } |
gstedile | 2:968b38c3ef49 | 1060 | else { |
gstedile | 2:968b38c3ef49 | 1061 | |
gstedile | 2:968b38c3ef49 | 1062 | print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz,R,G,B,SIN_DT,NO,PRFM); // SIN DATOS: SOLO RECUADRO PARA TEXTO |
gstedile | 2:968b38c3ef49 | 1063 | |
gstedile | 2:968b38c3ef49 | 1064 | } |
gstedile | 2:968b38c3ef49 | 1065 | |
gstedile | 2:968b38c3ef49 | 1066 | // =================================== ZONA PERFORMANCE =================================================================== |
gstedile | 2:968b38c3ef49 | 1067 | |
gstedile | 2:968b38c3ef49 | 1068 | if (PRFM >= 0) print_signal(305, 85,385,175, R, G, B,GAUGE,SENTIDO,PRFM); |
gstedile | 2:968b38c3ef49 | 1069 | else print_signal(305, 85, 385,175, R, G, B,GAUGE,UP, 2.35); |
gstedile | 2:968b38c3ef49 | 1070 | |
gstedile | 2:968b38c3ef49 | 1071 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 1072 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 1073 | |
gstedile | 2:968b38c3ef49 | 1074 | // =================================== FIN ZONA PERFORMANCE =================================================================== |
gstedile | 2:968b38c3ef49 | 1075 | |
gstedile | 2:968b38c3ef49 | 1076 | //############################## MODULO DE PERIODO NO VALIDADO ######################################################################### |
gstedile | 2:968b38c3ef49 | 1077 | } |
gstedile | 2:968b38c3ef49 | 1078 | else {lcd.puts("Periodo no valido!\r\n"); |
gstedile | 2:968b38c3ef49 | 1079 | wait(1); |
gstedile | 2:968b38c3ef49 | 1080 | print_fondo1(0,0,0,0,0,255); |
gstedile | 2:968b38c3ef49 | 1081 | print_fondo2(255,255,255,0,0,255); |
gstedile | 2:968b38c3ef49 | 1082 | } |
gstedile | 0:e40cf759ba9a | 1083 | |
gstedile | 2:968b38c3ef49 | 1084 | } |
gstedile | 2:968b38c3ef49 | 1085 | else { // No hay datos gps |
gstedile | 2:968b38c3ef49 | 1086 | |
gstedile | 2:968b38c3ef49 | 1087 | lcd.foreground(RGB(0,255,0)); // Seteo del color de las letras. |
gstedile | 2:968b38c3ef49 | 1088 | lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 1089 | lcd.SetTextCursor(10,10); |
gstedile | 2:968b38c3ef49 | 1090 | if (DEBUG1){ |
gstedile | 2:968b38c3ef49 | 1091 | if (!mtrx2sd(NAVIGATION_VMATRIX, sd_file)) lcd.printf("Datos default guardados en SD card\r\n"); //DEBUG |
gstedile | 2:968b38c3ef49 | 1092 | else lcd.printf("Error al guardar los datos default.\r\n"); //DEBUG |
gstedile | 2:968b38c3ef49 | 1093 | lcd.printf("Aun no hay datos gps disponibles. Usando historicos.\r\n"); |
gstedile | 2:968b38c3ef49 | 1094 | } |
gstedile | 2:968b38c3ef49 | 1095 | |
gstedile | 1:30b1ca228fc7 | 1096 | NAVIGATION_V_SMOOTH_MTRX.smooth(4, NAVIGATION_VMATRIX); // Genera matriz de datos filtrados con pasabajos |
gstedile | 1:30b1ca228fc7 | 1097 | int VCO=NAVIGATION_V_SMOOTH_MTRX.get_VCO(&VCC[0]); // VCO OBTENIDA DE MATRIZ FILTRADA. |
gstedile | 1:30b1ca228fc7 | 1098 | |
gstedile | 2:968b38c3ef49 | 1099 | if(!SIMULATION) print_values(-1, VCC[0],VCC[1],-1, NAVIGATION_OBJECT.LAST_NAV_DATA[cons_hour_p], LCounter); |
gstedile | 2:968b38c3ef49 | 1100 | |
gstedile | 2:968b38c3ef49 | 1101 | |
gstedile | 1:30b1ca228fc7 | 1102 | |
gstedile | 1:30b1ca228fc7 | 1103 | //_____________________________________________________________________________________________________________________ |
gstedile | 2:968b38c3ef49 | 1104 | // REGION DE SEÑALIZACION |
gstedile | 2:968b38c3ef49 | 1105 | |
gstedile | 2:968b38c3ef49 | 1106 | if (prueba >= NAVIGATION_VMATRIX.vel_max) prueba=prueba-NAVIGATION_VMATRIX.vel_max; |
gstedile | 2:968b38c3ef49 | 1107 | PRFM=NAVIGATION_V_SMOOTH_MTRX.performance(prueba); // PERFORMANCE OBTENIDA DE MATRIZ FILTRADA. |
gstedile | 2:968b38c3ef49 | 1108 | |
gstedile | 2:968b38c3ef49 | 1109 | float delta_vel= NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[speed_p]-VCC[0]; // Diferencia de velocidad respecto de la vco |
gstedile | 1:30b1ca228fc7 | 1110 | if (PRFM!=-1 && VCC[0]!=-1){ |
gstedile | 2:968b38c3ef49 | 1111 | if (fabs(delta_vel)<2) FIG=ZONA; |
gstedile | 1:30b1ca228fc7 | 1112 | else FIG=FLECHA; |
gstedile | 1:30b1ca228fc7 | 1113 | if (delta_vel<0) SENTIDO=UP; |
gstedile | 1:30b1ca228fc7 | 1114 | else SENTIDO=DWN; |
gstedile | 2:968b38c3ef49 | 1115 | |
gstedile | 2:968b38c3ef49 | 1116 | print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz, 0, 255, 0,FIG,SENTIDO,PRFM); // SI ESTA EN ENTORNO DE VCO--> IMPRIMIR "ZONA VCO". |
gstedile | 1:30b1ca228fc7 | 1117 | } |
gstedile | 1:30b1ca228fc7 | 1118 | else { |
gstedile | 2:968b38c3ef49 | 1119 | print_signal(signal_x, signal_y, signal_x + signal_x_sz,signal_y + signal_y_sz,R,G,B,SIN_DT,NO,PRFM); // SIN DATOS SUFICIENTES |
gstedile | 1:30b1ca228fc7 | 1120 | |
gstedile | 1:30b1ca228fc7 | 1121 | } |
gstedile | 2:968b38c3ef49 | 1122 | // =================================== ZONA PERFORMANCE =================================================================== |
gstedile | 2:968b38c3ef49 | 1123 | |
gstedile | 2:968b38c3ef49 | 1124 | if (PRFM >= 0) print_signal(305, 85,385,175, R, G, B,GAUGE,SENTIDO,PRFM); |
gstedile | 2:968b38c3ef49 | 1125 | else print_signal(305, 85, 385,175, R, G, B,GAUGE,UP, 2.35); |
gstedile | 2:968b38c3ef49 | 1126 | |
gstedile | 2:968b38c3ef49 | 1127 | print_values(NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[speed_p], VCC[0],VCC[1], NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[cons_mile_p], NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[cons_hour_p], LCounter); |
gstedile | 1:30b1ca228fc7 | 1128 | |
gstedile | 1:30b1ca228fc7 | 1129 | lcd.background(Black); |
gstedile | 1:30b1ca228fc7 | 1130 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 1131 | lcd.SetTextCursor(223,12); |
gstedile | 2:968b38c3ef49 | 1132 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 1133 | //lcd.printf("Speedsim[%d]: %.1f \r\n",prueba,NAVIGATION_VMATRIX.NAV_DATA[prueba].LAST_NAV_DATA[speed_p]); |
gstedile | 2:968b38c3ef49 | 1134 | lcd.printf("SIMULACION"); |
gstedile | 2:968b38c3ef49 | 1135 | wait_ms(600); |
gstedile | 2:968b38c3ef49 | 1136 | lcd.foreground(RGB(255,0,0)); |
gstedile | 2:968b38c3ef49 | 1137 | lcd.SetTextCursor(223,12); |
gstedile | 2:968b38c3ef49 | 1138 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 1139 | lcd.printf("SIMULACION"); |
gstedile | 2:968b38c3ef49 | 1140 | prueba++; |
gstedile | 2:968b38c3ef49 | 1141 | // ====================================== FIN ZONA PERFORMANCE =============================================================== |
gstedile | 2:968b38c3ef49 | 1142 | |
gstedile | 2:968b38c3ef49 | 1143 | //%%%%%%%%%%%%%%%%% ESTA PARTE ES PARA VALIDAR EL FUNCIONAMIENTO DE LA ROTACION Y ALMACENAMIENTO DE DATOS %%%%%%%%%%%%%%%%%%%%% |
gstedile | 2:968b38c3ef49 | 1144 | |
gstedile | 2:968b38c3ef49 | 1145 | if (TESTING){ //DEBUG |
gstedile | 2:968b38c3ef49 | 1146 | float vrtl_speed=12; // pruebo cargar datos para velocidad 12. |
gstedile | 2:968b38c3ef49 | 1147 | TestNAV.LAST_NAV_DATA[cons_interpolated]=0; // --> -1:Datos iniciales. 0--> recolectado (setear para testing) |
gstedile | 2:968b38c3ef49 | 1148 | err_Mtrx=build_default_Mtrx(NAVIGATION_VMATRIX, TestNAV, vrtl_speed, virtual_tmstmp); |
gstedile | 2:968b38c3ef49 | 1149 | if(err_Mtrx!=0){ |
gstedile | 2:968b38c3ef49 | 1150 | 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 | 2:968b38c3ef49 | 1151 | } |
gstedile | 2:968b38c3ef49 | 1152 | else lcd.printf("Datos para virtual_speed= %.1f cargado con exito.\r\n",vrtl_speed); |
gstedile | 2:968b38c3ef49 | 1153 | lcd.printf("Virtual_Timestamp=%.2f.\t",virtual_tmstmp);//DEBUG |
gstedile | 2:968b38c3ef49 | 1154 | virtual_tmstmp+=delta; // DEBUG Esta en formato NMEA(hhmmss.ss): no son validos los valores de segundos mayores a 59, por lo tanto |
gstedile | 2:968b38c3ef49 | 1155 | // cuando se ingrese 100,00 despues de 95,00 se espera que el sistema no valide la ronda pues en ese |
gstedile | 2:968b38c3ef49 | 1156 | // formato 100,00 < 95,00 (1m < 95s); seria un valor entrante menor que el anterior. |
gstedile | 2:968b38c3ef49 | 1157 | |
gstedile | 2:968b38c3ef49 | 1158 | lcd.printf("V_time(h):%lf\r\n",TestNAV.time_NMEA2hours(virtual_tmstmp)); |
gstedile | 2:968b38c3ef49 | 1159 | } |
gstedile | 2:968b38c3ef49 | 1160 | //%%%%%%%%%%%%% FIN DE LA PARTE PARA PROBAR EL FUNCIONAMIENTO DE LA ROTACION Y ALMACENAMIENTO DE DATOS......DEBUG.%%%%%%%%%%%%%%%%%%%%% |
gstedile | 1:30b1ca228fc7 | 1161 | |
gstedile | 2:968b38c3ef49 | 1162 | //%%%%%%%%%%%%% DEBUG2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
gstedile | 2:968b38c3ef49 | 1163 | if (DEBUG2){ |
gstedile | 2:968b38c3ef49 | 1164 | int buff_indx=int(NAVIGATION_VMATRIX.NAV_DATA[NAVIGATION_VMATRIX.vel_max].LAST_NAV_DATA[speed_p]+0.5); // DEBUG |
gstedile | 2:968b38c3ef49 | 1165 | 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 | 2:968b38c3ef49 | 1166 | lcd.printf("Dist_p[%d]= %lf ml\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[distance_p]); |
gstedile | 2:968b38c3ef49 | 1167 | lcd.printf("Tiempo_f[%d]= %lf h\t",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[time_f]); |
gstedile | 2:968b38c3ef49 | 1168 | lcd.printf("Tiempo_i[%d]= %lf h\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[time_i]); |
gstedile | 2:968b38c3ef49 | 1169 | lcd.printf("Buff_INDX = %d \t", buff_indx); |
gstedile | 2:968b38c3ef49 | 1170 | lcd.printf("Speed_p[%d]= %.2f knots\r\n",buff_indx, NAVIGATION_VMATRIX.NAV_DATA[buff_indx].LAST_NAV_DATA[speed_p]); |
gstedile | 2:968b38c3ef49 | 1171 | lcd.printf("Per_con[vel_max]= %d \t", NAVIGATION_VMATRIX.NAV_DATA[NAVIGATION_VMATRIX.vel_max].np_concat); |
gstedile | 2:968b38c3ef49 | 1172 | 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 | 2:968b38c3ef49 | 1173 | lcd.printf("TestNAV-time_f = %lf \t", TestNAV.LAST_NAV_DATA[time_f]); |
gstedile | 2:968b38c3ef49 | 1174 | lcd.printf("TestNAV-time_i = %lf \r\n", TestNAV.LAST_NAV_DATA[time_i]); |
gstedile | 2:968b38c3ef49 | 1175 | lcd.printf("TestNAV-max_per_t = %lf \t", TestNAV.max_period_time); |
gstedile | 2:968b38c3ef49 | 1176 | lcd.printf("TestNAV-time_p = %lf \r\n", TestNAV.LAST_NAV_DATA[time_f]-TestNAV.LAST_NAV_DATA[time_i]); |
gstedile | 2:968b38c3ef49 | 1177 | lcd.printf("TestNAV-cons_m_p = %lf \t", TestNAV.LAST_NAV_DATA[cons_mile_p]); |
gstedile | 2:968b38c3ef49 | 1178 | lcd.printf("TestNAV-cons_h_p = %lf \r\n", TestNAV.LAST_NAV_DATA[cons_hour_p]); |
gstedile | 2:968b38c3ef49 | 1179 | //lcd.SelectUserFont(BPG_Arial20x20); // Seleccion de tipo y tamaño de letras |
gstedile | 2:968b38c3ef49 | 1180 | } |
gstedile | 2:968b38c3ef49 | 1181 | //%%%%%%%%%%%%% FIN DEBUG2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
gstedile | 2:968b38c3ef49 | 1182 | } |
gstedile | 1:30b1ca228fc7 | 1183 | |
gstedile | 2:968b38c3ef49 | 1184 | //===========================TOUCH & ACTIONS =================================================================================================== |
gstedile | 2:968b38c3ef49 | 1185 | lcd.fillroundrect(PrintScreenFillRectB1,5,2, RGB(50,100,0)); |
gstedile | 2:968b38c3ef49 | 1186 | lcd.roundrect(PrintScreenRectB1, 8,3, RGB(0,0,255)); |
gstedile | 2:968b38c3ef49 | 1187 | lcd.fillroundrect(PrintScreenFillRectB3,10,10, RGB(100,0,0)); |
gstedile | 2:968b38c3ef49 | 1188 | lcd.roundrect(PrintScreenRectB3, 12,12, RGB(255,0,0)); |
gstedile | 2:968b38c3ef49 | 1189 | lcd.foreground(RGB(0,0,255)); |
gstedile | 2:968b38c3ef49 | 1190 | lcd.background(RGB(50,100,0)); |
gstedile | 2:968b38c3ef49 | 1191 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 1192 | lcd.puts(butt_x1-18, butt_y1+4, "CURVA"); |
gstedile | 2:968b38c3ef49 | 1193 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 1194 | lcd.foreground(RGB(255,0,0)); |
gstedile | 2:968b38c3ef49 | 1195 | lcd.background(RGB(100,0,0)); |
gstedile | 2:968b38c3ef49 | 1196 | lcd.puts(butt_x3-10, butt_y3+10, "OFF"); |
gstedile | 2:968b38c3ef49 | 1197 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 1198 | |
gstedile | 2:968b38c3ef49 | 1199 | for (int i=0;i<2000;i++) { // Barrido para el touch |
gstedile | 2:968b38c3ef49 | 1200 | point_t p; |
gstedile | 2:968b38c3ef49 | 1201 | if (lcd.TouchPanelReadable(&p)) { |
gstedile | 2:968b38c3ef49 | 1202 | menu_flag1=Intersect(PrintScreenRectB1, p); // Levanta menu_flag1 |
gstedile | 2:968b38c3ef49 | 1203 | menu_flag3=Intersect(PrintScreenRectB3, p); // Levanta menu_flag3 |
gstedile | 2:968b38c3ef49 | 1204 | if (menu_flag1){ |
gstedile | 2:968b38c3ef49 | 1205 | lcd.foreground(RGB(255,0,0)); |
gstedile | 2:968b38c3ef49 | 1206 | lcd.background(RGB(50,255,0)); |
gstedile | 2:968b38c3ef49 | 1207 | lcd.puts(butt_x1-18, butt_y1+4, "CURVA"); // Indica boton presionado |
gstedile | 2:968b38c3ef49 | 1208 | i=2000; |
gstedile | 2:968b38c3ef49 | 1209 | menu_flag2=0; |
gstedile | 2:968b38c3ef49 | 1210 | } // Baja menu_flag2 |
gstedile | 2:968b38c3ef49 | 1211 | else { |
gstedile | 2:968b38c3ef49 | 1212 | if (menu_flag3) despedida(); |
gstedile | 2:968b38c3ef49 | 1213 | } |
gstedile | 2:968b38c3ef49 | 1214 | } |
gstedile | 2:968b38c3ef49 | 1215 | wait_ms(2); |
gstedile | 2:968b38c3ef49 | 1216 | } |
gstedile | 2:968b38c3ef49 | 1217 | lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 1218 | } // Fin if menu_flag1 |
gstedile | 1:30b1ca228fc7 | 1219 | |
gstedile | 2:968b38c3ef49 | 1220 | else { // Boton 1 presionado |
gstedile | 2:968b38c3ef49 | 1221 | |
gstedile | 2:968b38c3ef49 | 1222 | if(!menu_flag2) { // Boton 2 no presionado |
gstedile | 2:968b38c3ef49 | 1223 | |
gstedile | 2:968b38c3ef49 | 1224 | //if(build_default_Mtrx(NAVIGATION_VMATRIX)==-1) lcd.printf("Error al crear la Matriz default...\r\n"); // DEBUG Curve |
gstedile | 2:968b38c3ef49 | 1225 | NAVIGATION_V_SMOOTH_MTRX.smooth(4, NAVIGATION_VMATRIX); // Genera matriz de datos filtrados con pasabajos |
gstedile | 1:30b1ca228fc7 | 1226 | |
gstedile | 2:968b38c3ef49 | 1227 | print_VCO_curve(NAVIGATION_VMATRIX,0); // Valores recolectados |
gstedile | 2:968b38c3ef49 | 1228 | |
gstedile | 2:968b38c3ef49 | 1229 | wait(2); |
gstedile | 2:968b38c3ef49 | 1230 | print_VCO_curve(NAVIGATION_VMATRIX,1); // Interpolados (puntos) |
gstedile | 2:968b38c3ef49 | 1231 | wait(2); |
gstedile | 2:968b38c3ef49 | 1232 | print_VCO_curve(NAVIGATION_V_SMOOTH_MTRX,1); // Suavizado (puntos) |
gstedile | 2:968b38c3ef49 | 1233 | wait(2); |
gstedile | 2:968b38c3ef49 | 1234 | |
gstedile | 2:968b38c3ef49 | 1235 | print_VCO_curve(NAVIGATION_VMATRIX,2); // Interpolados (lineas) |
gstedile | 2:968b38c3ef49 | 1236 | wait(2); |
gstedile | 2:968b38c3ef49 | 1237 | print_VCO_curve(NAVIGATION_V_SMOOTH_MTRX,2); // Suavizados (lineas) |
gstedile | 2:968b38c3ef49 | 1238 | |
gstedile | 2:968b38c3ef49 | 1239 | |
gstedile | 2:968b38c3ef49 | 1240 | lcd.SelectUserFont(BPG_Arial10x10); |
gstedile | 2:968b38c3ef49 | 1241 | lcd.fillroundrect(PrintScreenFillRectB2,5,2, BrightBlue); |
gstedile | 2:968b38c3ef49 | 1242 | lcd.roundrect(PrintScreenRectB2, 8,5, White); |
gstedile | 2:968b38c3ef49 | 1243 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 1244 | lcd.background(BrightBlue); |
gstedile | 2:968b38c3ef49 | 1245 | for (int j=0;j<2000;j++) { // Barrido para el touch |
gstedile | 2:968b38c3ef49 | 1246 | point_t p2; |
gstedile | 1:30b1ca228fc7 | 1247 | |
gstedile | 2:968b38c3ef49 | 1248 | lcd.puts(butt_x2-21, butt_y2 +4, "VOLVER"); |
gstedile | 2:968b38c3ef49 | 1249 | //lcd.background(Black); |
gstedile | 2:968b38c3ef49 | 1250 | if (lcd.TouchPanelReadable(&p2)) { |
gstedile | 2:968b38c3ef49 | 1251 | menu_flag2=Intersect(PrintScreenRectB2, p2); |
gstedile | 2:968b38c3ef49 | 1252 | if (menu_flag2) { |
gstedile | 2:968b38c3ef49 | 1253 | lcd.foreground(Red); |
gstedile | 2:968b38c3ef49 | 1254 | lcd.puts(butt_x2-40, butt_y2 +4, "VOLVER"); |
gstedile | 2:968b38c3ef49 | 1255 | menu_flag1=0; // Bajo menu_flag1; |
gstedile | 2:968b38c3ef49 | 1256 | j=2000; |
gstedile | 2:968b38c3ef49 | 1257 | print_fondo1(0,0,0,0,0,255); //Imprimo fondo de pantalla ppal. |
gstedile | 2:968b38c3ef49 | 1258 | print_fondo2(50,50,255,0,0,255); |
gstedile | 2:968b38c3ef49 | 1259 | } |
gstedile | 2:968b38c3ef49 | 1260 | } |
gstedile | 2:968b38c3ef49 | 1261 | } |
gstedile | 2:968b38c3ef49 | 1262 | |
gstedile | 2:968b38c3ef49 | 1263 | } // Fin if boton2 no presionado |
gstedile | 2:968b38c3ef49 | 1264 | |
gstedile | 2:968b38c3ef49 | 1265 | } // Fin else (boton 1 presionado) |
gstedile | 2:968b38c3ef49 | 1266 | |
gstedile | 2:968b38c3ef49 | 1267 | lcd.foreground(RGB(0,255,0)); |
gstedile | 2:968b38c3ef49 | 1268 | } //Fin while 1 |
gstedile | 2:968b38c3ef49 | 1269 | |
gstedile | 2:968b38c3ef49 | 1270 | } |
gstedile | 0:e40cf759ba9a | 1271 | |
gstedile | 0:e40cf759ba9a | 1272 | |
gstedile | 0:e40cf759ba9a | 1273 |