Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341
Dependencies: SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 172:53548bf8bf85
- Parent:
- 171:355e284f5201
- Child:
- 173:9815b1467039
--- a/main.cpp Sat Dec 28 14:53:14 2013 +0000 +++ b/main.cpp Sun Dec 29 12:38:00 2013 +0000 @@ -11,8 +11,8 @@ // * Add climate control impact to main max/min dte and new trip display // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes) -// rev171 -// Converted dte display braking bargraph to kW +// rev172 +// added wh/gid display to Health screen #include "mbed.h" #include "CAN.h" @@ -22,7 +22,8 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "171"; // gg - revision string, max 6 characters + +char revStr[7] = "172"; unsigned long maxTarget = 1000; FATFS USBdrive; LocalFileSystem local("local"); @@ -77,7 +78,6 @@ char writeBuffer[maxBufLen][13] __attribute__ ((section("AHBSRAM1"))); // buffer for USB write char indexLastMsg[0x800]={0}; // index table for last message CANMessage lastMsg[100]; // table to store last message of eachtype -CANMessage msg; unsigned char battData[BatDataBufMax]={0}; // 7 * 0x3D = BatDataBufMax @@ -116,6 +116,7 @@ float scale12V = 16.2; // R1:R2 ratio float kWperGid = 0.080; unsigned short startGids = 0; // Gids at start of trip +bool getGids = false; signed long mWs_x4 = 0; unsigned short numWsamples = 0; unsigned short numSsamples = 0; @@ -816,12 +817,12 @@ metric = !miles_kmbar; } accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th - accOn=(accV>5)?true:false; + accOn=(playbackOpen||(accV>5))?true:false; moving=(mph[0]>0.1); charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging if (laccOn&&!accOn){ // Car turned off lHeaterOn=false; - if (showHealth){ + if (showHealth&&!playbackOpen){ if (saveDmode==99){ saveDmode=dMode[0]; } @@ -869,7 +870,8 @@ kWh_trip[0]=0; CCkWh_trip[0]=0; wait5secs=5; - if (showHealth){ + getGids=true; + if (showHealth&&!playbackOpen){ if (saveDmode==99){ saveDmode=dMode[0]; } @@ -889,24 +891,30 @@ } else { dled = ledLo; } + if(getGids){ + startGids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6); //Get gids + if((startGids>0)&&(startGids<300)){ + getGids=false; + } + } if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's wait5secs-=1; - if (repeatPoll&&(wait5secs==0)) { // Poll on startup if autopoll enabled - logOnce=true; - reqMsgCnt=0; - msgReq.attach(&sendReq,0.015); - lastDMode[0]=99; - lastDMode[1]=99; - msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids - startGids=(msg.data[0]<<2)+(msg.data[1]>>6); + if(wait5secs==0){ + if (repeatPoll) { // Poll on startup if autopoll enabled + logOnce=true; + reqMsgCnt=0; + msgReq.attach(&sendReq,0.015); + lastDMode[0]=99; + lastDMode[1]=99; + } + //remove health screen once moving + if(moving&&(saveDmode<99)){ + dMode[0]=saveDmode; + saveDmode=99; + } } } - //remove health screen once moving - if(moving&&(saveDmode<99)&&(wait5secs==0)){ - dMode[0]=saveDmode; - saveDmode=99; - } //compute historic efficiency if(numSsamples>0){ // Avoid div0 @@ -937,7 +945,7 @@ } numWsamples=0; - if((accOn||playbackEn)&&!charging){ // Calculate averages + if(accOn&&!charging){ // Calculate averages for(i=1;i<39;i++){ average=mph[i]/timeConstant[i]; mph[i]-=average;