Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
165:4daa921730dd
Parent:
164:46ed06263b0e
Child:
166:ec3951ba9701
--- a/displayModes.cpp	Thu Nov 28 03:23:30 2013 +0000
+++ b/displayModes.cpp	Tue Dec 03 02:56:50 2013 +0000
@@ -6,11 +6,11 @@
 
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC_x10, packV_x2, tireP;
-    float useable_kWh,dte,total_kW;
+    float dte,total_kW;
     unsigned char aTemp;
     static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0;
     static unsigned char laTemp=0;
-    static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0;
+    static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0, useable_kWh=0;
 
     CANMessage msg;
 
@@ -29,23 +29,58 @@
     tt.set_font((unsigned char*) Arial28x28);
     if(force) tt.cls();
     if(skin==ttSkin){
-        if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){
-            tt.locate(16,10);
+        if(force||gids!=lgids){
+            tt.locate(16,4);
             tt.foreground(White);
-            printf("%3d gids \n",gids);
-            tt.locate(10,40);
-            tt.foreground(Cyan);
+            printf("%dgids \n",gids);
             useable_kWh = (float)(gids-5)*0.075;
             if (useable_kWh<0){
                 useable_kWh=0;
             }
-            printf("%4.1f kWh \n",useable_kWh);
-
+            if (useable_kWh<10){
+                tt.locate(166,4);
+                printf("  %3.1fkWh\n",useable_kWh);
+            } else {
+                tt.locate(166,4);
+                printf(" %3.1fkWh\n",useable_kWh);
+            }
+        }
+        if(force||SOC_x10!=lSOC){
+            tt.locate(16,34);//216,10
+            tt.foreground(LightGrey);
+            printf("%4.1f%s\n",(float)SOC_x10/10,"%");
+            lSOC=SOC_x10;
+        }
+        total_kW=kW[0]+CCkW;
+        if(force||total_kW!=lkW){
+            tt.foreground(Yellow);
+            if(total_kW<-10){ //Right justify
+                tt.locate(171,34);
+                printf("%4.2fkW\n",total_kW);
+            } else if (total_kW<0){
+                tt.locate(171,34);
+                printf(" %4.2fkW\n",total_kW);
+            } else if (total_kW<10){
+                tt.locate(165,34);
+                printf("  %4.2fkW\n",total_kW);
+            } else {
+                tt.locate(165,34);
+                printf(" %4.2fkW\n",total_kW);
+            }
+            lkW=total_kW;
+            if(CCon){
+                tt.set_font((unsigned char*) Arial12x12);
+                tt.locate(231,64);
+                printf("  %3.2fkW\n",CCkW);
+                tt.set_font((unsigned char*) Arial28x28);
+            }
+        }
+        if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){
             // Display DTE
             // worse-case DTE
             dte=convertDistance(minTripEff*useable_kWh); //LM - add metric conversion
             tt.foreground(Green);
-            tt.locate(20,90);            
+            tt.locate(16,84);            
             if(dte>=9.5){
                 printf("%2.0f \n",dte);
             }else{
@@ -61,28 +96,30 @@
             }
             // " "=0x10, "."=0x15, #=0x1D
             if(dte>=99.5){
-                tt.locate(80,85);
+                tt.locate(70,85);
                 printf(" %3.0f\n",dte); 
             }else if(dte>=9.5){
-                tt.locate(94,85);
+                tt.locate(84,85);
                 printf("  %2.0f\n",dte);
             }else{
-                tt.locate(89,85);
+                tt.locate(79,85);
                 printf(" %2.1f\n",dte);
             }
             tt.set_font((unsigned char*) Arial28x28);
-            tt.locate(195,106);
+            tt.locate(185,106);
             printf("%s\n",distanceUnit());
 
             // No Climate Control DTE
             tt.set_font((unsigned char*) Arial24x23);
             tt.foreground(Green);
             if(CCon) {
-                dte=convertDistance(mpkWh_noCC*useable_kWh); //LM - add metric conversion
+                dte=convertDistance((mpkWh_noCC-mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion
                 if(dte>199){
                     dte=199;
                 }
-                // " "=13, "."=5, #=17
+                tt.locate(130,134);
+                printf("+%2.1f \n",dte);
+                /*// " "=13, "."=5, #=17
                 if(dte>=99.5){
                     tt.locate(120,134);
                     printf(" %3.0f\n",dte); 
@@ -92,55 +129,25 @@
                 }else{
                     tt.locate(111,134);
                     printf("   %2.1f\n",dte);
-                }
+                }*/
             }
             // best-case DTE
             tt.set_font((unsigned char*) Arial28x28);
             dte=convertDistance(maxTripEff*useable_kWh); //LM - add metric conversion
             tt.foreground(Orange);
             if(dte>=99.5){
-                tt.locate(255,90);            
+                tt.locate(255,84);            
                 printf("%3.0f \n",dte);          
             }else if(dte>=9.5){
-                tt.locate(270,90);            
+                tt.locate(270,84);            
                 printf("%2.0f \n",dte);
             }else{
-                tt.locate(265,90);            
+                tt.locate(265,84);            
                 printf("%2.1f \n",dte);
             }
-            lgids=gids;
             lmpkWh=mpkWh[dtePeriod];
-        }
-        total_kW=kW[0]+CCkW;
-        if(force||total_kW!=lkW){
-            tt.foreground(Cyan);
-            if(total_kW<-10){ //Right justify
-                tt.locate(171,40);
-                printf("%4.2fkW\n",total_kW);
-            } else if (total_kW<0){
-                tt.locate(171,40);
-                printf(" %4.2fkW\n",total_kW);
-            } else if (total_kW<10){
-                tt.locate(165,40);
-                printf("  %4.2fkW\n",total_kW);
-            } else {
-                tt.locate(165,40);
-                printf(" %4.2fkW\n",total_kW);
-            }
-            lkW=total_kW;
-            if(CCon){
-                tt.set_font((unsigned char*) Arial12x12);
-                tt.locate(232,70);
-                printf("  %3.2fkW\n",CCkW);
-                tt.set_font((unsigned char*) Arial28x28);
-            }
-        }
-        if(force||SOC_x10!=lSOC){
-            tt.locate(215,10);
-            tt.foreground(White);
-            printf("%4.1f%s\n",(float)SOC_x10/10,"%");
-            lSOC=SOC_x10;
-        }
+        } //!(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh)
+        lgids=gids;
         if(force||packV_x2!=lpackV_x2){
             tt.locate(210,176);
             tt.foreground(Yellow);
@@ -150,7 +157,7 @@
         }
         if(force||aTemp!=laTemp){
             tt.foreground(Cyan);
-            tt.locate(20,146);
+            tt.locate(16,146);
             printf("%2.0f%s\n",convertF(aTemp),temperatureUnit());
             laTemp=aTemp;
         }
@@ -165,7 +172,7 @@
             lmaxTemp=maxTemp;
         }
         if(force||accV!=laccV){
-            tt.locate(20,176);
+            tt.locate(16,176);
             tt.foreground(Yellow);
             printf("%3.1fV  \n",accV);
             laccV=accV;
@@ -1217,18 +1224,15 @@
             if(CCon) {
                 tt.foreground(Green);
                 tt.set_font((unsigned char*) Arial24x23);
-                miles = mpkWh_noCC*((float)(gids-5)*.075);
+                miles = (mpkWh_noCC-mpkWh[dtePeriod])*((float)(gids-5)*.075);
                 miles = convertDistance(miles); // LM - Metric support
                 // Right justify
-                if (miles>99.9){ //space=13; num=17; . = 5
-                    tt.locate(191,52);
-                    printf("%4.1f\n",miles);
-                } else if (miles>9.9){
+                if (miles>9.9){
+                    tt.locate(190,52);
+                    printf(" +%3.1f \n",miles);
+                } else {
                     tt.locate(182,52);
-                    printf("  %3.1f\n",miles);
-                } else {
-                    tt.locate(173,52);
-                    printf("    %2.1f\n",miles);
+                    printf("   +%2.1f \n",miles);
                 }
             }
         } else {
@@ -1237,8 +1241,8 @@
             if(CCon) {
                 tt.foreground(Green);
                 tt.set_font((unsigned char*) Arial24x23);
-                tt.locate(240,52);
-                printf("%3.1f \n",mpkWh_noCC);
+                tt.locate(190,52);
+                printf(" +%2.1f \n",(mpkWh_noCC-mpkWh[dtePeriod]));
             }
         }
         lx=50;