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:
Thu Oct 31 14:41:24 2013 +0000
Parent:
157:1a100a5ed06f
Child:
159:577e9d015693
Commit message:
// Fixed bug in date/time sync to sync on all days of the month; // Added auto time sync enable/disable button to cofig2 screen; // Highlight data if changed in testScreen;

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	Wed Oct 30 03:16:51 2013 +0000
+++ b/displayModes.cpp	Thu Oct 31 14:41:24 2013 +0000
@@ -897,20 +897,9 @@
         tt.cls();
     }
     //-------- top row --------
-    //showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
     showButton(1,0," Reset","",4,4);
     showButton(2,0,"  Save"," Config",4,4);
-           
-    // a button to step to the next skin
-    //unsigned int nextSkin = skin + 1 ;
-    //if( nextSkin > maxSkin ) nextSkin = 0 ;
-    
-    //if( nextSkin == ttSkin ) sprintf(sTemp1,"Skin TT");
-    //else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG");
-    //else sprintf(sTemp1,"Skin %d",nextSkin);
-
-    //showButton(3,0,"  Use",sTemp1,4,4);
-    
+               
     //------- second row -----
     if (logEn&&usbEn) {
         sprintf(sTemp1,"Disable");
@@ -933,15 +922,8 @@
         sprintf(sTemp1,"Enable");
     }
     showButton(2,1,sTemp1,"Batt Log",4,4);
-    
-    // add Enable/Disable Debug - debugMode
-    //if (debugMode) {
-    //    sprintf(sTemp1," Disable");
-    //} else {
-    //    sprintf(sTemp1," Enable");
-    //}
-    //showButton(3,1,sTemp1," Debug",4,4);    
 
+    //------- third row -----
     if(brakeMon)
         showButton(0,2,"Disable","BrkMon",4,4);
     else
@@ -951,16 +933,6 @@
         showButton(1,2,"Disable","RegMon",4,4);
     else
         showButton(1,2," Enable"," RegMon",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);
-    
 }
 
 void config2(bool force, bool showButtons){
@@ -970,8 +942,6 @@
     }
     //-------- top row --------
     showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
-    showButton(1,0," Reset","  DTE",4,4);
-    //showButton(2,0,"  Save"," Config",4,4);
            
     // a button to step to the next skin
     unsigned int nextSkin = skin + 1 ;
@@ -984,28 +954,6 @@
     showButton(3,0,"  Use",sTemp1,4,4);
     
     //------- second row -----
-    //if (logEn&&usbEn) {
-    //    sprintf(sTemp1,"Disable");
-    //} else {
-    //    sprintf(sTemp1,"Enable");
-    //}
-    //showButton(0,1,sTemp1,"Logging",4,4);
-    
-    //if (repeatPoll) {
-    //    sprintf(sTemp1,"Disable");
-    //} else {
-    //    sprintf(sTemp1,"Enable");
-    //}
-    //showButton(1,1,sTemp1,"Auto CP",4,4);
-    
-    // add Enable/Disable Batt Log gg - yesBattLog
-    //if (yesBattLog) {
-    //    sprintf(sTemp1,"Disable");
-    //} else {
-    //    sprintf(sTemp1,"Enable");
-    //}
-    //showButton(2,1,sTemp1,"Batt Log",4,4);
-    
     // add Enable/Disable Debug - debugMode
     if (debugMode) {
         sprintf(sTemp1," Disable");
@@ -1014,11 +962,13 @@
     }
     showButton(3,1,sTemp1," Debug",4,4);    
 
-    //if(brakeMon)
-    //    showButton(0,2,"Disable","BrkMon",4,4);
-    //else
-    //    showButton(0,2," Enable"," BrkMon",4,4);
-    
+    //------- third row -----
+    if (autoSync) {
+        sprintf(sTemp1," Disable");
+    } else {
+        sprintf(sTemp1," Enable");
+    }
+    showButton(0,2,sTemp1," tSync",4,4);    
     showButton(1,2,"  Set"," Time",4,4);
     if (showHealth) {
         sprintf(sTemp1," Hide");
@@ -1027,7 +977,6 @@
     }
     showButton(2,2,sTemp1," Health",4,4);
     showButton(3,2,"Update","Firmware",4,4);
-    
 }
 
 void pbScreen(bool force, bool showButtons){
@@ -1341,8 +1290,8 @@
 }
 
 void testDisplay (bool force, bool showButtons){
-    static unsigned short maxPS=0;
-    unsigned char i, uData[8], year, month, day, hour, minute, second;
+    static unsigned short maxPS=0, oldData[8]={0};
+    unsigned char i, uData[8];//, year, month, day, hour, minute, second;
     CANMessage msg;
 
     tt.set_font((unsigned char*) Arial24x23);
@@ -1351,10 +1300,12 @@
     if(force){
         tt.cls();
     }
-    if(pointerSep>maxPS){maxPS=pointerSep;}
-    tt.locate(10,10);
-    printf("%3d sep  %3d max\n",pointerSep,maxPS);
-    msg = lastMsg[indexLastMsg[0x5fa]];
+    if(logEn){
+        if(pointerSep>maxPS){maxPS=pointerSep;}
+        tt.locate(10,10);
+        printf("%3d sep  %3d max\n",pointerSep,maxPS);
+    }
+    /*msg = lastMsg[indexLastMsg[0x5fa]];
     month = msg.data[5]>>4;
     day = msg.data[2]>>3;
     msg = lastMsg[indexLastMsg[0x5fb]];
@@ -1364,16 +1315,58 @@
     minute = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
     second = msg.data[1]>>2;
     tt.locate(0,40);
-    printf("%02d%02d%02d %02d%02d%03d\n",hour,minute,second,month,day,year);
+    printf("%02d%02d%02d %02d%02d%03d\n",hour,minute,second,month,day,year);*/
     //printf("%4.2fV %4.2fV \n",accV,accV2);
+
+    /*for (i=0; i<4; i++){
+        msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]];
+        uData[i] = msg.data[(uMsgId[i]&0x000f)];
+        msg = lastMsg[indexLastMsg[(uMsgId[i+4]>>4)]];
+        uData[i+4] = msg.data[(uMsgId[i+4]&0x000f)];
+        tt.locate(10,90+i*30);
+        if(clearTest){
+            oldData[i]=uData[i];
+            oldData[i+4]=uData[i+4];
+            tt.foreground(Yellow);
+            tt.background(Navy);
+            printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
+        }else if((uData[i]!=oldData[i])||(uData[i+4]!=oldData[i+4])){
+            tt.foreground(Yellow);
+            tt.background(Navy);
+            tt.foreground(Navy);
+            tt.background(Yellow);
+            printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
+        }else if(force){
+            tt.foreground(Yellow);
+            tt.background(Navy);
+            printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
+        }
+    }*/
     for (i=0; i<8; i++){
         msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]];
         uData[i] = msg.data[(uMsgId[i]&0x000f)];
+        if(i%2==0){
+            tt.locate(10,90+(i/2)*30);
+        }else{
+            tt.locate(170,90+(i/2)*30);
+        }
+        if(clearTest){
+            oldData[i]=uData[i];
+            tt.foreground(Yellow);
+            tt.background(Navy);
+            printf("%4x:%2x\n",uMsgId[i],uData[i]);
+        }else if(uData[i]!=oldData[i]){
+            tt.foreground(Navy);
+            tt.background(Yellow);
+            printf("%4x:%2x\n",uMsgId[i],uData[i]);
+        }else if(force){
+            tt.foreground(Yellow);
+            tt.background(Navy);
+            printf("%4x:%2x\n",uMsgId[i],uData[i]);
+        }
     }
-    for (i=0; i<4; i++){
-        tt.locate(10,90+i*30);
-        printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
-    }
+    clearTest=false;    
+    showButton(3,0,"Reset","flags",4,4);               
 }
 
 void updateDisplay(char display){
@@ -1526,7 +1519,6 @@
                         sprintf(sTemp2,"Health");
                         break;
                     case testScreen:
-                        showButton(3,0,sTemp1,"",4,4);
                         sprintf(sTemp2," Test");
                         break;
                     case indexScreen: // gg - index
--- a/displayModes.h	Wed Oct 30 03:16:51 2013 +0000
+++ b/displayModes.h	Thu Oct 31 14:41:24 2013 +0000
@@ -68,6 +68,8 @@
 extern unsigned short modelYear;
 extern bool enableSound;
 extern bool idir;
+extern bool autoSync;
+extern bool clearTest;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Wed Oct 30 03:16:51 2013 +0000
+++ b/main.cpp	Thu Oct 31 14:41:24 2013 +0000
@@ -5,15 +5,14 @@
 // * Add linear efficiency graph with 10 minute values
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add in-device config editor
-// * Store efficiency data at different temperatures
 // * Change pack volt color when CVLI fails
 // * 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
 
-
-// rev157
-// Added trip max/min efficiency reset
-// Added second config screen and RegenMon enable/disable
+// rev158
+// Fixed bug in date/time sync to sync on all days of the month
+// Added auto time sync enable/disable button to cofig2 screen
+// Highlighted row if data changed in testScreen
 
 #include "mbed.h"
 #include "CAN.h"
@@ -23,7 +22,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "157"; // gg - revision string, max 6 characters
+char revStr[7] = "158"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -127,8 +126,8 @@
 float kWh_trip[3]={0};
 float miles_trip[3]={0};
 float curEff = 0;
-float maxTripEff = 4;
-float minTripEff = 4;
+float maxTripEff = 0;
+float minTripEff = 5;
 float mph[39]={0};
 float kW[39]={0};
 float mpkWh[39]={0};
@@ -158,6 +157,7 @@
 unsigned short modelYear = 2011;
 bool idir, lidir;
 bool enableSound=false;
+bool clearTest=true;
 
 int main() {
     char sTemp[40];
@@ -464,8 +464,8 @@
                                 } else if (dMode[whichTouched]==configScreen) {
                                     mbed_reset();
                                 } else if (dMode[whichTouched]==config2Screen) { // reset DTE Max/Min
-                                    maxTripEff = 4;
-                                    minTripEff = 4;
+                                    maxTripEff = 0;
+                                    minTripEff = 5;
                                 } else if (dMode[whichTouched]==playbackScreen) { // pause/unpause
                                     playbackEn=!playbackEn;
                                     if(playbackEn){
@@ -517,7 +517,9 @@
                                 } else if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = healthScreen ; // Goto health screen
                                     sMode=0;
-                                } else {
+                                } else if (dMode[whichTouched] == testScreen) { // gg - index
+                                    clearTest=true;
+                                } else { // top-right corner always mute/unmute unless used by specific screen
                                     enableSound = !enableSound;
                                     if(!enableSound) spkr=0;
                                 }
@@ -631,23 +633,25 @@
                                     }else{
                                         geiger.detach();
                                     }
+                                } else if (dMode[whichTouched]==config2Screen) {
+                                    autoSync = !autoSync;                                
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 }            
                                 break;
                                 
                              case 12: // left-middle col, bottom row (not nav)
-                                if (dMode[whichTouched] == config2Screen) { // gg - index
+                                if (dMode[whichTouched]==configScreen) {
+                                    regenMon = !regenMon;                                
+                                } else if (dMode[whichTouched]==config2Screen) { // gg - index
                                     dMode[whichTouched] = dateScreen ; // GoTo Set Date/Time Screen  
-                                } else if (dMode[whichTouched]==configScreen) {
-                                    regenMon = !regenMon;                                
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 } 
                                 break;
                              
                              case 22: // right-middle col, bottom row (not nav)
-                                if (dMode[whichTouched] == indexScreen) { // gg - index
+                                if (dMode[whichTouched]==indexScreen) { // gg - index
                                     dMode[whichTouched] = logScreen ;    
                                 } else if (dMode[whichTouched]==config2Screen) {
                                     showHealth = !showHealth;
@@ -657,15 +661,15 @@
                                 break;
 
                              case 32: // right col, bottom row (not nav)  
-                                if (dMode[whichTouched] == config2Screen) {
+                                if (dMode[whichTouched]==config2Screen) {
                                     logEn=false;
                                     updateFirmware();
-                                } else if (dMode[whichTouched] == tripScreen) {
+                                } else if (dMode[whichTouched]==tripScreen) {
                                     miles_trip[2]=0;
                                     kWh_trip[2]=0;
                                     sMode=0;
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
-                                } else if (dMode[whichTouched] == indexScreen) {
+                                } else if (dMode[whichTouched]==indexScreen) {
                                     dMode[whichTouched] = tripScreen ;    
                                 } else if (dMode[whichTouched]==dateScreen){
                                     autoSync=!autoSync; // toggle autoSync mode
@@ -757,7 +761,7 @@
                     userIdle=false;
                 }
                 // Keep track of max and min trip efficiency
-                if (miles_trip[0]>3){ // Ignore very short trips
+                if (miles_trip[0]>5){ // Ignore short trips
                     if (maxTripEff<curEff) {
                         maxTripEff=curEff;
                     }
--- a/utility.cpp	Wed Oct 30 03:16:51 2013 +0000
+++ b/utility.cpp	Thu Oct 31 14:41:24 2013 +0000
@@ -529,11 +529,11 @@
     fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp);
     fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp);
     fprintf(cfile,"x_mid %d\r\n",tt.x_mid);
-    if (dMode[0]==configScreen)
+    if ((dMode[0]==configScreen)||(dMode[0]==config2Screen))
         fprintf(cfile,"dMode0 %d\r\n",mainScreen);
     else
         fprintf(cfile,"dMode0 %d\r\n",dMode[0]);
-    if (dMode[1]==configScreen)
+    if ((dMode[1]==configScreen)||(dMode[1]==config2Screen))
         fprintf(cfile,"dMode1 %d\r\n",mainScreen);
     else
         fprintf(cfile,"dMode1 %d\r\n",dMode[1]);
@@ -664,7 +664,7 @@
         }
         if(ff>8){
             fscanf(cfile, "modelYear %d\r\n", &modelYear);            
-            fscanf(cfile, "modelYear %d\r\n", &readBool);            
+            fscanf(cfile, "autoSync %d\r\n", &readBool);            
             autoSync = (bool)readBool;
         }
         fclose(cfile);
@@ -794,7 +794,7 @@
         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
+    if((t.tm_mon>=0)&&(t.tm_mon<12)&&(t.tm_mday>0)&&(t.tm_mday<32)&&(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{
@@ -945,6 +945,7 @@
     char buffer[bufSize];
     FILE *lfile;    
 
+    tt.set_font((unsigned char*) Arial12x12);
     tt.background(Blue);
     tt.foreground(Yellow);
     tt.locate(0,10);
--- a/utility.h	Wed Oct 30 03:16:51 2013 +0000
+++ b/utility.h	Thu Oct 31 14:41:24 2013 +0000
@@ -81,6 +81,7 @@
 extern bool autoSync;
 extern unsigned short modelYear;
 extern bool enableSound;
+extern const unsigned char Arial12x12[];
 
 extern "C" {
     void mbed_reset();