Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
155:f31006516956
Parent:
154:90ea16ca7475
Child:
156:4e5d30535cf9
--- a/utility.cpp	Wed Oct 16 03:47:48 2013 +0000
+++ b/utility.cpp	Sat Oct 19 15:38:44 2013 +0000
@@ -2,6 +2,7 @@
 #include "utility.h"
 unsigned long brkMonRate = 400000;
 unsigned short brkMonThr = 4000;
+Timeout beepOff;
 
 void mbed_reset();
 
@@ -139,7 +140,7 @@
                     // We previously lost messages that did not get into the buffer
                     sprintf(sTemp,"-- Lost %d Messages.\n", nLost);
                     printMsg(sTemp); // write buffer overrun
-                    //if(enableSound) spkr.beep(500,0.25);
+                    //beep(500,0.25);
                     
                     nLost = 0 ;
                 }
@@ -170,7 +171,7 @@
             if (writePointer==readPointer) {
                 // Just caught up to read pointer
                 printMsg("Write buffer overrun.\n"); // write buffer overrun
-                if(enableSound) spkr.beep(500,0.25);
+                beep(500,0.25);
             }
         }
     }
@@ -546,7 +547,7 @@
     fprintf(cfile,"metric %d\r\n",(metric?1:0));
     fprintf(cfile, "firmware %d\r\n", fwCount );            
     fprintf(cfile,"showHealth %d\r\n",(showHealth?1:0));
-    fprintf(cfile,"brakeMon %d\r\n",(brakeMon?1:0));
+    fprintf(cfile,"brakeMon %d\r\n",(brakeMon?2:0)+(regenMon?1:0));
     fprintf(cfile,"brkMonRate %d\r\n", brkMonRate );            
     fprintf(cfile,"brkMonThr %d\r\n", brkMonThr );            
     for(char i=0;i<8;i++){
@@ -580,7 +581,7 @@
     cfile = fopen("/local/ehist.cny", "r");
     sfr = f_open(&efile,"ehist.bak",FA_WRITE|FA_CREATE_NEW);    
     if((cfile != NULL)&&(sfr == FR_OK)){
-        printMsg("Copy config file to USB\n");
+        printMsg("Copy ehist file to USB\n");
         while (!feof(cfile))
         {
             bytesRW=fread(buffer, 1, bufSize, cfile);
@@ -648,8 +649,9 @@
             showHealth = (bool)readBool;
         }
         if(ff>6){
-            fscanf(cfile, "brakeMon %d\r\n", &readBool );            
-            brakeMon = (bool)readBool;
+            fscanf(cfile, "brakeMon %d\r\n", &readBool );
+            brakeMon = (bool)(readBool&1);
+            regenMon = (bool)(readBool&2);
             fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate );        
             fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr );            
         }
@@ -693,6 +695,7 @@
             fwCount=1;
             showHealth=true;
             brakeMon=true;
+            regenMon=true;
             brkMonRate=400000;
             brkMonThr=4000;
             uMsgId[0]=0x5103;
@@ -866,6 +869,7 @@
 
 void tripLog() { // Daily log
     char sTemp[40];
+    unsigned char ambient;
     struct tm t; // pointer to a static tm structure
     short unsigned max, min, jv, i, bd;
     unsigned avg;
@@ -879,6 +883,8 @@
     seconds = time(NULL); // Turbo3
     t = *localtime(&seconds) ; // Turbo3 
     
+    msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient
+    ambient = msg.data[6]-56;
     msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
     gids = (msg.data[0]<<2)+(msg.data[1]>>6);
     msg = lastMsg[indexLastMsg[0x5c5]]; //Get odometer
@@ -911,10 +917,11 @@
     bfr = f_open(&bfile,"triplog.txt",FA_WRITE|FA_OPEN_ALWAYS);
     if(bfr==FR_OK) {
         f_lseek(&bfile,0xffffffff); // go to end of file to append
+        // timestamp, odometer, accV, gids, SOC, SOH2, Ah, Vbatt, Ibatt, Rest, maxCP, minCP, avgCO, maxCP-minCP, CVLI_jv, miles_trip, kWh_trip, ambient, T1raw, T1, T2raw, T2, T3raw, T3, T4raw, T4, CP1, CP2, ... , CP96
         strftime(sTemp, 40, "%a %m/%d/%Y %X", &t);
         f_printf(&bfile,"%s,",sTemp);
-        sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,Resr,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]);
-        f_printf(&bfile,"%s,",sTemp);           
+        sprintf(sTemp,"%d,%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%4.3f,%d,%d,%d,%d,%d,%4.1f,%4.1f",odo,accV,gids,(float)SOC/10, (float)SOH2_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,Resr,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]);
+        f_printf(&bfile,"%s,%d,",sTemp,ambient);           
         f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]);
         f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]);
         for(i=0; i<96; i++) {
@@ -1062,12 +1069,30 @@
     return(usbEn);
 }
 
+void spkrOff(void){
+    spkr=0;
+    dled.period(.001);
+}
+
+void beep(float freq, float time){
+    if (enableSound) {
+        spkr.period(1.0/freq);
+        spkr=0.5;
+        if(!headlights){
+                dled = ledHi;
+            } else {
+                dled = ledLo;
+            }
+        beepOff.attach(&spkrOff, time);
+    }
+}
+
 void chirp(void){
     static unsigned short counter=0;
     
     if(chirpInt>0){
         if(++counter>chirpInt){
-            if(enableSound) spkr.beep(1600,0.015);
+            beep(1600,0.015);
             counter=0;
         }
     }else{