Marcel Visser
/
DisplayBRW
brw1
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "RA8875.h" 00003 00004 Serial Fc(p28, p27); 00005 00006 int fuelcellStatus = -1; 00007 int fuelcellAmbientRawT; 00008 float fuelcellAmbientT; 00009 int fuelcellStackRawV; 00010 int fuelcellStackRawIHighByte; 00011 int fuelcellStackRawILowByte; 00012 int fuelcellStackRawH2Sensor; 00013 00014 int fuelcellStackRawT; 00015 int fuelcellRawOutputCurrent1; //high byte 00016 int fuelcellRawOutputCurrent2; //low byte 00017 int fuelcellBatteryRawV; 00018 float fuelcellStackV; 00019 float fuelcellStackI; 00020 float h2SensorVoltage; 00021 float fuelcellStackPower; 00022 float fuelcellStackT; 00023 float fuelcellOutputCurrent;// 00024 float fuelcellBatteryV; 00025 float PWRused = 0.0; 00026 00027 InterruptIn S(p15); 00028 float speed = 0.0; 00029 float avgspeed = 0.0; 00030 float necspeed = 0.0; 00031 float wielomtrek = 1.75; 00032 bool rond = 0; 00033 Timer t; 00034 Timer teller; 00035 Ticker tick; 00036 00037 int seconde = 0; 00038 int sec = 0; 00039 int min = 0; 00040 int lmin = 39; 00041 int lsec = 0; 00042 00043 float afstandtogo = 17000.0; 00044 float afstand = 0.0; 00045 float tijd = 39.0*60.0; 00046 color_t Kleur1; 00047 color_t Kleur6; 00048 00049 00050 00051 void tel(){ 00052 rond=1; 00053 } 00054 00055 00056 void counters(){ 00057 seconde++; 00058 PWRused += (fuelcellStackPower * (1.0/3600.0)); 00059 if(seconde >= 39*60) 00060 { 00061 00062 min = 39; 00063 sec = 00; 00064 lmin = 00; 00065 lsec = 00; 00066 Kleur1 = BrightRed; 00067 Kleur6 = BrightRed; 00068 } 00069 else if(seconde >= 34*60) 00070 { 00071 00072 min = seconde/60; 00073 sec = seconde - (min*60); 00074 lsec--; 00075 if(lsec < 0){ 00076 lsec = 59; 00077 lmin--; 00078 } 00079 00080 Kleur1 = Yellow; 00081 Kleur6 = Yellow; 00082 } 00083 else 00084 { 00085 00086 min = seconde/60; 00087 sec = seconde - (min*60); 00088 lsec--; 00089 if(lsec < 0){ 00090 lsec = 59; 00091 lmin--; 00092 } 00093 00094 Kleur1 = BrightGreen; 00095 Kleur6 = BrightGreen; 00096 } 00097 00098 } 00099 00100 void snelheidmeten(){ 00101 if (rond){ 00102 speed = (wielomtrek/t.read())*3,6; 00103 afstand += wielomtrek; 00104 t.reset(); 00105 } 00106 tijd -= teller.read(); 00107 necspeed = ((afstandtogo-afstand)/tijd)*3.6; 00108 avgspeed = (afstand/teller.read())*3.6; 00109 00110 if(t.read() > 2.5) 00111 speed = 0.0; 00112 00113 rond = 0; 00114 00115 } 00116 00117 void checkIncomingFcData() { 00118 00119 // anything in the buffer? yes check if its a valid packet. no, return 00120 if (Fc.readable()) { 00121 00122 00123 00124 fuelcellStatus = Fc.getc(); 00125 fuelcellAmbientRawT = Fc.getc(); 00126 fuelcellStackRawV = Fc.getc(); 00127 fuelcellStackRawH2Sensor = Fc.getc(); 00128 fuelcellStackRawT= Fc.getc(); 00129 fuelcellStackRawIHighByte = Fc.getc(); 00130 fuelcellStackRawILowByte = Fc.getc(); 00131 fuelcellBatteryRawV = Fc.getc(); 00132 00133 //calculate actual values 00134 fuelcellAmbientT = fuelcellAmbientRawT * .5; 00135 fuelcellStackV = fuelcellStackRawV * .33333; 00136 fuelcellStackT = fuelcellStackRawT * .5; 00137 fuelcellStackI = ((fuelcellStackRawIHighByte<<8) + fuelcellStackRawILowByte) * .2;// 00138 fuelcellBatteryV = fuelcellBatteryRawV * .10; 00139 fuelcellStackPower = fuelcellStackI * fuelcellStackV; 00140 h2SensorVoltage = fuelcellStackRawH2Sensor *.10; 00141 00142 } 00143 } 00144 00145 00146 00147 00148 00149 int main() 00150 { 00151 teller.start(); 00152 t.start(); 00153 S.rise(&tel); 00154 float f = 10000000; 00155 00156 00157 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name 00158 lcd.init(800, 480, 24, true, false, false); 00159 00160 lcd.frequency(f); 00161 AnalogIn ain(A5); 00162 tick.attach(&counters, 1.0); 00163 lcd.cls(); 00164 wait_ms(250); 00165 00166 00167 00168 00169 lcd.background(White); 00170 lcd.fillrect( 0,0, 800,480, White); 00171 lcd.fillrect( 0,79, 800,81 , Black); // hor strepen over het hele beeld 00172 lcd.fillrect( 0,159, 800,161, Black); 00173 lcd.fillrect( 0,239, 800,241, Black); 00174 lcd.fillrect( 0,319, 800,321, Black); 00175 lcd.fillrect( 0,399, 800,401, Black); 00176 00177 lcd.fillrect( 759,80 , 761,240, Black); //verticale streep boven 00178 lcd.fillrect( 759,320, 761,480, Black); //verticale streep onder 00179 00180 lcd.fillrect( 371,119, 800,121, Black); //hor strepen vanaf halve cirkel 00181 lcd.fillrect( 396,199, 800,201, Black); 00182 lcd.fillrect( 371,359, 800,361, Black); 00183 lcd.fillrect( 315,439, 800,441, Black); 00184 00185 lcd.line( 209,0 , 280,80 , Black); //binnenste halve cirkel 00186 lcd.line( 280,80 , 321,160, Black); 00187 lcd.line( 321,160, 331,240, Black); 00188 lcd.line( 331,240, 321,320, Black); 00189 lcd.line( 321,320, 280,400, Black); 00190 lcd.line( 280,400, 209,480, Black); 00191 00192 lcd.line( 209+70,0 , 280+70,80 , Black); //buitenste halve cirkel (+70) 00193 lcd.line( 280+70,80 , 321+70,160, Black); 00194 lcd.line( 321+70,160, 331+70,240, Black); 00195 lcd.line( 331+70,240, 321+70,320, Black); 00196 lcd.line( 321+70,320, 280+70,400, Black); 00197 lcd.line( 280+70,400, 209+70,480, Black); 00198 00199 Kleur1 = BrightGreen; 00200 Kleur6 = BrightGreen; 00201 00202 lcd.SetTextFontSize(2,2); 00203 int H = lcd.fontheight()/2; 00204 lcd.puts(411,40-H, "STATUS FUEL CELL"); 00205 lcd.puts(411,280-H, "GENERAL STATUS"); 00206 00207 lcd.SetTextFontSize(1,1); 00208 H = lcd.fontheight()/2; 00209 00210 00211 color_t Kleur2; 00212 color_t Kleur3; 00213 color_t Kleur4; 00214 color_t Kleur5; 00215 00216 color_t KleurA; 00217 color_t KleurB; 00218 color_t KleurC; 00219 color_t KleurD; 00220 color_t KleurE; 00221 color_t KleurF; 00222 color_t KleurG; 00223 color_t KleurH; 00224 00225 00226 while(1){ 00227 checkIncomingFcData(); 00228 snelheidmeten(); 00229 00230 if (avgspeed >= 26.0 && avgspeed <= 27.3) 00231 { 00232 00233 Kleur2 = BrightGreen; 00234 } 00235 else if(avgspeed <= 25.0 || avgspeed >= 28.5) 00236 Kleur2 = BrightRed; 00237 else{ 00238 Kleur2 = Yellow; 00239 } 00240 Kleur3 = BrightBlue; 00241 00242 00243 Kleur4 = BrightBlue; 00244 00245 00246 Kleur5 = BrightBlue; 00247 00248 if(fuelcellStackV >= 22 && fuelcellStackV <= 45) 00249 { 00250 KleurA = BrightGreen; 00251 } 00252 else if(fuelcellStackV <= 20 || fuelcellStackV >= 48){ 00253 KleurA = BrightRed; 00254 } 00255 else{ 00256 KleurA = Yellow; 00257 } 00258 00259 00260 if(fuelcellStackI <= 25) 00261 { 00262 KleurB = BrightGreen; 00263 } 00264 else if(fuelcellStackI >= 27){ 00265 KleurB = BrightRed; 00266 } 00267 else{ 00268 KleurB = Yellow; 00269 } 00270 00271 00272 00273 if(fuelcellStackPower <=1000){ 00274 KleurC = BrightGreen; 00275 } 00276 else if(fuelcellStackPower >= 1200){ 00277 KleurC = BrightRed; 00278 } 00279 else{ 00280 KleurC = Yellow; 00281 } 00282 00283 00284 if(fuelcellStackT <=38){ 00285 KleurD = BrightGreen; 00286 } 00287 else if(fuelcellStackT >= 40){ 00288 KleurD = BrightRed; 00289 } 00290 else{ 00291 KleurD = Yellow; 00292 } 00293 00294 00295 if((ain*20*3.3) <=45){ 00296 KleurE = BrightGreen; 00297 } 00298 else if((ain*20*3.3) >= 48){ 00299 KleurE = BrightRed; 00300 } 00301 else{ 00302 KleurE = Yellow; 00303 } 00304 00305 00306 if(fuelcellAmbientT <=28){ 00307 KleurF = BrightGreen; 00308 } 00309 else if(fuelcellAmbientT >= 30){ 00310 KleurF = BrightRed; 00311 } 00312 else{ 00313 KleurF = Yellow; 00314 } 00315 00316 00317 00318 00319 00320 00321 00322 lcd.foreground(Black); 00323 00324 lcd.SetTextCursor(10,40-H); //16 00325 lcd.printf("Total time %02d:%02d",min,sec ); 00326 lcd.SetTextCursor(10,120-H); 00327 lcd.printf("Average speed %.1f km/h ",avgspeed); 00328 lcd.SetTextCursor(10,200-H); 00329 lcd.printf("Necessary speed %.1f km/h ",necspeed); 00330 lcd.SetTextCursor(10,280-H); 00331 lcd.printf("Actual speed %.1f km/h ",speed); 00332 lcd.SetTextCursor(10,360-H); 00333 lcd.printf("Power used %.1f Wh ",PWRused); 00334 lcd.SetTextCursor(10,440-H); 00335 lcd.printf("Time left %02d:%02d",lmin,lsec); 00336 00337 lcd.SetTextCursor(411,100-H); 00338 lcd.printf("Voltage fuel cell %.2f V ",fuelcellStackV); 00339 lcd.SetTextCursor(411,140-H); 00340 lcd.printf("Current fuel cell %.2f A ",fuelcellStackI); 00341 lcd.SetTextCursor(411,180-H); 00342 lcd.printf("Power fuel cell %.2f W ",fuelcellStackPower); 00343 lcd.SetTextCursor(411,220-H); 00344 lcd.printf("Temperature fuel cell %.2f %cC ",fuelcellStackT,176); 00345 lcd.SetTextCursor(411,340-H); 00346 lcd.printf("Voltage supercapacitors %.2f V ",ain*20*3.3); 00347 lcd.SetTextCursor(411,380-H); 00348 lcd.printf("Ambient temperature %.2f %cC ",fuelcellAmbientT,176); 00349 lcd.SetTextCursor(411,420-H); 00350 00351 switch(fuelcellStatus) 00352 { 00353 case 0: 00354 lcd.printf("Status fuelcell: NORMAL "); 00355 KleurG = BrightGreen; 00356 KleurH = BrightGreen; 00357 break; 00358 00359 case 1: 00360 lcd.printf("Status fuelcell: BATTERY LOW "); 00361 KleurG = BrightRed; 00362 KleurH = BrightRed; 00363 break; 00364 00365 case 2: 00366 lcd.printf("Status fuelcell: FC VOLTAGE LOW "); 00367 KleurG = BrightRed; 00368 KleurH = BrightRed; 00369 break; 00370 00371 case 3: 00372 lcd.printf("Status fuelcell: H2% HIGH "); 00373 KleurG = BrightRed; 00374 KleurH = BrightRed; 00375 break; 00376 00377 case 4: 00378 lcd.printf("Status fuelcell: CURRENT HIGH "); 00379 KleurG = BrightRed; 00380 KleurH = BrightRed; 00381 break; 00382 00383 case 5: 00384 lcd.printf("Status fuelcell: TEMPERATURE HIGH"); 00385 KleurG = BrightRed; 00386 KleurH = BrightRed; 00387 break; 00388 00389 case 20: 00390 lcd.printf("Status fuelcell: MANUAL TURN OFF "); 00391 KleurG = BrightRed; 00392 KleurH = BrightRed; 00393 break; 00394 00395 default: 00396 lcd.printf("Status fuelcell: NO STATUS "); 00397 KleurG = Yellow; 00398 KleurH = Yellow; 00399 } 00400 00401 00402 00403 00404 00405 00406 // vakjes in de halve cirkel 00407 lcd.filltriangle( 210,0, 281,78, 278,0, Kleur1); //vakje 1 00408 lcd.filltriangle( 349,78, 281,78, 278,0, Kleur1); 00409 00410 lcd.filltriangle( 281,82, 322,158, 349,82, Kleur2); //vakje 2 00411 lcd.filltriangle( 390,158, 322,158, 349,82, Kleur2); 00412 00413 lcd.filltriangle( 322,162, 332,238, 390,162, Kleur3); //vakje 3 00414 lcd.filltriangle( 400,238, 332,238, 390,162, Kleur3); 00415 00416 lcd.filltriangle( 332,242, 322,318, 400,242, Kleur4); //vakje 4 00417 lcd.filltriangle( 390,318, 322,318, 400,242, Kleur4); 00418 00419 lcd.filltriangle( 322,322, 281,398, 390,322, Kleur5); //vakje 5 00420 lcd.filltriangle( 349,398, 281,398, 390,322, Kleur5); 00421 00422 lcd.filltriangle( 281,402, 210,480, 349,402, Kleur6); //vakje 6 00423 lcd.filltriangle( 278,480, 210,480, 349,402, Kleur6); 00424 00425 //vierkantjes aan de rechterkant 00426 00427 lcd.fillrect( 762,82, 800,118, KleurA); // Vierkant A 00428 lcd.fillrect( 762,122, 800,158, KleurB); // Vierkant B 00429 lcd.fillrect( 762,162, 800,198, KleurC); // Vierkant C 00430 lcd.fillrect( 762,202, 800,238, KleurD); // Vierkant D 00431 lcd.fillrect( 762,322, 800,358, KleurE); // Vierkant E 00432 lcd.fillrect( 762,362, 800,398, KleurF); // Vierkant F 00433 lcd.fillrect( 762,402, 800,438, KleurG); // Vierkant G 00434 lcd.fillrect( 762,442, 800,480, KleurH); // Vierkant H 00435 00436 wait(0.2); 00437 } 00438 }
Generated on Fri Jul 15 2022 05:44:41 by 1.7.2