basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
montgojj
Date:
Tue Apr 05 15:02:48 2016 +0000
Revision:
11:f6a146b62579
Parent:
10:c56b7ca4805f
Child:
12:c19239029172
Child:
13:8f23699b9c9f
Added comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cratliff 5:e2e04cb5eada 1 /*
cratliff 5:e2e04cb5eada 2 Title Block
cratliff 5:e2e04cb5eada 3 ** Project : CLC Brew Panel
montgojj 11:f6a146b62579 4 ** Engineers : Justin Montgomery and Cortland Ratliff
cratliff 6:f698d8ba4cd6 5 ** Processor : MK20
cratliff 5:e2e04cb5eada 6 ** Version : 1.0
cratliff 5:e2e04cb5eada 7 ** Compiler : mbed
cratliff 5:e2e04cb5eada 8 ** Date/Time : 3/27/2016
montgojj 11:f6a146b62579 9 ** Abstract : This program was written for a marketing panel called the Brew Panel. The purpose of this program is to control two ITVs that
montgojj 11:f6a146b62579 10 ** regulate two different pressure lines that control two diaphragm pumps. The two pumps then pump and generate a flow rate for
montgojj 11:f6a146b62579 11 ** two different colored liquids. Another purpose of this program is to also read back feedback from the two ITVs, a PF3W flow meter,
montgojj 11:f6a146b62579 12 ** and a PSE pressure sensor. The program also interfaces with an HMI controlled by a FT810 LCD driver. The interface controls the hardware
montgojj 11:f6a146b62579 13 ** and displays graphics. This program was designed for the Teensy and to control the Closed Loop Controller Brew Panel prototype board.
montgojj 11:f6a146b62579 14 **
montgojj 11:f6a146b62579 15 ** 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
montgojj 11:f6a146b62579 16 so in order to draw an image further away we had to use the translate command.
cratliff 6:f698d8ba4cd6 17 **
montgojj 11:f6a146b62579 18 ** Todo :
cratliff 5:e2e04cb5eada 19 */
montgojj 11:f6a146b62579 20 #include "mbed.h" // library #includes
cratliff 0:aa55c6eb6867 21 #include "FT_Platform.h"
cratliff 0:aa55c6eb6867 22 #include "FT_color.h"
cratliff 0:aa55c6eb6867 23 #include "stdio.h"
montgojj 4:a48fc7a3bda9 24 #include "float.h"
montgojj 4:a48fc7a3bda9 25 #include "SDFileSystem.h"
montgojj 4:a48fc7a3bda9 26 #include "MCP4725.h"
cratliff 0:aa55c6eb6867 27
montgojj 11:f6a146b62579 28 #define K20 // used to simplify defining for different microcontroller platforms
montgojj 11:f6a146b62579 29 #define Program_Button // used add easy way to reprogram without using the phsyical button.
montgojj 11:f6a146b62579 30 //#define Debug_Swipe // reads back touch data in real time on the screen
cratliff 0:aa55c6eb6867 31
montgojj 4:a48fc7a3bda9 32 #ifdef K20
montgojj 11:f6a146b62579 33 FT800 TFT(D11,D12,D13,D9,D8,D14); // create object for the LCD, handles all of the data passing and slave select commands (SPI)
montgojj 11:f6a146b62579 34 SDFileSystem sd(D11, D12, D13, D10, "sd"); // create object for the SD card, handles all of the data passing and slave select commands (SPI)
montgojj 11:f6a146b62579 35 MCP4725 dac1(D18, D19, MCP4725::ADDRESS_2); // create object for the first DAC board, handles all fo the data addressing (I2C)
montgojj 11:f6a146b62579 36 MCP4725 dac2(D18, D19, MCP4725::ADDRESS_3); // create object for the second DAC board, handles all fo the data addressing (I2C)
montgojj 4:a48fc7a3bda9 37
montgojj 11:f6a146b62579 38 AnalogIn PSEpressure_raw(A9); // analog 9 pin connected to the PSE input
montgojj 11:f6a146b62579 39 AnalogIn PFWflowrate_raw(A8); // analog 9 pin connected to the PFW input
montgojj 11:f6a146b62579 40 AnalogIn ITVpressure1_feedback_raw(A3); // analog 9 pin connected to the ITV1 input
montgojj 11:f6a146b62579 41 AnalogIn ITVpressure2_feedback_raw(A2); // analog 9 pin connected to the ITV2 input
montgojj 11:f6a146b62579 42 DigitalIn card_present(D7); // analog 9 pin connected to the SD card detect pin input
cratliff 0:aa55c6eb6867 43 #endif
cratliff 0:aa55c6eb6867 44
montgojj 11:f6a146b62579 45 // global variables
montgojj 11:f6a146b62579 46 unsigned int CalVal0, CalVal1, CalVal2, CalVal3, CalVal4, curX, curY, pasX, pasY; // touchscreen calibration data and swiping variables.
montgojj 11:f6a146b62579 47 float PSEpressure, PFWflowrate = 0.0; // variables to store data used in calculating flow and pressure
montgojj 11:f6a146b62579 48 float ITVpressure1_feedback, ITVpressure2_feedback, ITVpressure1_user_input, ITVpressure2_user_input = 0.0; // variables to store data thats used in calculating the output and input pressure for the ITVs
montgojj 11:f6a146b62579 49 float ITV1_pre, ITV1_fcal, ITV2_pre, ITV2_fcal, PFW_pre, PFW_fcal, PSE_pre, PSE_fcal = 0.0; // moving average filter variables
montgojj 11:f6a146b62579 50 static float avg1 = 0.05; // filter value for new samples
montgojj 11:f6a146b62579 51 static float avg2 = 0.95; // filter value previous samples
montgojj 11:f6a146b62579 52 uint16_t ITVpressure1_input_raw, ITVpressure2_input_raw = 0; // stores the raw 16 bit reads for the ITVs
montgojj 11:f6a146b62579 53 int16_t velocity, distance, touched, location, paslocation; // variables to handle the swiping and multiple pages
montgojj 11:f6a146b62579 54 char buffer[50]; // temporary buffer for writing characters to the LCD
montgojj 11:f6a146b62579 55 uint8_t tcal[24]; // touch screen Calibration
montgojj 11:f6a146b62579 56 char tstr[40]; // temp location for Touch Screen Calibration
montgojj 11:f6a146b62579 57 ft_int16_t x_size, y_size; // stores size data for loaded jpegs, not currently used
montgojj 11:f6a146b62579 58 unsigned int err[7] = {0,0,0,0,0,0,0}; // array to store returned values from Load_jpg function, possible future error handling
cratliff 5:e2e04cb5eada 59
montgojj 11:f6a146b62579 60 /****************************************************************************/
montgojj 11:f6a146b62579 61 /* Serves as the bootup screen as the images are loaded from the SD card */
montgojj 11:f6a146b62579 62 /* A spinner shows the delay */
montgojj 11:f6a146b62579 63 /****************************************************************************/
cratliff 0:aa55c6eb6867 64 ft_void_t Start_Screen(ft_char8_t *str)
cratliff 0:aa55c6eb6867 65 {
montgojj 11:f6a146b62579 66 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 67 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
montgojj 11:f6a146b62579 68 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 11:f6a146b62579 69
montgojj 11:f6a146b62579 70 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format
montgojj 4:a48fc7a3bda9 71 TFT.DL(BEGIN(LINES));
montgojj 4:a48fc7a3bda9 72 TFT.DL(LINE_WIDTH(8 * 16));
montgojj 4:a48fc7a3bda9 73 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 74 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 75 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 76 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 77 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 78 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 79 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 80 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 11:f6a146b62579 81 TFT.DL(END());
cratliff 5:e2e04cb5eada 82
montgojj 11:f6a146b62579 83 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
montgojj 11:f6a146b62579 84 TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel"); // draw Text with font 31
montgojj 11:f6a146b62579 85 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // change current color
montgojj 11:f6a146b62579 86 TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner
cratliff 0:aa55c6eb6867 87
montgojj 11:f6a146b62579 88 TFT.DL(DISPLAY()); // Display the image
montgojj 11:f6a146b62579 89 TFT.Swap(); // Swap the current display list
montgojj 11:f6a146b62579 90 TFT.Flush_Co_Buffer(); // Download the command list into fifo
montgojj 11:f6a146b62579 91 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
montgojj 11:f6a146b62579 92 TFT.Sleep(1000); // Wait 1s to show
cratliff 0:aa55c6eb6867 93 }
cratliff 0:aa55c6eb6867 94
montgojj 11:f6a146b62579 95 /****************************************************************************/
montgojj 11:f6a146b62579 96 /* Main screen function that writes the SD images and external hardware */
montgojj 11:f6a146b62579 97 /* data to the screen, also controls the ITV pressure */
montgojj 11:f6a146b62579 98 /****************************************************************************/
montgojj 11:f6a146b62579 99 void Main_Screen()
cratliff 0:aa55c6eb6867 100 {
montgojj 11:f6a146b62579 101 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 102 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
montgojj 11:f6a146b62579 103 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 11:f6a146b62579 104 #ifdef Program_Button
montgojj 11:f6a146b62579 105 TFT.DL(TAG(200)); // assign TAG value 200
montgojj 11:f6a146b62579 106 TFT.Button(710, 10, 76, 22, 26, 0, "Reprogram"); // generate reprogram button, only works for teensy
montgojj 11:f6a146b62579 107 TFT.DL(TAG(3));
montgojj 11:f6a146b62579 108 #endif
montgojj 11:f6a146b62579 109
montgojj 4:a48fc7a3bda9 110 /***************************************************************************************************/
montgojj 4:a48fc7a3bda9 111 /*Border Creation*/
montgojj 11:f6a146b62579 112 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format
montgojj 4:a48fc7a3bda9 113 TFT.DL(BEGIN(LINES));
montgojj 4:a48fc7a3bda9 114 TFT.DL(LINE_WIDTH(8 * 16));
montgojj 4:a48fc7a3bda9 115 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 116 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 117 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 118 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 119 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 120 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 121 TFT.DL(VERTEX2F(0*16,479*16));
cratliff 5:e2e04cb5eada 122 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 123 TFT.DL(END());
montgojj 4:a48fc7a3bda9 124 /***************************************************************************************************/
cratliff 0:aa55c6eb6867 125
montgojj 4:a48fc7a3bda9 126 /***************************************************************************************************/
montgojj 8:886908a6127c 127 /*ITV 1 Screen Display*/
montgojj 11:f6a146b62579 128 TFT.DL(COLOR_RGB(255,255,255)); // set background to white
montgojj 11:f6a146b62579 129 TFT.DL(VERTEX_TRANSLATE_X(location* 16)); // page 1
montgojj 11:f6a146b62579 130
montgojj 11:f6a146b62579 131 TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the first screens images
montgojj 11:f6a146b62579 132 TFT.DL(VERTEX2II(265,50,0,0)); // draw logo image with bit handle 0
montgojj 11:f6a146b62579 133 TFT.DL(VERTEX2II(75,50,1,0)); // draw ITV_1 image with bit handle 1
montgojj 11:f6a146b62579 134 TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)); // translate right 149 pixels for third image, location controls what page the screen is on
montgojj 11:f6a146b62579 135 TFT.DL(VERTEX2II(511,50,2,0)); // draw ITV_2 image with bit handle 2
montgojj 11:f6a146b62579 136 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)); // translate back to prevent the remaining commands from also being translated
montgojj 4:a48fc7a3bda9 137 TFT.DL(END());
montgojj 11:f6a146b62579 138
montgojj 11:f6a146b62579 139 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for the text
montgojj 11:f6a146b62579 140 TFT.Text(265, 200, 31, 0, "ITV 1 Pressure"); // title block for screen
montgojj 11:f6a146b62579 141 TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written
montgojj 11:f6a146b62579 142 TFT.DL(VERTEX2F(300*16,265*16));
montgojj 8:886908a6127c 143 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 144 TFT.DL(END());
montgojj 11:f6a146b62579 145 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
montgojj 11:f6a146b62579 146 ITV1_fcal = ITVpressure1_feedback; // moving average filter
montgojj 11:f6a146b62579 147 ITV1_fcal *= avg1;
montgojj 9:bf787d41b645 148 ITV1_fcal += ITV1_pre * avg2;
montgojj 9:bf787d41b645 149 ITV1_pre = ITV1_fcal;
montgojj 11:f6a146b62579 150 ITVpressure1_feedback = ITV1_fcal; // store the filtered value in the feedback variable
montgojj 11:f6a146b62579 151 TFT.DL(COLOR_RGB(255,255,255)); // set color to white for the text
montgojj 11:f6a146b62579 152 sprintf(buffer, "%.1f", ITVpressure1_feedback); // write the feedback pressure to the screen
montgojj 11:f6a146b62579 153 TFT.Text(325,275,31,0,buffer);
montgojj 11:f6a146b62579 154 TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen
montgojj 11:f6a146b62579 155
montgojj 11:f6a146b62579 156 TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format
montgojj 11:f6a146b62579 157 TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format
montgojj 11:f6a146b62579 158 TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format
montgojj 11:f6a146b62579 159 TFT.DL(TAG(1)); // assign TAG value 1
montgojj 11:f6a146b62579 160 TFT.Slider(225,375,350,30,0,ITVpressure1_user_input,2355); // generate slider that controls the output pressure of ITV1
montgojj 11:f6a146b62579 161 TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors
montgojj 4:a48fc7a3bda9 162 /***************************************************************************************************/
cratliff 5:e2e04cb5eada 163
montgojj 4:a48fc7a3bda9 164 /***************************************************************************************************/
montgojj 8:886908a6127c 165 /*ITV 2 and PF3W Screen Display*/
montgojj 11:f6a146b62579 166 TFT.DL(COLOR_RGB(255,255,255)); // set background color to white
montgojj 11:f6a146b62579 167 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
montgojj 11:f6a146b62579 168 TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the second screens images
montgojj 11:f6a146b62579 169 TFT.DL(VERTEX2II(30,75,3,0)); // write PF3W_1 image to the LCD
montgojj 11:f6a146b62579 170 TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)+12800); // translate right 149 pixels for third image, location controls what page the screen is on
montgojj 11:f6a146b62579 171 TFT.DL(VERTEX2II(411,75,4,0)); // write PF3W_2 image to the LCD
montgojj 11:f6a146b62579 172 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+12800); // translate back to 0 for remaining screen writes
montgojj 8:886908a6127c 173 TFT.DL(END());
montgojj 11:f6a146b62579 174
montgojj 11:f6a146b62579 175 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue, RGB format
montgojj 11:f6a146b62579 176 TFT.Text(265, 200, 31, 0, "ITV 2 Pressure"); // write title block to screen
montgojj 11:f6a146b62579 177 TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written
montgojj 8:886908a6127c 178 TFT.DL(VERTEX2F(300*16,265*16));
montgojj 8:886908a6127c 179 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 180 TFT.DL(END());
montgojj 11:f6a146b62579 181
montgojj 11:f6a146b62579 182 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
montgojj 11:f6a146b62579 183 ITV2_fcal = ITVpressure2_feedback; // moving average filter
montgojj 9:bf787d41b645 184 ITV2_fcal *= avg1;
montgojj 9:bf787d41b645 185 ITV2_fcal += ITV2_pre * avg2;
montgojj 9:bf787d41b645 186 ITV2_pre = ITV2_fcal;
montgojj 11:f6a146b62579 187 ITVpressure2_feedback = ITV2_fcal; // store filtered value in feedback variable
montgojj 11:f6a146b62579 188 TFT.DL(COLOR_RGB(255,255,255)); // set color for text to white
montgojj 11:f6a146b62579 189 sprintf(buffer, "%.1f", ITVpressure2_feedback); // write feedback to screen in white
montgojj 11:f6a146b62579 190 TFT.Text(325,275,31,0,buffer);
montgojj 11:f6a146b62579 191 TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen
montgojj 11:f6a146b62579 192 TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format
montgojj 11:f6a146b62579 193 TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format
montgojj 11:f6a146b62579 194 TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format
montgojj 11:f6a146b62579 195 TFT.DL(TAG(2)); // assign tag 2 to slider for ITV2
montgojj 11:f6a146b62579 196 TFT.Slider(225,375,350,30,0,ITVpressure2_user_input,2387); // generate slider that controls the output pressure of ITV2
montgojj 11:f6a146b62579 197 TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors
montgojj 11:f6a146b62579 198
montgojj 11:f6a146b62579 199 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for text
montgojj 11:f6a146b62579 200 TFT.Text(250, 20, 31, 0, "PF3W Flow Rate"); // write title block to screen
montgojj 11:f6a146b62579 201 TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written
montgojj 8:886908a6127c 202 TFT.DL(VERTEX2F(300*16,85*16));
montgojj 8:886908a6127c 203 TFT.DL(VERTEX2F(505*16,150*16));
montgojj 11:f6a146b62579 204 PFWflowrate = (PFWflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0; // calibration and scaling math for the PFW feedback, 51920 = 20mA, 10355 = 4mA
montgojj 11:f6a146b62579 205 PFW_fcal = PFWflowrate; // moving average filter
montgojj 9:bf787d41b645 206 PFW_fcal *= avg1;
montgojj 9:bf787d41b645 207 PFW_fcal += PFW_pre * avg2;
montgojj 9:bf787d41b645 208 PFW_pre = PFW_fcal;
montgojj 11:f6a146b62579 209 PFWflowrate = PFW_fcal; // store filtered value in feedback variable
montgojj 11:f6a146b62579 210 TFT.DL(COLOR_RGB(255,255,255)); // set text feedback text color to white
montgojj 11:f6a146b62579 211 sprintf(buffer, "%.1f", PFWflowrate); // write feedback to LCD
montgojj 8:886908a6127c 212 TFT.Text(285,95,31,0,buffer);
montgojj 11:f6a146b62579 213 TFT.Text(385, 95, 31, 0, " L/min"); // write units to LCD
montgojj 8:886908a6127c 214 /***************************************************************************************************/
montgojj 8:886908a6127c 215
montgojj 8:886908a6127c 216 /***************************************************************************************************/
montgojj 8:886908a6127c 217 /*ISE Screen Display*/
montgojj 11:f6a146b62579 218 TFT.DL(COLOR_RGB(255,255,255)); // set the background for page 3 to white
montgojj 11:f6a146b62579 219 TFT.DL(VERTEX_TRANSLATE_X(location* 16)+25600); // translate screen writes by 25600 which is a 1/16th pixel format, this creates page 3 of the screen
montgojj 11:f6a146b62579 220 TFT.DL(BEGIN(BITMAPS)); // create bitmap to draw images on LCD
montgojj 11:f6a146b62579 221 TFT.DL(VERTEX2II(265,50,0,0)); // wrtie the SMC logo to the screen
montgojj 11:f6a146b62579 222 TFT.DL(VERTEX2II(75,50,5,0)); // write PSE_1 image to the screen
montgojj 11:f6a146b62579 223 TFT.DL(VERTEX_TRANSLATE_X((99+location)*16)+25600); // translate right by 99 pixels for the next image write
montgojj 11:f6a146b62579 224 TFT.DL(VERTEX2II(511,85,6,0)); // write PSE_2 image to the screen
montgojj 11:f6a146b62579 225 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+25600); // translate back to pixel 0 for the remaining screen writes
montgojj 8:886908a6127c 226 TFT.DL(END());
montgojj 11:f6a146b62579 227
montgojj 11:f6a146b62579 228 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue
montgojj 11:f6a146b62579 229 TFT.Text(280, 200, 31, 0, "PSE Pressure"); // write title block to screen
montgojj 11:f6a146b62579 230 TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written
montgojj 8:886908a6127c 231 TFT.DL(VERTEX2F(295*16,265*16));
montgojj 8:886908a6127c 232 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 233 TFT.DL(END());
montgojj 11:f6a146b62579 234 PSEpressure = (PSEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0; // calibration and scaling math for the PFW feedback, 52350 = 20mA, 10440 = 4mA
montgojj 11:f6a146b62579 235 PSE_fcal = PSEpressure; // moving average filter
montgojj 9:bf787d41b645 236 PSE_fcal *= avg1;
montgojj 9:bf787d41b645 237 PSE_fcal += PSE_pre * avg2;
montgojj 9:bf787d41b645 238 PSE_pre = PSE_fcal;
montgojj 11:f6a146b62579 239 PSEpressure = PSE_fcal; // store the filtered value in feedback variable
montgojj 11:f6a146b62579 240 TFT.DL(COLOR_RGB(255,255,255)); // set text color to white
montgojj 11:f6a146b62579 241 sprintf(buffer, "%.2f", PSEpressure); // write feedback to screen
montgojj 8:886908a6127c 242 TFT.Text(300,275,31,0,buffer);
montgojj 11:f6a146b62579 243 TFT.Text(405, 275, 31, 0, " MPa"); // write units to LCD
montgojj 8:886908a6127c 244 /***************************************************************************************************/
montgojj 8:886908a6127c 245
montgojj 11:f6a146b62579 246 #ifdef Debug_Swipe // writes touch data to screen
montgojj 11:f6a146b62579 247 TFT.DL(COLOR_RGB(0,0,0)); // set text color to black
montgojj 11:f6a146b62579 248 TFT.Number(20, 450, 26, 0, distance); // write distance value to screen
montgojj 11:f6a146b62579 249 TFT.Number(80, 450, 26, 0, velocity); // write velocity to screen
cratliff 7:e525bfa17136 250 #endif
montgojj 11:f6a146b62579 251
montgojj 11:f6a146b62579 252 #ifdef Debug_Touch_File // debug the touch up load
montgojj 11:f6a146b62579 253 TFT.DL(COLOR_RGB(0,0,0)); // set text color to black
montgojj 11:f6a146b62579 254 int j; // loop counter
montgojj 11:f6a146b62579 255 for (j = 0; j < 24; j++) { // write file data to screen
montgojj 11:f6a146b62579 256 TFT.Number(j*30+20, 450, 26, 0, tcal[j]);
cratliff 5:e2e04cb5eada 257 }
cratliff 5:e2e04cb5eada 258 #endif
cratliff 5:e2e04cb5eada 259
montgojj 11:f6a146b62579 260 TFT.DL(DISPLAY()); // display the image
montgojj 11:f6a146b62579 261 TFT.Swap(); // swap the current display list
montgojj 11:f6a146b62579 262 TFT.Flush_Co_Buffer(); // download the command list into fifo
montgojj 11:f6a146b62579 263 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 264 }
cratliff 0:aa55c6eb6867 265
montgojj 11:f6a146b62579 266 /****************************************************************************/
montgojj 11:f6a146b62579 267 /* This function displays the error screen when an SD card isn't detected */
montgojj 11:f6a146b62579 268 /* the function causes the screen to flash yellow and writes text to the LCD*/
montgojj 11:f6a146b62579 269 /****************************************************************************/
cratliff 5:e2e04cb5eada 270 void error_screen_SD()
cratliff 5:e2e04cb5eada 271 {
montgojj 4:a48fc7a3bda9 272 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 273 TFT.DL(CLEAR_COLOR_RGB(255,242,0)); // clear the screen and set the background to yellow
montgojj 4:a48fc7a3bda9 274 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 4:a48fc7a3bda9 275 TFT.DL(COLOR_RGB(0,0,0));
montgojj 11:f6a146b62579 276 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, "Error!"); // draw Text with font 31
montgojj 11:f6a146b62579 277 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, "Insert SD Card!"); // draw Text with font 31
montgojj 11:f6a146b62579 278 TFT.DL(DISPLAY()); // display the image
montgojj 11:f6a146b62579 279 TFT.Swap(); // swap the current display list
montgojj 11:f6a146b62579 280 TFT.Flush_Co_Buffer(); // download the command list into fifo
montgojj 11:f6a146b62579 281 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
montgojj 4:a48fc7a3bda9 282 TFT.Sleep(1000);
cratliff 5:e2e04cb5eada 283
montgojj 11:f6a146b62579 284 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 285 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set clear color to white
montgojj 11:f6a146b62579 286 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer;
montgojj 4:a48fc7a3bda9 287 TFT.DL(COLOR_RGB(0,0,0));
montgojj 11:f6a146b62579 288 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, "Error!"); // draw Text with font 31
montgojj 11:f6a146b62579 289 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, "Insert SD Card!"); // draw Text with font 31
montgojj 11:f6a146b62579 290 TFT.DL(DISPLAY()); // display the image
montgojj 11:f6a146b62579 291 TFT.Swap(); // swap the current display list
montgojj 11:f6a146b62579 292 TFT.Flush_Co_Buffer(); // download the command list into fifo
montgojj 11:f6a146b62579 293 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
montgojj 4:a48fc7a3bda9 294 TFT.Sleep(1000);
montgojj 4:a48fc7a3bda9 295 }
cratliff 0:aa55c6eb6867 296
montgojj 11:f6a146b62579 297 /****************************************************************************/
montgojj 11:f6a146b62579 298 /* Checks for an SD card and reads/writes the touchscreen calibration data */
montgojj 11:f6a146b62579 299 /* from the SD card */
montgojj 11:f6a146b62579 300 /****************************************************************************/
montgojj 8:886908a6127c 301 void touchscreen_Calibration()
cratliff 5:e2e04cb5eada 302 {
montgojj 11:f6a146b62579 303 int i = 0; // loop counter
montgojj 11:f6a146b62579 304 while(card_present.read()) { // checks for SD card, if not present hold program until a SD card is inserted
montgojj 11:f6a146b62579 305 error_screen_SD(); // write error screen to LCD
montgojj 11:f6a146b62579 306 }
montgojj 11:f6a146b62579 307 FILE *fp = fopen("/sd/TCal/TCalData.txt", "a"); // open touchscreen calibration data from SD card
montgojj 4:a48fc7a3bda9 308 fp= fopen("/sd/TCal/TCalData.txt", "r");
montgojj 11:f6a146b62579 309 if(!fp) { // could not open file for read so generate data then store on SD card
montgojj 11:f6a146b62579 310 TFT.Calibrate(); // calibrate the touch screen
montgojj 11:f6a146b62579 311 TFT.read_calibrate(tcal); // read in cal data from screen
montgojj 11:f6a146b62579 312 mkdir("/sd/TCal", 0777); // open file for to save calibration data
montgojj 4:a48fc7a3bda9 313 FILE *fp = fopen("/sd/TCal/TCalData.txt", "w");
montgojj 11:f6a146b62579 314 for (i = 0; i < 25; i++) { // save integers one at a time to the file
cratliff 5:e2e04cb5eada 315 fprintf(fp, "%c", tcal[i] );
cratliff 5:e2e04cb5eada 316 }
montgojj 11:f6a146b62579 317 fclose(fp); // close SD card file
montgojj 11:f6a146b62579 318 } else { // file found, read in data
montgojj 4:a48fc7a3bda9 319 fread(tstr,24,1,fp);
montgojj 11:f6a146b62579 320 for (i = 0; i < 24; i++) { // convert from int to char
montgojj 4:a48fc7a3bda9 321 tcal[i] = tstr[i];
montgojj 4:a48fc7a3bda9 322 }
montgojj 11:f6a146b62579 323 TFT.write_calibrate(tcal); // write cal data to screen
montgojj 4:a48fc7a3bda9 324 }
montgojj 8:886908a6127c 325 }
cratliff 0:aa55c6eb6867 326
montgojj 11:f6a146b62579 327 /****************************************************************************/
montgojj 11:f6a146b62579 328 /* Loads all of the images from the SD card and assigns them bitmap handles */
montgojj 11:f6a146b62579 329 /****************************************************************************/
montgojj 8:886908a6127c 330 void initialize_Images()
montgojj 8:886908a6127c 331 {
montgojj 11:f6a146b62579 332 TFT.DLstart(); // start a new display command list
montgojj 11:f6a146b62579 333 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 8:886908a6127c 334
montgojj 11:f6a146b62579 335 TFT.DL(BITMAP_HANDLE(0)); // assign bitmap handle 0 to logo.jpg
montgojj 11:f6a146b62579 336 err[0] = TFT.Load_jpg("/sd/Logo.jpg",& x_size,& y_size, 0); // load the jpg and write it to address 0 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 337 TFT.DL(BITMAP_HANDLE(1)); // assign bitmap handle 1 to ITV_1.jpg
montgojj 11:f6a146b62579 338 err[1] = TFT.Load_jpg("/sd/ITV_1.jpg",& x_size,& y_size, 45000); // load the jpg and write it to address 45,000 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 339 TFT.DL(BITMAP_HANDLE(2)); // assign bitmap handle 2 to ITV_2.jpg
montgojj 11:f6a146b62579 340 err[2] = TFT.Load_jpg("/sd/ITV_2.jpg",& x_size,& y_size, 60000); // load the jpg and write it to address 60,000 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 341 TFT.DL(BITMAP_HANDLE(3)); // assign bitmap handle 3 to PF3W_1.jpg
montgojj 11:f6a146b62579 342 err[3] = TFT.Load_jpg("/sd/PF3W_1.jpg",& x_size,& y_size, 85000); // load the jpg and write it to address 85,000 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 343 TFT.DL(BITMAP_HANDLE(4)); // assign bitmap handle 4 to PF3W_2.jpg
montgojj 11:f6a146b62579 344 err[4] = TFT.Load_jpg("/sd/PF3W_2.jpg",& x_size,& y_size, 150000); // load the jpg and write it to address 150,000 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 345 TFT.DL(BITMAP_HANDLE(5)); // assign bitmap handle 5 to PSE_1.jpg
montgojj 11:f6a146b62579 346 err[5] = TFT.Load_jpg("/sd/PSE_1.jpg",& x_size,& y_size, 230000); // load the jpg and write it to address 230,000 in the FT810 RAM and store error result in array
montgojj 11:f6a146b62579 347 TFT.DL(BITMAP_HANDLE(6)); // assign bitmap handle 6 to PSE_2.jpg
montgojj 11:f6a146b62579 348 err[6] = TFT.Load_jpg("/sd/PSE_2.jpg",& x_size,& y_size, 260000); // load the jpg and write it to address 260,000 in the FT810 RAM and store error result in array
montgojj 8:886908a6127c 349
montgojj 11:f6a146b62579 350 TFT.DL(DISPLAY()); // display the image
montgojj 11:f6a146b62579 351 TFT.Swap(); // swap the current display list
montgojj 11:f6a146b62579 352 TFT.Flush_Co_Buffer(); // download the command list into fifo
montgojj 8:886908a6127c 353 TFT.WaitCmdfifo_empty();
montgojj 8:886908a6127c 354 }
montgojj 8:886908a6127c 355
montgojj 11:f6a146b62579 356 /****************************************************************************/
montgojj 11:f6a146b62579 357 /* Main function that tracks all of the touchscreen data and updates the */
montgojj 11:f6a146b62579 358 /* screen accordingly */
montgojj 11:f6a146b62579 359 /****************************************************************************/
montgojj 8:886908a6127c 360 int main()
montgojj 8:886908a6127c 361 {
montgojj 11:f6a146b62579 362 dac1.wakeup(); // activate DAC boards
montgojj 8:886908a6127c 363 dac2.wakeup();
montgojj 11:f6a146b62579 364 dac1.write_u12(0); // the natural DAC output value is 50% of its maximum value
montgojj 11:f6a146b62579 365 dac2.write_u12(0); // the program has to immediately write a 0 to the DAC to turn off the outputs
montgojj 11:f6a146b62579 366 ft_uint32_t TrackRegisterVal = 0; // touch track variable
montgojj 8:886908a6127c 367
montgojj 11:f6a146b62579 368 TFT.MemWrite(REG_ROTATE, 1); // rotate screen
montgojj 8:886908a6127c 369 TFT.Rotate(1);
montgojj 8:886908a6127c 370
montgojj 11:f6a146b62579 371 Start_Screen("Starting..."); // show start screen
montgojj 11:f6a146b62579 372 touchscreen_Calibration(); // load touchscreen calibration data
montgojj 11:f6a146b62579 373 initialize_Images(); // load and initialize images
montgojj 11:f6a146b62579 374
montgojj 11:f6a146b62579 375 TFT.Track(200, 400, 375, 50, 1); // track sliders
montgojj 10:c56b7ca4805f 376 TFT.Track(200, 400, 375, 50, 2);
montgojj 11:f6a146b62579 377 TFT.Flush_Co_Buffer(); // download the command list into fifo
montgojj 11:f6a146b62579 378 TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation
montgojj 11:f6a146b62579 379
cratliff 0:aa55c6eb6867 380 while(1) {
montgojj 11:f6a146b62579 381 curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff; // touch positions
cratliff 7:e525bfa17136 382 curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16;
montgojj 11:f6a146b62579 383 ft_uint8_t tagval = 0; // initialize return tag value
montgojj 11:f6a146b62579 384 TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched
montgojj 11:f6a146b62579 385 tagval = TrackRegisterVal & 0xff; // store return tag value
montgojj 11:f6a146b62579 386 // check what tag was touched
montgojj 11:f6a146b62579 387 if(1 == tagval) { // tag value for ITV1 slider touch
montgojj 11:f6a146b62579 388 ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095); // calculate new slider value so that the slider updates graphically
montgojj 11:f6a146b62579 389 ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590; // calculate raw 12 bit input number, includes calibration number to never go above 20mA
montgojj 11:f6a146b62579 390 dac1.write_u12(ITVpressure1_input_raw); // write 12 bit number to DAC to fire the ITV
montgojj 11:f6a146b62579 391 }
montgojj 11:f6a146b62579 392
montgojj 11:f6a146b62579 393 else if(2 == tagval) { // tag value for ITV2 slider touch
montgojj 11:f6a146b62579 394 ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095); // calculate new slider value so that the slider updates graphically
montgojj 11:f6a146b62579 395 ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585; // calculate raw 12 bit input number, includes calibration number to never go above 20mA
montgojj 11:f6a146b62579 396 dac2.write_u12(ITVpressure2_input_raw); // write 12 bit number to DAC to fire the ITV
montgojj 11:f6a146b62579 397 }
montgojj 11:f6a146b62579 398
montgojj 11:f6a146b62579 399 else if (200 == tagval) {
montgojj 8:886908a6127c 400 break;
cratliff 7:e525bfa17136 401 } else if(curX !=0x8000 && touched>0) {
cratliff 7:e525bfa17136 402 touched++;
cratliff 7:e525bfa17136 403 distance = curX - pasX;
cratliff 7:e525bfa17136 404 location = (int16_t)paslocation + distance;
cratliff 7:e525bfa17136 405
cratliff 7:e525bfa17136 406
montgojj 11:f6a146b62579 407 }
montgojj 11:f6a146b62579 408
montgojj 11:f6a146b62579 409 else if(curX !=0x8000 && !touched) {
cratliff 7:e525bfa17136 410 touched++;
cratliff 7:e525bfa17136 411 pasX = curX;
cratliff 7:e525bfa17136 412 //
montgojj 11:f6a146b62579 413 }
montgojj 11:f6a146b62579 414
montgojj 11:f6a146b62579 415 else if(curX ==0x8000 && touched) {
cratliff 7:e525bfa17136 416 velocity = distance/touched;
cratliff 7:e525bfa17136 417 paslocation = location;
cratliff 7:e525bfa17136 418 touched=0;
cratliff 7:e525bfa17136 419
cratliff 7:e525bfa17136 420
cratliff 7:e525bfa17136 421
montgojj 11:f6a146b62579 422 }
montgojj 11:f6a146b62579 423
montgojj 11:f6a146b62579 424 else {
cratliff 7:e525bfa17136 425 //page 4 location
cratliff 7:e525bfa17136 426 if (location < - 2300 && location > -2500) {
cratliff 7:e525bfa17136 427 if (velocity) {
cratliff 7:e525bfa17136 428 velocity = (location + 2400)/-5;
cratliff 7:e525bfa17136 429 location += (int16_t) velocity;
cratliff 7:e525bfa17136 430 paslocation = location;
montgojj 11:f6a146b62579 431 }
montgojj 11:f6a146b62579 432 else {
cratliff 7:e525bfa17136 433 location = -2400;
cratliff 7:e525bfa17136 434 }
cratliff 7:e525bfa17136 435
cratliff 7:e525bfa17136 436 }
cratliff 7:e525bfa17136 437 //page 3 location
cratliff 7:e525bfa17136 438 else if (location < - 1500 && location > -1700) {
cratliff 7:e525bfa17136 439 if (velocity) {
cratliff 7:e525bfa17136 440 velocity = (location + 1600)/-5;
cratliff 7:e525bfa17136 441 location += (int16_t) velocity;
cratliff 7:e525bfa17136 442 paslocation = location;
montgojj 11:f6a146b62579 443 }
montgojj 11:f6a146b62579 444 else {
cratliff 7:e525bfa17136 445 location = -1600;
cratliff 7:e525bfa17136 446 }
cratliff 5:e2e04cb5eada 447
cratliff 7:e525bfa17136 448 }
cratliff 7:e525bfa17136 449 //page 2
cratliff 7:e525bfa17136 450 else if (location < - 700 && location > -900) {
cratliff 7:e525bfa17136 451 if (velocity) {
cratliff 7:e525bfa17136 452 velocity = (location + 800)/-5;
cratliff 7:e525bfa17136 453 location += (int16_t) velocity;
cratliff 7:e525bfa17136 454 paslocation = location;
montgojj 11:f6a146b62579 455 }
montgojj 11:f6a146b62579 456 else {
cratliff 7:e525bfa17136 457 location = -800;
cratliff 7:e525bfa17136 458 }
cratliff 7:e525bfa17136 459 //page 1
montgojj 11:f6a146b62579 460 }
montgojj 11:f6a146b62579 461 else if (location > -100 && location < 100) {
cratliff 7:e525bfa17136 462
cratliff 7:e525bfa17136 463 if (velocity) {
cratliff 7:e525bfa17136 464 velocity = location/-5;
cratliff 7:e525bfa17136 465 location += (int16_t) velocity;
cratliff 7:e525bfa17136 466 paslocation = location;
montgojj 11:f6a146b62579 467 }
montgojj 11:f6a146b62579 468 else {
cratliff 7:e525bfa17136 469 location = 0;
cratliff 7:e525bfa17136 470 }
cratliff 7:e525bfa17136 471 //no page 0
cratliff 7:e525bfa17136 472 } else if (location >60) {
cratliff 7:e525bfa17136 473 velocity = -10;
cratliff 7:e525bfa17136 474 location += (int16_t) velocity;
cratliff 7:e525bfa17136 475 paslocation = location;
cratliff 7:e525bfa17136 476 //no page 5
montgojj 11:f6a146b62579 477 }
montgojj 11:f6a146b62579 478 else if (location <-1700) {
cratliff 7:e525bfa17136 479 velocity = 10;
cratliff 7:e525bfa17136 480 location += (int16_t) velocity;
cratliff 7:e525bfa17136 481 paslocation = location;
cratliff 7:e525bfa17136 482 //between pages
montgojj 11:f6a146b62579 483 }
montgojj 11:f6a146b62579 484 else if (velocity) {
cratliff 7:e525bfa17136 485 location += (int16_t) velocity;
cratliff 7:e525bfa17136 486 paslocation = location;
cratliff 7:e525bfa17136 487 //acceleration between pages
cratliff 7:e525bfa17136 488 if (velocity >0) {
cratliff 7:e525bfa17136 489 velocity+= 2;
montgojj 11:f6a146b62579 490 }
montgojj 11:f6a146b62579 491 else {
cratliff 7:e525bfa17136 492 velocity-= 2;
cratliff 7:e525bfa17136 493 }
cratliff 7:e525bfa17136 494 }
montgojj 8:886908a6127c 495 }
cratliff 7:e525bfa17136 496
montgojj 11:f6a146b62579 497 Main_Screen(); // paint new screen
montgojj 11:f6a146b62579 498 TFT.Sleep(10); // wait 10ms for next time to repaint the screen
montgojj 11:f6a146b62579 499 } // end of display loop
montgojj 8:886908a6127c 500 }