Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
161:71ac85d11f03
Parent:
159:577e9d015693
Child:
162:c6545fc0164a
--- a/displayModes.cpp	Wed Nov 20 13:13:54 2013 +0000
+++ b/displayModes.cpp	Thu Nov 21 14:17:35 2013 +0000
@@ -6,7 +6,7 @@
 
 void mainDisplay (bool force, bool showButtons){
     unsigned short gids, SOC_x10, packV_x2, tireP;
-    float useable_kWh,dte;
+    float useable_kWh,dte,total_kW;
     unsigned char aTemp;
     static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0;
     static unsigned char laTemp=0;
@@ -87,22 +87,23 @@
             lgids=gids;
             lmpkWh=mpkWh[dtePeriod];
         }
-        if(force||kW[0]!=lkW){
+        total_kW=kW[0]+CCkW;
+        if(force||total_kW!=lkW){
             tt.foreground(Cyan);
-            if(kW[0]<-10){ //Right justify
+            if(total_kW<-10){ //Right justify
                 tt.locate(171,40);
-                printf("%4.2fkW\n",kW[0]);
-            } else if (kW[0]<0){
+                printf("%4.2fkW\n",total_kW);
+            } else if (total_kW<0){
                 tt.locate(171,40);
-                printf(" %4.2fkW\n",kW[0]);
-            } else if (kW[0]<10){
+                printf(" %4.2fkW\n",total_kW);
+            } else if (total_kW<10){
                 tt.locate(165,40);
-                printf("  %4.2fkW\n",kW[0]);
+                printf("  %4.2fkW\n",total_kW);
             } else {
                 tt.locate(165,40);
-                printf(" %4.2fkW\n",kW[0]);
+                printf(" %4.2fkW\n",total_kW);
             }
-            lkW=kW[0];
+            lkW=total_kW;
         }
         if(force||SOC_x10!=lSOC){
             tt.locate(215,10);
@@ -218,10 +219,11 @@
             printf("%3.1fV  \n",accV);
             laccV=accV;
         }
-        if(force||kW[0]!=lkW){
+        total_kW=kW[0]+CCkW;
+        if(force||total_kW!=lkW){
             tt.locate(160,40); // gg - move left to keep from wrap
-            printf("%3.2fkw \n",kW[0]); // use small w to save space
-            lkW=kW[0];
+            printf("%3.2fkw \n",total_kW); // use small w to save space
+            lkW=total_kW;
         }
     }
     if(led4){
@@ -727,11 +729,10 @@
           nBar[i] *= nBarScale ; // scale, as needed
         }
         
-        // label the X axis (approximate)
-        //tt.locate( 2, yWinMin-14 ); printf("%04d = %04d from %1.4f", max, int( height / nBarScale ) + min, nBarScale );
+        // label the Y axis
         tt.locate( 2, yWinMin-14 ); printf("%04d = (%d) mv range.\n", max , max - min );
         tt.locate( 2, yWinMax+5); printf("%04d\n", min );
-        // values, for now
+
         // BatDataBaseG4 * 7 = 280
         tt.locate( 0, yWinMax+40 );
         char* sTemperatureUnit = temperatureUnit();
@@ -817,13 +818,10 @@
         int xWinMax = 300;
         int yWinMin = 50;
         int yWinMax = 150;
-        // draw the Histogram Frame, 2 pixels wide
-        tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
-        tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
-        
+
         // binning
         short nBin[301] ; // bins to count Min values in nBin[0], etc.
-        int height ;
+        int height;
         int iBinIndxMax = 300 ;
         int iBinValMax = max - min ; // zero to N
         if( iBinValMax > iBinIndxMax ) iBinValMax = iBinIndxMax ;
@@ -837,38 +835,31 @@
         for(int i=0; i<96; i++){
           bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4] - min ;
           if( bd > iBinValMax ) bd = iBinValMax ;
-          nBin[bd] ++ ;
+          nBin[bd]++ ;
         }
-        
-        //----------------
-        if( iBinValMax == 0 ) {
-            // for testing
-            min = 10 ; 
-            max = 50 ;
-            avg = ( max + min ) / 2;
-            iBinValMax = max - min ;
-            for(int i=0; i<=(iBinValMax/2); i++) {
-              nBin[i] = i ;
-              nBin[iBinValMax-i] = i ;
-            }
-        }
-        
-        // the values, for now
-        // BatDataBaseG4 * 7 = 280        
+
+        // label the Y axis
+        tt.locate( 0, yWinMin ); printf("25\n");
+        tt.locate( 0, yWinMax-6 ); printf("0\n");  
+        tt.locate( xWinMin-12, yWinMax+6 ); printf("%04d\n", min);
+        tt.locate( xWinMax-18, yWinMax+6 ); printf("%04d\n", max);
+        // draw the Histogram Frame, 2 pixels wide
+        tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
+        tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green);
         tt.locate( 0, yWinMax+40 );
         char* sTemperatureUnit = temperatureUnit();
         printf(" MAX  MIN  AVG CVLI T1  T2  T3  T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n",
             max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit,
             convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit);
-
+        
         //---------------
         // show the bars
-        int nBarWidth = 3 ;
-        int nBarSpace = 1 ; // 1 for testing
+        int nBarWidth = (xWinMax-xWinMin-2)/iBinValMax-1; //3
+        int nBarSpace = 1 ;
         
         int xPos = (xWinMin + xWinMax) / 2 ; 
         xPos -= (avg-min) * (nBarWidth + nBarSpace) ;
-        
+
         for( int i=0; i<=iBinValMax; i++) {
             height = 4 * nBin[i] ;
             if( height > 100 ) height = 100 ; // clip tops
@@ -897,7 +888,7 @@
         tt.cls();
     }
     //-------- top row --------
-    showButton(1,0," Reset","",4,4);
+    showButton(1,0," Reset","CANary",4,4);
     showButton(2,0,"  Save"," Config",4,4);
                
     //------- second row -----
@@ -948,7 +939,8 @@
     }
     //-------- top row --------
     showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
-           
+    showButton(1,0," Reset","Max/Min",4,4);
+          
     // a button to step to the next skin
     unsigned int nextSkin = skin + 1 ;
     if( nextSkin > maxSkin ) nextSkin = 0 ;