Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
136:41a204105511
Parent:
134:ad243e4f1a17
Child:
137:70853cf5a30f
--- 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){