basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
montgojj
Date:
Fri Apr 01 18:32:03 2016 +0000
Revision:
8:886908a6127c
Parent:
7:e525bfa17136
Child:
9:bf787d41b645
Fully functional?

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
cratliff 5:e2e04cb5eada 4 ** Project : CLC Brew Panel
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
cratliff 5:e2e04cb5eada 9 ** Abstract : ?
cratliff 5:e2e04cb5eada 10 **
cratliff 5:e2e04cb5eada 11 **
cratliff 6:f698d8ba4cd6 12 **
cratliff 6:f698d8ba4cd6 13 ** Todo :
cratliff 5:e2e04cb5eada 14 */
cratliff 0:aa55c6eb6867 15 #include "mbed.h"
cratliff 0:aa55c6eb6867 16 #include "FT_Platform.h"
cratliff 0:aa55c6eb6867 17 #include "FT_color.h"
cratliff 0:aa55c6eb6867 18 #include "stdio.h"
montgojj 4:a48fc7a3bda9 19 #include "float.h"
montgojj 4:a48fc7a3bda9 20 #include "SDFileSystem.h"
montgojj 4:a48fc7a3bda9 21 #include "MCP4725.h"
cratliff 0:aa55c6eb6867 22
cratliff 0:aa55c6eb6867 23 #define SAMAPP_DELAY_BTW_APIS (1000)
cratliff 0:aa55c6eb6867 24 #define SAMAPP_ENABLE_DELAY() Ft_Gpu_Hal_Sleep(SAMAPP_DELAY_BTW_APIS)
cratliff 0:aa55c6eb6867 25 #define SAMAPP_ENABLE_DELAY_VALUE(x) Ft_Gpu_Hal_Sleep(x)
cratliff 0:aa55c6eb6867 26
montgojj 4:a48fc7a3bda9 27 //#define Nucleo_F303K8
montgojj 4:a48fc7a3bda9 28 #define K20
cratliff 7:e525bfa17136 29 // used add easy way to reprogram without using the phsyical button.
cratliff 6:f698d8ba4cd6 30 #define Program_Button
montgojj 8:886908a6127c 31 //#define Debug_Swipe
cratliff 0:aa55c6eb6867 32
cratliff 0:aa55c6eb6867 33 #ifdef Nucleo_F303K8
cratliff 0:aa55c6eb6867 34 FT800 TFT(PB_5,PB_4,PB_3,PA_11,PA_8,PF_1); // the FT800 is connected to SPI 5-7, then we have CS, INT, PD
cratliff 0:aa55c6eb6867 35 #endif
cratliff 0:aa55c6eb6867 36
montgojj 4:a48fc7a3bda9 37 #ifdef K20
montgojj 4:a48fc7a3bda9 38 FT800 TFT(D11,D12,D13,D9,D8,D14);
montgojj 4:a48fc7a3bda9 39 SDFileSystem sd(D11, D12, D13, D10, "sd");
montgojj 4:a48fc7a3bda9 40 MCP4725 dac1(D18, D19, MCP4725::ADDRESS_2);
montgojj 4:a48fc7a3bda9 41 MCP4725 dac2(D18, D19, MCP4725::ADDRESS_3);
montgojj 4:a48fc7a3bda9 42
montgojj 8:886908a6127c 43 AnalogIn PSEpressure_raw(A9);
montgojj 8:886908a6127c 44 AnalogIn PFWflowrate_raw(A8);
montgojj 4:a48fc7a3bda9 45 AnalogIn ITVpressure1_feedback_raw(A3);
montgojj 4:a48fc7a3bda9 46 AnalogIn ITVpressure2_feedback_raw(A2);
montgojj 4:a48fc7a3bda9 47 DigitalIn card_present(D7);
cratliff 0:aa55c6eb6867 48 #endif
cratliff 0:aa55c6eb6867 49
montgojj 4:a48fc7a3bda9 50 // global Vars
cratliff 7:e525bfa17136 51 unsigned int r, b, g, CalVal0, CalVal1, CalVal2, CalVal3, CalVal4, curX, curY, pasX, pasY;
montgojj 8:886908a6127c 52 float PSEpressure, PFWflowrate = 0.0;
cratliff 7:e525bfa17136 53 float ITVpressure1_feedback, ITVpressure2_feedback, ITVpressure1_user_input, ITVpressure2_user_input = 0.0;
montgojj 4:a48fc7a3bda9 54 uint16_t ITVpressure1_input_raw, ITVpressure2_input_raw, test = 0;
cratliff 7:e525bfa17136 55 int16_t velocity, distance, touched, location, paslocation ;
montgojj 4:a48fc7a3bda9 56 char buffer[50];
montgojj 4:a48fc7a3bda9 57 uint8_t tcal[24]; //Touch screen Calibration
cratliff 5:e2e04cb5eada 58 char tstr[40]; // Temp location for Touch Screen Calibration
montgojj 8:886908a6127c 59 ft_int16_t x_size,y_size;
cratliff 5:e2e04cb5eada 60
montgojj 8:886908a6127c 61 unsigned int err[7];
cratliff 0:aa55c6eb6867 62
cratliff 0:aa55c6eb6867 63 /***************************************************************************/
cratliff 0:aa55c6eb6867 64 /* Show a Screen with Text for 5 seconds */
cratliff 0:aa55c6eb6867 65 /* A spinner shows the delay */
cratliff 0:aa55c6eb6867 66 /***************************************************************************/
cratliff 0:aa55c6eb6867 67
cratliff 0:aa55c6eb6867 68 ft_void_t Start_Screen(ft_char8_t *str)
cratliff 0:aa55c6eb6867 69 {
cratliff 0:aa55c6eb6867 70 TFT.DLstart(); // start a new display command list
cratliff 0:aa55c6eb6867 71 TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white
cratliff 0:aa55c6eb6867 72 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
cratliff 5:e2e04cb5eada 73 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
cratliff 5:e2e04cb5eada 74
cratliff 5:e2e04cb5eada 75 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 4:a48fc7a3bda9 76 TFT.DL(BEGIN(LINES));
montgojj 4:a48fc7a3bda9 77 TFT.DL(LINE_WIDTH(8 * 16));
montgojj 4:a48fc7a3bda9 78 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 79 TFT.DL(VERTEX2F(799*16,0*16));
cratliff 5:e2e04cb5eada 80
montgojj 4:a48fc7a3bda9 81 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 82 TFT.DL(VERTEX2F(799*16,479*16));
cratliff 5:e2e04cb5eada 83
montgojj 4:a48fc7a3bda9 84 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 85 TFT.DL(VERTEX2F(0*16,479*16));
cratliff 5:e2e04cb5eada 86
montgojj 4:a48fc7a3bda9 87 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 88 TFT.DL(VERTEX2F(0*16,0*16));
cratliff 5:e2e04cb5eada 89
cratliff 0:aa55c6eb6867 90 TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
montgojj 8:886908a6127c 91 TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel"); // draw Text with font 31
montgojj 4:a48fc7a3bda9 92 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // change current color
cratliff 0:aa55c6eb6867 93 TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner
cratliff 5:e2e04cb5eada 94
cratliff 0:aa55c6eb6867 95 TFT.DL(DISPLAY()); // Display the image
cratliff 0:aa55c6eb6867 96 TFT.Swap(); // Swap the current display list
cratliff 0:aa55c6eb6867 97 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cratliff 0:aa55c6eb6867 98
cratliff 0:aa55c6eb6867 99 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 100 TFT.Sleep(1000); // Wait 5 s to show
cratliff 0:aa55c6eb6867 101 }
cratliff 0:aa55c6eb6867 102
cratliff 0:aa55c6eb6867 103 // construct the screen and download it to the LCD
montgojj 4:a48fc7a3bda9 104 void screen_1()
cratliff 0:aa55c6eb6867 105 {
cratliff 0:aa55c6eb6867 106 TFT.DLstart(); // start a new display command list
montgojj 8:886908a6127c 107 TFT.DL(CLEAR_COLOR_RGB(255,255,255));
cratliff 0:aa55c6eb6867 108 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 8:886908a6127c 109 #ifdef Program_Button
montgojj 8:886908a6127c 110 TFT.DL(TAG(200)); // assign TAG value 200
montgojj 8:886908a6127c 111 TFT.Button(710, 10, 76, 22, 26, 0, "Reprogram");
montgojj 8:886908a6127c 112 TFT.DL(TAG(3));
montgojj 8:886908a6127c 113 #endif
montgojj 4:a48fc7a3bda9 114 /***************************************************************************************************/
montgojj 8:886908a6127c 115 // some temp location holder for each page showing the transitions
montgojj 8:886908a6127c 116 /*TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800));
cratliff 7:e525bfa17136 117 TFT.Text(300, 200, 31, 0, "Page 2");
cratliff 7:e525bfa17136 118 TFT.DL(VERTEX_TRANSLATE_X(location* 16+25600));
cratliff 7:e525bfa17136 119 TFT.Text(300, 200, 31, 0, "Page 3");
cratliff 7:e525bfa17136 120 TFT.DL(VERTEX_TRANSLATE_X(location* 16+38400));
cratliff 7:e525bfa17136 121 TFT.Text(300, 200, 31, 0, "Page 4");
cratliff 7:e525bfa17136 122 TFT.DL(CLEAR_COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 123 TFT.DL(VERTEX_TRANSLATE_X(location* 16));*/
montgojj 8:886908a6127c 124
montgojj 4:a48fc7a3bda9 125 /*Border Creation*/
montgojj 4:a48fc7a3bda9 126 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 4:a48fc7a3bda9 127 TFT.DL(BEGIN(LINES));
montgojj 4:a48fc7a3bda9 128 TFT.DL(LINE_WIDTH(8 * 16));
montgojj 4:a48fc7a3bda9 129 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 130 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 131 TFT.DL(VERTEX2F(799*16,0*16));
montgojj 4:a48fc7a3bda9 132 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 133 TFT.DL(VERTEX2F(799*16,479*16));
montgojj 4:a48fc7a3bda9 134 TFT.DL(VERTEX2F(0*16,479*16));
montgojj 4:a48fc7a3bda9 135 TFT.DL(VERTEX2F(0*16,479*16));
cratliff 5:e2e04cb5eada 136 TFT.DL(VERTEX2F(0*16,0*16));
montgojj 4:a48fc7a3bda9 137 TFT.DL(END());
montgojj 4:a48fc7a3bda9 138 /***************************************************************************************************/
cratliff 0:aa55c6eb6867 139
montgojj 4:a48fc7a3bda9 140 /***************************************************************************************************/
montgojj 8:886908a6127c 141 /*ITV 1 Screen Display*/
montgojj 8:886908a6127c 142 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 143 TFT.DL(VERTEX_TRANSLATE_X(location* 16));
montgojj 8:886908a6127c 144
montgojj 8:886908a6127c 145 TFT.DL(BEGIN(BITMAPS));
montgojj 8:886908a6127c 146 TFT.DL(VERTEX2II(265,50,0,0));
montgojj 8:886908a6127c 147 TFT.DL(VERTEX2II(75,50,1,0));
montgojj 8:886908a6127c 148 TFT.DL(VERTEX_TRANSLATE_X((149+location)*16));
montgojj 8:886908a6127c 149 TFT.DL(VERTEX2II(511,50,2,0));
montgojj 8:886908a6127c 150 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16));
montgojj 4:a48fc7a3bda9 151 TFT.DL(END());
montgojj 8:886908a6127c 152
montgojj 8:886908a6127c 153 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 8:886908a6127c 154 TFT.Text(265, 200, 31, 0, "ITV 1 Pressure");
montgojj 8:886908a6127c 155 TFT.DL(BEGIN(RECTS));
montgojj 8:886908a6127c 156 TFT.DL(VERTEX2F(300*16,265*16));
montgojj 8:886908a6127c 157 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 158 TFT.DL(END());
montgojj 4:a48fc7a3bda9 159 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 160 sprintf(buffer, "%.1f", ITVpressure1_feedback);
montgojj 8:886908a6127c 161 TFT.Text(325,275,31,0,buffer);
montgojj 8:886908a6127c 162 TFT.Text(415, 275, 31, 0, " PSI");
montgojj 8:886908a6127c 163 ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0;
montgojj 8:886908a6127c 164 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 165 TFT.FgColor(COLOR_RGB(0,124,196));
montgojj 8:886908a6127c 166 TFT.BgColor(COLOR_RGB(0,124,196));
montgojj 8:886908a6127c 167 TFT.DL(TAG(1)); // assign TAG value 1
montgojj 8:886908a6127c 168 TFT.Slider(225,375,350,30,0,ITVpressure1_user_input,2355);
montgojj 8:886908a6127c 169 TFT.DL(TAG(3));
montgojj 4:a48fc7a3bda9 170 /***************************************************************************************************/
cratliff 5:e2e04cb5eada 171
montgojj 4:a48fc7a3bda9 172 /***************************************************************************************************/
montgojj 8:886908a6127c 173 /*ITV 2 and PF3W Screen Display*/
montgojj 8:886908a6127c 174 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 175 TFT.DL(VERTEX_TRANSLATE_X(location* 16)+12800);
montgojj 8:886908a6127c 176 TFT.DL(BEGIN(BITMAPS));
montgojj 8:886908a6127c 177 //TFT.DL(VERTEX2II(265,50,0,0));
montgojj 8:886908a6127c 178 TFT.DL(VERTEX2II(30,75,3,0));
montgojj 8:886908a6127c 179 TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)+12800);
montgojj 8:886908a6127c 180 TFT.DL(VERTEX2II(411,75,4,0));
montgojj 8:886908a6127c 181 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+12800);
montgojj 8:886908a6127c 182 TFT.DL(END());
montgojj 8:886908a6127c 183
montgojj 8:886908a6127c 184 TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800));
montgojj 8:886908a6127c 185 // Slide
montgojj 8:886908a6127c 186 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 8:886908a6127c 187 TFT.Text(265, 200, 31, 0, "ITV 2 Pressure");
montgojj 8:886908a6127c 188 TFT.DL(BEGIN(RECTS));
montgojj 8:886908a6127c 189 TFT.DL(VERTEX2F(300*16,265*16));
montgojj 8:886908a6127c 190 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 191 TFT.DL(END());
montgojj 8:886908a6127c 192 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 193 sprintf(buffer, "%.1f", ITVpressure2_feedback);
montgojj 8:886908a6127c 194 TFT.Text(325,275,31,0,buffer);
montgojj 8:886908a6127c 195 TFT.Text(415, 275, 31, 0, " PSI");
montgojj 8:886908a6127c 196 ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0;
montgojj 8:886908a6127c 197 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 198 TFT.FgColor(COLOR_RGB(0,124,196));
montgojj 8:886908a6127c 199 TFT.BgColor(COLOR_RGB(0,124,196));
montgojj 8:886908a6127c 200 TFT.DL(TAG(2)); // assign TAG value 2
montgojj 8:886908a6127c 201 TFT.Slider(225,375,350,30,0,ITVpressure2_user_input,2387);
montgojj 8:886908a6127c 202 TFT.DL(TAG(3));
montgojj 8:886908a6127c 203
montgojj 8:886908a6127c 204 TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800));
montgojj 4:a48fc7a3bda9 205 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 8:886908a6127c 206 TFT.Text(250, 20, 31, 0, "PF3W Flow Rate");
montgojj 4:a48fc7a3bda9 207 TFT.DL(BEGIN(RECTS));
montgojj 8:886908a6127c 208 TFT.DL(VERTEX2F(300*16,85*16));
montgojj 8:886908a6127c 209 TFT.DL(VERTEX2F(505*16,150*16));
montgojj 8:886908a6127c 210 PFWflowrate = (PFWflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0;
montgojj 8:886908a6127c 211 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 212 sprintf(buffer, "%.1f", PFWflowrate);
montgojj 8:886908a6127c 213 TFT.Text(285,95,31,0,buffer);
montgojj 8:886908a6127c 214 TFT.Text(385, 95, 31, 0, " L/min");
montgojj 8:886908a6127c 215 /***************************************************************************************************/
montgojj 8:886908a6127c 216
montgojj 8:886908a6127c 217 /***************************************************************************************************/
montgojj 8:886908a6127c 218 /*ISE Screen Display*/
montgojj 8:886908a6127c 219 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 220 TFT.DL(VERTEX_TRANSLATE_X(location* 16)+25600);
montgojj 8:886908a6127c 221 TFT.DL(BEGIN(BITMAPS));
montgojj 8:886908a6127c 222 TFT.DL(TAG(3));
montgojj 8:886908a6127c 223 TFT.DL(VERTEX2II(265,50,0,0));
montgojj 8:886908a6127c 224 TFT.DL(VERTEX2II(75,50,5,0));
montgojj 8:886908a6127c 225 TFT.DL(VERTEX_TRANSLATE_X((99+location)*16)+25600);
montgojj 8:886908a6127c 226 TFT.DL(VERTEX2II(511,85,6,0));
montgojj 8:886908a6127c 227 TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+25600);
montgojj 8:886908a6127c 228 TFT.DL(END());
montgojj 8:886908a6127c 229
montgojj 8:886908a6127c 230 TFT.DL(VERTEX_TRANSLATE_X(location* 16+25600)); //page 3
montgojj 8:886908a6127c 231 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 8:886908a6127c 232 TFT.Text(280, 200, 31, 0, "PSE Pressure");
montgojj 8:886908a6127c 233 TFT.DL(BEGIN(RECTS));
montgojj 8:886908a6127c 234 TFT.DL(VERTEX2F(295*16,265*16));
montgojj 8:886908a6127c 235 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 8:886908a6127c 236 TFT.DL(END());
montgojj 8:886908a6127c 237 PSEpressure = (PSEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0;;
montgojj 8:886908a6127c 238 TFT.DL(COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 239 sprintf(buffer, "%.2f", PSEpressure);
montgojj 8:886908a6127c 240 //test = ISEpressure_raw.read_u16();
montgojj 8:886908a6127c 241 //sprintf(buffer, "%d", test);
montgojj 8:886908a6127c 242 TFT.Text(300,275,31,0,buffer);
montgojj 8:886908a6127c 243 TFT.Text(405, 275, 31, 0, " MPa");
montgojj 8:886908a6127c 244 /***************************************************************************************************/
montgojj 8:886908a6127c 245
montgojj 8:886908a6127c 246 /***************************************************************************************************/
montgojj 8:886908a6127c 247 /*PFM Screen Display*/
montgojj 8:886908a6127c 248 /*TFT.DL(VERTEX_TRANSLATE_X(location* 16+38400)); // page 4
montgojj 8:886908a6127c 249 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4));
montgojj 8:886908a6127c 250 TFT.Text(265, 200, 31, 0, "PFW Flow Rate");
montgojj 8:886908a6127c 251 TFT.DL(BEGIN(RECTS));
montgojj 8:886908a6127c 252 TFT.DL(VERTEX2F(300*16,265*16));
montgojj 8:886908a6127c 253 TFT.DL(VERTEX2F(505*16,330*16));
montgojj 4:a48fc7a3bda9 254 TFT.DL(END());
montgojj 4:a48fc7a3bda9 255 PFMflowrate = (PFMflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0;
montgojj 4:a48fc7a3bda9 256 TFT.DL(COLOR_RGB(255,255,255));
montgojj 4:a48fc7a3bda9 257 sprintf(buffer, "%.1f", PFMflowrate);
montgojj 8:886908a6127c 258 TFT.Text(295,275,31,0,buffer);
montgojj 8:886908a6127c 259 TFT.Text(385, 275, 31, 0, " L/min");*/
montgojj 4:a48fc7a3bda9 260 /***************************************************************************************************/
cratliff 5:e2e04cb5eada 261
cratliff 5:e2e04cb5eada 262
montgojj 8:886908a6127c 263 // add button to make for easy reprogramming
montgojj 8:886908a6127c 264
cratliff 6:f698d8ba4cd6 265
cratliff 7:e525bfa17136 266 #ifdef Debug_Swipe
cratliff 7:e525bfa17136 267 TFT.DL(COLOR_RGB(0,0,0));
cratliff 7:e525bfa17136 268 //sprintf(buffer, "%.2f", distance);
cratliff 7:e525bfa17136 269 //TFT.Text(20, 450, 26, 0, buffer);
cratliff 7:e525bfa17136 270 TFT.Number(20, 450, 26, 0, distance);
cratliff 7:e525bfa17136 271 TFT.Number(80, 450, 26, 0, velocity);
cratliff 7:e525bfa17136 272 #endif
cratliff 5:e2e04cb5eada 273 // Debug the touch up load
cratliff 5:e2e04cb5eada 274 #ifdef Debug_Touch_File
cratliff 5:e2e04cb5eada 275 TFT.DL(COLOR_RGB(0,0,0));
cratliff 5:e2e04cb5eada 276 int i;
cratliff 5:e2e04cb5eada 277 for (i = 0; i < 24; i++) {
cratliff 5:e2e04cb5eada 278 TFT.Number(i*30+20, 450, 26, 0, tcal[i]);
cratliff 5:e2e04cb5eada 279
cratliff 5:e2e04cb5eada 280 }
cratliff 5:e2e04cb5eada 281 #endif
cratliff 5:e2e04cb5eada 282
cratliff 0:aa55c6eb6867 283 TFT.DL(DISPLAY()); // Display the image
cratliff 0:aa55c6eb6867 284 TFT.Swap(); // Swap the current display list
cratliff 0:aa55c6eb6867 285 TFT.Flush_Co_Buffer(); // Download the command list into fifo
cratliff 0:aa55c6eb6867 286 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
cratliff 0:aa55c6eb6867 287 }
cratliff 0:aa55c6eb6867 288
cratliff 5:e2e04cb5eada 289 void error_screen_SD()
cratliff 5:e2e04cb5eada 290 {
montgojj 4:a48fc7a3bda9 291 TFT.DLstart(); // start a new display command list
montgojj 4:a48fc7a3bda9 292 TFT.DL(CLEAR_COLOR_RGB(255,242,0));
montgojj 4:a48fc7a3bda9 293 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer
montgojj 4:a48fc7a3bda9 294 TFT.DL(COLOR_RGB(0,0,0));
montgojj 4:a48fc7a3bda9 295 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, "Error!"); // draw Text with font 31
montgojj 4:a48fc7a3bda9 296 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, "Insert SD Card!"); // draw Text with font 31
montgojj 4:a48fc7a3bda9 297 TFT.DL(DISPLAY()); // Display the image
montgojj 4:a48fc7a3bda9 298 TFT.Swap(); // Swap the current display list
montgojj 4:a48fc7a3bda9 299 TFT.Flush_Co_Buffer(); // Download the command list into fifo
montgojj 4:a48fc7a3bda9 300 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
montgojj 4:a48fc7a3bda9 301 TFT.Sleep(1000);
cratliff 5:e2e04cb5eada 302
montgojj 4:a48fc7a3bda9 303 TFT.DLstart(); // start a new display command list
montgojj 4:a48fc7a3bda9 304 TFT.DL(CLEAR_COLOR_RGB(255,255,255));
montgojj 4:a48fc7a3bda9 305 TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer;
montgojj 4:a48fc7a3bda9 306 TFT.DL(COLOR_RGB(0,0,0));
montgojj 4:a48fc7a3bda9 307 TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, "Error!"); // draw Text with font 31
montgojj 4:a48fc7a3bda9 308 TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, "Insert SD Card!"); // draw Text with font 31
montgojj 4:a48fc7a3bda9 309 TFT.DL(DISPLAY()); // Display the image
montgojj 4:a48fc7a3bda9 310 TFT.Swap(); // Swap the current display list
montgojj 4:a48fc7a3bda9 311 TFT.Flush_Co_Buffer(); // Download the command list into fifo
montgojj 4:a48fc7a3bda9 312 TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation
montgojj 4:a48fc7a3bda9 313 TFT.Sleep(1000);
montgojj 4:a48fc7a3bda9 314 }
cratliff 0:aa55c6eb6867 315
montgojj 8:886908a6127c 316 void touchscreen_Calibration()
cratliff 5:e2e04cb5eada 317 {
cratliff 5:e2e04cb5eada 318 int i = 0;
montgojj 4:a48fc7a3bda9 319 FILE *fp = fopen("/sd/TCal/TCalData.txt", "a");
montgojj 4:a48fc7a3bda9 320 fp= fopen("/sd/TCal/TCalData.txt", "r");
montgojj 4:a48fc7a3bda9 321 if(!fp) {
montgojj 4:a48fc7a3bda9 322 //Could not open file for read
montgojj 4:a48fc7a3bda9 323 TFT.Calibrate(); // calibrate the touch screen
montgojj 4:a48fc7a3bda9 324 TFT.read_calibrate(tcal); // Read in cal data from screen
montgojj 4:a48fc7a3bda9 325 //Convert from Int to Char to save to SD card
cratliff 5:e2e04cb5eada 326 /* no longer needed
montgojj 4:a48fc7a3bda9 327 for (i = 0; i < 25; i++) {
montgojj 4:a48fc7a3bda9 328 tstr[i] = tcal[i];
montgojj 4:a48fc7a3bda9 329 }
cratliff 5:e2e04cb5eada 330 */
montgojj 4:a48fc7a3bda9 331 //Open file for to save calibration data
montgojj 4:a48fc7a3bda9 332 mkdir("/sd/TCal", 0777);
montgojj 4:a48fc7a3bda9 333 FILE *fp = fopen("/sd/TCal/TCalData.txt", "w");
cratliff 5:e2e04cb5eada 334 //Save integers one at a time to the file
cratliff 5:e2e04cb5eada 335 for (i = 0; i < 25; i++) {
cratliff 5:e2e04cb5eada 336 fprintf(fp, "%c", tcal[i] );
cratliff 5:e2e04cb5eada 337 }
montgojj 4:a48fc7a3bda9 338 fclose(fp);
cratliff 5:e2e04cb5eada 339 } else {
montgojj 4:a48fc7a3bda9 340 //Read in calibration Data
montgojj 4:a48fc7a3bda9 341 fread(tstr,24,1,fp);
montgojj 4:a48fc7a3bda9 342 //Convert from Char to Int
montgojj 4:a48fc7a3bda9 343 for (i = 0; i < 24; i++) {
montgojj 4:a48fc7a3bda9 344 tcal[i] = tstr[i];
montgojj 4:a48fc7a3bda9 345 }
montgojj 4:a48fc7a3bda9 346 TFT.write_calibrate(tcal); // write cal data to screen
montgojj 4:a48fc7a3bda9 347 }
montgojj 8:886908a6127c 348 }
cratliff 0:aa55c6eb6867 349
montgojj 8:886908a6127c 350 void initialize_Images()
montgojj 8:886908a6127c 351 {
montgojj 8:886908a6127c 352 TFT.DLstart();
montgojj 8:886908a6127c 353 TFT.DL(CLEAR_COLOR_RGB(255,255,255));
montgojj 8:886908a6127c 354 TFT.DL(CLEAR(1,1,1));
montgojj 8:886908a6127c 355
montgojj 8:886908a6127c 356 TFT.DL(BITMAP_HANDLE(0));
montgojj 8:886908a6127c 357 err[0] = TFT.Load_jpg("/sd/Logo.jpg",& x_size,& y_size, 0);
montgojj 8:886908a6127c 358 TFT.DL(BITMAP_HANDLE(1));
montgojj 8:886908a6127c 359 err[1] = TFT.Load_jpg("/sd/ITV_1.jpg",& x_size,& y_size, 45000);
montgojj 8:886908a6127c 360 TFT.DL(BITMAP_HANDLE(2));
montgojj 8:886908a6127c 361 err[2] = TFT.Load_jpg("/sd/ITV_2.jpg",& x_size,& y_size, 60000);
montgojj 8:886908a6127c 362 TFT.DL(BITMAP_HANDLE(3));
montgojj 8:886908a6127c 363 err[3] = TFT.Load_jpg("/sd/PF3W_1.jpg",& x_size,& y_size, 85000);
montgojj 8:886908a6127c 364 TFT.DL(BITMAP_HANDLE(4));
montgojj 8:886908a6127c 365 err[4] = TFT.Load_jpg("/sd/PF3W_2.jpg",& x_size,& y_size, 150000);
montgojj 8:886908a6127c 366 TFT.DL(BITMAP_HANDLE(5));
montgojj 8:886908a6127c 367 err[5] = TFT.Load_jpg("/sd/PSE_1.jpg",& x_size,& y_size, 230000);
montgojj 8:886908a6127c 368 TFT.DL(BITMAP_HANDLE(6));
montgojj 8:886908a6127c 369 err[6] = TFT.Load_jpg("/sd/PSE_2.jpg",& x_size,& y_size, 260000);
montgojj 8:886908a6127c 370
montgojj 8:886908a6127c 371 TFT.DL(DISPLAY()); // Display the image
montgojj 8:886908a6127c 372 TFT.Swap(); // Swap the current display list
montgojj 8:886908a6127c 373 TFT.Flush_Co_Buffer(); // Download the command list into fifo
montgojj 8:886908a6127c 374 TFT.WaitCmdfifo_empty();
montgojj 8:886908a6127c 375 }
montgojj 8:886908a6127c 376
montgojj 8:886908a6127c 377 int main()
montgojj 8:886908a6127c 378 {
montgojj 8:886908a6127c 379 dac1.wakeup();
montgojj 8:886908a6127c 380 dac2.wakeup();
montgojj 8:886908a6127c 381 dac1.write_u12(0);
montgojj 8:886908a6127c 382 dac2.write_u12(0);
montgojj 8:886908a6127c 383 ft_uint32_t TrackRegisterVal = 0; // touch track
montgojj 8:886908a6127c 384
montgojj 8:886908a6127c 385 TFT.MemWrite(REG_ROTATE, 1);
montgojj 8:886908a6127c 386 TFT.Rotate(1);
montgojj 8:886908a6127c 387
montgojj 8:886908a6127c 388 Start_Screen("Starting..."); // Show start screen
montgojj 8:886908a6127c 389
montgojj 8:886908a6127c 390 while(card_present.read()) {
montgojj 8:886908a6127c 391 error_screen_SD();
montgojj 8:886908a6127c 392 }
montgojj 8:886908a6127c 393
montgojj 8:886908a6127c 394 touchscreen_Calibration();
montgojj 8:886908a6127c 395
montgojj 8:886908a6127c 396 initialize_Images();
montgojj 8:886908a6127c 397 TFT.Track(200, 400, 375, 30, 1);
montgojj 8:886908a6127c 398 TFT.Track(200, 400, 375, 30, 2);
cratliff 0:aa55c6eb6867 399 TFT.Flush_Co_Buffer(); // Download the commands into fifo
montgojj 8:886908a6127c 400 TFT.WaitCmdfifo_empty();
montgojj 4:a48fc7a3bda9 401 /* the demo is updating the screen in a endless loop*/
cratliff 0:aa55c6eb6867 402 while(1) {
cratliff 7:e525bfa17136 403 // Touch position
cratliff 7:e525bfa17136 404 curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff;
cratliff 7:e525bfa17136 405 curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16;
cratliff 0:aa55c6eb6867 406 ft_uint8_t tagval = 0;
cratliff 0:aa55c6eb6867 407 TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched
cratliff 0:aa55c6eb6867 408 tagval = TrackRegisterVal & 0xff;
montgojj 8:886908a6127c 409 if(1 == tagval) {
montgojj 8:886908a6127c 410 ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095);
montgojj 8:886908a6127c 411 ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590;
montgojj 8:886908a6127c 412 dac1.write_u12(ITVpressure1_input_raw);
montgojj 8:886908a6127c 413 } else if(2 == tagval) { // the slider is touched
montgojj 8:886908a6127c 414 ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095);
montgojj 8:886908a6127c 415 ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585;
montgojj 8:886908a6127c 416 dac2.write_u12(ITVpressure2_input_raw);
montgojj 8:886908a6127c 417 } else if (200 == tagval) {
montgojj 8:886908a6127c 418 break;
cratliff 7:e525bfa17136 419 } else if(curX !=0x8000 && touched>0) {
cratliff 7:e525bfa17136 420 touched++;
cratliff 7:e525bfa17136 421 distance = curX - pasX;
cratliff 7:e525bfa17136 422 location = (int16_t)paslocation + distance;
cratliff 7:e525bfa17136 423
cratliff 7:e525bfa17136 424
cratliff 7:e525bfa17136 425 } else if(curX !=0x8000 && !touched) {
cratliff 7:e525bfa17136 426 touched++;
cratliff 7:e525bfa17136 427 pasX = curX;
cratliff 7:e525bfa17136 428 //
cratliff 7:e525bfa17136 429 } else if(curX ==0x8000 && touched) {
cratliff 7:e525bfa17136 430 velocity = distance/touched;
cratliff 7:e525bfa17136 431 paslocation = location;
cratliff 7:e525bfa17136 432 touched=0;
cratliff 7:e525bfa17136 433
cratliff 7:e525bfa17136 434
cratliff 7:e525bfa17136 435
cratliff 7:e525bfa17136 436 } else {
cratliff 7:e525bfa17136 437 //page 4 location
cratliff 7:e525bfa17136 438 if (location < - 2300 && location > -2500) {
cratliff 7:e525bfa17136 439 if (velocity) {
cratliff 7:e525bfa17136 440 velocity = (location + 2400)/-5;
cratliff 7:e525bfa17136 441 location += (int16_t) velocity;
cratliff 7:e525bfa17136 442 paslocation = location;
cratliff 7:e525bfa17136 443 } else {
cratliff 7:e525bfa17136 444 location = -2400;
cratliff 7:e525bfa17136 445 }
cratliff 7:e525bfa17136 446
cratliff 7:e525bfa17136 447 }
cratliff 7:e525bfa17136 448 //page 3 location
cratliff 7:e525bfa17136 449 else if (location < - 1500 && location > -1700) {
cratliff 7:e525bfa17136 450 if (velocity) {
cratliff 7:e525bfa17136 451 velocity = (location + 1600)/-5;
cratliff 7:e525bfa17136 452 location += (int16_t) velocity;
cratliff 7:e525bfa17136 453 paslocation = location;
cratliff 7:e525bfa17136 454 } else {
cratliff 7:e525bfa17136 455 location = -1600;
cratliff 7:e525bfa17136 456 }
cratliff 5:e2e04cb5eada 457
cratliff 7:e525bfa17136 458 }
cratliff 7:e525bfa17136 459 //page 2
cratliff 7:e525bfa17136 460 else if (location < - 700 && location > -900) {
cratliff 7:e525bfa17136 461 if (velocity) {
cratliff 7:e525bfa17136 462 velocity = (location + 800)/-5;
cratliff 7:e525bfa17136 463 location += (int16_t) velocity;
cratliff 7:e525bfa17136 464 paslocation = location;
cratliff 7:e525bfa17136 465 } else {
cratliff 7:e525bfa17136 466 location = -800;
cratliff 7:e525bfa17136 467 }
cratliff 7:e525bfa17136 468 //page 1
cratliff 7:e525bfa17136 469 } else if (location > -100 && location < 100) {
cratliff 7:e525bfa17136 470
cratliff 7:e525bfa17136 471 if (velocity) {
cratliff 7:e525bfa17136 472 velocity = location/-5;
cratliff 7:e525bfa17136 473 location += (int16_t) velocity;
cratliff 7:e525bfa17136 474 paslocation = location;
cratliff 7:e525bfa17136 475 } else {
cratliff 7:e525bfa17136 476 location = 0;
cratliff 7:e525bfa17136 477 }
cratliff 7:e525bfa17136 478 //no page 0
cratliff 7:e525bfa17136 479 } else if (location >60) {
cratliff 7:e525bfa17136 480 velocity = -10;
cratliff 7:e525bfa17136 481 location += (int16_t) velocity;
cratliff 7:e525bfa17136 482 paslocation = location;
cratliff 7:e525bfa17136 483 //no page 5
montgojj 8:886908a6127c 484 } else if (location <-1700) {
cratliff 7:e525bfa17136 485 velocity = 10;
cratliff 7:e525bfa17136 486 location += (int16_t) velocity;
cratliff 7:e525bfa17136 487 paslocation = location;
cratliff 7:e525bfa17136 488 //between pages
cratliff 7:e525bfa17136 489 } else if (velocity) {
cratliff 7:e525bfa17136 490 location += (int16_t) velocity;
cratliff 7:e525bfa17136 491 paslocation = location;
cratliff 7:e525bfa17136 492 //acceleration between pages
cratliff 7:e525bfa17136 493 if (velocity >0) {
cratliff 7:e525bfa17136 494 velocity+= 2;
cratliff 7:e525bfa17136 495 } else {
cratliff 7:e525bfa17136 496 velocity-= 2;
cratliff 7:e525bfa17136 497 }
cratliff 7:e525bfa17136 498 }
montgojj 8:886908a6127c 499 }
cratliff 7:e525bfa17136 500
montgojj 8:886908a6127c 501 screen_1(); // paint new screen
montgojj 8:886908a6127c 502 TFT.Sleep(10); // wait 10ms for next time to repaint the screen
montgojj 8:886908a6127c 503 } // end of display loop
montgojj 8:886908a6127c 504 }