basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Revision:
12:c19239029172
Parent:
11:f6a146b62579
--- a/main.cpp	Tue Apr 05 15:02:48 2016 +0000
+++ b/main.cpp	Tue Apr 05 18:16:12 2016 +0000
@@ -11,7 +11,7 @@
 **                   two different colored liquids. Another purpose of this program is to also read back feedback from the two ITVs, a PF3W flow meter,
 **                   and a PSE pressure sensor. The program also interfaces with an HMI controlled by a FT810 LCD driver. The interface controls the hardware
 **                   and displays graphics. This program was designed for the Teensy and to control the Closed Loop Controller Brew Panel prototype board.
-**                  
+**
 **     Notes       : The limitations of the VERTEX2II program forced us to create a bandage when trying to write images past pixel 511. The range of VERTEX2II is 0 to 511
                      so in order to draw an image further away we had to use the translate command.
 **
@@ -66,7 +66,7 @@
     TFT.DLstart();                                             // start a new display command list
     TFT.DL(CLEAR_COLOR_RGB(255,255,255));                      // set the clear color to white
     TFT.DL(CLEAR(1,1,1));                                      // clear buffers -> color buffer,stencil buffer, tag buffer
-    
+
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));                         // generate border in SMC blue, all functions are in 1/16 pixel format
     TFT.DL(BEGIN(LINES));
     TFT.DL(LINE_WIDTH(8 * 16));
@@ -139,12 +139,12 @@
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));                                  // set color to SMC blue for the text
     TFT.Text(265, 200, 31, 0, "ITV 1 Pressure");                        // title block for screen
     TFT.DL(BEGIN(RECTS));                                               // draw rounded rectangle in SMC blue to act as background for where the feedback will be written
-    TFT.DL(VERTEX2F(300*16,265*16));                                    
+    TFT.DL(VERTEX2F(300*16,265*16));
     TFT.DL(VERTEX2F(505*16,330*16));
     TFT.DL(END());
     ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0;        // calibration and scaling math for the ITV feedback, 48430 = 20mA, 9430 = 4mA
-    ITV1_fcal = ITVpressure1_feedback;                                  // moving average filter                     
-    ITV1_fcal *= avg1;                                                 
+    ITV1_fcal = ITVpressure1_feedback;                                  // moving average filter
+    ITV1_fcal *= avg1;
     ITV1_fcal += ITV1_pre * avg2;
     ITV1_pre = ITV1_fcal;
     ITVpressure1_feedback = ITV1_fcal;                                  // store the filtered value in the feedback variable
@@ -152,7 +152,7 @@
     sprintf(buffer, "%.1f", ITVpressure1_feedback);                     // write the feedback pressure to the screen
     TFT.Text(325,275,31,0,buffer);
     TFT.Text(415, 275, 31, 0, " PSI");                                  // write the units to the screen
-                                    
+
     TFT.DL(COLOR_RGB(255,255,255));                                     // controls the color of the slider bar in RGB format
     TFT.FgColor(COLOR_RGB(0,124,196));                                  // foreground color set to SMC blue in RGB format
     TFT.BgColor(COLOR_RGB(0,124,196));                                  // background color set to SMC blue in RGB format
@@ -165,7 +165,7 @@
     /*ITV 2 and PF3W Screen Display*/
     TFT.DL(COLOR_RGB(255,255,255));                                     // set background color to white
     TFT.DL(VERTEX_TRANSLATE_X(location* 16)+12800);                     // translate screen writes by 12800 which is a 1/16th pixel format, this creates page 2 of the screen
-    TFT.DL(BEGIN(BITMAPS));                                             // draw a bitmap that stores the second screens images 
+    TFT.DL(BEGIN(BITMAPS));                                             // draw a bitmap that stores the second screens images
     TFT.DL(VERTEX2II(30,75,3,0));                                       // write PF3W_1 image to the LCD
     TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)+12800);                // translate right 149 pixels for third image, location controls what page the screen is on
     TFT.DL(VERTEX2II(411,75,4,0));                                      // write PF3W_2 image to the LCD
@@ -178,7 +178,7 @@
     TFT.DL(VERTEX2F(300*16,265*16));
     TFT.DL(VERTEX2F(505*16,330*16));
     TFT.DL(END());
-    
+
     ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0; // calibration and scaling math for the ITV feedback, 48420 = 20mA, 9365 = 4mA
     ITV2_fcal = ITVpressure2_feedback;                                  // moving average filter
     ITV2_fcal *= avg1;
@@ -188,7 +188,7 @@
     TFT.DL(COLOR_RGB(255,255,255));                                     // set color for text to white
     sprintf(buffer, "%.1f", ITVpressure2_feedback);                     // write feedback to screen in white
     TFT.Text(325,275,31,0,buffer);
-    TFT.Text(415, 275, 31, 0, " PSI");                                  // write the units to the screen       
+    TFT.Text(415, 275, 31, 0, " PSI");                                  // write the units to the screen
     TFT.DL(COLOR_RGB(255,255,255));                                     // controls the color of the slider bar in RGB format
     TFT.FgColor(COLOR_RGB(0,124,196));                                  // foreground color set to SMC blue in RGB format
     TFT.BgColor(COLOR_RGB(0,124,196));                                  // background color set to SMC blue in RGB format
@@ -248,7 +248,7 @@
     TFT.Number(20, 450, 26, 0, distance);            // write distance value to screen
     TFT.Number(80, 450, 26, 0, velocity);            // write velocity to screen
 #endif
-    
+
 #ifdef Debug_Touch_File                              // debug the touch up load
     TFT.DL(COLOR_RGB(0,0,0));                        // set text color to black
     int j;                                           // loop counter
@@ -371,77 +371,66 @@
     Start_Screen("Starting...");                                        // show start screen
     touchscreen_Calibration();                                          // load touchscreen calibration data
     initialize_Images();                                                // load and initialize images
-    
+
     TFT.Track(200, 400, 375, 50, 1);                                    // track sliders
     TFT.Track(200, 400, 375, 50, 2);
     TFT.Flush_Co_Buffer();                                              // download the command list into fifo
     TFT.WaitCmdfifo_empty();                                            // wait till coprocessor completes the operation
-    
+
+    // Main Loop
     while(1) {
-        curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff;                   // touch positions
-        curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16;
+        curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff;                   // Get the current touch screen position
+        curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16;                       // if not touch the results are 0x8000 for x and y
         ft_uint8_t tagval = 0;                                          // initialize return tag value
         TrackRegisterVal = TFT.Rd32(REG_TRACKER);                       // check if one of the two tracking fields is touched
         tagval = TrackRegisterVal & 0xff;                               // store return tag value
         // check what tag was touched
-        if(1 == tagval) {                                                                       // tag value for ITV1 slider touch                             
+        if(1 == tagval) {                                                                       // tag value for ITV1 slider touch
             ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095);                   // calculate new slider value so that the slider updates graphically
             ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590;              // calculate raw 12 bit input number, includes calibration number to never go above 20mA
             dac1.write_u12(ITVpressure1_input_raw);                                             // write 12 bit number to DAC to fire the ITV
-        } 
-        
+        }
+
         else if(2 == tagval) {                                                                  // tag value for ITV2 slider touch
             ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095);                   // calculate new slider value so that the slider updates graphically
             ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585;              // calculate raw 12 bit input number, includes calibration number to never go above 20mA
             dac2.write_u12(ITVpressure2_input_raw);                                             // write 12 bit number to DAC to fire the ITV
-        } 
-        
-        else if (200 == tagval) {
+        }
+
+        else if (200 == tagval) {                                                               // tag for the reprogram button that works by exiting the program which cases the teensy to load the bootloader
             break;
-        } else if(curX !=0x8000 && touched>0) {
-            touched++;
-            distance = curX - pasX;
-            location = (int16_t)paslocation + distance;
-
-
-        } 
-        
-        else if(curX !=0x8000 && !touched) {
+        } else if(curX !=0x8000 && touched>0) {                                                 // If the sceen is being touched and has been touched before and is not on a tag
+            touched++;                                                                          // touched is used to determine how long the screen has beed touched for and if it is currently being touched
+            distance = curX - pasX;                                                             // find the swipe distance in pixels
+            location = (int16_t)paslocation + distance;                                         // add the distance of the swipe to the location so the screen moves as you swipe
+            
+        } else if(curX !=0x8000 && !touched) {                                                  // If the screen is being touched but was not the pervious time through the loop then this is the starting point of the swipe
             touched++;
             pasX = curX;
-            //
-        } 
-        
-        else if(curX ==0x8000 && touched) {
-            velocity = distance/touched;
-            paslocation = location;
-            touched=0;
 
-
-
-        } 
-        
-        else {
+        } else if(curX ==0x8000 && touched) {                                                   // Not being touched currently but was touched last time through the loop
+            velocity = distance/touched;                                                        // Now that the swipe is finished we can calculate the velocity from the distance and time touched
+            paslocation = location;                                                             // Store Location data away
+            touched=0;                                                                          // Reset for the next touch
+        // If not being touched
+        } else {
             //page 4 location
-            if (location < - 2300 && location > -2500) {
-                if (velocity) {
-                    velocity = (location + 2400)/-5;
-                    location += (int16_t) velocity;
+            if (location < - 2300 && location > -2500) {                                        // If you are close to the edge of the fourth Page
+                if (velocity) {                                                                 // and you have some velocity
+                    velocity = (location + 2400)/-5;                                            // adjust velocity based on how close to the edge
+                    location += (int16_t) velocity;                                             // move the location at the speed of velocity                                            
                     paslocation = location;
-                } 
-                else {
+                } else {                                                                        // velocity will become zero as you get closer to the edge when this happens finish the move
                     location = -2400;
                 }
-
             }
             //page 3 location
-            else if (location < - 1500 && location > -1700) {
+            else if (location < - 1500 && location > -1700) {                                   // repeat for each page
                 if (velocity) {
                     velocity = (location + 1600)/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } 
-                else {
+                } else {
                     location = -1600;
                 }
 
@@ -452,43 +441,37 @@
                     velocity = (location + 800)/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } 
-                else {
+                } else {
                     location = -800;
                 }
                 //page 1
-            } 
-            else if (location > -100 && location < 100) {
+            } else if (location > -100 && location < 100) {
 
                 if (velocity) {
                     velocity = location/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } 
-                else {
+                } else {
                     location = 0;
+                    
                 }
                 //no page 0
-            } else if (location >60) {
-                velocity = -10;
+            } else if (location >60) {                                                          // Do not allow the page screen to go to -1 page
+                velocity = -10;                                                                 // Change the velocity to return
                 location += (int16_t) velocity;
                 paslocation = location;
-                //no page 5
-            } 
-            else if (location <-1700) {
-                velocity = 10;
+                //no page 4
+            } else if (location <-1700) {                                                       // Do not allow the page screen to go pass top page
+                velocity = 10;                                                                  // Change the velocity to return
                 location += (int16_t) velocity;
                 paslocation = location;
                 //between pages
-            } 
-            else if (velocity) {
+            } else if (velocity) {                                                              // if the page is not at edge but has velocity 
                 location += (int16_t) velocity;
-                paslocation = location;
-                //acceleration between pages
-                if (velocity >0) {
-                    velocity+= 2;
-                } 
-                else {
+                paslocation = location;                                                     
+                if (velocity >0) {                                                              // acceleration between pages so it does not take forever
+                    velocity+= 2;                                                               // increase velocity 
+                } else {
                     velocity-= 2;
                 }
             }