Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
178:bf6404312c45
Parent:
177:6fda79c2fda1
Child:
179:e4094e55f079
--- 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);