Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
179:e4094e55f079
Parent:
178:bf6404312c45
Child:
180:5fdeeb86f3a3
--- a/main.cpp	Wed Mar 19 14:08:56 2014 +0000
+++ b/main.cpp	Sun Mar 23 22:04:44 2014 +0000
@@ -11,8 +11,7 @@
 // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
 
 
-// rev178
-// Added Wh/gid display
+// rev179
 
 #include "mbed.h"
 #include "CAN.h"
@@ -23,7 +22,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "178";
+char revStr[7] = "179";
 unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -182,13 +181,15 @@
 unsigned long fbScalar = 132;
 int effCheckTime = 3;
 bool ignoreDayData = true;
-unsigned short cgids,lgids;
-unsigned char whpg[300];
+unsigned short cgids,lgids=0;
+unsigned short whpg[300]={0};
+unsigned short wh[300]={0};
 
 int main() {
     char sTemp[40];
     unsigned long secs;
-    unsigned char i,j,display=0,lwt=0;
+    unsigned short i,j;
+    unsigned char display=0,lwt=0;
     point lastTouch;
     float average;
     tt.set_orientation(1);
@@ -233,6 +234,10 @@
     sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision
     printMsg(sTemp); // revision
 
+    for(i=0;i<300;i++){ // initialize wh lookup
+        wh[i]=i*80;
+    }
+
     //read efficiency history data
     hfile = fopen("/local/ehist.cny", "r");
     if (hfile!=NULL){ // found a efficiency history file
@@ -258,6 +263,11 @@
         if(!feof(hfile)){
             fscanf(hfile,"%f %f\r\n",&maxTripCCkWh,&minTripCCkWh);
         }
+        if(!feof(hfile)){
+            for(i=0;i<300;i++){
+                fscanf(hfile,"%d\r\n",&wh[i]);
+            }
+        }
         fclose(hfile);
         printMsg("History Loaded.\n"); // History loaded
     } else { // create initial file
@@ -892,6 +902,9 @@
                     CCkWh_trip[3]=0;
                     ignoreDayData=false;
                     lt=t; // Remember when counters were cleared
+                    for(i=0;i<300;i++){ // Clear whpg array
+                        whpg[i]=0;
+                    }
                 }
                 wait5secs=5;
                 if (showHealth&&!playbackOpen){
@@ -924,17 +937,16 @@
                 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((cgids>0)&&(cgids<300)){
+                if(cgids<lgids){
+                    whpg[cgids] = (unsigned short) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                    lgids=cgids;
+                }else if(cgids>lgids){
+                    whpg[cgids] = (unsigned short) (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;
@@ -1005,7 +1017,7 @@
                 miles_trip[0]+=mph[0]/3600; // per trip
                 miles_trip[1]+=mph[0]/3600; // per charge
                 miles_trip[2]+=mph[0]/3600; // user
-                miles_trip[3]+=mph[0]/3600; // user
+                miles_trip[3]+=mph[0]/3600; // per day/roundtrip
                 kWh_trip[0]+=kW[0]/3600;
                 kWh_trip[1]+=kW[0]/3600;
                 kWh_trip[2]+=kW[0]/3600;