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:
Sat Jul 27 22:19:01 2013 +0000
Parent:
135:89986950d501
Child:
137:70853cf5a30f
Commit message:
Updated mainDisplay

Changed in this revision

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
--- a/displayModes.cpp	Fri Jul 26 04:35:31 2013 +0000
+++ b/displayModes.cpp	Sat Jul 27 22:19:01 2013 +0000
@@ -6,6 +6,7 @@
 
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC_x10, packV_x2, tireP;
+    float useable_kWh,dte;
     static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0, maxPS=0;
     static float lmaxTemp=0;
     static float lkW=0, laccV=0, lmpkWh=0;
@@ -22,61 +23,70 @@
     tireP = msg.data[2]+msg.data[3]+msg.data[4]+msg.data[5];
 
     tt.background(Navy);
-    tt.foreground(Yellow);
     tt.set_font((unsigned char*) Arial28x28);
     if(force) tt.cls();
     if(skin==ttSkin){
         if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){
-            tt.locate(10,10);
-            printf("%4d gids \n",gids);
+            tt.locate(16,10);
+            tt.foreground(White);
+            printf("%3d gids \n",gids);
             if(debugMode){
                 if(pointerSep>maxPS){maxPS=pointerSep;}
                 tt.locate(10,70);
                 printf("%3d sep %3d max\n",pointerSep,maxPS);
             }
             tt.locate(10,40);
-            float useable_kWh = (float)(gids-5)*0.075;
+            tt.foreground(Cyan);
+            useable_kWh = (float)(gids-5)*0.075;
+            if (useable_kWh<0){
+                useable_kWh=0;
+            }
             printf("%4.1f kWh \n",useable_kWh);
+
             // Display DTE
+            dte=convertDistance(minTripEff*useable_kWh);
+            tt.foreground(Green);
+            tt.locate(30,80);            
+            if(dte>=10){
+                printf("%2.0f \n",dte); //LM - add metric conversion
+            }else{
+                printf("%2.1f \n",dte); //LM - add metric conversion
+            }
+
             tt.set_font((unsigned char*) SCProSB31x55);
-            tt.foreground(Green);
-            tt.locate(60,80);            
-            printf("%4.1f %s  \n",convertDistance(mpkWh[dtePeriod]*useable_kWh),distanceUnit()); //LM - add metric conversion
+            tt.foreground(Yellow);
+            dte=convertDistance(mpkWh[dtePeriod]*useable_kWh);
+            if(dte>199){
+                dte=199;
+            }
+            // " "=0x10, "."=0x15, #=0x1D
+            if(dte>=100){
+                tt.locate(75,85);
+                printf(" %2.0f\n",dte); //LM - add metric conversion
+            }else if(dte>=10){
+                tt.locate(89,85);
+                printf("  %2.0f\n",dte); //LM - add metric conversion
+            }else{
+                tt.locate(84,85);
+                printf(" %2.1f\n",dte); //LM - add metric conversion
+            }
+            tt.set_font((unsigned char*) Arial28x28);
+            tt.locate(190,80);
+            printf("%s",distanceUnit()); //LM - add metric conversion
+
+            dte=convertDistance(maxTripEff*useable_kWh);
+            tt.foreground(Orange);
+            tt.locate(260,80);            
+            if(dte>=10){
+                printf("%2.0f \n",dte); //LM - add metric conversion
+            }else{
+                printf("%2.1f \n",dte); //LM - add metric conversion
+            }
             lgids=gids;
             lmpkWh=mpkWh[dtePeriod];
-            if(minTripEff<10){
-                // Display max & min DTE
-                tt.set_font((unsigned char*) Arial12x12_prop);
-                tt.locate(5,120);            
-                printf("%3.1f \n",convertDistance(minTripEff*useable_kWh));
-                tt.locate(280,120);            
-                printf("%4.1f \n",convertDistance(maxTripEff*useable_kWh));
-            }
-            tt.foreground(Yellow);
-            tt.set_font((unsigned char*) Arial28x28);
-        }
-        if(force||SOC_x10!=lSOC){
-            tt.locate(200,10);
-            printf("%4.1f%s\n",(float)SOC_x10/10,"% ");
-            lSOC=SOC_x10;
-        }
-        if(force||packV_x2!=lpackV_x2){
-            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);
-            printf("%4.1f%s\n",convertTemperature(maxTemp),temperatureUnit());
-            lmaxTemp=maxTemp;
-        }
-        if(force||accV!=laccV){
-            tt.locate(20,176);
-            printf("%3.1fV  \n",accV);
-            laccV=accV;
         }
         if(force||kW[0]!=lkW){
+            tt.foreground(Cyan);
             if(kW[0]<-10){ //Right justify
                 tt.locate(171,40);
                 printf("%4.2fkW\n",kW[0]);
@@ -92,6 +102,36 @@
             }
             lkW=kW[0];
         }
+        if(force||SOC_x10!=lSOC){
+            tt.locate(215,10);
+            tt.foreground(White);
+            printf("%4.1f%s\n",(float)SOC_x10/10,"%");
+            lSOC=SOC_x10;
+        }
+        if(force||packV_x2!=lpackV_x2){
+            tt.locate(210,176);
+            tt.foreground(Yellow);
+            printf("%4.1fV\n",(float)packV_x2/2);
+            lpackV_x2=packV_x2;
+            ltireP=0;//Force tire pressure redraw, too
+        }
+        if(force||maxTemp!=lmaxTemp){
+            tt.foreground(Cyan);
+            if (convertTemperature(maxTemp)<100){
+                tt.locate(210,146);
+                printf(" %3.1f%s\n",convertTemperature(maxTemp),temperatureUnit());
+            }else{
+                tt.locate(210,146);
+                printf("%4.1f%s\n",convertTemperature(maxTemp),temperatureUnit());
+            }
+            lmaxTemp=maxTemp;
+        }
+        if(force||accV!=laccV){
+            tt.locate(20,176);
+            tt.foreground(Yellow);
+            printf("%3.1fV  \n",accV);
+            laccV=accV;
+        }
         if(force||tireP!=ltireP){
             if(msg.data[2]<minTirePressure){
                 tt.foreground(Orange); // Hi-light if any are low (<35psi)
@@ -134,7 +174,6 @@
                 tt.locate(250,206);
                 printf("%3.1f\n",(float)msg.data[5]/4);
             }
-            tt.foreground(Yellow);
             ltireP=tireP;
         }
     }else {//if(skin==ggSkin){
--- a/main.cpp	Fri Jul 26 04:35:31 2013 +0000
+++ b/main.cpp	Sat Jul 27 22:19:01 2013 +0000
@@ -10,9 +10,7 @@
 // * Subtract accessory power from efficiency history (add back in when displaying)
 // * Add trip history display
 
-// rev135
-// Hide buttons on health screen on powerdown
-// Turn off screen even if logging if car off and user idle
+// rev136
 
 #include "mbed.h"
 #include "CAN.h"
@@ -24,7 +22,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "135"; // gg - revision string, max 6 characters
+char revStr[7] = "136"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -347,7 +345,7 @@
             if (repeatPoll) { // re-enable autopolling if enabled
                 autoPoll.attach(&autoPollISR,pollInt);
             }
-            wait5secs=3; // Refresh screen after 3 seconds
+            wait5secs=5; // Refresh screen after 5 seconds
         } // if idle
         
         if(touched){ // call touchscreen procedure if touch interrupt detected
@@ -543,8 +541,8 @@
                                                 playback.attach(&playbackISR,playbackInt);
                                                 printMsg("Starting playback\n"); // start playback
                                                 spkr.beep(2000,0.25);
-                                                can1.attach(&doNothing);// Stop recieving CAN data
-                                                can2.attach(&doNothing);
+                                                can1.attach(NULL);// Stop recieving CAN data
+                                                can2.attach(NULL);
                                             }
                                         } else {
                                             printMsg("Must stop logging first\n");
--- a/utility.cpp	Fri Jul 26 04:35:31 2013 +0000
+++ b/utility.cpp	Sat Jul 27 22:19:01 2013 +0000
@@ -451,9 +451,6 @@
     step=true;
 }
 
-void doNothing(){ //CAN deattach work-around
-}
-
 void recieve1() {
     CANMessage msg1;
     can1.read(msg1);