Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Revision:
178:bf6404312c45
Parent:
177:6fda79c2fda1
Child:
179:e4094e55f079
--- a/main.cpp	Thu Mar 06 15:37:40 2014 +0000
+++ b/main.cpp	Wed Mar 19 14:08:56 2014 +0000
@@ -11,11 +11,8 @@
 // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
 
 
-// rev176
-// Changed effciency counter to check after charging after 3am
-// Added cancel day data button to trip display
-// Base best and worse case on full round trip (per charge efficiency)
-// Track daily wh/gid
+// rev178
+// Added Wh/gid display
 
 #include "mbed.h"
 #include "CAN.h"
@@ -26,7 +23,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "176";
+char revStr[7] = "178";
 unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -185,6 +182,8 @@
 unsigned long fbScalar = 132;
 int effCheckTime = 3;
 bool ignoreDayData = true;
+unsigned short cgids,lgids;
+unsigned char whpg[300];
 
 int main() {
     char sTemp[40];
@@ -919,12 +918,24 @@
             } else {
                 dled = ledLo;
             }
+            cgids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6);
             if(getGids){
-                startGids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6);  //Get gids
+                startGids=cgids;  //Get gids
                 if((startGids>0)&&(startGids<300)){ // Ignore bogus values at startup
                     getGids=false;
+                    lgids=startGids; // initialize wh/gid array
+                    for(i=0;i<299;i++){
+                        whpg[i]=255;
+                    }
                 }
             }
+            if(cgids<lgids){
+                whpg[lgids]= (unsigned char) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                lgids=cgids;
+            }else if(cgids>lgids){
+                whpg[cgids]= (unsigned char) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                lgids=cgids;
+            }
             if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's
                 wait5secs-=1;
                 if(wait5secs==0){