basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Revision:
16:19ade236df07
Parent:
15:25cbc8345067
Child:
17:f98333612db8
--- a/main.cpp	Wed Apr 27 11:38:56 2016 +0000
+++ b/main.cpp	Fri Jul 01 14:17:45 2016 +0000
@@ -1,21 +1,33 @@
 /*
 Title Block
-**     Project     : CLC Brew Panel
-**     Engineers   : Justin Montgomery and Cortland Ratliff
+**     Project     : data logger: lcd power levels
+**     Engineers   : Curtis Mattull
 **     Processor   : MK20
 **     Version     : 1.0
 **     Compiler    : mbed
-**     Date/Time   : 3/27/2016
-**     Abstract    : This program was written for a marketing panel called the Brew Panel. The purpose of this program is to control two ITVs that
-**                   regulate two different pressure lines that control two diaphragm pumps. The two pumps then pump and generate a flow rate for
-**                   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.
+**     Date/Time   : 7/1/2016
+**     Abstract    : This program demonstrates the possible power saving modes using the LCD touch screen.
+                     This program also serves as a learning experience with using touch screen LCDs.
+                     
+                     Power modes: (mcu never sleeps)
+                        1. Screen off, touch off
+                        2. Screen off, touch on.        wake from touch input
+                        3. Screen dim, touch on.        touch to brighten screen
+                        4. After time-out delay,
+                            System can enter power modes 1,2, or 3.
+                       
+                     Take measurements of power consumed on 3.3V bus for each state.
+                     
+                    
+                     bonus points:
+                        1. sleep between data captures, then using interrupt, wake mcu with touch input.
+                        2. 
+                   
 **
 **     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.
 **
-**     Todo        :
+**     Todo        :    
 */
 #include "mbed.h"                               // library #includes
 #include "FT_Platform.h"
@@ -60,12 +72,12 @@
 /****************************************************************************************/
 /* The DeviceCal array stores the external hardware calibration data.                   */
 /* The array format is as follows:                                                      */
-/* DeviceCal[0] = 5V input from device 1, DeviceCal[1] = 1V input from device 1         */
-/* DeviceCal[2] = 20mA input from device 2, DeviceCal[3] = 4mA input from device 2      */
-/* DeviceCal[4] = 5V input from device 3, DeviceCal[5] = 1V input from device 3         */
-/* DeviceCal[6] = 20mA output from device 3, DeviceCal[7] = 4mA output from device 3    */
-/* DeviceCal[8] = 5V input from device 4, DeviceCal[9] = 1V input from device 4         */
-/* DeviceCal[10] = 20mA output from device 4, DeviceCal[11] = 4mA output from device 4  */
+/* DeviceCal[0] = 5V input from device 1,       DeviceCal[1] = 1V input from device 1   */
+/* DeviceCal[2] = 20mA input from device 2,     DeviceCal[3] = 4mA input from device 2  */
+/* DeviceCal[4] = 5V input from device 3,       DeviceCal[5] = 1V input from device 3   */
+/* DeviceCal[6] = 20mA output from device 3,    DeviceCal[7] = 4mA output from device 3 */
+/* DeviceCal[8] = 5V input from device 4,       DeviceCal[9] = 1V input from device 4   */
+/* DeviceCal[10] = 20mA output from device 4,   DeviceCal[11] = 4mA output from device 4*/
 /****************************************************************************************/
 uint16_t DeviceCal[12];                     // array that stores calibraton data
 unsigned char DeviceCal_buffer[50];         // buffer to store char data read back from SD card before it's converted into an integer
@@ -399,117 +411,145 @@
 /****************************************************************************/
 int main()
 {
-    dac1.wakeup();                                                      // activate DAC boards
-    dac2.wakeup();
-    dac1.write_u12(0);                                                  // the natural DAC output value is 50% of its maximum value
-    dac2.write_u12(0);                                                  // the program has to immediately write a 0 to the DAC to turn off the outputs
+//    dac1.wakeup();                                                      // activate DAC boards
+//    dac2.wakeup();
+//    dac1.write_u12(0);                                                  // the natural DAC output value is 50% of its maximum value
+//    dac2.write_u12(0);                                                  // the program has to immediately write a 0 to the DAC to turn off the outputs
+
     ft_uint32_t TrackRegisterVal = 0;                                   // touch track variable
-
+//
     TFT.MemWrite(REG_ROTATE, 1);                                        // rotate screen
     TFT.Rotate(1);
-
-    SupplyPressure_Check(0,0);                                          // check for any supply pressure
+//
+//    //SupplyPressure_Check(0,0);                                          // check for any supply pressure
     read_Calibration();                                                 // load touchscreen calibration data
     initialize_Images();                                                // load and initialize images
     Start_Screen("Starting...");                                        // show start screen
-
+//
     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
 
-    while(1) {
+    while(1) 
+    {
         Main_Screen();                                                  // paint new screen
         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
             ITVpressure1_input_scaled = (ITVpressure1_input_raw-590)*(70.0)/(4095)+0;
         }
 
-        else if(2 == tagval) {                                                                  // tag value for ITV2 slider touch
+        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
+//            dac2.write_u12(ITVpressure2_input_raw);                                             // write 12 bit number to DAC to fire the ITV
             ITVpressure2_input_scaled = (ITVpressure2_input_raw-590)*(70.0)/(4095)+0;
         }
 
-        else if (200 == tagval) {                                                               // tag for the reprogram button that works by exiting the program which cases the teensy to load the bootloader
+        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) {                                                 // If the sceen is being touched and has been touched before and is not on a tag
+        } 
+        
+        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
+        } 
+        
+        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) {                                                   // Not being touched currently but was touched last time through the loop
+        } 
+        
+        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 3 location
-            if (location < - 1500 && location > -1700) {                                   // repeat for each page
-                if (velocity) {
+            touched=0;                                                                          // Reset for the next touch                                                                                     // If not being touched
+        } 
+        
+        else 
+        {   
+            if (location < - 1500 && location > -1700)                                  //page 3 location
+            {                                                                           // repeat for each page
+                if (velocity)
+                {
                     velocity = (location + 1600)/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } else {
+                } 
+                else
+                {
                     location = -1600;
                 }
-
             }
-            //page 2
-            else if (location < - 700 && location > -900) {
-                if (velocity) {
+            else if (location < - 700 && location > -900)                               //page 2
+            {
+                if (velocity)
+                {
                     velocity = (location + 800)/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } else {
+                } 
+                else 
+                {
                     location = -800;
                 }
-                //page 1
-            } else if (location > -100 && location < 100) {
-
-                if (velocity) {
+            }
+            else if (location > -100 && location < 100)                                  //page 1
+            {
+                if (velocity)
+                {
                     velocity = location/-5;
                     location += (int16_t) velocity;
                     paslocation = location;
-                } else {
+                }
+                else 
+                {
                     location = 0;
-
                 }
-                //no page 0
-            } else if (location >60) {                                                          // Do not allow the page screen to go to -1 page
-                velocity = -10;                                                                 // Change the velocity to return
+            } 
+            else if (location >60)                                          //no page 0  
+            {                                                               // 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 4
-            } else if (location <-1700) {                                                       // Do not allow the page screen to go pass top page
-                velocity = 10;                                                                  // Change the velocity to return
+            } 
+            else if (location <-1700)                                       //no page 4
+            {                                                               // 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) {                                                              // if the page is not at edge but has velocity
+            } 
+            else if (velocity)                                              //between pages 
+            {                                                               // if the page is not at edge but has velocity
                 location += (int16_t) velocity;
                 paslocation = location;
-                if (velocity >0) {                                                              // acceleration between pages so it does not take forever
+                if (velocity >0) 
+                {                                                              // acceleration between pages so it does not take forever
                     velocity+= 2;                                                               // increase velocity
-                } else {
+                }
+                else 
+                {
                     velocity-= 2;
                 }
             }
         }
-        SupplyPressure_Check(ITVpressure1_input_scaled, ITVpressure2_input_scaled);     // check to see if theres enough supply pressure for the ITVs
+        //SupplyPressure_Check(ITVpressure1_input_scaled, ITVpressure2_input_scaled);     // check to see if theres enough supply pressure for the ITVs
         TFT.Sleep(10);                  // wait 10ms for next time to repaint the screen
     }                                   // end of display loop
 }
\ No newline at end of file