basic functional test of FT810 LCD via SPI

Dependencies:   FT810 mbed

Committer:
cratliff
Date:
Thu Mar 31 17:17:30 2016 +0000
Revision:
7:e525bfa17136
Parent:
6:f698d8ba4cd6
Child:
8:886908a6127c
Added swipe function rev. 0.1

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