Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: main.cpp
- Revision:
- 52:d5385fbf4ea1
- Parent:
- 51:6187c5264a73
- Child:
- 53:8a51361434ae
- Child:
- 55:591406a71fa8
diff -r 6187c5264a73 -r d5385fbf4ea1 main.cpp --- a/main.cpp Sun Apr 07 17:11:28 2013 +0000 +++ b/main.cpp Tue Apr 09 04:13:20 2013 +0000 @@ -101,12 +101,11 @@ float kW[39]={0}; float mpkWh[39]={0}; // Logarithmic division scale (roughly - snapped to common units of time) -// First 10 are updated each second; the rest are updated each minute float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute - 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 hour - 60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*24, // 1 day - 60*24*1.58, 60*24*2.51, 60*24*3.98, 60*24*6.31, 60*24*10, 60*24*15.8, 60*24*30, // 1 month - 60*24*39.8, 60*24*63.1, 60*24*100, 60*24*158, 60*24*251, 60*24*365}; // 1 year + 60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*25.1, 60*39.8, 60*60, // 1 hour + 60*60*1.58, 60*60*2.51, 60*60*3.98, 60*60*6.31, 60*60*10, 60*60*15.8, 60*60*24, // 1 day + 60*60*24*1.58, 60*60*24*2.51, 60*60*24*3.98, 60*60*24*6.31, 60*60*24*10, 60*60*24*15.8, 60*60*24*30, // 1 month + 60*60*24*39.8, 60*60*24*63.1, 60*60*24*100, 60*60*24*158, 60*60*24*251, 60*60*24*365}; // 1 year bool updateDTE = false; int main() { @@ -114,9 +113,8 @@ char sTemp[40]; unsigned long secs; unsigned char i,j,display=0,lwt=0; - unsigned char minuteCount=0; point lastTouch; - float average,mph9,kW9; + float average; can1.monitor(true); // set to snoop mode can2.monitor(true); // set to snoop mode @@ -155,7 +153,7 @@ t = *localtime(&seconds) ; strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t); logMsg(sTemp); - sprintf(sTemp,"CANary firmware rev51\n"); + sprintf(sTemp,"CANary firmware rev52\n"); logMsg(sTemp); // Look for new binary on thumbdrive @@ -559,38 +557,21 @@ numSsamples=0; mWs_x4=0; numWsamples=0; - // First ten are updated each second - for(i=1;i<10;i++){ - mph9=mph[i]/timeConstant[i]; - mph[i]-=mph9; - mph[i]+=mph[0]; - kW9=kW[i]/timeConstant[i]; - kW[i]-=kW9; - kW[i]+=kW[0]; - mpkWh[i]=mph[i]; - mpkWh[i]/=kW[i]; - if (mpkWh[i]<0) { - mpkWh[i]=99;// negative means inf. - } - //mpkWh[i]=floor(mpkWh[i]*10+0.5)/10; // Round to nearest 10th - } - // The rest are updated each minute - if(++minuteCount>59){ // - minuteCount=0; - for(i=10;i<39;i++){ + if(accOn){ + for(i=1;i<39;i++){ average=mph[i]/timeConstant[i]; mph[i]-=average; - mph[i]+=mph9; + mph[i]+=mph[0]; + mpkWh[i]=average; average=kW[i]/timeConstant[i]; kW[i]-=average; - kW[i]+=kW9; - mpkWh[i]=mph[i]; - mpkWh[i]/=kW[i]; + kW[i]+=kW[0]; + mpkWh[i]/=average; if (mpkWh[i]<0) { mpkWh[i]=99;// negative means inf. } //mpkWh[i]=floor(mpkWh[i]*10+0.5)/10; // Round to nearest 10th - } + } } updateDTE=true; if(logCP)