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