Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Mon Jul 22 00:02:51 2013 +0000
Parent:
129:8991d0de01ab
Child:
131:0d926c080a65
Commit message:
Pulled last good metric rev into default branch

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	Sun Jul 21 23:59:00 2013 +0000
+++ b/common.h	Mon Jul 22 00:02:51 2013 +0000
@@ -35,4 +35,4 @@
 #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 1 // Set to 0 if using VP231 (sleep disables RX)
\ No newline at end of file
--- a/displayModes.cpp	Sun Jul 21 23:59:00 2013 +0000
+++ b/displayModes.cpp	Mon Jul 22 00:02:51 2013 +0000
@@ -572,7 +572,7 @@
         showButton(3,1," GoTo"," Config",4,4);               
         // bottom (not Nav) row        
         showButton(0,2," GoTo","Playback",4,4);               
-        //showButton(1,2," GoTo","Set Time",4,4);             
+        showButton(1,2," GoTo","Set Time",4,4);             
         showButton(2,2," GoTo"," Log",4,4);     
         showButton(3,2," GoTo"," Trip",4,4);     
     
@@ -844,7 +844,7 @@
     //-------- top row --------
     showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
     showButton(1,0," Reset","",4,4);
-    showButton(2,0,"  Save"," Config",4,4);
+    showButton(2,0," Save"," Config",4,4);
            
     // a button to step to the next skin
     unsigned int nextSkin = skin + 1 ;
@@ -854,7 +854,7 @@
     else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG");
     else sprintf(sTemp1,"Skin %d",nextSkin);
 
-    showButton(3,0,"  Use",sTemp1,4,4);
+    showButton(3,0," Use",sTemp1,4,4);
     
     //------- second row -----
     if (logEn&&usbEn) {
@@ -881,9 +881,9 @@
     
     // add Enable/Disable Debug - debugMode
     if (debugMode) {
-        sprintf(sTemp1," Disable");
+        sprintf(sTemp1,"Disable");
     } else {
-        sprintf(sTemp1," Enable");
+        sprintf(sTemp1,"Enable");
     }
     showButton(3,1,sTemp1," Debug",4,4);    
     
@@ -892,13 +892,6 @@
     else
        showButton(0,2,"Metric","",4,4);
     
-    showButton(1,2,"  Set"," Time",4,4);
-    if (showHealth) {
-        sprintf(sTemp1," Hide");
-    } else {
-        sprintf(sTemp1," Show");
-    }
-    showButton(2,2,sTemp1," Health",4,4);
     showButton(3,2,"Update","Firmware",4,4);
     
 }
@@ -966,6 +959,9 @@
                 case 5:
                     sprintf(sTemp1,"Second");
                     break;
+                case 6:
+                    sprintf(sTemp1,"Select");
+                    break;
                 default:
                     break;
             }
@@ -1031,8 +1027,8 @@
         tt.set_font((unsigned char*) Arial24x23);
         //for(i=0;i<10;i++){
             //y=200-i*20;
-        for(i=2;i<7;i++){
-            y=200-(i-2)*40;
+        for(i=3;i<8;i++){
+            y=200-(i-3)*40;
             tt.locate(0,y-8);
             if (showMiles){
                 printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support
@@ -1045,8 +1041,8 @@
         lgids=gids;    
     }
     if(tock||force){
-        for(i=2;i<7;i++){
-            y=200-(i-2)*40;
+        for(i=3;i<8;i++){
+            y=200-(i-3)*40;
             tt.line(40,y,158,y,DarkGrey);
         }
 
@@ -1116,11 +1112,11 @@
                 radius=2;
                 color=Green;
             }
-            if(y<60){
+            if(y<100){
                 y=220;
                 color=Red;
-            }else if(y<280) {
-                y=280-y;
+            }else if(y<320) {
+                y=320-y;
             }else{
                 y=0;
             }
--- a/displayModes.h	Sun Jul 21 23:59:00 2013 +0000
+++ b/displayModes.h	Mon Jul 22 00:02:51 2013 +0000
@@ -57,7 +57,6 @@
 extern bool shunt[96];
 extern float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin;
 extern signed short Imax, Imin;
-extern bool showHealth;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Sun Jul 21 23:59:00 2013 +0000
+++ b/main.cpp	Mon Jul 22 00:02:51 2013 +0000
@@ -4,11 +4,12 @@
 // * Audible friction brake feedback
 // * User-configurable watchpoint
 // * Add 50% charge option
+// * Tire Pressure Sensor display
+// * Fix bug in playback while connected to canbus (hangs)
 // * Add coasting regen to regen/braking display
 // * 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
-// * Subtract accessory power from efficiency history (add back in when displaying)
 
 #include "mbed.h"
 #include "CAN.h"
@@ -20,7 +21,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "128b"; // gg - revision string, max 6 characters
+char revStr[7] = "130"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -53,7 +54,7 @@
 
 bool debugMode = false;
 bool usbEn = false;
-bool logEn = false;
+bool logEn = true;
 bool logOpen = false; 
 bool yesBattLog = true; // gg - Batt Log
 unsigned char tNavRow = 3; // gg - 4x4 touch
@@ -83,7 +84,7 @@
 unsigned char dMode[2] = {mainScreen,brakeScreen}; //display mode
 unsigned char sMode = 0; // setup mode
 unsigned char lastDMode[2] = {0,0}; //last screen mode
-unsigned char dtMode = 0;
+unsigned char dtMode = 6;
 char displayLog[20][40];
 unsigned char displayLoc = 0;
 unsigned int fwCount=1;
@@ -138,9 +139,6 @@
 bool metric = false;
 bool shunt[96]={0};
 bool charging=false;
-bool showHealth=false;
-unsigned char saveDmode=99;
-bool moving=false;
 
 int main() {
     //can1SleepMode.mode(OpenDrain);
@@ -226,7 +224,7 @@
     secsNoTouch=2;
     while (true) {
         if (!logOpen) { // Open new file if one is not already open
-            if(logEn&&usbEn){ //logging enabled and USB device detected
+            if(logEn&&usbEn){ //logging enables and USB device detected
                 strftime(fileName, 32, "%m%d%H%M.alc", &t); //mmddhhmm.alc
                 efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS);
                 seconds = time(NULL);
@@ -494,7 +492,7 @@
                                     dMode[whichTouched] = cpScreen ; // GoTo CP Data Screen                                
                                     sMode=0;
                                 } else if (dMode[whichTouched]==dateScreen){
-                                    dtMode=(dtMode<5)?dtMode+1:0;
+                                    dtMode=(dtMode<6)?dtMode+1:0;
                                     lastDMode[whichTouched]=99;
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
@@ -516,9 +514,7 @@
                                 } else if (dMode[whichTouched]==playbackScreen) {
                                     // Start/stop playback
                                     if(!playbackOpen){
-                                        if(!canIdle){
-                                            printMsg("Cannot playback while connected to canbus\n");
-                                        }else if(!logOpen){
+                                        if(!logOpen){
                                             efr = f_open(&efile,"playback.alc",FA_READ|FA_OPEN_EXISTING);
                                             lastDMode[whichTouched]=99;//force refresh
                                             if(efr != FR_OK){
@@ -596,7 +592,7 @@
                                 break;
                                 
                              case 12: // left-middle col, bottom row (not nav)
-                                if (dMode[whichTouched] == configScreen) { // gg - index
+                                if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = dateScreen ; // GoTo Set Date/Time Screen  
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
@@ -606,8 +602,6 @@
                              case 22: // right-middle col, bottom row (not nav)
                                 if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = logScreen ;    
-                                } else if (dMode[whichTouched]==configScreen) {
-                                    showHealth = !showHealth;
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 } 
@@ -679,8 +673,7 @@
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
             accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th
             accOn=(accV>5)?true:false;
-            moving=(mph[0]>0.1);
-            charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
+            charging=(mph[0]<0.1)&&(kW[0]<-1); // not moving and generating energy so much be charging
             if(laccOn&&!accOn){ // Car turned off
                 if (repeatPoll) { // Log on shutdown if autopoll enabled
                     tripLog(); // Write trip log on powerdown
@@ -698,10 +691,6 @@
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
                 wait5secs=5;
-                if(showHealth){
-                    saveDmode=dMode[0];
-                    dMode[0]=healthScreen;
-                }
             }
             laccOn=accOn;
             if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity
@@ -719,10 +708,6 @@
                     msgReq.attach(&sendReq,0.015);
                 }
             }
-            if(moving&&(saveDmode<99)&&(wait5secs==0)){
-                dMode[0]=saveDmode;
-                saveDmode=99;
-            }
 
             //compute historic efficiency
             if(numSsamples>0){ // Avoid div0
--- a/utility.cpp	Sun Jul 21 23:59:00 2013 +0000
+++ b/utility.cpp	Mon Jul 22 00:02:51 2013 +0000
@@ -490,7 +490,7 @@
 void saveConfig(){
     FILE *cfile;
     cfile = fopen("/local/config.txt", "w");    
-    fprintf(cfile,"format 6\r\n");
+    fprintf(cfile,"format 5\r\n");
     fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
     fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
     fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
@@ -517,14 +517,12 @@
     fprintf(cfile,"DebugMode %d\r\n",(debugMode?1:0));
     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));
     fclose(cfile);
 }
 
 void readConfig(){
     FILE *cfile;
     int ff;
-
     cfile = fopen("/local/config.txt", "r");
     if (cfile==NULL){ // if doesn't exist --> create
         printMsg("No config file found.\n"); // no config file
@@ -573,13 +571,8 @@
             fscanf(cfile, "firmware %d\r\n", &iMetric );
             fwCount = iMetric;
         }
-        if(ff>5){
-            int ishowHealth;
-            fscanf(cfile, "showHealth %d\r\n", &ishowHealth );            
-            showHealth = (bool)ishowHealth;
-        }
         fclose(cfile);
-        if(ff<6){//If not latest format, save as latest format
+        if(ff<4){//If not latest format, save as latest format
             saveConfig();
             printMsg("Config file format updated.\n"); // config forat updates
         }
@@ -752,15 +745,14 @@
         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]);
-        /*for(i=0; i<96; i++) {
+        for(i=0; i<96; i++) {
             bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4];
             f_printf(&bfile,",%d",bd);
-        }*/
+        }
         // temporariliy dump everything
-        for(i=0; i<BatDataBufMax; i++) {
-            sprintf(sTemp,",%02x",battData[i]);
-            f_printf(&bfile,"%s",sTemp);
-        }
+        /*for(i=0; i<BatDataBufMax; i++) {
+            f_printf(&bfile,",%02x",battData[i]);
+        }*/
 
         f_printf(&bfile,"\r\n");
         f_close(&bfile);
@@ -775,26 +767,6 @@
     FRESULT sfr; // external file access flags
     unsigned int bytesRW;
     char sTemp[40];
-    const int bufSize = 2048;
-    char buffer[bufSize];
-    FILE *destFile;    
-
-    // Check for config file on USB drive
-    sfr = f_open(&sfile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);    
-    if(sfr == FR_OK)
-    {        
-        printf("Copy config file from USB\n");
-        destFile = fopen("/local/CONFIG.TXT", "w");
-        while (!f_eof(&sfile))
-        {
-            sfr=f_read(&sfile,&buffer,bufSize,&bytesRW);
-            fwrite(buffer, 1, bytesRW, destFile);
-        }
-        fflush(destFile);
-        fclose(destFile);
-        f_close(&sfile);
-    }    
-    
     sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);    
     if(sfr != FR_OK)
     {        
@@ -839,17 +811,21 @@
     printf("copying new firmware\n");
     tt.cls();
     //Copy the new firmware from usb->local
-    //The newest bin file is the one that is used by the mbed  
+    //The newest bin file is the one that is used by the mbed
+    const int bufSize = 2048;
+    FILE *destFile;    
     sprintf(sTemp,"/local/fw%d.bin",fwCount);
     printf("Writing %s\n",sTemp);
     wait(2);
     destFile = fopen(sTemp, "wb");
     if(destFile == NULL)
     {
-        printf("Couldn't Open Destination\n");
+        sprintf(sTemp,"Couldn't Open Destination\n");
+        printf(sTemp);
         wait(3);
         return;
     }
+    char buffer[bufSize];
 
     while (!f_eof(&sfile))
     {
@@ -869,39 +845,11 @@
 }
 
 bool detectUSB(void){
-    /*FIL tfile; // external usb file
+    FIL tfile; // external usb file
     bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK);
     if(usbEn){
         f_close(&tfile);
         f_unlink("usb.det");
     }
-    return(usbEn);*/
-    return(true
-    );
+    return(usbEn);
 }
-
-//Sample CONFIG.TXT
-/*
-format 5
-x0_off 5732
-y0_off 34009
-x0_pp 77
-y0_pp 106
-x1_off 33955
-y1_off 6310
-x1_pp 80
-y1_pp 104
-x_mid 31986
-dMode0 4
-dMode1 2
-ledHi 0.800
-ledLo 0.100
-pollInt 300
-scale12V 16.20
-skin 0
-dtePeriod 14
-DebugMode 0
-metric 0
-firmware 11
-showHealth 1
-*/
\ No newline at end of file
--- a/utility.h	Sun Jul 21 23:59:00 2013 +0000
+++ b/utility.h	Mon Jul 22 00:02:51 2013 +0000
@@ -66,7 +66,6 @@
 extern bool debugMode;
 extern bool shunt[96];
 extern float accV;
-extern bool showHealth;
 
 extern "C" {
     void mbed_reset();