test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Fri Jul 05 15:38:40 2013 +0000
Branch:
Metric
Parent:
117:49883c779a74
Child:
119:0e2b641e98a2
Commit message:
Added Resr tracking and health display;

Changed in this revision

common.h Show annotated file Show diff for this revision Revisions of this file
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/common.h	Thu Jul 04 18:01:52 2013 +0000
+++ b/common.h	Fri Jul 05 15:38:40 2013 +0000
@@ -14,7 +14,8 @@
 #define configScreen 13
 #define indexScreen 14
 #define tripScreen 15
-#define maxScreens 15
+#define healthScreen 16
+#define maxScreens 16
 
 #define btnGap 10
 #define ttSkin 0
@@ -32,11 +33,3 @@
 #define BatDataBaseG5 0x2B // 11 frames
 #define BatDataBaseG6 0x36
 #define BatDataBufMax 0x1B2 // 7 x 3E bytes
-
-
-// gg - 4x4 touch
-// #define tNavRow = 2 ; // for 3x3
-extern unsigned char tNavRow ; // gg - 4x4
-extern char revStr[7]; // gg - version
-
-extern bool debugMode;
--- a/displayModes.cpp	Thu Jul 04 18:01:52 2013 +0000
+++ b/displayModes.cpp	Fri Jul 05 15:38:40 2013 +0000
@@ -4,97 +4,6 @@
 char sTemp1[40];
 char sTemp2[16];
 
-void printLast (bool force, bool showButtons){
-    CANMessage msg;
-    tt.locate(0,6);
-    tt.foreground(Red);
-    tt.background(Yellow);
-    if(force) tt.cls(); // Just clear screen if forced - always update display
-    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
-    for(int i=0; i<19; i++){
-        msg = lastMsg[i+indexOffset];
-        printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x    \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
-    }
-    if((sMode==1)&&showButtons){
-        tt.foreground(Yellow);
-        tt.background(DarkCyan);
-        tt.set_font((unsigned char*) Arial12x12);
-        
-        showButton(0,0," <up>","",4,4);
-        showButton(2,0,"<down>","",4,4);
-    }
-}
-
-void printChanged (bool force, bool showButtons){
-    CANMessage msg;
-    unsigned char i,j;
-    tt.locate(0,6);
-    tt.foreground(Red);
-    tt.background(Yellow);
-    if(force) tt.cls(); // Just clear screen if forced - always update display
-    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
-    i=0;
-    j=indexOffset;
-    do{
-        j=j<99?j+1:j;
-        if(msgChanged[j]>0){
-            msg = lastMsg[j];
-            printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x    \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
-            i++;
-        }// if changed
-    }while(i<19&&j<99);
-    if((sMode==1)&&showButtons){
-        tt.foreground(Yellow);
-        tt.background(DarkCyan);
-        tt.set_font((unsigned char*) Arial12x12);
-        
-        showButton(0,0,"  <up>","",4,4);
-        showButton(2,0," <down>","",4,4);
-        showButton(1,0," Reset","Baseline",4,4);
-    }
-}
-
-void printLog (bool force, bool showButtons){
-    static unsigned char lastldl = 0;
-    unsigned char ldl=displayLoc;
-    if(force||ldl!=lastldl){ //only update if changed
-        tt.foreground(Amber);
-        tt.background(Black);
-        tt.cls();
-        tt.locate(0,6);
-        tt.set_font((unsigned char*) Arial12x12);
-        for(int i=0; i<19; i++){
-            printf("%s",displayLog[ldl]);
-            ldl=ldl>17?0:ldl+1;
-        }
-    }
-    lastldl=ldl;
-}
-
-void tripDisplay (bool force, bool showButtons){
-    static float lkWh=0;
-    tt.background(White);
-    if(force){
-        tt.cls();
-    }
-    if(force||(int)(lkWh*100)!=(int)(kWh_trip[0]*100)){ //only update if changed
-        tt.foreground(Navy);
-        tt.set_font((unsigned char*) Arial28x28);
-        tt.locate(6,210);
-        printf("kWh : %s : Eff\n",distanceUnit());
-        for(int i=0; i<3; i++){
-            tt.locate(6,20+i*60);
-            printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
-        }
-        tt.set_font((unsigned char*) Arial12x12);
-        tt.background(DarkCyan);
-        tt.foreground(Yellow);
-        showButton(3,1," Reset","   A",4,4);
-        showButton(3,2," Reset","   B",4,4);
-        lkWh=kWh_trip[0];
-    }
-}
-
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC, packV;
     static unsigned short lgids=0, lSOC=0, lSOH=0, lpackV=0, maxPS=0;
@@ -110,6 +19,7 @@
     msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts
     packV = (msg.data[2]<<2)+(msg.data[3]>>6);
 
+
     tt.background(Navy);
     tt.foreground(Yellow);
     tt.set_font((unsigned char*) Arial28x28);
@@ -219,6 +129,149 @@
     }
 }
 
+void printLast (bool force, bool showButtons){
+    CANMessage msg;
+    tt.locate(0,6);
+    tt.foreground(Red);
+    tt.background(Yellow);
+    if(force) tt.cls(); // Just clear screen if forced - always update display
+    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
+    for(int i=0; i<19; i++){
+        msg = lastMsg[i+indexOffset];
+        printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x    \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
+    }
+    if((sMode==1)&&showButtons){
+        tt.foreground(Yellow);
+        tt.background(DarkCyan);
+        tt.set_font((unsigned char*) Arial12x12);
+        
+        showButton(0,0," <up>","",4,4);
+        showButton(2,0,"<down>","",4,4);
+    }
+}
+
+void printChanged (bool force, bool showButtons){
+    CANMessage msg;
+    unsigned char i,j;
+    tt.locate(0,6);
+    tt.foreground(Red);
+    tt.background(Yellow);
+    if(force) tt.cls(); // Just clear screen if forced - always update display
+    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
+    i=0;
+    j=indexOffset;
+    do{
+        j=j<99?j+1:j;
+        if(msgChanged[j]>0){
+            msg = lastMsg[j];
+            printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x    \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
+            i++;
+        }// if changed
+    }while(i<19&&j<99);
+    if((sMode==1)&&showButtons){
+        tt.foreground(Yellow);
+        tt.background(DarkCyan);
+        tt.set_font((unsigned char*) Arial12x12);
+        
+        showButton(0,0,"  <up>","",4,4);
+        showButton(2,0," <down>","",4,4);
+        showButton(1,0," Reset","Baseline",4,4);
+    }
+}
+
+void printLog (bool force, bool showButtons){
+    static unsigned char lastldl = 0;
+    unsigned char ldl=displayLoc;
+    if(force||ldl!=lastldl){ //only update if changed
+        tt.foreground(Amber);
+        tt.background(Black);
+        tt.cls();
+        tt.locate(0,6);
+        tt.set_font((unsigned char*) Arial12x12);
+        for(int i=0; i<19; i++){
+            printf("%s",displayLog[ldl]);
+            ldl=ldl>17?0:ldl+1;
+        }
+    }
+    lastldl=ldl;
+}
+
+void tripDisplay (bool force, bool showButtons){
+    static float lkWh=0;
+    tt.background(White);
+    if(force){
+        tt.cls();
+    }
+    if(force||(int)(lkWh*100)!=(int)(kWh_trip[0]*100)){ //only update if changed
+        tt.foreground(Navy);
+        tt.set_font((unsigned char*) Arial28x28);
+        tt.locate(6,210);
+        printf("kWh : %s : Eff\n",distanceUnit());
+        for(int i=0; i<3; i++){
+            tt.locate(6,20+i*60);
+            printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
+        }
+        tt.set_font((unsigned char*) Arial12x12);
+        tt.background(DarkCyan);
+        tt.foreground(Yellow);
+        showButton(3,1," Reset","   A",4,4);
+        showButton(3,2," Reset","   B",4,4);
+        lkWh=kWh_trip[0];
+    }
+}
+
+void healthDisplay (bool force, bool showButtons){
+    unsigned short gids, SOC;
+    static unsigned short lgids=0, lSOC=0, lSOH=0;
+    static float lmaxTemp=0, lresr=0, lunlV=0;
+    static unsigned long lAh=0;
+    CANMessage msg;
+
+    msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
+    gids = (msg.data[0]<<2)+(msg.data[1]>>6);
+    msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC
+    SOC = (msg.data[0]<<2)+(msg.data[1]>>6);
+
+    tt.background(Blue);
+    tt.foreground(Yellow);
+    tt.set_font((unsigned char*) Arial28x28);
+    if(force) tt.cls();
+    if(force||gids!=lgids){
+        tt.locate(10,10);
+        printf("%4d gids \n",gids);
+    }
+    if(force||SOC!=lSOC){
+        tt.locate(0,40);
+        printf("%4.1f%s\n",(float)SOC/10,"% SOC");
+        lSOC=SOC;
+    }
+    if(force||SOH_x100!=lSOH){
+        tt.locate(10,70);
+        printf(" %3.1f%s\n",(float)SOH_x100/100,"% SOH");
+        lSOH=SOH_x100;
+    }
+    if(force||Ah_x10000!=lAh){
+        tt.locate(10,100);
+        printf("% 4.2fAh \n",(float)Ah_x10000/10000);
+        lAh=Ah_x10000;
+    }
+    if(force||maxTemp!=lmaxTemp){
+        tt.locate(10,130);
+        printf("%4.1f%s max\n",convertTemperature(maxTemp),temperatureUnit());
+        lmaxTemp=maxTemp;
+    }
+    if(force||unloadedV!=lunlV){
+        tt.locate(10,160);
+        printf("%4.1fV (unloaded)\n",unloadedV);
+        lunlV=unloadedV;
+    }
+    if(force||Resr!=lresr){
+        tt.locate(10,190);
+        printf("%4.1fmOhms ESR\n",Resr);
+        lresr=Resr;
+    }
+}
+
 void braking (bool force, bool showButtons, bool prdata=false){
     unsigned long targetBraking, regenBraking;
     static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000;
@@ -1114,6 +1167,9 @@
         case tripScreen:
             tripDisplay(changed,(display==whichTouched));
             break;
+        case healthScreen:
+            healthDisplay(changed,(display==whichTouched));
+            break;
         default:
             if (changed){
                 tt.background(Black);
@@ -1182,6 +1238,9 @@
                     case tripScreen:
                         sprintf(sTemp2," Trip");
                         break;
+                    case healthScreen:
+                        sprintf(sTemp2,"Health");
+                        break;
                     case indexScreen: // gg - index
                         sprintf(sTemp2," Index");
                         break;
@@ -1296,102 +1355,3 @@
         return "C";
     return "F";
 }
-
-//-------------
-// below is braking screen normalized to power rather than force
-// changed to force since power had too large a dynamic range
-/*void braking (bool force, bool showButtons, bool prdata=false){
-    unsigned long targetBraking, regenBraking, speed;
-    static unsigned long maxTarget = 20000, maxRegen = 20000, tardivreg_x1000 = 1000;
-    short rpm;
-    unsigned long temp;
-    static unsigned char lastPressure[4] = {200,200,200,200};
-    unsigned char i,r,t;
-    static unsigned char lr, lt;
-    CANMessage msg;
-
-    msg = lastMsg[indexLastMsg[0x1cb]]; //Get Target and Regen
-    regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5);
-    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[0x176]]; //Get rpms - not sure what this is but scales to mph with .0725
-    rpm = ((short)msg.data[0]<<8)+msg.data[1];
-    speed =rpm>0?rpm>>3:-rpm>>3; //Take absolute to get speed; div8
-    if ((targetBraking>2039)||(speed>200)) { //Filter weird messages
-        targetBraking = 0;
-        regenBraking = 0;
-    } else {
-        if ((targetBraking>50)&&(regenBraking>50)){
-            temp = targetBraking;
-            temp *= 1000;
-            temp /= regenBraking;
-            if (temp<tardivreg_x1000) tardivreg_x1000=temp;
-        }
-        targetBraking *= speed;
-        regenBraking *= speed;
-        if (targetBraking>maxTarget) maxTarget=targetBraking;
-        if (regenBraking>maxRegen) maxRegen=regenBraking;
-    }
-
-    msg = lastMsg[indexLastMsg[0x1ca]]; //Get brake pressure
-    tt.background(Navy);
-    if (force) {
-        tt.cls();
-        tt.rect(0,111,170,239,White);
-        tt.line(0,207,170,207,White);
-        tt.line(0,175,170,175,White);
-        tt.line(0,143,170,143,White);
-        lastPressure[0] = 200;
-        lastPressure[1] = 200;
-        lastPressure[2] = 200;
-        lastPressure[3] = 200;
-    }
-    // plot bar graph for each wheel pressure
-    for (i=0; i<4; i++){
-        if (msg.data[i]<239) {
-            if (msg.data[i]>lastPressure[i]){
-                tt.fillrect(10+40*i,239-msg.data[i],40+40*i,239,Red);
-            } else if (msg.data[i]<lastPressure[i]) {
-                tt.fillrect(10+40*i,238-lastPressure[i],40+40*i,238-msg.data[i],Navy);
-            }
-            lastPressure[i]=msg.data[i];
-        }
-    }
-
-    temp = targetBraking;
-    temp *=200;
-    temp /= maxTarget;
-    t = (char) temp;
-    if (t>200) t=200;
-    temp = regenBraking;
-    temp *= tardivreg_x1000;
-    temp /= maxTarget;
-    temp /= 5;
-    r = (char) temp;
-    if (r>200) r=200;
-    if(lr!=r&&prdata){
-        tt.foreground(Yellow);
-        tt.set_font((unsigned char*) Arial28x28);
-        tt.locate(100,40);
-        printf("%d %d    \n",regenBraking,maxRegen);
-        tt.locate(100,70);
-        printf("%3.1f (%3.1f%s)    \n",(float)tardivreg_x1000/10,(float)regenBraking*tardivreg_x1000/targetBraking/10,"%");
-    }    
-    if(lt!=t&&prdata){
-        tt.foreground(Yellow);
-        tt.set_font((unsigned char*) Arial28x28);
-        tt.locate(100,10);
-        printf("%d %d    \n",targetBraking,maxTarget);
-    }
-    if (r>t) t=r;  //Should never happen
-    if((lr!=r||lt!=t)&&!prdata){
-        tt.fillrect(200,10,300,239-t,Navy);
-        tt.fillrect(200,239-t,300,239-r,Red);
-        tt.fillrect(200,239-r,300,239,Green);
-    }
-    lt=t;
-    lr=r;
-}*/
\ No newline at end of file
--- a/displayModes.h	Thu Jul 04 18:01:52 2013 +0000
+++ b/displayModes.h	Fri Jul 05 15:38:40 2013 +0000
@@ -49,6 +49,11 @@
 extern unsigned long SOC_x10000;
 extern unsigned short SOH_x100;
 extern bool metric;
+extern unsigned char tNavRow ; // gg - 4x4
+extern char revStr[7]; // gg - version
+extern bool debugMode;
+extern float unloadedV;
+extern float Resr;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Thu Jul 04 18:01:52 2013 +0000
+++ b/main.cpp	Fri Jul 05 15:38:40 2013 +0000
@@ -12,7 +12,6 @@
 // * Change semilog efficiency graph to linear with 10 minute values
 // * Add additional 79b bank readouts
 // * Add ability to transfer settings config file to/from USB
-// * Move log dump to ISR (but CAN RX at higher priority)
 
 #include "mbed.h"
 #include "CAN.h"
@@ -24,7 +23,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "117"; // gg - revision string, max 6 characters
+char revStr[7] = "118"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -123,6 +122,7 @@
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
+float unloadedVavg,unloadedV,Resr,Rlms,redRlms,incRlms;
 // Logarithmic division scale (roughly - snapped to common units of time)
 float timeConstant[39] = {1, 1.58, 2.51, 3.98, 6.31, 10, 15.8, 25.1, 39.8, 60, // 1 minute
                      60*1.58, 60*2.51, 60*3.98, 60*6.31, 60*10, 60*15.8, 60*25.1, 60*39.8, 60*60, // 1 hour
@@ -152,7 +152,7 @@
     touchpad.rise(&touch_ISR);
     tt.wfi();               // enable interrupt on touch
     dled = 0.8; // turn on display LED 80%
-
+    Resr = 0.1; // initial guess of Resr
     timer.start() ;
     RTC_Init(); // start the RTC Interrupts that sync the timer
     struct tm t; // pointer to a static tm structure
@@ -724,9 +724,22 @@
                 if (mpkWh[0]<0) {
                     mpkWh[0]=99;// negative means inf.
                 }
+                unloadedV = unloadedVavg/numWsamples;
+                //Rlms /= numWsamples; //unecessary
+                //redRlms /= numWsamples;
+                //incRlms /= numWsamples;
+                if (redRlms<Rlms) {
+                    Resr-=0.001;
+                } else if (incRlms<Rlms) {
+                    Resr+=0.001;
+                }
             } else {
                 kW[0]=0;
                 mpkWh[0]=0;
+                unloadedVavg=0;
+                Rlms=0;
+                redRlms=0;
+                incRlms=0;
             }
             kWh_trip[0]+=kW[0]/3600;
             kWh_trip[1]+=kW[0]/3600;
--- a/utility.cpp	Thu Jul 04 18:01:52 2013 +0000
+++ b/utility.cpp	Fri Jul 05 15:38:40 2013 +0000
@@ -297,8 +297,12 @@
             packA -= 1; //Slight correction to value required (unique to my Leaf?)
             imWs_x4 = packV; // Volts*milliSeconds*2
             imWs_x4 *= -packA; // milliWattseconds*4
-                mWs_x4 += imWs_x4; // total mWs_x4
-                numWsamples++;
+            mWs_x4 += imWs_x4; // total mWs_x4
+            unloadedVavg += packV-Resr*packA;
+            Rlms    += (packV-Resr*packA-unloadedV)*(packV-Resr*packA-unloadedV);
+            redRlms += (packV-(Resr-0.001)*packA-unloadedV)*(packV-(Resr-0.001)*packA-unloadedV);
+            incRlms += (packV-(Resr+0.001)*packA-unloadedV)*(packV-(Resr+0.001)*packA-unloadedV);
+            numWsamples++;
         }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed
             imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5]));
             if(imotorRPM<0){ // take absolute value
--- a/utility.h	Thu Jul 04 18:01:52 2013 +0000
+++ b/utility.h	Fri Jul 05 15:38:40 2013 +0000
@@ -63,6 +63,10 @@
 extern bool metric;
 extern unsigned char lastDMode[2];
 extern unsigned char whichTouched;
+extern float unloadedVavg,unloadedV,Resr,Rlms,redRlms,incRlms;
+extern unsigned char tNavRow ; // gg - 4x4
+extern char revStr[7]; // gg - version
+extern bool debugMode;
 
 extern "C" {
     void mbed_reset();