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:
Thu Oct 24 19:51:31 2013 +0000
Parent:
155:f31006516956
Child:
157:1a100a5ed06f
Commit message:
// Changed efficency screen braking monitor to use actual motor amps instead of target regen signal; // Changed braking screen to use actual regen signal instead of target regen signal;

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
--- a/displayModes.cpp	Sat Oct 19 15:38:44 2013 +0000
+++ b/displayModes.cpp	Thu Oct 24 19:51:31 2013 +0000
@@ -22,10 +22,6 @@
     packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6);
     msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient
     aTemp = msg.data[6]-56;
-    //msg = lastMsg[indexLastMsg[0x79a]]; //Get ambient and cabin temperature
-    //aTemp = msg.data[5]-41; // Need to add convertsion to C if metric
-    //c1Temp = msg.data[4]-41;
-    //c2Temp = msg.data[6]-41;
     msg = lastMsg[indexLastMsg[0x385]]; //Get tire pressure
     tireP = msg.data[2]+msg.data[3]+msg.data[4]+msg.data[5];
 
@@ -500,14 +496,11 @@
         }
     }
 
-    msg = lastMsg[indexLastMsg[0x1d5]]; //Get Regen
+    msg = lastMsg[indexLastMsg[0x1cb]];
+    targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5); //Get target total braking force
+    //regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5); //Get target regen portion
+    msg = lastMsg[indexLastMsg[0x1d5]]; //Get regen portion - seems to be actual regen versus target regen
     regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
-    msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target
-    targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
-    msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode
-    if (msg.data[0]==0x18) { // In Neutral
-        regenBraking = 0;  // No regen when in Neutral
-    }
 
     if (targetBraking<2045){
         if ((targetBraking>50)&&(regenBraking>50)){
@@ -867,9 +860,7 @@
         printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n",
             max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
             convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
-        //printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n",
-        //        max,min,avg,jv,  battData[BatDataBaseG2*7+BatDataBaseG4*7+5],battData[BatDataBaseG2*7+BatDataBaseG4*7+8],  battData[BatDataBaseG2*7+BatDataBaseG4*7+11],battData[BatDataBaseG2*7+BatDataBaseG4*7+14]);
-        
+
         //---------------
         // show the bars
         int nBarWidth = 3 ;
@@ -994,7 +985,6 @@
 }
 
 void showDateTime(bool force, bool showButtons){
-    //unsigned char year, month, day, hour, minute, second;
     CANMessage msg;
     struct tm t; // pointer to a static tm structure
     time_t seconds ;
@@ -1002,18 +992,6 @@
     tt.background(Black);
     if (force||tock) {
         tt.cls();
-
-        // Read time from car
-        /*msg = lastMsg[indexLastMsg[0x5fa]];
-        month = msg.data[5]>>4;
-        day = msg.data[2]>>3;
-        msg = lastMsg[indexLastMsg[0x5fb]];
-        year = msg.data[1];
-        msg = lastMsg[indexLastMsg[0x5fc]];
-        hour = msg.data[0]>>3;
-        minute = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
-        second = msg.data[1]>>2;*/
-
         tt.locate(10,10);
         tt.set_font((unsigned char*) Arial12x12);
         if(accOn){
@@ -1039,7 +1017,6 @@
             }
 
             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);
         }
         seconds = time(NULL);
@@ -1092,7 +1069,8 @@
     static unsigned char leff[39]={0};
     CANMessage msg;
     unsigned long targetBraking, regenBraking, temp;
-    static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
+    //static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
+    static unsigned long maxTarget = 1000, tardivreg_x1000 = 1400;
     static unsigned char lr=0, lt=0;
 
     msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
@@ -1247,23 +1225,26 @@
         leff[i-1]=y;
     }
 
-    msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen
-    regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
+    msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target total braking
     targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
-    msg = lastMsg[indexLastMsg[0x421]]; //Get Drive Mode
-    if (msg.data[0]==0x18) { // In Neutral
-        regenBraking = 0;  // No regen when in Neutral
+
+    msg = lastMsg[indexLastMsg[0x1d4]]; //Get Motor Amps - simlar to 1d5/1.4 but includes coast regen
+    temp = (msg.data[2]<<4)+(msg.data[3]>>4);
+    if(temp>0x7ff){ // invert and chop positive current
+        regenBraking=0x1000-temp;
+    }else{
+        regenBraking=0;
     }
 
     if (targetBraking<2045){
-        if ((targetBraking>50)&&(regenBraking>50)){
-            temp = targetBraking;
-            temp *= 1000;
-            temp /= regenBraking;
-            if (temp<tardivreg_x1000) tardivreg_x1000=temp;
-        }
+        //if ((targetBraking>50)&&(regenBraking>50)){
+        //    temp = targetBraking;
+        //    temp *= 1000;
+        //    temp /= regenBraking;
+        //    if (temp<tardivreg_x1000) tardivreg_x1000=temp;
+        //}
         if (targetBraking>maxTarget) maxTarget=targetBraking;
-        if (regenBraking>maxRegen) maxRegen=regenBraking;
+        //if (regenBraking>maxRegen) maxRegen=regenBraking;
     
         temp = targetBraking;
         temp *=200;
--- a/displayModes.h	Sat Oct 19 15:38:44 2013 +0000
+++ b/displayModes.h	Thu Oct 24 19:51:31 2013 +0000
@@ -67,6 +67,7 @@
 extern bool autoSync;
 extern unsigned short modelYear;
 extern bool enableSound;
+extern bool idir;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Sat Oct 19 15:38:44 2013 +0000
+++ b/main.cpp	Thu Oct 24 19:51:31 2013 +0000
@@ -2,7 +2,6 @@
 //
 //To Do:
 // * Add 50% charge option
-// * Add coasting regen to regen/braking display; fix regen display to show actual instead of target regen (EX: on 100% charge)
 // * Add linear efficiency graph with 10 minute values
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add in-device config editor
@@ -12,12 +11,9 @@
 // * Add heater activation warning message
 // * Add trip max/min efficiency reset
 
-// rev155
-// Added workoaround to hardware limitation where changing pwm frequency for sound sometimes also deactivated the screen backlight
-// Added ambient temperature to trip log
-// Save Resr in history file so it doesn't reset to 75mOhms on CANary reset
-// Changed regen to 1d5 message (appears to be closer to actual regen versus 1cb being target regen)
-// Fixed Resr formatting in trip log so it show 3 decimal places
+// rev156
+// Changed efficency screen braking monitor to use actual motor amps instead of target regen signal
+// Changed braking screen to use actual regen signal instead of target regen signal
 
 #include "mbed.h"
 #include "CAN.h"
@@ -27,7 +23,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "155"; // gg - revision string, max 6 characters
+char revStr[7] = "156"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -731,7 +727,11 @@
 
         if(tick){ // Executes once a second
             tick=false;
-            curEff = miles_trip[0]/kWh_trip[0];
+            if (miles_trip[0]>0.25) {
+                curEff = miles_trip[0]/kWh_trip[0];
+            } else {
+                curEff = 0;
+            }
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
             if(accOn&&indexLastMsg[0x355]>0){
                 miles_kmbar = (lastMsg[indexLastMsg[0x355]].data[4]&0x20)?true:false;  // indicates selected distance units
--- a/utility.cpp	Sat Oct 19 15:38:44 2013 +0000
+++ b/utility.cpp	Thu Oct 24 19:51:31 2013 +0000
@@ -140,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
-                    //beep(500,0.25);
+                    beep(500,0.25);
                     
                     nLost = 0 ;
                 }
@@ -171,7 +171,7 @@
             if (writePointer==readPointer) {
                 // Just caught up to read pointer
                 printMsg("Write buffer overrun.\n"); // write buffer overrun
-                beep(500,0.25);
+                //beep(500,0.25);
             }
         }
     }