Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 41:8d4609ea7259
- Parent:
- 40:0e6e71a7323f
- Child:
- 42:4533b13b297d
diff -r 0e6e71a7323f -r 8d4609ea7259 main.cpp --- a/main.cpp Sun Mar 31 17:45:05 2013 +0000 +++ b/main.cpp Sun Mar 31 18:57:36 2013 +0000 @@ -1,14 +1,11 @@ // main.cpp //To Do: -// * Use timestamp for mWs but override with playbackInt based calc in playback -// * Log file playback (to enable testing of new passive display modes without having to drive around) // * USB device detect // * Ability to update binary from the thumb-drive (requires file timestamp) // * Cellpair histogram // * Audible friction brake feedback // * User-configurable watchpoint -// * Immediately turn off when car is turned off and logging // * Better graphical DTE display with historic efficiency information considered and displayed // * Add 50% charge option // * Tire Pressure Sensor display @@ -67,7 +64,7 @@ volatile bool userIdle; bool touched=false; //flag to read touchscreen char counter = 0; -unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode +unsigned char dMode[2] = {mainScreen,brakeScreen}; //display mode unsigned char sMode = 0; // setup mode unsigned char lastDMode[2] = {0,0}; //last screen mode unsigned char dtMode = 6; @@ -87,7 +84,8 @@ float scale12V = 16.2; // R1:R2 ratio signed long mWs_x4 = 0; unsigned short numWsamples = 0; -unsigned long miles = 0; +unsigned short numSsamples = 0; +float kW = 0; float mpkWh = 0; float accV = 0; bool playbackEn = false; @@ -96,6 +94,8 @@ bool step = false; char header[5]; char data[8]; +signed long motorRPM; +float MPH = 0; int main() { int readPointer=0; @@ -454,8 +454,7 @@ } if(tick){ // Executes once a second - accV=floor(mon12V*scale12V*10+0.5)/10; - //accV=mon12V*scale12V; + accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th accOn=(accV>5)?true:false; if(!accOn&&!logEn&&userIdle&&!playbackEn){ //sprintf(sTemp,"Display Off %4.2f\n",accV); @@ -466,13 +465,18 @@ }else{ dled = ledLo; } - //if(mWs_x4>0){ - if(numWsamples>0){ - mpkWh= ((float) mWs_x4)/numWsamples/4e3; // just kW for now + if(numSsamples>0){ // Avoid div0 + MPH=((float) motorRPM)/numSsamples/215; // Empirically derived - may change car to car }else{ - mpkWh=99; + MPH=0; } - miles=0; + if(numWsamples>0){ // Avoid div0 + kW=((float) mWs_x4)/numWsamples/4e3; + mpkWh=floor(MPH*10/kW+0.5)/10; // Round to nearest 10th + }else{ + kW=0; + } motorRPM=0; + numSsamples=0; mWs_x4=0; numWsamples=0; if(logCP) @@ -487,19 +491,14 @@ sendCPreq(); // send cellpair data request. wait_ms(16); sendTreq(); //send temperature request - //wait_ms(16); - //showCP=true; pollCP=false; } if(step){ // playback if(playbackOpen&&playbackEn){ - //sprintf(sTemp,"step\n"); - //logMsg(sTemp); for(i=0;i<120;i++){ if(!feof(file)){ fscanf(file,"%5c%8c",&header,&data); - //pbts=(header[1]<<8)|header[2]; logCan(header[0],CANMessage(0x7ff&((header[4]<<8)+header[3]), data, 8)); }else{ fclose(file); // restart