Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
main.cpp@15:25cbc8345067, 2016-04-27 (annotated)
- Committer:
- montgojj
- Date:
- Wed Apr 27 11:38:56 2016 +0000
- Revision:
- 15:25cbc8345067
- Parent:
- 14:52a03b4a0365
- Child:
- 16:19ade236df07
Added functionality to read in data from SD card for input/output calibration.
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 | ** Project : CLC Brew Panel |
montgojj | 11:f6a146b62579 | 4 | ** Engineers : Justin Montgomery and Cortland Ratliff |
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 |
montgojj | 11:f6a146b62579 | 9 | ** Abstract : This program was written for a marketing panel called the Brew Panel. The purpose of this program is to control two ITVs that |
montgojj | 11:f6a146b62579 | 10 | ** regulate two different pressure lines that control two diaphragm pumps. The two pumps then pump and generate a flow rate for |
montgojj | 11:f6a146b62579 | 11 | ** two different colored liquids. Another purpose of this program is to also read back feedback from the two ITVs, a PF3W flow meter, |
montgojj | 11:f6a146b62579 | 12 | ** and a PSE pressure sensor. The program also interfaces with an HMI controlled by a FT810 LCD driver. The interface controls the hardware |
montgojj | 11:f6a146b62579 | 13 | ** and displays graphics. This program was designed for the Teensy and to control the Closed Loop Controller Brew Panel prototype board. |
montgojj | 13:8f23699b9c9f | 14 | ** |
montgojj | 11:f6a146b62579 | 15 | ** Notes : The limitations of the VERTEX2II program forced us to create a bandage when trying to write images past pixel 511. The range of VERTEX2II is 0 to 511 |
montgojj | 13:8f23699b9c9f | 16 | ** so in order to draw an image further away we had to use the translate command. |
cratliff | 6:f698d8ba4cd6 | 17 | ** |
montgojj | 11:f6a146b62579 | 18 | ** Todo : |
cratliff | 5:e2e04cb5eada | 19 | */ |
montgojj | 11:f6a146b62579 | 20 | #include "mbed.h" // library #includes |
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 | |
montgojj | 11:f6a146b62579 | 28 | #define K20 // used to simplify defining for different microcontroller platforms |
montgojj | 14:52a03b4a0365 | 29 | //#define Program_Button // used add easy way to reprogram without using the phsyical button. |
montgojj | 11:f6a146b62579 | 30 | //#define Debug_Swipe // reads back touch data in real time on the screen |
cratliff | 0:aa55c6eb6867 | 31 | |
montgojj | 4:a48fc7a3bda9 | 32 | #ifdef K20 |
montgojj | 11:f6a146b62579 | 33 | FT800 TFT(D11,D12,D13,D9,D8,D14); // create object for the LCD, handles all of the data passing and slave select commands (SPI) |
montgojj | 11:f6a146b62579 | 34 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // create object for the SD card, handles all of the data passing and slave select commands (SPI) |
montgojj | 11:f6a146b62579 | 35 | MCP4725 dac1(D18, D19, MCP4725::ADDRESS_2); // create object for the first DAC board, handles all fo the data addressing (I2C) |
montgojj | 11:f6a146b62579 | 36 | MCP4725 dac2(D18, D19, MCP4725::ADDRESS_3); // create object for the second DAC board, handles all fo the data addressing (I2C) |
montgojj | 4:a48fc7a3bda9 | 37 | |
montgojj | 11:f6a146b62579 | 38 | AnalogIn PSEpressure_raw(A9); // analog 9 pin connected to the PSE input |
montgojj | 11:f6a146b62579 | 39 | AnalogIn PFWflowrate_raw(A8); // analog 9 pin connected to the PFW input |
montgojj | 11:f6a146b62579 | 40 | AnalogIn ITVpressure1_feedback_raw(A3); // analog 9 pin connected to the ITV1 input |
montgojj | 11:f6a146b62579 | 41 | AnalogIn ITVpressure2_feedback_raw(A2); // analog 9 pin connected to the ITV2 input |
montgojj | 11:f6a146b62579 | 42 | DigitalIn card_present(D7); // analog 9 pin connected to the SD card detect pin input |
cratliff | 0:aa55c6eb6867 | 43 | #endif |
cratliff | 0:aa55c6eb6867 | 44 | |
montgojj | 11:f6a146b62579 | 45 | // global variables |
montgojj | 11:f6a146b62579 | 46 | unsigned int CalVal0, CalVal1, CalVal2, CalVal3, CalVal4, curX, curY, pasX, pasY; // touchscreen calibration data and swiping variables. |
montgojj | 11:f6a146b62579 | 47 | float PSEpressure, PFWflowrate = 0.0; // variables to store data used in calculating flow and pressure |
montgojj | 11:f6a146b62579 | 48 | float ITVpressure1_feedback, ITVpressure2_feedback, ITVpressure1_user_input, ITVpressure2_user_input = 0.0; // variables to store data thats used in calculating the output and input pressure for the ITVs |
montgojj | 13:8f23699b9c9f | 49 | float ITVpressure1_input_scaled, ITVpressure2_input_scaled = 0.0; |
montgojj | 11:f6a146b62579 | 50 | float ITV1_pre, ITV1_fcal, ITV2_pre, ITV2_fcal, PFW_pre, PFW_fcal, PSE_pre, PSE_fcal = 0.0; // moving average filter variables |
montgojj | 13:8f23699b9c9f | 51 | static float avg1 = 0.15; // filter value for new samples |
montgojj | 13:8f23699b9c9f | 52 | static float avg2 = 0.85; // filter value previous samples |
montgojj | 11:f6a146b62579 | 53 | uint16_t ITVpressure1_input_raw, ITVpressure2_input_raw = 0; // stores the raw 16 bit reads for the ITVs |
montgojj | 11:f6a146b62579 | 54 | int16_t velocity, distance, touched, location, paslocation; // variables to handle the swiping and multiple pages |
montgojj | 11:f6a146b62579 | 55 | char buffer[50]; // temporary buffer for writing characters to the LCD |
montgojj | 11:f6a146b62579 | 56 | uint8_t tcal[24]; // touch screen Calibration |
montgojj | 11:f6a146b62579 | 57 | char tstr[40]; // temp location for Touch Screen Calibration |
montgojj | 11:f6a146b62579 | 58 | ft_int16_t x_size, y_size; // stores size data for loaded jpegs, not currently used |
montgojj | 11:f6a146b62579 | 59 | unsigned int err[7] = {0,0,0,0,0,0,0}; // array to store returned values from Load_jpg function, possible future error handling |
montgojj | 15:25cbc8345067 | 60 | /****************************************************************************************/ |
montgojj | 15:25cbc8345067 | 61 | /* The DeviceCal array stores the external hardware calibration data. */ |
montgojj | 15:25cbc8345067 | 62 | /* The array format is as follows: */ |
montgojj | 15:25cbc8345067 | 63 | /* DeviceCal[0] = 5V input from device 1, DeviceCal[1] = 1V input from device 1 */ |
montgojj | 15:25cbc8345067 | 64 | /* DeviceCal[2] = 20mA input from device 2, DeviceCal[3] = 4mA input from device 2 */ |
montgojj | 15:25cbc8345067 | 65 | /* DeviceCal[4] = 5V input from device 3, DeviceCal[5] = 1V input from device 3 */ |
montgojj | 15:25cbc8345067 | 66 | /* DeviceCal[6] = 20mA output from device 3, DeviceCal[7] = 4mA output from device 3 */ |
montgojj | 15:25cbc8345067 | 67 | /* DeviceCal[8] = 5V input from device 4, DeviceCal[9] = 1V input from device 4 */ |
montgojj | 15:25cbc8345067 | 68 | /* DeviceCal[10] = 20mA output from device 4, DeviceCal[11] = 4mA output from device 4 */ |
montgojj | 15:25cbc8345067 | 69 | /****************************************************************************************/ |
montgojj | 15:25cbc8345067 | 70 | uint16_t DeviceCal[12]; // array that stores calibraton data |
montgojj | 15:25cbc8345067 | 71 | unsigned char DeviceCal_buffer[50]; // buffer to store char data read back from SD card before it's converted into an integer |
cratliff | 5:e2e04cb5eada | 72 | |
montgojj | 11:f6a146b62579 | 73 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 74 | /* Serves as the bootup screen as the images are loaded from the SD card */ |
montgojj | 11:f6a146b62579 | 75 | /* A spinner shows the delay */ |
montgojj | 11:f6a146b62579 | 76 | /****************************************************************************/ |
cratliff | 0:aa55c6eb6867 | 77 | ft_void_t Start_Screen(ft_char8_t *str) |
cratliff | 0:aa55c6eb6867 | 78 | { |
montgojj | 11:f6a146b62579 | 79 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 80 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
montgojj | 11:f6a146b62579 | 81 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 13:8f23699b9c9f | 82 | |
montgojj | 11:f6a146b62579 | 83 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format |
montgojj | 4:a48fc7a3bda9 | 84 | TFT.DL(BEGIN(LINES)); |
montgojj | 4:a48fc7a3bda9 | 85 | TFT.DL(LINE_WIDTH(8 * 16)); |
montgojj | 4:a48fc7a3bda9 | 86 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 87 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 88 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 89 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 90 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 91 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 92 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 93 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 11:f6a146b62579 | 94 | TFT.DL(END()); |
cratliff | 5:e2e04cb5eada | 95 | |
montgojj | 11:f6a146b62579 | 96 | TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 97 | TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel"); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 98 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // change current color |
montgojj | 11:f6a146b62579 | 99 | TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner |
cratliff | 0:aa55c6eb6867 | 100 | |
montgojj | 11:f6a146b62579 | 101 | TFT.DL(DISPLAY()); // Display the image |
montgojj | 11:f6a146b62579 | 102 | TFT.Swap(); // Swap the current display list |
montgojj | 11:f6a146b62579 | 103 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
montgojj | 11:f6a146b62579 | 104 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
montgojj | 11:f6a146b62579 | 105 | TFT.Sleep(1000); // Wait 1s to show |
cratliff | 0:aa55c6eb6867 | 106 | } |
cratliff | 0:aa55c6eb6867 | 107 | |
montgojj | 11:f6a146b62579 | 108 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 109 | /* Main screen function that writes the SD images and external hardware */ |
montgojj | 11:f6a146b62579 | 110 | /* data to the screen, also controls the ITV pressure */ |
montgojj | 11:f6a146b62579 | 111 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 112 | void Main_Screen() |
cratliff | 0:aa55c6eb6867 | 113 | { |
montgojj | 11:f6a146b62579 | 114 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 115 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
montgojj | 11:f6a146b62579 | 116 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 11:f6a146b62579 | 117 | #ifdef Program_Button |
montgojj | 11:f6a146b62579 | 118 | TFT.DL(TAG(200)); // assign TAG value 200 |
montgojj | 11:f6a146b62579 | 119 | TFT.Button(710, 10, 76, 22, 26, 0, "Reprogram"); // generate reprogram button, only works for teensy |
montgojj | 11:f6a146b62579 | 120 | TFT.DL(TAG(3)); |
montgojj | 11:f6a146b62579 | 121 | #endif |
montgojj | 11:f6a146b62579 | 122 | |
montgojj | 4:a48fc7a3bda9 | 123 | /***************************************************************************************************/ |
montgojj | 4:a48fc7a3bda9 | 124 | /*Border Creation*/ |
montgojj | 11:f6a146b62579 | 125 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format |
montgojj | 4:a48fc7a3bda9 | 126 | TFT.DL(BEGIN(LINES)); |
montgojj | 4:a48fc7a3bda9 | 127 | TFT.DL(LINE_WIDTH(8 * 16)); |
montgojj | 4:a48fc7a3bda9 | 128 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 129 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 130 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 131 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 132 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 133 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 134 | TFT.DL(VERTEX2F(0*16,479*16)); |
cratliff | 5:e2e04cb5eada | 135 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 136 | TFT.DL(END()); |
montgojj | 4:a48fc7a3bda9 | 137 | /***************************************************************************************************/ |
cratliff | 0:aa55c6eb6867 | 138 | |
montgojj | 4:a48fc7a3bda9 | 139 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 140 | /*ITV 1 Screen Display*/ |
montgojj | 11:f6a146b62579 | 141 | TFT.DL(COLOR_RGB(255,255,255)); // set background to white |
montgojj | 11:f6a146b62579 | 142 | TFT.DL(VERTEX_TRANSLATE_X(location* 16)); // page 1 |
montgojj | 11:f6a146b62579 | 143 | |
montgojj | 11:f6a146b62579 | 144 | TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the first screens images |
montgojj | 11:f6a146b62579 | 145 | TFT.DL(VERTEX2II(265,50,0,0)); // draw logo image with bit handle 0 |
montgojj | 11:f6a146b62579 | 146 | TFT.DL(VERTEX2II(75,50,1,0)); // draw ITV_1 image with bit handle 1 |
montgojj | 11:f6a146b62579 | 147 | TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)); // translate right 149 pixels for third image, location controls what page the screen is on |
montgojj | 11:f6a146b62579 | 148 | TFT.DL(VERTEX2II(511,50,2,0)); // draw ITV_2 image with bit handle 2 |
montgojj | 11:f6a146b62579 | 149 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)); // translate back to prevent the remaining commands from also being translated |
montgojj | 4:a48fc7a3bda9 | 150 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 151 | |
montgojj | 11:f6a146b62579 | 152 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for the text |
montgojj | 11:f6a146b62579 | 153 | TFT.Text(265, 200, 31, 0, "ITV 1 Pressure"); // title block for screen |
montgojj | 11:f6a146b62579 | 154 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 13:8f23699b9c9f | 155 | TFT.DL(VERTEX2F(300*16,265*16)); |
montgojj | 8:886908a6127c | 156 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 157 | TFT.DL(END()); |
montgojj | 15:25cbc8345067 | 158 | ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - DeviceCal[5]) * (70.0) / (DeviceCal[4] - DeviceCal[5]) + 0; // calibration and scaling math for the ITV feedback |
montgojj | 13:8f23699b9c9f | 159 | ITV1_fcal = ITVpressure1_feedback; // moving average filter |
montgojj | 13:8f23699b9c9f | 160 | ITV1_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 161 | ITV1_fcal += ITV1_pre * avg2; |
montgojj | 9:bf787d41b645 | 162 | ITV1_pre = ITV1_fcal; |
montgojj | 11:f6a146b62579 | 163 | ITVpressure1_feedback = ITV1_fcal; // store the filtered value in the feedback variable |
montgojj | 11:f6a146b62579 | 164 | TFT.DL(COLOR_RGB(255,255,255)); // set color to white for the text |
montgojj | 11:f6a146b62579 | 165 | sprintf(buffer, "%.1f", ITVpressure1_feedback); // write the feedback pressure to the screen |
montgojj | 11:f6a146b62579 | 166 | TFT.Text(325,275,31,0,buffer); |
montgojj | 11:f6a146b62579 | 167 | TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen |
montgojj | 13:8f23699b9c9f | 168 | |
montgojj | 11:f6a146b62579 | 169 | TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format |
montgojj | 11:f6a146b62579 | 170 | TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 171 | TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 172 | TFT.DL(TAG(1)); // assign TAG value 1 |
montgojj | 11:f6a146b62579 | 173 | TFT.Slider(225,375,350,30,0,ITVpressure1_user_input,2355); // generate slider that controls the output pressure of ITV1 |
montgojj | 11:f6a146b62579 | 174 | TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors |
montgojj | 4:a48fc7a3bda9 | 175 | /***************************************************************************************************/ |
cratliff | 5:e2e04cb5eada | 176 | |
montgojj | 4:a48fc7a3bda9 | 177 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 178 | /*ITV 2 and PF3W Screen Display*/ |
montgojj | 11:f6a146b62579 | 179 | TFT.DL(COLOR_RGB(255,255,255)); // set background color to white |
montgojj | 11:f6a146b62579 | 180 | TFT.DL(VERTEX_TRANSLATE_X(location* 16)+12800); // translate screen writes by 12800 which is a 1/16th pixel format, this creates page 2 of the screen |
montgojj | 13:8f23699b9c9f | 181 | TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the second screens images |
montgojj | 11:f6a146b62579 | 182 | TFT.DL(VERTEX2II(30,75,3,0)); // write PF3W_1 image to the LCD |
montgojj | 11:f6a146b62579 | 183 | TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)+12800); // translate right 149 pixels for third image, location controls what page the screen is on |
montgojj | 11:f6a146b62579 | 184 | TFT.DL(VERTEX2II(411,75,4,0)); // write PF3W_2 image to the LCD |
montgojj | 11:f6a146b62579 | 185 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+12800); // translate back to 0 for remaining screen writes |
montgojj | 8:886908a6127c | 186 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 187 | |
montgojj | 11:f6a146b62579 | 188 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue, RGB format |
montgojj | 11:f6a146b62579 | 189 | TFT.Text(265, 200, 31, 0, "ITV 2 Pressure"); // write title block to screen |
montgojj | 11:f6a146b62579 | 190 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 191 | TFT.DL(VERTEX2F(300*16,265*16)); |
montgojj | 8:886908a6127c | 192 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 193 | TFT.DL(END()); |
montgojj | 13:8f23699b9c9f | 194 | |
montgojj | 15:25cbc8345067 | 195 | ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- DeviceCal[9]) * (70.0) / (DeviceCal[8] - DeviceCal[9]) + 0; // calibration and scaling math for the ITV feedback |
montgojj | 11:f6a146b62579 | 196 | ITV2_fcal = ITVpressure2_feedback; // moving average filter |
montgojj | 9:bf787d41b645 | 197 | ITV2_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 198 | ITV2_fcal += ITV2_pre * avg2; |
montgojj | 9:bf787d41b645 | 199 | ITV2_pre = ITV2_fcal; |
montgojj | 11:f6a146b62579 | 200 | ITVpressure2_feedback = ITV2_fcal; // store filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 201 | TFT.DL(COLOR_RGB(255,255,255)); // set color for text to white |
montgojj | 11:f6a146b62579 | 202 | sprintf(buffer, "%.1f", ITVpressure2_feedback); // write feedback to screen in white |
montgojj | 11:f6a146b62579 | 203 | TFT.Text(325,275,31,0,buffer); |
montgojj | 13:8f23699b9c9f | 204 | TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen |
montgojj | 11:f6a146b62579 | 205 | TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format |
montgojj | 11:f6a146b62579 | 206 | TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 207 | TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 208 | TFT.DL(TAG(2)); // assign tag 2 to slider for ITV2 |
montgojj | 11:f6a146b62579 | 209 | TFT.Slider(225,375,350,30,0,ITVpressure2_user_input,2387); // generate slider that controls the output pressure of ITV2 |
montgojj | 11:f6a146b62579 | 210 | TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors |
montgojj | 11:f6a146b62579 | 211 | |
montgojj | 11:f6a146b62579 | 212 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for text |
montgojj | 11:f6a146b62579 | 213 | TFT.Text(250, 20, 31, 0, "PF3W Flow Rate"); // write title block to screen |
montgojj | 11:f6a146b62579 | 214 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 215 | TFT.DL(VERTEX2F(300*16,85*16)); |
montgojj | 8:886908a6127c | 216 | TFT.DL(VERTEX2F(505*16,150*16)); |
montgojj | 15:25cbc8345067 | 217 | PFWflowrate = (PFWflowrate_raw.read_u16() - DeviceCal[3]) * (40.0) / (DeviceCal[2] - DeviceCal[3]) + 0; // calibration and scaling math for the PFW feedback |
montgojj | 11:f6a146b62579 | 218 | PFW_fcal = PFWflowrate; // moving average filter |
montgojj | 9:bf787d41b645 | 219 | PFW_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 220 | PFW_fcal += PFW_pre * avg2; |
montgojj | 9:bf787d41b645 | 221 | PFW_pre = PFW_fcal; |
montgojj | 11:f6a146b62579 | 222 | PFWflowrate = PFW_fcal; // store filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 223 | TFT.DL(COLOR_RGB(255,255,255)); // set text feedback text color to white |
montgojj | 11:f6a146b62579 | 224 | sprintf(buffer, "%.1f", PFWflowrate); // write feedback to LCD |
montgojj | 14:52a03b4a0365 | 225 | TFT.Text(305,95,31,0,buffer); |
montgojj | 11:f6a146b62579 | 226 | TFT.Text(385, 95, 31, 0, " L/min"); // write units to LCD |
montgojj | 8:886908a6127c | 227 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 228 | |
montgojj | 8:886908a6127c | 229 | /***************************************************************************************************/ |
montgojj | 13:8f23699b9c9f | 230 | /*PSE Screen Display*/ |
montgojj | 11:f6a146b62579 | 231 | TFT.DL(COLOR_RGB(255,255,255)); // set the background for page 3 to white |
montgojj | 11:f6a146b62579 | 232 | TFT.DL(VERTEX_TRANSLATE_X(location* 16)+25600); // translate screen writes by 25600 which is a 1/16th pixel format, this creates page 3 of the screen |
montgojj | 11:f6a146b62579 | 233 | TFT.DL(BEGIN(BITMAPS)); // create bitmap to draw images on LCD |
montgojj | 11:f6a146b62579 | 234 | TFT.DL(VERTEX2II(265,50,0,0)); // wrtie the SMC logo to the screen |
montgojj | 11:f6a146b62579 | 235 | TFT.DL(VERTEX2II(75,50,5,0)); // write PSE_1 image to the screen |
montgojj | 11:f6a146b62579 | 236 | TFT.DL(VERTEX_TRANSLATE_X((99+location)*16)+25600); // translate right by 99 pixels for the next image write |
montgojj | 11:f6a146b62579 | 237 | TFT.DL(VERTEX2II(511,85,6,0)); // write PSE_2 image to the screen |
montgojj | 11:f6a146b62579 | 238 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+25600); // translate back to pixel 0 for the remaining screen writes |
montgojj | 8:886908a6127c | 239 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 240 | |
montgojj | 11:f6a146b62579 | 241 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue |
montgojj | 11:f6a146b62579 | 242 | TFT.Text(280, 200, 31, 0, "PSE Pressure"); // write title block to screen |
montgojj | 11:f6a146b62579 | 243 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 244 | TFT.DL(VERTEX2F(295*16,265*16)); |
montgojj | 8:886908a6127c | 245 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 246 | TFT.DL(END()); |
montgojj | 15:25cbc8345067 | 247 | PSEpressure = ((PSEpressure_raw.read_u16() - DeviceCal[1]) * (1.0) / (DeviceCal[0] - DeviceCal[1]) + 0)*145.0377; // calibration and scaling math for the PSE feedback |
montgojj | 11:f6a146b62579 | 248 | PSE_fcal = PSEpressure; // moving average filter |
montgojj | 9:bf787d41b645 | 249 | PSE_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 250 | PSE_fcal += PSE_pre * avg2; |
montgojj | 9:bf787d41b645 | 251 | PSE_pre = PSE_fcal; |
montgojj | 11:f6a146b62579 | 252 | PSEpressure = PSE_fcal; // store the filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 253 | TFT.DL(COLOR_RGB(255,255,255)); // set text color to white |
montgojj | 14:52a03b4a0365 | 254 | sprintf(buffer, "%.1f", PSEpressure); // write feedback to screen |
montgojj | 8:886908a6127c | 255 | TFT.Text(300,275,31,0,buffer); |
montgojj | 14:52a03b4a0365 | 256 | TFT.Text(405, 275, 31, 0, " PSI"); // write units to LCD |
montgojj | 8:886908a6127c | 257 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 258 | |
montgojj | 11:f6a146b62579 | 259 | #ifdef Debug_Swipe // writes touch data to screen |
montgojj | 11:f6a146b62579 | 260 | TFT.DL(COLOR_RGB(0,0,0)); // set text color to black |
montgojj | 11:f6a146b62579 | 261 | TFT.Number(20, 450, 26, 0, distance); // write distance value to screen |
montgojj | 11:f6a146b62579 | 262 | TFT.Number(80, 450, 26, 0, velocity); // write velocity to screen |
cratliff | 7:e525bfa17136 | 263 | #endif |
montgojj | 13:8f23699b9c9f | 264 | |
montgojj | 11:f6a146b62579 | 265 | #ifdef Debug_Touch_File // debug the touch up load |
montgojj | 11:f6a146b62579 | 266 | TFT.DL(COLOR_RGB(0,0,0)); // set text color to black |
montgojj | 11:f6a146b62579 | 267 | int j; // loop counter |
montgojj | 11:f6a146b62579 | 268 | for (j = 0; j < 24; j++) { // write file data to screen |
montgojj | 11:f6a146b62579 | 269 | TFT.Number(j*30+20, 450, 26, 0, tcal[j]); |
cratliff | 5:e2e04cb5eada | 270 | } |
cratliff | 5:e2e04cb5eada | 271 | #endif |
cratliff | 5:e2e04cb5eada | 272 | |
montgojj | 11:f6a146b62579 | 273 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 274 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 275 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 276 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
cratliff | 0:aa55c6eb6867 | 277 | } |
cratliff | 0:aa55c6eb6867 | 278 | |
montgojj | 11:f6a146b62579 | 279 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 280 | /* This function displays the error screen */ |
montgojj | 11:f6a146b62579 | 281 | /* the function causes the screen to flash yellow and writes text to the LCD*/ |
montgojj | 11:f6a146b62579 | 282 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 283 | void error_screen(ft_char8_t *str1, ft_char8_t *str2) |
cratliff | 5:e2e04cb5eada | 284 | { |
montgojj | 4:a48fc7a3bda9 | 285 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 286 | TFT.DL(CLEAR_COLOR_RGB(255,242,0)); // clear the screen and set the background to yellow |
montgojj | 4:a48fc7a3bda9 | 287 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 4:a48fc7a3bda9 | 288 | TFT.DL(COLOR_RGB(0,0,0)); |
montgojj | 13:8f23699b9c9f | 289 | TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, str1); // draw Text with font 31 |
montgojj | 13:8f23699b9c9f | 290 | TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, str2); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 291 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 292 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 293 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 294 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
montgojj | 4:a48fc7a3bda9 | 295 | TFT.Sleep(1000); |
cratliff | 5:e2e04cb5eada | 296 | |
montgojj | 11:f6a146b62579 | 297 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 298 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set clear color to white |
montgojj | 11:f6a146b62579 | 299 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer; |
montgojj | 4:a48fc7a3bda9 | 300 | TFT.DL(COLOR_RGB(0,0,0)); |
montgojj | 13:8f23699b9c9f | 301 | TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, str1); // draw Text with font 31 |
montgojj | 13:8f23699b9c9f | 302 | TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, str2); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 303 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 304 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 305 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 306 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
montgojj | 4:a48fc7a3bda9 | 307 | TFT.Sleep(1000); |
montgojj | 4:a48fc7a3bda9 | 308 | } |
cratliff | 0:aa55c6eb6867 | 309 | |
montgojj | 11:f6a146b62579 | 310 | /****************************************************************************/ |
montgojj | 15:25cbc8345067 | 311 | /* Checks for an SD card and reads/writes the calibration data */ |
montgojj | 11:f6a146b62579 | 312 | /* from the SD card */ |
montgojj | 11:f6a146b62579 | 313 | /****************************************************************************/ |
montgojj | 15:25cbc8345067 | 314 | void read_Calibration() |
cratliff | 5:e2e04cb5eada | 315 | { |
montgojj | 15:25cbc8345067 | 316 | int i = 0; |
montgojj | 15:25cbc8345067 | 317 | int k = -4; // loop counter |
montgojj | 11:f6a146b62579 | 318 | while(card_present.read()) { // checks for SD card, if not present hold program until a SD card is inserted |
montgojj | 13:8f23699b9c9f | 319 | error_screen("Error!","Insert SD card!"); // write error screen to LCD |
montgojj | 11:f6a146b62579 | 320 | } |
montgojj | 15:25cbc8345067 | 321 | FILE *fp= fopen("/sd/TCal/TCalData.txt", "r"); |
montgojj | 11:f6a146b62579 | 322 | if(!fp) { // could not open file for read so generate data then store on SD card |
montgojj | 11:f6a146b62579 | 323 | TFT.Calibrate(); // calibrate the touch screen |
montgojj | 11:f6a146b62579 | 324 | TFT.read_calibrate(tcal); // read in cal data from screen |
montgojj | 11:f6a146b62579 | 325 | mkdir("/sd/TCal", 0777); // open file for to save calibration data |
montgojj | 4:a48fc7a3bda9 | 326 | FILE *fp = fopen("/sd/TCal/TCalData.txt", "w"); |
montgojj | 11:f6a146b62579 | 327 | for (i = 0; i < 25; i++) { // save integers one at a time to the file |
cratliff | 5:e2e04cb5eada | 328 | fprintf(fp, "%c", tcal[i] ); |
cratliff | 5:e2e04cb5eada | 329 | } |
montgojj | 11:f6a146b62579 | 330 | } else { // file found, read in data |
montgojj | 4:a48fc7a3bda9 | 331 | fread(tstr,24,1,fp); |
montgojj | 11:f6a146b62579 | 332 | for (i = 0; i < 24; i++) { // convert from int to char |
montgojj | 4:a48fc7a3bda9 | 333 | tcal[i] = tstr[i]; |
montgojj | 4:a48fc7a3bda9 | 334 | } |
montgojj | 11:f6a146b62579 | 335 | TFT.write_calibrate(tcal); // write cal data to screen |
montgojj | 4:a48fc7a3bda9 | 336 | } |
montgojj | 15:25cbc8345067 | 337 | fclose(fp); // close SD card file |
montgojj | 15:25cbc8345067 | 338 | |
montgojj | 15:25cbc8345067 | 339 | FILE *fp2= fopen("/sd/DeviceCalData.txt", "r"); // read DeviceCalData.txt where the external hardware calibration data where is integer is stored in 4 sets of 4 bit chars. |
montgojj | 15:25cbc8345067 | 340 | fread(DeviceCal_buffer,48,1,fp2); // read the data |
montgojj | 15:25cbc8345067 | 341 | for (i = 0; i < 12; i++) { // convert from int to char |
montgojj | 15:25cbc8345067 | 342 | DeviceCal[i] = (uint16_t)((DeviceCal_buffer[4+k]<<12) | (DeviceCal_buffer[k+5]<<8) | (DeviceCal_buffer[6+k]<<4) | (DeviceCal_buffer[k+7]<<0)); // take 4 sets of 4 bit chars and rebuild it into 1 integer |
montgojj | 15:25cbc8345067 | 343 | k=k+4; // increment loop |
montgojj | 15:25cbc8345067 | 344 | } |
montgojj | 15:25cbc8345067 | 345 | fclose(fp2); // close file |
montgojj | 8:886908a6127c | 346 | } |
cratliff | 0:aa55c6eb6867 | 347 | |
montgojj | 11:f6a146b62579 | 348 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 349 | /* Loads all of the images from the SD card and assigns them bitmap handles */ |
montgojj | 11:f6a146b62579 | 350 | /****************************************************************************/ |
montgojj | 8:886908a6127c | 351 | void initialize_Images() |
montgojj | 8:886908a6127c | 352 | { |
montgojj | 14:52a03b4a0365 | 353 | while(card_present.read()) { // checks for SD card, if not present hold program until a SD card is inserted |
montgojj | 14:52a03b4a0365 | 354 | error_screen("Error!","Insert SD card!"); // write error screen to LCD |
montgojj | 14:52a03b4a0365 | 355 | } |
montgojj | 11:f6a146b62579 | 356 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 357 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 8:886908a6127c | 358 | |
montgojj | 11:f6a146b62579 | 359 | TFT.DL(BITMAP_HANDLE(0)); // assign bitmap handle 0 to logo.jpg |
montgojj | 11:f6a146b62579 | 360 | err[0] = TFT.Load_jpg("/sd/Logo.jpg",& x_size,& y_size, 0); // load the jpg and write it to address 0 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 361 | TFT.DL(BITMAP_HANDLE(1)); // assign bitmap handle 1 to ITV_1.jpg |
montgojj | 11:f6a146b62579 | 362 | err[1] = TFT.Load_jpg("/sd/ITV_1.jpg",& x_size,& y_size, 45000); // load the jpg and write it to address 45,000 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 363 | TFT.DL(BITMAP_HANDLE(2)); // assign bitmap handle 2 to ITV_2.jpg |
montgojj | 11:f6a146b62579 | 364 | err[2] = TFT.Load_jpg("/sd/ITV_2.jpg",& x_size,& y_size, 60000); // load the jpg and write it to address 60,000 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 365 | TFT.DL(BITMAP_HANDLE(3)); // assign bitmap handle 3 to PF3W_1.jpg |
montgojj | 11:f6a146b62579 | 366 | err[3] = TFT.Load_jpg("/sd/PF3W_1.jpg",& x_size,& y_size, 85000); // load the jpg and write it to address 85,000 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 367 | TFT.DL(BITMAP_HANDLE(4)); // assign bitmap handle 4 to PF3W_2.jpg |
montgojj | 11:f6a146b62579 | 368 | err[4] = TFT.Load_jpg("/sd/PF3W_2.jpg",& x_size,& y_size, 150000); // load the jpg and write it to address 150,000 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 369 | TFT.DL(BITMAP_HANDLE(5)); // assign bitmap handle 5 to PSE_1.jpg |
montgojj | 11:f6a146b62579 | 370 | err[5] = TFT.Load_jpg("/sd/PSE_1.jpg",& x_size,& y_size, 230000); // load the jpg and write it to address 230,000 in the FT810 RAM and store error result in array |
montgojj | 11:f6a146b62579 | 371 | TFT.DL(BITMAP_HANDLE(6)); // assign bitmap handle 6 to PSE_2.jpg |
montgojj | 11:f6a146b62579 | 372 | err[6] = TFT.Load_jpg("/sd/PSE_2.jpg",& x_size,& y_size, 260000); // load the jpg and write it to address 260,000 in the FT810 RAM and store error result in array |
montgojj | 8:886908a6127c | 373 | |
montgojj | 11:f6a146b62579 | 374 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 375 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 376 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 8:886908a6127c | 377 | TFT.WaitCmdfifo_empty(); |
montgojj | 8:886908a6127c | 378 | } |
montgojj | 8:886908a6127c | 379 | |
montgojj | 11:f6a146b62579 | 380 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 381 | /* Function that checks for a inadequate supply pressure and displays */ |
montgojj | 13:8f23699b9c9f | 382 | /* an error */ |
montgojj | 13:8f23699b9c9f | 383 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 384 | void SupplyPressure_Check(float check1, float check2) |
montgojj | 13:8f23699b9c9f | 385 | { |
montgojj | 15:25cbc8345067 | 386 | while(((PSEpressure) < (check1 - 10)) || ((PSEpressure) < (check2 - 10))) { |
montgojj | 13:8f23699b9c9f | 387 | dac1.write_u12(0); // turn off ITVs |
montgojj | 13:8f23699b9c9f | 388 | dac2.write_u12(0); |
montgojj | 13:8f23699b9c9f | 389 | error_screen("Supply pressure too low!", ""); // display error |
montgojj | 15:25cbc8345067 | 390 | PSEpressure = ((PSEpressure_raw.read_u16() - DeviceCal[1]) * (1.0) / (DeviceCal[0] - DeviceCal[1]) + 0)*145.0377; // calibration and scaling math for the PSE feedback |
montgojj | 13:8f23699b9c9f | 391 | } |
montgojj | 13:8f23699b9c9f | 392 | dac1.write_u12(ITVpressure1_input_raw); // restore ITV pressure |
montgojj | 13:8f23699b9c9f | 393 | dac2.write_u12(ITVpressure2_input_raw); |
montgojj | 13:8f23699b9c9f | 394 | } |
montgojj | 13:8f23699b9c9f | 395 | |
montgojj | 13:8f23699b9c9f | 396 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 397 | /* Main function that tracks all of the touchscreen data and updates the */ |
montgojj | 11:f6a146b62579 | 398 | /* screen accordingly */ |
montgojj | 11:f6a146b62579 | 399 | /****************************************************************************/ |
montgojj | 8:886908a6127c | 400 | int main() |
montgojj | 8:886908a6127c | 401 | { |
montgojj | 11:f6a146b62579 | 402 | dac1.wakeup(); // activate DAC boards |
montgojj | 8:886908a6127c | 403 | dac2.wakeup(); |
montgojj | 11:f6a146b62579 | 404 | dac1.write_u12(0); // the natural DAC output value is 50% of its maximum value |
montgojj | 11:f6a146b62579 | 405 | dac2.write_u12(0); // the program has to immediately write a 0 to the DAC to turn off the outputs |
montgojj | 11:f6a146b62579 | 406 | ft_uint32_t TrackRegisterVal = 0; // touch track variable |
montgojj | 8:886908a6127c | 407 | |
montgojj | 11:f6a146b62579 | 408 | TFT.MemWrite(REG_ROTATE, 1); // rotate screen |
montgojj | 8:886908a6127c | 409 | TFT.Rotate(1); |
montgojj | 8:886908a6127c | 410 | |
montgojj | 13:8f23699b9c9f | 411 | SupplyPressure_Check(0,0); // check for any supply pressure |
montgojj | 15:25cbc8345067 | 412 | read_Calibration(); // load touchscreen calibration data |
montgojj | 11:f6a146b62579 | 413 | initialize_Images(); // load and initialize images |
montgojj | 13:8f23699b9c9f | 414 | Start_Screen("Starting..."); // show start screen |
montgojj | 13:8f23699b9c9f | 415 | |
montgojj | 11:f6a146b62579 | 416 | TFT.Track(200, 400, 375, 50, 1); // track sliders |
montgojj | 10:c56b7ca4805f | 417 | TFT.Track(200, 400, 375, 50, 2); |
montgojj | 11:f6a146b62579 | 418 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 419 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
montgojj | 13:8f23699b9c9f | 420 | |
cratliff | 0:aa55c6eb6867 | 421 | while(1) { |
montgojj | 15:25cbc8345067 | 422 | Main_Screen(); // paint new screen |
montgojj | 13:8f23699b9c9f | 423 | curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff; // get the current touch screen position |
montgojj | 13:8f23699b9c9f | 424 | curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16; // if not touch the results are 0x8000 for x and y |
montgojj | 11:f6a146b62579 | 425 | ft_uint8_t tagval = 0; // initialize return tag value |
montgojj | 11:f6a146b62579 | 426 | TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched |
montgojj | 11:f6a146b62579 | 427 | tagval = TrackRegisterVal & 0xff; // store return tag value |
montgojj | 11:f6a146b62579 | 428 | // check what tag was touched |
montgojj | 13:8f23699b9c9f | 429 | if(1 == tagval) { // tag value for ITV1 slider touch |
montgojj | 11:f6a146b62579 | 430 | ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095); // calculate new slider value so that the slider updates graphically |
montgojj | 11:f6a146b62579 | 431 | ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590; // calculate raw 12 bit input number, includes calibration number to never go above 20mA |
montgojj | 11:f6a146b62579 | 432 | dac1.write_u12(ITVpressure1_input_raw); // write 12 bit number to DAC to fire the ITV |
montgojj | 13:8f23699b9c9f | 433 | ITVpressure1_input_scaled = (ITVpressure1_input_raw-590)*(70.0)/(4095)+0; |
montgojj | 13:8f23699b9c9f | 434 | } |
montgojj | 13:8f23699b9c9f | 435 | |
montgojj | 11:f6a146b62579 | 436 | else if(2 == tagval) { // tag value for ITV2 slider touch |
montgojj | 11:f6a146b62579 | 437 | ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095); // calculate new slider value so that the slider updates graphically |
montgojj | 11:f6a146b62579 | 438 | ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585; // calculate raw 12 bit input number, includes calibration number to never go above 20mA |
montgojj | 11:f6a146b62579 | 439 | dac2.write_u12(ITVpressure2_input_raw); // write 12 bit number to DAC to fire the ITV |
montgojj | 13:8f23699b9c9f | 440 | ITVpressure2_input_scaled = (ITVpressure2_input_raw-590)*(70.0)/(4095)+0; |
montgojj | 13:8f23699b9c9f | 441 | } |
montgojj | 13:8f23699b9c9f | 442 | |
montgojj | 13:8f23699b9c9f | 443 | else if (200 == tagval) { // tag for the reprogram button that works by exiting the program which cases the teensy to load the bootloader |
montgojj | 8:886908a6127c | 444 | break; |
montgojj | 13:8f23699b9c9f | 445 | } else if(curX !=0x8000 && touched>0) { // If the sceen is being touched and has been touched before and is not on a tag |
montgojj | 13:8f23699b9c9f | 446 | touched++; // touched is used to determine how long the screen has beed touched for and if it is currently being touched |
montgojj | 13:8f23699b9c9f | 447 | distance = curX - pasX; // find the swipe distance in pixels |
montgojj | 13:8f23699b9c9f | 448 | location = (int16_t)paslocation + distance; // add the distance of the swipe to the location so the screen moves as you swipe |
cratliff | 7:e525bfa17136 | 449 | |
montgojj | 13:8f23699b9c9f | 450 | } else if(curX !=0x8000 && !touched) { // If the screen is being touched but was not the pervious time through the loop then this is the starting point of the swipe |
cratliff | 7:e525bfa17136 | 451 | touched++; |
cratliff | 7:e525bfa17136 | 452 | pasX = curX; |
cratliff | 7:e525bfa17136 | 453 | |
montgojj | 13:8f23699b9c9f | 454 | } else if(curX ==0x8000 && touched) { // Not being touched currently but was touched last time through the loop |
montgojj | 13:8f23699b9c9f | 455 | velocity = distance/touched; // Now that the swipe is finished we can calculate the velocity from the distance and time touched |
montgojj | 13:8f23699b9c9f | 456 | paslocation = location; // Store Location data away |
montgojj | 13:8f23699b9c9f | 457 | touched=0; // Reset for the next touch |
montgojj | 13:8f23699b9c9f | 458 | // If not being touched |
montgojj | 13:8f23699b9c9f | 459 | } else { |
cratliff | 7:e525bfa17136 | 460 | //page 3 location |
montgojj | 14:52a03b4a0365 | 461 | if (location < - 1500 && location > -1700) { // repeat for each page |
cratliff | 7:e525bfa17136 | 462 | if (velocity) { |
cratliff | 7:e525bfa17136 | 463 | velocity = (location + 1600)/-5; |
cratliff | 7:e525bfa17136 | 464 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 465 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 466 | } else { |
cratliff | 7:e525bfa17136 | 467 | location = -1600; |
cratliff | 7:e525bfa17136 | 468 | } |
cratliff | 5:e2e04cb5eada | 469 | |
cratliff | 7:e525bfa17136 | 470 | } |
cratliff | 7:e525bfa17136 | 471 | //page 2 |
cratliff | 7:e525bfa17136 | 472 | else if (location < - 700 && location > -900) { |
cratliff | 7:e525bfa17136 | 473 | if (velocity) { |
cratliff | 7:e525bfa17136 | 474 | velocity = (location + 800)/-5; |
cratliff | 7:e525bfa17136 | 475 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 476 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 477 | } else { |
cratliff | 7:e525bfa17136 | 478 | location = -800; |
cratliff | 7:e525bfa17136 | 479 | } |
cratliff | 7:e525bfa17136 | 480 | //page 1 |
montgojj | 13:8f23699b9c9f | 481 | } else if (location > -100 && location < 100) { |
cratliff | 7:e525bfa17136 | 482 | |
cratliff | 7:e525bfa17136 | 483 | if (velocity) { |
cratliff | 7:e525bfa17136 | 484 | velocity = location/-5; |
cratliff | 7:e525bfa17136 | 485 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 486 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 487 | } else { |
cratliff | 7:e525bfa17136 | 488 | location = 0; |
montgojj | 13:8f23699b9c9f | 489 | |
cratliff | 7:e525bfa17136 | 490 | } |
cratliff | 7:e525bfa17136 | 491 | //no page 0 |
montgojj | 13:8f23699b9c9f | 492 | } else if (location >60) { // Do not allow the page screen to go to -1 page |
montgojj | 13:8f23699b9c9f | 493 | velocity = -10; // Change the velocity to return |
cratliff | 7:e525bfa17136 | 494 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 495 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 496 | //no page 4 |
montgojj | 13:8f23699b9c9f | 497 | } else if (location <-1700) { // Do not allow the page screen to go pass top page |
montgojj | 13:8f23699b9c9f | 498 | velocity = 10; // Change the velocity to return |
cratliff | 7:e525bfa17136 | 499 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 500 | paslocation = location; |
cratliff | 7:e525bfa17136 | 501 | //between pages |
montgojj | 13:8f23699b9c9f | 502 | } else if (velocity) { // if the page is not at edge but has velocity |
cratliff | 7:e525bfa17136 | 503 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 504 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 505 | if (velocity >0) { // acceleration between pages so it does not take forever |
montgojj | 13:8f23699b9c9f | 506 | velocity+= 2; // increase velocity |
montgojj | 13:8f23699b9c9f | 507 | } else { |
cratliff | 7:e525bfa17136 | 508 | velocity-= 2; |
cratliff | 7:e525bfa17136 | 509 | } |
cratliff | 7:e525bfa17136 | 510 | } |
montgojj | 8:886908a6127c | 511 | } |
montgojj | 13:8f23699b9c9f | 512 | SupplyPressure_Check(ITVpressure1_input_scaled, ITVpressure2_input_scaled); // check to see if theres enough supply pressure for the ITVs |
montgojj | 11:f6a146b62579 | 513 | TFT.Sleep(10); // wait 10ms for next time to repaint the screen |
montgojj | 11:f6a146b62579 | 514 | } // end of display loop |
montgojj | 8:886908a6127c | 515 | } |