Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Wed Mar 19 14:08:56 2014 +0000
Parent:
177:6fda79c2fda1
Child:
179:e4094e55f079
Commit message:
// Added Wh/gid display

Changed in this revision

common.h Show annotated file Show diff for this revision Revisions of this file
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
--- a/common.h	Thu Mar 06 15:37:40 2014 +0000
+++ b/common.h	Wed Mar 19 14:08:56 2014 +0000
@@ -18,7 +18,8 @@
 #define ccTripScreen 17
 #define healthScreen 18
 #define testScreen 19
-#define maxScreens 19
+#define whpgScreen 20
+#define maxScreens 20
 
 #define btnGap 10
 #define ttSkin 0
--- a/displayModes.cpp	Thu Mar 06 15:37:40 2014 +0000
+++ b/displayModes.cpp	Wed Mar 19 14:08:56 2014 +0000
@@ -1423,6 +1423,87 @@
     showButton(3,0,"Reset","flags",4,4);               
 }
 
+void whpgDisplay(bool force, bool showButtons){ 
+    unsigned short maxVal, minVal, maxGid, minGid, avg, i, j;
+
+    if(force){
+        tt.foreground(White);
+        tt.background(Navy);
+        tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
+        maxVal=0;
+        minVal=9999;
+        maxGid=0;
+        minGid=9999;
+        avg=0;
+       
+        // find max/min/avg
+        for(i=0; i<300; i++){
+            j=whpg[i];
+            if(j<255){
+                avg+=j;
+                if(j>maxVal) maxVal=j;
+                if(j<minVal) minVal=j;
+                if(i>maxGid) maxGid=i;
+                if(i<minGid) minGid=i;
+            }
+        }
+        avg /= (maxGid-minGid+1);
+
+        //------------------
+        tt.cls();
+
+        // show as vertical bar plot
+        int xWinMin = 26;
+        int xWinMax = 316;
+        int yWinMin = 50;
+        int yWinMax = 150;
+        // draw the Bar Graph 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);
+        
+        // bar heights
+        int height = yWinMax - yWinMin ;
+        int iBarValMax = maxVal - minVal ; // zero to N
+        
+        //----------------
+        if( iBarValMax > 0 ) {
+
+            // label the Y axis
+            tt.locate( 2, yWinMin-14 ); printf("%02d\n", maxVal );
+            tt.locate( 2, yWinMax+5); printf("%02d\n", minVal );
+            tt.locate( 2, (yWinMax+yWinMin)/2); printf("%02d avg\n", avg );
+                   
+            //---------------
+            // show the bars
+            int nBarWidth = 1 ;
+            int nBarSpace = 0 ; // 1 for testing
+            
+            int xPos = xWinMin + 2 ; // start one from the left
+             
+            for( int i=minGid; i<=maxGid; i++) {
+                height = whpg[i] ;
+                if( height > 100 ) height = 100 ; // clip tops
+                
+                // draw the bar, is always inside x-window
+                tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);  
+                // tic mark the x axis each 10
+                if(i%10 == 9){
+                   tt.line( xPos,yWinMax+2, xPos,yWinMax+5, White);  // a white tick mark
+                   tt.line( xPos+1,yWinMax+2, xPos+1,yWinMax+5, White);  // a white tick mark, to widen
+                }
+                // label the x axis each 20
+                if(i%20 == 19){
+                   tt.locate( xPos-6, yWinMax+8 );
+                   printf("%02d\n", i+1 );
+                }
+                
+                // step to the next bar position
+                xPos += nBarWidth + nBarSpace ; 
+            }
+        }
+    }
+}
+
 void updateDisplay(char display){
     bool changed,showButtons;
     changed = (dMode[display]!=lastDMode[display]);
@@ -1486,6 +1567,9 @@
         case testScreen:
             testDisplay(changed,showButtons);
             break;
+        case whpgScreen:
+            whpgDisplay(changed,showButtons);
+            break;        
         default:
             if (changed){
                 tt.background(Black);
@@ -1581,6 +1665,9 @@
                     case indexScreen: // gg - index
                         sprintf(sTemp2," Index");
                         break;
+                    case whpgScreen: // gg - index
+                        sprintf(sTemp2," WHPG");
+                        break;
                 }
                 showButton(1,tNavRow," Select",sTemp2,4,4);
                 
--- a/displayModes.h	Thu Mar 06 15:37:40 2014 +0000
+++ b/displayModes.h	Wed Mar 19 14:08:56 2014 +0000
@@ -15,6 +15,7 @@
 extern char displayLog[20][40];
 extern unsigned char displayLoc;
 extern char indexLastMsg[0x800];
+extern unsigned char whpg[300];
 
 //extern unsigned char battData[256]; // 
 extern unsigned char battData[BatDataBufMax]; // BatDataBufMax
--- a/main.cpp	Thu Mar 06 15:37:40 2014 +0000
+++ b/main.cpp	Wed Mar 19 14:08:56 2014 +0000
@@ -11,11 +11,8 @@
 // * Be more efficient with write buffer (use msgLen instead of always storing 8 bytes)
 
 
-// rev176
-// Changed effciency counter to check after charging after 3am
-// Added cancel day data button to trip display
-// Base best and worse case on full round trip (per charge efficiency)
-// Track daily wh/gid
+// rev178
+// Added Wh/gid display
 
 #include "mbed.h"
 #include "CAN.h"
@@ -26,7 +23,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "176";
+char revStr[7] = "178";
 unsigned long maxTarget = 1000;
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -185,6 +182,8 @@
 unsigned long fbScalar = 132;
 int effCheckTime = 3;
 bool ignoreDayData = true;
+unsigned short cgids,lgids;
+unsigned char whpg[300];
 
 int main() {
     char sTemp[40];
@@ -919,12 +918,24 @@
             } else {
                 dled = ledLo;
             }
+            cgids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6);
             if(getGids){
-                startGids=(lastMsg[indexLastMsg[0x5bc]].data[0]<<2)+(lastMsg[indexLastMsg[0x5bc]].data[1]>>6);  //Get gids
+                startGids=cgids;  //Get gids
                 if((startGids>0)&&(startGids<300)){ // Ignore bogus values at startup
                     getGids=false;
+                    lgids=startGids; // initialize wh/gid array
+                    for(i=0;i<299;i++){
+                        whpg[i]=255;
+                    }
                 }
             }
+            if(cgids<lgids){
+                whpg[lgids]= (unsigned char) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                lgids=cgids;
+            }else if(cgids>lgids){
+                whpg[cgids]= (unsigned char) (1000*kWh_trip[3]); // Save kWh for each gid since last charge
+                lgids=cgids;
+            }
             if(wait5secs>0){ // Wait a few seconds after poweron to give BMS time to measure CP's
                 wait5secs-=1;
                 if(wait5secs==0){