datalogger with touch screen gui

Dependencies:   FT800_beyondtek SDFileSystem Brew_Panel_FT810 mbed

Fork of Brew_Panel_FT810 by The Best

Committer:
cratliff
Date:
Wed Mar 30 14:52:16 2016 +0000
Revision:
5:e2e04cb5eada
Parent:
4:a48fc7a3bda9
Child:
6:f698d8ba4cd6
Added title block.  Fixed calibration save to file;

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