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