Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Sat Oct 12 03:48:30 2013 +0000
Parent:
152:a4d66901785d
Child:
154:90ea16ca7475
Commit message:
// Added current reversal tone; // Added MY2013 autoSync support (just time - no date)

Changed in this revision

displayModes.cpp Show annotated file Show diff for this revision Revisions of this file
displayModes.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
utility.cpp Show annotated file Show diff for this revision Revisions of this file
utility.h Show annotated file Show diff for this revision Revisions of this file
--- a/displayModes.cpp	Sun Oct 06 14:49:09 2013 +0000
+++ b/displayModes.cpp	Sat Oct 12 03:48:30 2013 +0000
@@ -1017,16 +1017,26 @@
         tt.set_font((unsigned char*) Arial12x12);
         if(accOn){
             seconds = time(NULL);
-            t = *localtime(&seconds);        
-            msg = lastMsg[indexLastMsg[0x5fa]];
-            t.tm_mon = (msg.data[5]>>4)-1;
-            t.tm_mday = msg.data[2]>>3;
-            msg = lastMsg[indexLastMsg[0x5fb]];
-            //t.tm_year = msg.data[1];
-            msg = lastMsg[indexLastMsg[0x5fc]];
-            t.tm_hour = msg.data[0]>>3;
-            t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
-            t.tm_sec = msg.data[1]>>2;
+            t = *localtime(&seconds);
+            
+            if(modelYear<2013){
+                msg = lastMsg[indexLastMsg[0x5fa]];
+                t.tm_mon = (msg.data[5]>>4)-1;
+                t.tm_mday = msg.data[2]>>3;
+                // Have not figured out where the year is on MY2011
+                msg = lastMsg[indexLastMsg[0x5fc]];
+                t.tm_hour = msg.data[0]>>3;
+                t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
+                t.tm_sec = msg.data[1]>>2;
+            }else{
+                // Have not figured out where Year, Month, or Day is for MY2013
+                msg = lastMsg[indexLastMsg[0x5f9]];
+                t.tm_hour = msg.data[5]>>3;
+                t.tm_min = msg.data[4];
+                msg = lastMsg[indexLastMsg[0x509]];
+                t.tm_sec = msg.data[2]>>2;
+            }
+
             strftime(sTemp1, 32, "%a %m/%d/%Y %X  \n", &t);
             //printf("Leaf: %02d:%02d:%02d %02d/%02d/%03d\n",hour,minute,second,month,day,year);
             printf("Leaf: %s",sTemp1);
--- a/displayModes.h	Sun Oct 06 14:49:09 2013 +0000
+++ b/displayModes.h	Sat Oct 12 03:48:30 2013 +0000
@@ -65,6 +65,7 @@
 extern unsigned short uMsgId[8];
 extern bool accOn;
 extern bool autoSync;
+extern unsigned short modelYear;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Sun Oct 06 14:49:09 2013 +0000
+++ b/main.cpp	Sat Oct 12 03:48:30 2013 +0000
@@ -11,11 +11,10 @@
 // * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?)
 // * Add heater activation warning message
 // * Add trip max/min efficiency reset
-// * Add 2013 clock sync support
 
-// rev152
-// Added clock sync with car clock option (MY2011,2012 only)
-// Fixed wrap bug in manual date update (january=00, not 01)
+// rev153
+// Added current reversal tone
+// Added MY2013 autoSync support (just time - no date)
 
 #include "mbed.h"
 #include "CAN.h"
@@ -26,7 +25,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "152"; // gg - revision string, max 6 characters
+char revStr[7] = "153"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -158,6 +157,7 @@
 unsigned short chirpInt;
 unsigned short uMsgId[8] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte
 unsigned short modelYear = 2011;
+bool idir, lidir;
 
 int main() {
     char sTemp[40];
@@ -708,6 +708,17 @@
             }
         }
 
+        // Sound tone on power reversal
+        idir=(kW[0]>0)?true:false;
+        if(brakeMon){
+            if (idir&&!lidir){
+                spkr.beep(3200,0.03); // Started sinking current
+            }else if(!idir&&lidir){
+                spkr.beep(800,0.03); // Started regen
+            }
+            lidir=idir;
+        }
+
         if(tick){ // Executes once a second
             tick=false;
             curEff = miles_trip[0]/kWh_trip[0];
@@ -720,7 +731,6 @@
             accOn=(accV>5)?true:false;
             moving=(mph[0]>0.1);
             charging=(lastMsg[indexLastMsg[0x5bf]].data[2]>0)?true:false; // FF when charging
-            //charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
             if (laccOn&&!accOn){ // Car turned off
                 if (showHealth){
                     if (saveDmode==99){
@@ -886,10 +896,7 @@
                 }
             }
             if(!syncDone){
-                if((lastMsg[indexLastMsg[0x5fa]].data[2]>>3>0)&&(lastMsg[indexLastMsg[0x5fa]].data[2]>>3<32)&&(lastMsg[indexLastMsg[0x5fc]].data[1]>>2<60)){ // sanity check result first
-                    syncDateTime();
-                    syncDone=true;
-                }
+                syncDone=syncDateTime();
             }
             tock=true;
         } // tick
--- a/utility.cpp	Sun Oct 06 14:49:09 2013 +0000
+++ b/utility.cpp	Sat Oct 12 03:48:30 2013 +0000
@@ -768,22 +768,36 @@
     set_time(mktime(&t));
 }
 
-void syncDateTime(){ // doesn't work on MY2013
+bool syncDateTime(){ // doesn't work on MY2013
     struct tm t; // pointer to a static tm structure
     time_t seconds ;
     CANMessage msg;
     seconds = time(NULL);
     t = *localtime(&seconds);
-    msg = lastMsg[indexLastMsg[0x5fa]];
-    t.tm_mon = (msg.data[5]>>4)-1;
-    t.tm_mday = msg.data[2]>>3;
-    msg = lastMsg[indexLastMsg[0x5fb]];
-    //t.tm_year = msg.data[1]; // Have not figured out where the year is
-    msg = lastMsg[indexLastMsg[0x5fc]];
-    t.tm_hour = msg.data[0]>>3;
-    t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
-    t.tm_sec = msg.data[1]>>2;
-    set_time(mktime(&t));
+    if(modelYear<2013){ //MY2011,2012
+        msg = lastMsg[indexLastMsg[0x5fa]];
+        t.tm_mon = (msg.data[5]>>4)-1;
+        t.tm_mday = msg.data[2]>>3;
+        msg = lastMsg[indexLastMsg[0x5fb]];
+        //t.tm_year = msg.data[1]; // Have not figured out where the year is
+        msg = lastMsg[indexLastMsg[0x5fc]];
+        t.tm_hour = msg.data[0]>>3;
+        t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
+        t.tm_sec = msg.data[1]>>2;
+    }else{ // model year 2013 or higher
+        msg = lastMsg[indexLastMsg[0x5f9]];
+        t.tm_hour = msg.data[5]>>3;
+        t.tm_min = msg.data[4];
+        msg = lastMsg[indexLastMsg[0x509]];
+        t.tm_sec = msg.data[2]>>2;
+    }
+    if((t.tm_mon>=0)&&(t.tm_mon<12)&&(t.tm_mday>0)&&(t.tm_mday<8)&&(t.tm_hour>=0)&&(t.tm_hour<24)&&(t.tm_min>=0)&&(t.tm_min<60)&&(t.tm_sec>=0)&&(t.tm_sec<60)){ // sanity check result before using
+        set_time(mktime(&t));
+        return(true);
+    }else{
+        return(false);
+    }
+
 }
 
 void logPackVoltages() { // Turbo3 - routine to dump CP values to text file
@@ -1053,7 +1067,7 @@
     
     if(chirpInt>0){
         if(++counter>chirpInt){
-            spkr.beep(500,0.015);
+            spkr.beep(1600,0.015);
             counter=0;
         }
     }else{
@@ -1063,7 +1077,7 @@
 
 //Sample CONFIG.TXT
 /*
-format 7
+format 9
 x0_off 5732
 y0_off 34009
 x0_pp 77
--- a/utility.h	Sun Oct 06 14:49:09 2013 +0000
+++ b/utility.h	Sat Oct 12 03:48:30 2013 +0000
@@ -103,7 +103,7 @@
     void saveConfig();
     void readConfig();
     void upDate(unsigned char field, bool updownbar);
-    void syncDateTime();
+    bool syncDateTime();
     void logPackVoltages(); // Turbo3
     void tripLog(); // Turbo3
     void updateFirmware(); // LM - Update firmware off USB