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:
- 181:396fdcceefd2
- Parent:
- 180:5fdeeb86f3a3
- Child:
- 182:10017d74de67
diff -r 5fdeeb86f3a3 -r 396fdcceefd2 main.cpp --- a/main.cpp Mon Mar 24 01:18:05 2014 +0000 +++ b/main.cpp Tue Mar 25 19:57:08 2014 +0000 @@ -11,8 +11,8 @@ // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes) -// rev180 -// added wh lookup table with correction from whpg real use +// rev181 +// Added grid to whpg displays #include "mbed.h" #include "CAN.h" @@ -23,7 +23,7 @@ #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "180"; +char revStr[7] = "181"; unsigned long maxTarget = 1000; FATFS USBdrive; LocalFileSystem local("local"); @@ -237,7 +237,7 @@ printMsg(sTemp); // revision for(i=0;i<300;i++){ // initialize wh lookup - wh[i]=i*80; + wh[i]=i*kWperGid*1000; } //read efficiency history data @@ -887,32 +887,35 @@ seconds = time(NULL); t = *localtime(&seconds); if((t.tm_yday>lt.tm_yday)&&(t.tm_hour>effCheckTime)&&(miles_trip[1]<1)){ - // Check and reset daily efficiency if charged since last trip - if (!ignoreDayData&&(miles_trip[3]>25)){ // Ignore low mileage data - curEff = miles_trip[3]/kWh_trip[3]; + // Check and reset daily efficiency if charged since last trip and at least 24 hours has past + if (!ignoreDayData&&(miles_trip[3]>15)){ // Ignore low mileage data + curEff = miles_trip[3]/kWh_trip[3]; // Get current daily efficiency if (maxTripEff<curEff) { maxTripEff=curEff; maxTripMiles=miles_trip[3]; maxTripkWh=kWh_trip[3]; maxTripCCkWh=CCkWh_trip[3]; + printMsg("New max efficiency.\n"); } if (minTripEff>curEff) { minTripEff=curEff; minTripMiles=miles_trip[3]; minTripkWh=kWh_trip[3]; minTripCCkWh=CCkWh_trip[3]; + printMsg("New min efficiency.\n"); } } + // Clear daily efficiency data dailyGids=0; miles_trip[3]=0; kWh_trip[3]=0; CCkWh_trip[3]=0; ignoreDayData=false; - lt=t; // Remember when counters were cleared + lt=t; // Remember when counters were cleared (start time for new data) maxWhpg=0; minWh=0; whOff=0; - // Adjust wh lookup with whpg data weighted 20% and clear array + // Adjust wh lookup with whpg data weighted 20% for(i=1;i<300;i++){ if(whpg[i]>maxWhpg){ maxWhpg=whpg[i]; @@ -930,6 +933,8 @@ } wh[i] /=5; } + } + for(i=1;i<300;i++){ // clear array whpg[i]=0; } }