basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Revision:
5:e2e04cb5eada
Parent:
4:a48fc7a3bda9
Child:
6:f698d8ba4cd6
--- a/main.cpp	Tue Mar 29 13:41:12 2016 +0000
+++ b/main.cpp	Wed Mar 30 14:52:16 2016 +0000
@@ -1,3 +1,22 @@
+/*
+Title Block
+
+**     Project     : CLC Brew Panel
+**     Processor   : MK20 
+**     Version     : 1.0
+**     Compiler    : mbed
+**     Date/Time   : 3/27/2016
+**     Abstract    : ?
+**          
+**
+**
+**     Todo :  
+
+
+
+*/
+
+
 #include "mbed.h"
 #include "FT_Platform.h"
 #include "FT_color.h"
@@ -32,39 +51,39 @@
 
 // global Vars
 unsigned int r, b, g, CalVal0, CalVal1, CalVal2, CalVal3, CalVal4;
-float ISEpressure, PFMflowrate = 0.0; 
+float ISEpressure, PFMflowrate = 0.0;
 float ITVpressure1_feedback, ITVpressure2_feedback, ITVpressure1_user_input, ITVpressure2_user_input = 0.0;
 uint16_t ITVpressure1_input_raw, ITVpressure2_input_raw, test = 0;
 char buffer[50];
 uint8_t tcal[24]; //Touch screen Calibration
-char tstr[30]; // Temp location for Touch Screen Calibration
+char tstr[40]; // Temp location for Touch Screen Calibration
 
 void hsv2rgb(double H,double S, double V)
 {
     double f,h,p,q,t;
     int i;
     if( S == 0.0) {
-        r = V * 255;  
+        r = V * 255;
         g = V * 255;
         b = V * 255;
         return;
     }
     if(H > 480.0) H = 0.0;   // check values
-    if(S > 1.0) S = 1.0; 
+    if(S > 1.0) S = 1.0;
     if(S < 0.0) S = 0.0;
     if(V > 1.0) V = 1.0;
     if(V < 0.0) V = 0.0;
-    
+
     h = H / 60.0;
     i = (int) h;
     f = h - i;
     p = V * (1.0 - S);
     q = V * (1.0 - (S * f));
     t = V * (1.0 - (S * (1.0 - f)));
- 
+
     switch(i) {
         case 0:
-            r = V * 255;  
+            r = V * 255;
             g = t * 255;
             b = p * 255;
             break;
@@ -94,7 +113,7 @@
             g = p * 255;
             b = q * 255;
             break;
-    }  
+    }
 }
 
 
@@ -108,28 +127,28 @@
     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));   
-      
-    TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));     
+    TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
+
+    TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
     TFT.DL(BEGIN(LINES));
     TFT.DL(LINE_WIDTH(8 * 16));
     TFT.DL(VERTEX2F(0*16,0*16));
     TFT.DL(VERTEX2F(799*16,0*16));
-    
+
     TFT.DL(VERTEX2F(799*16,0*16));
     TFT.DL(VERTEX2F(799*16,479*16));
-    
+
     TFT.DL(VERTEX2F(799*16,479*16));
     TFT.DL(VERTEX2F(0*16,479*16));
-    
+
     TFT.DL(VERTEX2F(0*16,479*16));
     TFT.DL(VERTEX2F(0*16,0*16));
-    
+
     TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
     TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel!"); // draw Text with font 31
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));         // change current color
     TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0);  // draw a animated spinner
-    
+
     TFT.DL(DISPLAY());                         // Display the image
     TFT.Swap();                                            // Swap the current display list
     TFT.Flush_Co_Buffer();                                 // Download the command list into fifo
@@ -144,9 +163,9 @@
     TFT.DLstart();                         // start a new display command list
     TFT.DL(CLEAR_COLOR_RGB(255,255,255));
     TFT.DL(CLEAR(1,1,1));                  // clear buffers -> color buffer,stencil buffer, tag buffer
-    
+
     /***************************************************************************************************/
-    
+
     /*Border Creation*/
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
     TFT.DL(BEGIN(LINES));
@@ -158,12 +177,12 @@
     TFT.DL(VERTEX2F(799*16,479*16));
     TFT.DL(VERTEX2F(0*16,479*16));
     TFT.DL(VERTEX2F(0*16,479*16));
-    TFT.DL(VERTEX2F(0*16,0*16)); 
+    TFT.DL(VERTEX2F(0*16,0*16));
     TFT.DL(END());
     /***************************************************************************************************/
 
     /***************************************************************************************************/
-    
+
     /*ISE Screen Display*/
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
     TFT.Text(90, 20, 31, 0, "ISE Pressure");
@@ -179,9 +198,9 @@
     TFT.Text(135,95,31,0,buffer);
     TFT.Text(225, 95, 31, 0, " MPa");
     /***************************************************************************************************/
-    
+
     /***************************************************************************************************/
-    
+
     /*PFM Screen Display*/
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
     TFT.Text(455, 20, 31, 0, "PFM Flow Rate");
@@ -195,14 +214,14 @@
     TFT.Text(485,95,31,0,buffer);
     TFT.Text(575, 95, 31, 0, " L/min");
     /***************************************************************************************************/
-    
+
     /***************************************************************************************************/
-    
+
     /*ITV Screen Display*/
     TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
     TFT.Text(75, 200, 31, 0, "ITV 1 Pressure");
-    TFT.Text(455, 200, 31, 0, "ITV 2 Pressure");    
-    
+    TFT.Text(455, 200, 31, 0, "ITV 2 Pressure");
+
     TFT.DL(BEGIN(RECTS));
     TFT.DL(VERTEX2F(110*16,265*16));
     TFT.DL(VERTEX2F(315*16,330*16));
@@ -218,7 +237,7 @@
     TFT.Text(605, 275, 31, 0, " PSI");
     ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0;
     ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0;
-    TFT.DL(COLOR_RGB(255,255,255));  
+    TFT.DL(COLOR_RGB(255,255,255));
     TFT.FgColor(COLOR_RGB(0,124,196));
     TFT.BgColor(COLOR_RGB(0,124,196));
     TFT.DL(TAG(1));                        // assign TAG value 1
@@ -226,14 +245,26 @@
     TFT.DL(TAG(2));                        // assign TAG value 2
     TFT.Slider(450,375,280,30,0,ITVpressure2_user_input,2387);
     /***************************************************************************************************/
-    
+
+    // Debug the touch up load
+#ifdef Debug_Touch_File
+    TFT.DL(COLOR_RGB(0,0,0));
+    int i;
+    for (i = 0; i < 24; i++) {
+        TFT.Number(i*30+20, 450, 26, 0, tcal[i]);
+
+    }
+#endif
+
+
     TFT.DL(DISPLAY());                     // Display the image
     TFT.Swap();                            // Swap the current display list
     TFT.Flush_Co_Buffer();                 // Download the command list into fifo
     TFT.WaitCmdfifo_empty();               // Wait till coprocessor completes the operation
 }
 
-void error_screen_SD() {
+void error_screen_SD()
+{
     TFT.DLstart();                         // start a new display command list
     TFT.DL(CLEAR_COLOR_RGB(255,242,0));
     TFT.DL(CLEAR(1,1,1));                  // clear buffers -> color buffer,stencil buffer, tag buffer
@@ -245,7 +276,7 @@
     TFT.Flush_Co_Buffer();                 // Download the command list into fifo
     TFT.WaitCmdfifo_empty();               // Wait till coprocessor completes the operation
     TFT.Sleep(1000);
-    
+
     TFT.DLstart();                         // start a new display command list
     TFT.DL(CLEAR_COLOR_RGB(255,255,255));
     TFT.DL(CLEAR(1,1,1));                  // clear buffers -> color buffer,stencil buffer, tag buffer;
@@ -260,25 +291,25 @@
 }
 
 int main()
-{ 
-    dac1.wakeup();
-    dac2.wakeup();
-    dac1.write_u12(0);
-    dac2.write_u12(0);
+{
+    //  dac1.wakeup();
+    //  dac2.wakeup();
+    //  dac1.write_u12(0);
+//   dac2.write_u12(0);
     ft_uint32_t TrackRegisterVal = 0;              // touch track
-    int i;
-    
+    int i = 0;
+
     TFT.MemWrite(REG_ROTATE, 1);
     TFT.Rotate(1);
 
     Start_Screen("3");                // Show start screen
     Start_Screen("2");                // Show start screen
     Start_Screen("1");                // Show start screen
-    
+
     while(card_present.read()) {
-            error_screen_SD();
+        error_screen_SD();
     }
-    
+
     FILE *fp = fopen("/sd/TCal/TCalData.txt", "a");
     fp= fopen("/sd/TCal/TCalData.txt", "r");
     if(!fp) {
@@ -286,16 +317,20 @@
         TFT.Calibrate();                  // calibrate the touch screen
         TFT.read_calibrate(tcal);         // Read in cal data from screen
         //Convert from Int to Char to save to SD card
+        /* no longer needed
         for (i = 0; i < 25; i++) {
             tstr[i] = tcal[i];
         }
+        */
         //Open file for to save calibration data
         mkdir("/sd/TCal", 0777);
         FILE *fp = fopen("/sd/TCal/TCalData.txt", "w");
-        fprintf(fp, tstr);
+        //Save integers one at a time to the file
+        for (i = 0; i < 25; i++) {
+            fprintf(fp, "%c", tcal[i] );
+        }
         fclose(fp);
-    } 
-    else {
+    } else {
         //Read in calibration Data
         fread(tstr,24,1,fp);
         //Convert from Char to Int
@@ -319,17 +354,16 @@
         tagval = TrackRegisterVal & 0xff;
         if(0 != tagval) {                            // touch -> get new values
             if(1 == tagval) {
-                ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095);                      
+                ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095);
                 ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590;
-                dac1.write_u12(ITVpressure1_input_raw); 
-            } 
-            else if(2 == tagval) {                 // the slider is touched
-                ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095);                      
+                //dac1.write_u12(ITVpressure1_input_raw);
+            } else if(2 == tagval) {               // the slider is touched
+                ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095);
                 ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585;
-                dac2.write_u12(ITVpressure2_input_raw);       
-            } 
+                //dac2.write_u12(ITVpressure2_input_raw);
+            }
         }
-    
+
         screen_1();                  // paint new screen
         TFT.Sleep(10);               // wait 10ms for next time to repaint the screen
     }  // end of display loop