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:
Thu Jul 25 14:32:54 2013 +0000
Parent:
133:b0675d9d11dd
Child:
135:89986950d501
Commit message:
Added orange highlight if psi<32; Qualified max and min trip efficiency update with trips > 3 miles; Keep mbed asleep during charging (EVcan only) unless logging active; Added miles & kWh to trip log;

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
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	Wed Jul 24 12:33:49 2013 +0000
+++ b/common.h	Thu Jul 25 14:32:54 2013 +0000
@@ -23,7 +23,7 @@
 #define maxSkin 1
 
 #define maxBufLen 1024
-#define canTimeout 5
+#define canTimeout 10
 #define userTimeout 15
 
 #define BatDataBaseG1 0x00 // 6 frames - SOH, SOC, Ah
@@ -35,4 +35,6 @@
 #define BatDataBaseG7 0x3A
 #define BatDataBufMax 0x196 // 7 x 3A bytes
 
-#define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX)
\ No newline at end of file
+#define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX)
+
+#define minTirePressure 128 // 32psi X 4
\ No newline at end of file
--- a/displayModes.cpp	Wed Jul 24 12:33:49 2013 +0000
+++ b/displayModes.cpp	Thu Jul 25 14:32:54 2013 +0000
@@ -64,6 +64,7 @@
             tt.locate(200,176);
             printf("%4.1fV \n",(float)packV_x2/2);
             lpackV_x2=packV_x2;
+            ltireP=0;//Force tire pressure redraw, too
         }
         if(force||maxTemp!=lmaxTemp){
             tt.locate(200,146);
@@ -92,20 +93,44 @@
             lkW=kW[0];
         }
         if(force||tireP!=ltireP){
-            tt.foreground(LightGrey);
+            if(msg.data[2]<minTirePressure){
+                tt.foreground(Orange); // Hi-light if any are low (<35psi)
+            }else{
+                tt.foreground(LightGrey);
+            }
             if(msg.data[6]&0x80){
+                if(msg.data[2]<minTirePressure){
+                    tt.foreground(Orange); // Hi-light if any are low (<35psi)
+                }else{
+                    tt.foreground(LightGrey);
+                }
                 tt.locate(10,206);
                 printf("%3.1f\n",(float)msg.data[2]/4);
             }
             if(msg.data[6]&0x40){
+                if(msg.data[3]<minTirePressure){
+                    tt.foreground(Orange); // Hi-light if any are low (<35psi)
+                }else{
+                    tt.foreground(LightGrey);
+                }
                 tt.locate(90,206);
                 printf("%3.1f\n",(float)msg.data[3]/4);
             }
             if(msg.data[6]&0x20){
+                if(msg.data[4]<minTirePressure){
+                    tt.foreground(Orange); // Hi-light if any are low (<35psi)
+                }else{
+                    tt.foreground(LightGrey);
+                }
                 tt.locate(170,206);
                 printf("%3.1f\n",(float)msg.data[4]/4);
             }
             if(msg.data[6]&0x10){
+                if(msg.data[5]<minTirePressure){
+                    tt.foreground(Orange); // Hi-light if any are low (<35psi)
+                }else{
+                    tt.foreground(LightGrey);
+                }
                 tt.locate(250,206);
                 printf("%3.1f\n",(float)msg.data[5]/4);
             }
--- a/main.cpp	Wed Jul 24 12:33:49 2013 +0000
+++ b/main.cpp	Thu Jul 25 14:32:54 2013 +0000
@@ -10,6 +10,12 @@
 // * Add ability to transfer settings config file to/from USB
 // * Subtract accessory power from efficiency history (add back in when displaying)
 
+// rev134
+// Added orange highlight if psi<32
+// Qualified max and min trip efficiency update with trips > 3 miles
+// Keep mbed asleep during charging (EVcan only) unless logging active
+// Added miles & kWh to trip log
+
 #include "mbed.h"
 #include "CAN.h"
 #include "beep.h"
@@ -20,7 +26,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "133"; // gg - revision string, max 6 characters
+char revStr[7] = "134"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -117,8 +123,8 @@
 unsigned char dtePeriod = 14; //ten minute averaging interval
 float kWh_trip[3]={0};
 float miles_trip[3]={0};
-float maxTripEff = 0;
-float minTripEff = 99;
+float maxTripEff = 4;
+float minTripEff = 4;
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
@@ -195,6 +201,9 @@
                 mpkWh[i]=mph[i]/kW[i];
             }
         }
+        if(!feof(hfile)){
+            fscanf(hfile,"%f %f\r\n",&maxTripEff,&minTripEff);
+        }
         fclose(hfile);
         printMsg("History Loaded.\n"); // History loaded
     } else { // create initial file
@@ -292,7 +301,9 @@
             }
             if (logOpen){ //close file to dump buffer
                 f_close(&efile);
-            } // if (logOpen)
+            } else { //detach EVcan so only carcan will trigger wake
+                can1.attach(NULL);
+            }// if (logOpen)
             seconds = time(NULL);
             t = *localtime(&seconds) ;
             strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t);
@@ -312,6 +323,9 @@
                 //__wfi(); // freeze CPU and wait for interrupt (from canbus or touch)
                 Sleep();
             }
+            if (logOpen){ // Re-attach EVcan
+                can1.attach(&recieve1);
+            }
             lastDMode[0]=99;
             lastDMode[1]=99;
             secsNoTouch=2;
@@ -640,7 +654,6 @@
                             //-----------------------------------
                             // Select Screen Navigation
                             case 17:
-                                //secsNoTouch = userTimeout; // immediately exit config mode
                                 sMode=0;
                                 lastDMode[whichTouched]=99; // Repaint
                                 break;
@@ -683,16 +696,25 @@
             accOn=(accV>5)?true:false;
             moving=(mph[0]>0.1);
             charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
-            if(laccOn&&!accOn){ // Car turned off
-                saveDmode=dMode[0];
-                dMode[0]=healthScreen;
+            if (laccOn&&!accOn){ // Car turned off
+                if (showHealth){
+                    if (saveDmode==99){
+                        saveDmode=dMode[0];
+                    }
+                    dMode[0]=healthScreen;
+                    secsNoTouch=0;// Keep display on a few seconds
+                    sMode=0;
+                    userIdle=false;
+                }
                 // Keep track of max and min trip efficiency
-                float tmpeff = miles_trip[0]/kWh_trip[0];
-                if (maxTripEff<tmpeff) {
-                    maxTripEff=tmpeff;
-                }
-                if (minTripEff>tmpeff) {
-                    minTripEff=tmpeff;
+                if (miles_trip[0]>3){ // Ignore very short trips
+                    float tmpeff = miles_trip[0]/kWh_trip[0];
+                    if (maxTripEff<tmpeff) {
+                        maxTripEff=tmpeff;
+                    }
+                    if (minTripEff>tmpeff) {
+                        minTripEff=tmpeff;
+                    }
                 }
                 if (repeatPoll) { // Log on shutdown if autopoll enabled
                     tripLog(); // Write trip log on powerdown
@@ -703,22 +725,28 @@
                     for(i=0;i<39;i++){
                         fprintf(hfile,"%f %f\r\n",mph[i],kW[i]);
                     }
+                    fprintf(hfile,"%f %f\r\n",maxTripEff,minTripEff); // Save max and min
                     fclose(hfile);
                 }
             }
-            if(!laccOn&&accOn){ // Car turned on
+            if (!laccOn&&accOn){ // Car turned on
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
                 wait5secs=5;
-                if(showHealth){
-                    saveDmode=dMode[0];
+                if (showHealth){
+                    if (saveDmode==99){
+                        saveDmode=dMode[0];
+                    }
                     dMode[0]=healthScreen;
                 }
             }
             laccOn=accOn;
             if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity
-                dled = 0; 
-                dMode[0]=saveDmode;
+                dled = 0;
+                if (saveDmode<99){
+                    dMode[0]=saveDmode;
+                    saveDmode=99;
+                }
             }else if(!headlights){
                 dled = ledHi;
             } else {
@@ -732,6 +760,8 @@
                     msgReq.attach(&sendReq,0.015);
                 }
             }
+
+            //remove health screen once moving
             if(moving&&(saveDmode<99)&&(wait5secs==0)){
                 dMode[0]=saveDmode;
                 saveDmode=99;
--- a/utility.cpp	Wed Jul 24 12:33:49 2013 +0000
+++ b/utility.cpp	Thu Jul 25 14:32:54 2013 +0000
@@ -471,7 +471,7 @@
     can2.read(msg2);
     
     secsNoCarCanMsg=0; // reset deadman switch
-    if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus    
+    if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second CAR bus    
     if(msg2.id>0) {
         logCan(2, msg2); // CARcan Message Received
         led2 = !led2;
@@ -749,7 +749,7 @@
         f_lseek(&bfile,0xffffffff); // go to end of file to append
         strftime(sTemp, 40, "%a %m/%d/%Y %X", &t);
         f_printf(&bfile,"%s,",sTemp);
-        sprintf(sTemp,"%3.1f,%d,%5.1f%%,%5.1f%%, %4.2f, %5.1f,%4.1f,%d,%d,%d,%d,%d",accV,gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv);      
+        sprintf(sTemp,"%3.1f,%d,%5.1f%%,%5.1f%%,%4.2f,%5.1f,%4.1f,%d,%d,%d,%d,%d,%4.1f,$4.1f",accV,gids,(float)SOC/10, (float)SOH_x100/100,(float)Ah_x10000/10000,(float)packV_x2/2,(float)packA_x2/2,max,min,avg,max-min,jv,miles_trip[0],kWh_trip[0]);      
         f_printf(&bfile,"%s,",sTemp);           
         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]);
@@ -877,7 +877,6 @@
         f_unlink("usb.det");
     }
     return(usbEn);
-    //return(true);
 }
 
 //Sample CONFIG.TXT
--- a/utility.h	Wed Jul 24 12:33:49 2013 +0000
+++ b/utility.h	Thu Jul 25 14:32:54 2013 +0000
@@ -69,6 +69,8 @@
 extern bool shunt[96];
 extern float accV;
 extern bool showHealth;
+extern float kWh_trip[0];
+extern float miles_trip[0];
 
 extern "C" {
     void mbed_reset();