Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
main.cpp@13:8f23699b9c9f, 2016-04-05 (annotated)
- Committer:
- montgojj
- Date:
- Tue Apr 05 19:56:46 2016 +0000
- Revision:
- 13:8f23699b9c9f
- Parent:
- 11:f6a146b62579
- Child:
- 14:52a03b4a0365
Added Cortland''s comments, added low pressure detect functionality, and cleaned up the code.
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 | 11:f6a146b62579 | 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 |
cratliff | 5:e2e04cb5eada | 60 | |
montgojj | 11:f6a146b62579 | 61 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 62 | /* Serves as the bootup screen as the images are loaded from the SD card */ |
montgojj | 11:f6a146b62579 | 63 | /* A spinner shows the delay */ |
montgojj | 11:f6a146b62579 | 64 | /****************************************************************************/ |
cratliff | 0:aa55c6eb6867 | 65 | ft_void_t Start_Screen(ft_char8_t *str) |
cratliff | 0:aa55c6eb6867 | 66 | { |
montgojj | 11:f6a146b62579 | 67 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 68 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
montgojj | 11:f6a146b62579 | 69 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 13:8f23699b9c9f | 70 | |
montgojj | 11:f6a146b62579 | 71 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format |
montgojj | 4:a48fc7a3bda9 | 72 | TFT.DL(BEGIN(LINES)); |
montgojj | 4:a48fc7a3bda9 | 73 | TFT.DL(LINE_WIDTH(8 * 16)); |
montgojj | 4:a48fc7a3bda9 | 74 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 75 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 76 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 77 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 78 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 79 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 80 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 81 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 11:f6a146b62579 | 82 | TFT.DL(END()); |
cratliff | 5:e2e04cb5eada | 83 | |
montgojj | 11:f6a146b62579 | 84 | TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 85 | TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel"); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 86 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // change current color |
montgojj | 11:f6a146b62579 | 87 | TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner |
cratliff | 0:aa55c6eb6867 | 88 | |
montgojj | 11:f6a146b62579 | 89 | TFT.DL(DISPLAY()); // Display the image |
montgojj | 11:f6a146b62579 | 90 | TFT.Swap(); // Swap the current display list |
montgojj | 11:f6a146b62579 | 91 | TFT.Flush_Co_Buffer(); // Download the command list into fifo |
montgojj | 11:f6a146b62579 | 92 | TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation |
montgojj | 11:f6a146b62579 | 93 | TFT.Sleep(1000); // Wait 1s to show |
cratliff | 0:aa55c6eb6867 | 94 | } |
cratliff | 0:aa55c6eb6867 | 95 | |
montgojj | 11:f6a146b62579 | 96 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 97 | /* Main screen function that writes the SD images and external hardware */ |
montgojj | 11:f6a146b62579 | 98 | /* data to the screen, also controls the ITV pressure */ |
montgojj | 11:f6a146b62579 | 99 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 100 | void Main_Screen() |
cratliff | 0:aa55c6eb6867 | 101 | { |
montgojj | 11:f6a146b62579 | 102 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 103 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set the clear color to white |
montgojj | 11:f6a146b62579 | 104 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 11:f6a146b62579 | 105 | #ifdef Program_Button |
montgojj | 11:f6a146b62579 | 106 | TFT.DL(TAG(200)); // assign TAG value 200 |
montgojj | 11:f6a146b62579 | 107 | TFT.Button(710, 10, 76, 22, 26, 0, "Reprogram"); // generate reprogram button, only works for teensy |
montgojj | 11:f6a146b62579 | 108 | TFT.DL(TAG(3)); |
montgojj | 11:f6a146b62579 | 109 | #endif |
montgojj | 11:f6a146b62579 | 110 | |
montgojj | 4:a48fc7a3bda9 | 111 | /***************************************************************************************************/ |
montgojj | 4:a48fc7a3bda9 | 112 | /*Border Creation*/ |
montgojj | 11:f6a146b62579 | 113 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // generate border in SMC blue, all functions are in 1/16 pixel format |
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 | TFT.DL(VERTEX2F(799*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 119 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 120 | TFT.DL(VERTEX2F(799*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 121 | TFT.DL(VERTEX2F(0*16,479*16)); |
montgojj | 4:a48fc7a3bda9 | 122 | TFT.DL(VERTEX2F(0*16,479*16)); |
cratliff | 5:e2e04cb5eada | 123 | TFT.DL(VERTEX2F(0*16,0*16)); |
montgojj | 4:a48fc7a3bda9 | 124 | TFT.DL(END()); |
montgojj | 4:a48fc7a3bda9 | 125 | /***************************************************************************************************/ |
cratliff | 0:aa55c6eb6867 | 126 | |
montgojj | 4:a48fc7a3bda9 | 127 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 128 | /*ITV 1 Screen Display*/ |
montgojj | 11:f6a146b62579 | 129 | TFT.DL(COLOR_RGB(255,255,255)); // set background to white |
montgojj | 11:f6a146b62579 | 130 | TFT.DL(VERTEX_TRANSLATE_X(location* 16)); // page 1 |
montgojj | 11:f6a146b62579 | 131 | |
montgojj | 11:f6a146b62579 | 132 | TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the first screens images |
montgojj | 11:f6a146b62579 | 133 | TFT.DL(VERTEX2II(265,50,0,0)); // draw logo image with bit handle 0 |
montgojj | 11:f6a146b62579 | 134 | TFT.DL(VERTEX2II(75,50,1,0)); // draw ITV_1 image with bit handle 1 |
montgojj | 11:f6a146b62579 | 135 | 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 | 136 | TFT.DL(VERTEX2II(511,50,2,0)); // draw ITV_2 image with bit handle 2 |
montgojj | 11:f6a146b62579 | 137 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)); // translate back to prevent the remaining commands from also being translated |
montgojj | 4:a48fc7a3bda9 | 138 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 139 | |
montgojj | 11:f6a146b62579 | 140 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for the text |
montgojj | 11:f6a146b62579 | 141 | TFT.Text(265, 200, 31, 0, "ITV 1 Pressure"); // title block for screen |
montgojj | 11:f6a146b62579 | 142 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 13:8f23699b9c9f | 143 | TFT.DL(VERTEX2F(300*16,265*16)); |
montgojj | 8:886908a6127c | 144 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 145 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 146 | ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0; // calibration and scaling math for the ITV feedback, 48430 = 20mA, 9430 = 4mA |
montgojj | 13:8f23699b9c9f | 147 | ITV1_fcal = ITVpressure1_feedback; // moving average filter |
montgojj | 13:8f23699b9c9f | 148 | ITV1_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 149 | ITV1_fcal += ITV1_pre * avg2; |
montgojj | 9:bf787d41b645 | 150 | ITV1_pre = ITV1_fcal; |
montgojj | 11:f6a146b62579 | 151 | ITVpressure1_feedback = ITV1_fcal; // store the filtered value in the feedback variable |
montgojj | 11:f6a146b62579 | 152 | TFT.DL(COLOR_RGB(255,255,255)); // set color to white for the text |
montgojj | 11:f6a146b62579 | 153 | sprintf(buffer, "%.1f", ITVpressure1_feedback); // write the feedback pressure to the screen |
montgojj | 11:f6a146b62579 | 154 | TFT.Text(325,275,31,0,buffer); |
montgojj | 11:f6a146b62579 | 155 | TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen |
montgojj | 13:8f23699b9c9f | 156 | |
montgojj | 11:f6a146b62579 | 157 | TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format |
montgojj | 11:f6a146b62579 | 158 | TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 159 | TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 160 | TFT.DL(TAG(1)); // assign TAG value 1 |
montgojj | 11:f6a146b62579 | 161 | TFT.Slider(225,375,350,30,0,ITVpressure1_user_input,2355); // generate slider that controls the output pressure of ITV1 |
montgojj | 11:f6a146b62579 | 162 | TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors |
montgojj | 4:a48fc7a3bda9 | 163 | /***************************************************************************************************/ |
cratliff | 5:e2e04cb5eada | 164 | |
montgojj | 4:a48fc7a3bda9 | 165 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 166 | /*ITV 2 and PF3W Screen Display*/ |
montgojj | 11:f6a146b62579 | 167 | TFT.DL(COLOR_RGB(255,255,255)); // set background color to white |
montgojj | 11:f6a146b62579 | 168 | 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 | 169 | TFT.DL(BEGIN(BITMAPS)); // draw a bitmap that stores the second screens images |
montgojj | 11:f6a146b62579 | 170 | TFT.DL(VERTEX2II(30,75,3,0)); // write PF3W_1 image to the LCD |
montgojj | 11:f6a146b62579 | 171 | 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 | 172 | TFT.DL(VERTEX2II(411,75,4,0)); // write PF3W_2 image to the LCD |
montgojj | 11:f6a146b62579 | 173 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+12800); // translate back to 0 for remaining screen writes |
montgojj | 8:886908a6127c | 174 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 175 | |
montgojj | 11:f6a146b62579 | 176 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue, RGB format |
montgojj | 11:f6a146b62579 | 177 | TFT.Text(265, 200, 31, 0, "ITV 2 Pressure"); // write title block to screen |
montgojj | 11:f6a146b62579 | 178 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 179 | TFT.DL(VERTEX2F(300*16,265*16)); |
montgojj | 8:886908a6127c | 180 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 181 | TFT.DL(END()); |
montgojj | 13:8f23699b9c9f | 182 | |
montgojj | 11:f6a146b62579 | 183 | ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0; // calibration and scaling math for the ITV feedback, 48420 = 20mA, 9365 = 4mA |
montgojj | 11:f6a146b62579 | 184 | ITV2_fcal = ITVpressure2_feedback; // moving average filter |
montgojj | 9:bf787d41b645 | 185 | ITV2_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 186 | ITV2_fcal += ITV2_pre * avg2; |
montgojj | 9:bf787d41b645 | 187 | ITV2_pre = ITV2_fcal; |
montgojj | 11:f6a146b62579 | 188 | ITVpressure2_feedback = ITV2_fcal; // store filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 189 | TFT.DL(COLOR_RGB(255,255,255)); // set color for text to white |
montgojj | 11:f6a146b62579 | 190 | sprintf(buffer, "%.1f", ITVpressure2_feedback); // write feedback to screen in white |
montgojj | 11:f6a146b62579 | 191 | TFT.Text(325,275,31,0,buffer); |
montgojj | 13:8f23699b9c9f | 192 | TFT.Text(415, 275, 31, 0, " PSI"); // write the units to the screen |
montgojj | 11:f6a146b62579 | 193 | TFT.DL(COLOR_RGB(255,255,255)); // controls the color of the slider bar in RGB format |
montgojj | 11:f6a146b62579 | 194 | TFT.FgColor(COLOR_RGB(0,124,196)); // foreground color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 195 | TFT.BgColor(COLOR_RGB(0,124,196)); // background color set to SMC blue in RGB format |
montgojj | 11:f6a146b62579 | 196 | TFT.DL(TAG(2)); // assign tag 2 to slider for ITV2 |
montgojj | 11:f6a146b62579 | 197 | TFT.Slider(225,375,350,30,0,ITVpressure2_user_input,2387); // generate slider that controls the output pressure of ITV2 |
montgojj | 11:f6a146b62579 | 198 | TFT.DL(TAG(3)); // general tag assignment to prevent any tag assigning errors |
montgojj | 11:f6a146b62579 | 199 | |
montgojj | 11:f6a146b62579 | 200 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set color to SMC blue for text |
montgojj | 11:f6a146b62579 | 201 | TFT.Text(250, 20, 31, 0, "PF3W Flow Rate"); // write title block to screen |
montgojj | 11:f6a146b62579 | 202 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 203 | TFT.DL(VERTEX2F(300*16,85*16)); |
montgojj | 8:886908a6127c | 204 | TFT.DL(VERTEX2F(505*16,150*16)); |
montgojj | 11:f6a146b62579 | 205 | PFWflowrate = (PFWflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0; // calibration and scaling math for the PFW feedback, 51920 = 20mA, 10355 = 4mA |
montgojj | 11:f6a146b62579 | 206 | PFW_fcal = PFWflowrate; // moving average filter |
montgojj | 9:bf787d41b645 | 207 | PFW_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 208 | PFW_fcal += PFW_pre * avg2; |
montgojj | 9:bf787d41b645 | 209 | PFW_pre = PFW_fcal; |
montgojj | 11:f6a146b62579 | 210 | PFWflowrate = PFW_fcal; // store filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 211 | TFT.DL(COLOR_RGB(255,255,255)); // set text feedback text color to white |
montgojj | 11:f6a146b62579 | 212 | sprintf(buffer, "%.1f", PFWflowrate); // write feedback to LCD |
montgojj | 8:886908a6127c | 213 | TFT.Text(285,95,31,0,buffer); |
montgojj | 11:f6a146b62579 | 214 | TFT.Text(385, 95, 31, 0, " L/min"); // write units to LCD |
montgojj | 8:886908a6127c | 215 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 216 | |
montgojj | 8:886908a6127c | 217 | /***************************************************************************************************/ |
montgojj | 13:8f23699b9c9f | 218 | /*PSE Screen Display*/ |
montgojj | 11:f6a146b62579 | 219 | TFT.DL(COLOR_RGB(255,255,255)); // set the background for page 3 to white |
montgojj | 11:f6a146b62579 | 220 | 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 | 221 | TFT.DL(BEGIN(BITMAPS)); // create bitmap to draw images on LCD |
montgojj | 11:f6a146b62579 | 222 | TFT.DL(VERTEX2II(265,50,0,0)); // wrtie the SMC logo to the screen |
montgojj | 11:f6a146b62579 | 223 | TFT.DL(VERTEX2II(75,50,5,0)); // write PSE_1 image to the screen |
montgojj | 11:f6a146b62579 | 224 | TFT.DL(VERTEX_TRANSLATE_X((99+location)*16)+25600); // translate right by 99 pixels for the next image write |
montgojj | 11:f6a146b62579 | 225 | TFT.DL(VERTEX2II(511,85,6,0)); // write PSE_2 image to the screen |
montgojj | 11:f6a146b62579 | 226 | TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+25600); // translate back to pixel 0 for the remaining screen writes |
montgojj | 8:886908a6127c | 227 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 228 | |
montgojj | 11:f6a146b62579 | 229 | TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // set text color to SMC blue |
montgojj | 11:f6a146b62579 | 230 | TFT.Text(280, 200, 31, 0, "PSE Pressure"); // write title block to screen |
montgojj | 11:f6a146b62579 | 231 | TFT.DL(BEGIN(RECTS)); // draw rounded rectangle in SMC blue to act as background for where the feedback will be written |
montgojj | 8:886908a6127c | 232 | TFT.DL(VERTEX2F(295*16,265*16)); |
montgojj | 8:886908a6127c | 233 | TFT.DL(VERTEX2F(505*16,330*16)); |
montgojj | 8:886908a6127c | 234 | TFT.DL(END()); |
montgojj | 11:f6a146b62579 | 235 | PSEpressure = (PSEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0; // calibration and scaling math for the PFW feedback, 52350 = 20mA, 10440 = 4mA |
montgojj | 11:f6a146b62579 | 236 | PSE_fcal = PSEpressure; // moving average filter |
montgojj | 9:bf787d41b645 | 237 | PSE_fcal *= avg1; |
montgojj | 9:bf787d41b645 | 238 | PSE_fcal += PSE_pre * avg2; |
montgojj | 9:bf787d41b645 | 239 | PSE_pre = PSE_fcal; |
montgojj | 11:f6a146b62579 | 240 | PSEpressure = PSE_fcal; // store the filtered value in feedback variable |
montgojj | 11:f6a146b62579 | 241 | TFT.DL(COLOR_RGB(255,255,255)); // set text color to white |
montgojj | 11:f6a146b62579 | 242 | sprintf(buffer, "%.2f", PSEpressure); // write feedback to screen |
montgojj | 8:886908a6127c | 243 | TFT.Text(300,275,31,0,buffer); |
montgojj | 11:f6a146b62579 | 244 | TFT.Text(405, 275, 31, 0, " MPa"); // write units to LCD |
montgojj | 8:886908a6127c | 245 | /***************************************************************************************************/ |
montgojj | 8:886908a6127c | 246 | |
montgojj | 11:f6a146b62579 | 247 | #ifdef Debug_Swipe // writes touch data to screen |
montgojj | 11:f6a146b62579 | 248 | TFT.DL(COLOR_RGB(0,0,0)); // set text color to black |
montgojj | 11:f6a146b62579 | 249 | TFT.Number(20, 450, 26, 0, distance); // write distance value to screen |
montgojj | 11:f6a146b62579 | 250 | TFT.Number(80, 450, 26, 0, velocity); // write velocity to screen |
cratliff | 7:e525bfa17136 | 251 | #endif |
montgojj | 13:8f23699b9c9f | 252 | |
montgojj | 11:f6a146b62579 | 253 | #ifdef Debug_Touch_File // debug the touch up load |
montgojj | 11:f6a146b62579 | 254 | TFT.DL(COLOR_RGB(0,0,0)); // set text color to black |
montgojj | 11:f6a146b62579 | 255 | int j; // loop counter |
montgojj | 11:f6a146b62579 | 256 | for (j = 0; j < 24; j++) { // write file data to screen |
montgojj | 11:f6a146b62579 | 257 | TFT.Number(j*30+20, 450, 26, 0, tcal[j]); |
cratliff | 5:e2e04cb5eada | 258 | } |
cratliff | 5:e2e04cb5eada | 259 | #endif |
cratliff | 5:e2e04cb5eada | 260 | |
montgojj | 11:f6a146b62579 | 261 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 262 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 263 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 264 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
cratliff | 0:aa55c6eb6867 | 265 | } |
cratliff | 0:aa55c6eb6867 | 266 | |
montgojj | 11:f6a146b62579 | 267 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 268 | /* This function displays the error screen */ |
montgojj | 11:f6a146b62579 | 269 | /* the function causes the screen to flash yellow and writes text to the LCD*/ |
montgojj | 11:f6a146b62579 | 270 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 271 | void error_screen(ft_char8_t *str1, ft_char8_t *str2) |
cratliff | 5:e2e04cb5eada | 272 | { |
montgojj | 4:a48fc7a3bda9 | 273 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 274 | TFT.DL(CLEAR_COLOR_RGB(255,242,0)); // clear the screen and set the background to yellow |
montgojj | 4:a48fc7a3bda9 | 275 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 4:a48fc7a3bda9 | 276 | TFT.DL(COLOR_RGB(0,0,0)); |
montgojj | 13:8f23699b9c9f | 277 | TFT.Text((TFT.DispWidth/2), 170, 31, OPT_CENTERX, str1); // draw Text with font 31 |
montgojj | 13:8f23699b9c9f | 278 | TFT.Text((TFT.DispWidth/2), 215, 31, OPT_CENTERX, str2); // draw Text with font 31 |
montgojj | 11:f6a146b62579 | 279 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 280 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 281 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 282 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
montgojj | 4:a48fc7a3bda9 | 283 | TFT.Sleep(1000); |
cratliff | 5:e2e04cb5eada | 284 | |
montgojj | 11:f6a146b62579 | 285 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 286 | TFT.DL(CLEAR_COLOR_RGB(255,255,255)); // set clear color to white |
montgojj | 11:f6a146b62579 | 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); |
montgojj | 4:a48fc7a3bda9 | 296 | } |
cratliff | 0:aa55c6eb6867 | 297 | |
montgojj | 11:f6a146b62579 | 298 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 299 | /* Checks for an SD card and reads/writes the touchscreen calibration data */ |
montgojj | 11:f6a146b62579 | 300 | /* from the SD card */ |
montgojj | 11:f6a146b62579 | 301 | /****************************************************************************/ |
montgojj | 8:886908a6127c | 302 | void touchscreen_Calibration() |
cratliff | 5:e2e04cb5eada | 303 | { |
montgojj | 11:f6a146b62579 | 304 | int i = 0; // loop counter |
montgojj | 11:f6a146b62579 | 305 | while(card_present.read()) { // checks for SD card, if not present hold program until a SD card is inserted |
montgojj | 13:8f23699b9c9f | 306 | error_screen("Error!","Insert SD card!"); // write error screen to LCD |
montgojj | 11:f6a146b62579 | 307 | } |
montgojj | 11:f6a146b62579 | 308 | FILE *fp = fopen("/sd/TCal/TCalData.txt", "a"); // open touchscreen calibration data from SD card |
montgojj | 4:a48fc7a3bda9 | 309 | fp= fopen("/sd/TCal/TCalData.txt", "r"); |
montgojj | 11:f6a146b62579 | 310 | if(!fp) { // could not open file for read so generate data then store on SD card |
montgojj | 11:f6a146b62579 | 311 | TFT.Calibrate(); // calibrate the touch screen |
montgojj | 11:f6a146b62579 | 312 | TFT.read_calibrate(tcal); // read in cal data from screen |
montgojj | 11:f6a146b62579 | 313 | mkdir("/sd/TCal", 0777); // open file for to save calibration data |
montgojj | 4:a48fc7a3bda9 | 314 | FILE *fp = fopen("/sd/TCal/TCalData.txt", "w"); |
montgojj | 11:f6a146b62579 | 315 | for (i = 0; i < 25; i++) { // save integers one at a time to the file |
cratliff | 5:e2e04cb5eada | 316 | fprintf(fp, "%c", tcal[i] ); |
cratliff | 5:e2e04cb5eada | 317 | } |
montgojj | 11:f6a146b62579 | 318 | fclose(fp); // close SD card file |
montgojj | 11:f6a146b62579 | 319 | } else { // file found, read in data |
montgojj | 4:a48fc7a3bda9 | 320 | fread(tstr,24,1,fp); |
montgojj | 11:f6a146b62579 | 321 | for (i = 0; i < 24; i++) { // convert from int to char |
montgojj | 4:a48fc7a3bda9 | 322 | tcal[i] = tstr[i]; |
montgojj | 4:a48fc7a3bda9 | 323 | } |
montgojj | 11:f6a146b62579 | 324 | TFT.write_calibrate(tcal); // write cal data to screen |
montgojj | 4:a48fc7a3bda9 | 325 | } |
montgojj | 8:886908a6127c | 326 | } |
cratliff | 0:aa55c6eb6867 | 327 | |
montgojj | 11:f6a146b62579 | 328 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 329 | /* Loads all of the images from the SD card and assigns them bitmap handles */ |
montgojj | 11:f6a146b62579 | 330 | /****************************************************************************/ |
montgojj | 8:886908a6127c | 331 | void initialize_Images() |
montgojj | 8:886908a6127c | 332 | { |
montgojj | 11:f6a146b62579 | 333 | TFT.DLstart(); // start a new display command list |
montgojj | 11:f6a146b62579 | 334 | TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer |
montgojj | 8:886908a6127c | 335 | |
montgojj | 11:f6a146b62579 | 336 | TFT.DL(BITMAP_HANDLE(0)); // assign bitmap handle 0 to logo.jpg |
montgojj | 11:f6a146b62579 | 337 | 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 | 338 | TFT.DL(BITMAP_HANDLE(1)); // assign bitmap handle 1 to ITV_1.jpg |
montgojj | 11:f6a146b62579 | 339 | 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 | 340 | TFT.DL(BITMAP_HANDLE(2)); // assign bitmap handle 2 to ITV_2.jpg |
montgojj | 11:f6a146b62579 | 341 | 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 | 342 | TFT.DL(BITMAP_HANDLE(3)); // assign bitmap handle 3 to PF3W_1.jpg |
montgojj | 11:f6a146b62579 | 343 | 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 | 344 | TFT.DL(BITMAP_HANDLE(4)); // assign bitmap handle 4 to PF3W_2.jpg |
montgojj | 11:f6a146b62579 | 345 | 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 | 346 | TFT.DL(BITMAP_HANDLE(5)); // assign bitmap handle 5 to PSE_1.jpg |
montgojj | 11:f6a146b62579 | 347 | 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 | 348 | TFT.DL(BITMAP_HANDLE(6)); // assign bitmap handle 6 to PSE_2.jpg |
montgojj | 11:f6a146b62579 | 349 | 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 | 350 | |
montgojj | 11:f6a146b62579 | 351 | TFT.DL(DISPLAY()); // display the image |
montgojj | 11:f6a146b62579 | 352 | TFT.Swap(); // swap the current display list |
montgojj | 11:f6a146b62579 | 353 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 8:886908a6127c | 354 | TFT.WaitCmdfifo_empty(); |
montgojj | 8:886908a6127c | 355 | } |
montgojj | 8:886908a6127c | 356 | |
montgojj | 11:f6a146b62579 | 357 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 358 | /* Function that checks for a inadequate supply pressure and displays */ |
montgojj | 13:8f23699b9c9f | 359 | /* an error */ |
montgojj | 13:8f23699b9c9f | 360 | /****************************************************************************/ |
montgojj | 13:8f23699b9c9f | 361 | void SupplyPressure_Check(float check1, float check2) |
montgojj | 13:8f23699b9c9f | 362 | { |
montgojj | 13:8f23699b9c9f | 363 | while(((PSEpressure*145.0377) < (check1 - 10)) || ((PSEpressure*145.0377) < (check2 - 10))) { |
montgojj | 13:8f23699b9c9f | 364 | dac1.write_u12(0); // turn off ITVs |
montgojj | 13:8f23699b9c9f | 365 | dac2.write_u12(0); |
montgojj | 13:8f23699b9c9f | 366 | error_screen("Supply pressure too low!", ""); // display error |
montgojj | 13:8f23699b9c9f | 367 | PSEpressure = (PSEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0; // check for supply pressure |
montgojj | 13:8f23699b9c9f | 368 | } |
montgojj | 13:8f23699b9c9f | 369 | dac1.write_u12(ITVpressure1_input_raw); // restore ITV pressure |
montgojj | 13:8f23699b9c9f | 370 | dac2.write_u12(ITVpressure2_input_raw); |
montgojj | 13:8f23699b9c9f | 371 | } |
montgojj | 13:8f23699b9c9f | 372 | |
montgojj | 13:8f23699b9c9f | 373 | /****************************************************************************/ |
montgojj | 11:f6a146b62579 | 374 | /* Main function that tracks all of the touchscreen data and updates the */ |
montgojj | 11:f6a146b62579 | 375 | /* screen accordingly */ |
montgojj | 11:f6a146b62579 | 376 | /****************************************************************************/ |
montgojj | 8:886908a6127c | 377 | int main() |
montgojj | 8:886908a6127c | 378 | { |
montgojj | 11:f6a146b62579 | 379 | dac1.wakeup(); // activate DAC boards |
montgojj | 8:886908a6127c | 380 | dac2.wakeup(); |
montgojj | 11:f6a146b62579 | 381 | dac1.write_u12(0); // the natural DAC output value is 50% of its maximum value |
montgojj | 11:f6a146b62579 | 382 | dac2.write_u12(0); // the program has to immediately write a 0 to the DAC to turn off the outputs |
montgojj | 11:f6a146b62579 | 383 | ft_uint32_t TrackRegisterVal = 0; // touch track variable |
montgojj | 8:886908a6127c | 384 | |
montgojj | 11:f6a146b62579 | 385 | TFT.MemWrite(REG_ROTATE, 1); // rotate screen |
montgojj | 8:886908a6127c | 386 | TFT.Rotate(1); |
montgojj | 8:886908a6127c | 387 | |
montgojj | 13:8f23699b9c9f | 388 | SupplyPressure_Check(0,0); // check for any supply pressure |
montgojj | 11:f6a146b62579 | 389 | touchscreen_Calibration(); // load touchscreen calibration data |
montgojj | 11:f6a146b62579 | 390 | initialize_Images(); // load and initialize images |
montgojj | 13:8f23699b9c9f | 391 | Start_Screen("Starting..."); // show start screen |
montgojj | 13:8f23699b9c9f | 392 | |
montgojj | 11:f6a146b62579 | 393 | TFT.Track(200, 400, 375, 50, 1); // track sliders |
montgojj | 10:c56b7ca4805f | 394 | TFT.Track(200, 400, 375, 50, 2); |
montgojj | 11:f6a146b62579 | 395 | TFT.Flush_Co_Buffer(); // download the command list into fifo |
montgojj | 11:f6a146b62579 | 396 | TFT.WaitCmdfifo_empty(); // wait till coprocessor completes the operation |
montgojj | 13:8f23699b9c9f | 397 | |
cratliff | 0:aa55c6eb6867 | 398 | while(1) { |
montgojj | 13:8f23699b9c9f | 399 | curY = TFT.Rd32(REG_TOUCH_SCREEN_XY)& 0xffff; // get the current touch screen position |
montgojj | 13:8f23699b9c9f | 400 | curX = TFT.Rd32(REG_TOUCH_SCREEN_XY)>>16; // if not touch the results are 0x8000 for x and y |
montgojj | 11:f6a146b62579 | 401 | ft_uint8_t tagval = 0; // initialize return tag value |
montgojj | 11:f6a146b62579 | 402 | TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched |
montgojj | 11:f6a146b62579 | 403 | tagval = TrackRegisterVal & 0xff; // store return tag value |
montgojj | 11:f6a146b62579 | 404 | // check what tag was touched |
montgojj | 13:8f23699b9c9f | 405 | if(1 == tagval) { // tag value for ITV1 slider touch |
montgojj | 11:f6a146b62579 | 406 | ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095); // calculate new slider value so that the slider updates graphically |
montgojj | 11:f6a146b62579 | 407 | 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 | 408 | dac1.write_u12(ITVpressure1_input_raw); // write 12 bit number to DAC to fire the ITV |
montgojj | 13:8f23699b9c9f | 409 | ITVpressure1_input_scaled = (ITVpressure1_input_raw-590)*(70.0)/(4095)+0; |
montgojj | 13:8f23699b9c9f | 410 | } |
montgojj | 13:8f23699b9c9f | 411 | |
montgojj | 11:f6a146b62579 | 412 | else if(2 == tagval) { // tag value for ITV2 slider touch |
montgojj | 11:f6a146b62579 | 413 | ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095); // calculate new slider value so that the slider updates graphically |
montgojj | 11:f6a146b62579 | 414 | 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 | 415 | dac2.write_u12(ITVpressure2_input_raw); // write 12 bit number to DAC to fire the ITV |
montgojj | 13:8f23699b9c9f | 416 | ITVpressure2_input_scaled = (ITVpressure2_input_raw-590)*(70.0)/(4095)+0; |
montgojj | 13:8f23699b9c9f | 417 | } |
montgojj | 13:8f23699b9c9f | 418 | |
montgojj | 13:8f23699b9c9f | 419 | 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 | 420 | break; |
montgojj | 13:8f23699b9c9f | 421 | } 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 | 422 | touched++; // touched is used to determine how long the screen has beed touched for and if it is currently being touched |
montgojj | 13:8f23699b9c9f | 423 | distance = curX - pasX; // find the swipe distance in pixels |
montgojj | 13:8f23699b9c9f | 424 | location = (int16_t)paslocation + distance; // add the distance of the swipe to the location so the screen moves as you swipe |
cratliff | 7:e525bfa17136 | 425 | |
montgojj | 13:8f23699b9c9f | 426 | } 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 | 427 | touched++; |
cratliff | 7:e525bfa17136 | 428 | pasX = curX; |
cratliff | 7:e525bfa17136 | 429 | |
montgojj | 13:8f23699b9c9f | 430 | } else if(curX ==0x8000 && touched) { // Not being touched currently but was touched last time through the loop |
montgojj | 13:8f23699b9c9f | 431 | velocity = distance/touched; // Now that the swipe is finished we can calculate the velocity from the distance and time touched |
montgojj | 13:8f23699b9c9f | 432 | paslocation = location; // Store Location data away |
montgojj | 13:8f23699b9c9f | 433 | touched=0; // Reset for the next touch |
montgojj | 13:8f23699b9c9f | 434 | // If not being touched |
montgojj | 13:8f23699b9c9f | 435 | } else { |
cratliff | 7:e525bfa17136 | 436 | //page 4 location |
montgojj | 13:8f23699b9c9f | 437 | if (location < - 2300 && location > -2500) { // If you are close to the edge of the fourth Page |
montgojj | 13:8f23699b9c9f | 438 | if (velocity) { // and you have some velocity |
montgojj | 13:8f23699b9c9f | 439 | velocity = (location + 2400)/-5; // adjust velocity based on how close to the edge |
montgojj | 13:8f23699b9c9f | 440 | location += (int16_t) velocity; // move the location at the speed of velocity |
cratliff | 7:e525bfa17136 | 441 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 442 | } else { // velocity will become zero as you get closer to the edge when this happens finish the move |
cratliff | 7:e525bfa17136 | 443 | location = -2400; |
cratliff | 7:e525bfa17136 | 444 | } |
cratliff | 7:e525bfa17136 | 445 | } |
cratliff | 7:e525bfa17136 | 446 | //page 3 location |
montgojj | 13:8f23699b9c9f | 447 | else if (location < - 1500 && location > -1700) { // repeat for each page |
cratliff | 7:e525bfa17136 | 448 | if (velocity) { |
cratliff | 7:e525bfa17136 | 449 | velocity = (location + 1600)/-5; |
cratliff | 7:e525bfa17136 | 450 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 451 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 452 | } else { |
cratliff | 7:e525bfa17136 | 453 | location = -1600; |
cratliff | 7:e525bfa17136 | 454 | } |
cratliff | 5:e2e04cb5eada | 455 | |
cratliff | 7:e525bfa17136 | 456 | } |
cratliff | 7:e525bfa17136 | 457 | //page 2 |
cratliff | 7:e525bfa17136 | 458 | else if (location < - 700 && location > -900) { |
cratliff | 7:e525bfa17136 | 459 | if (velocity) { |
cratliff | 7:e525bfa17136 | 460 | velocity = (location + 800)/-5; |
cratliff | 7:e525bfa17136 | 461 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 462 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 463 | } else { |
cratliff | 7:e525bfa17136 | 464 | location = -800; |
cratliff | 7:e525bfa17136 | 465 | } |
cratliff | 7:e525bfa17136 | 466 | //page 1 |
montgojj | 13:8f23699b9c9f | 467 | } else if (location > -100 && location < 100) { |
cratliff | 7:e525bfa17136 | 468 | |
cratliff | 7:e525bfa17136 | 469 | if (velocity) { |
cratliff | 7:e525bfa17136 | 470 | velocity = location/-5; |
cratliff | 7:e525bfa17136 | 471 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 472 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 473 | } else { |
cratliff | 7:e525bfa17136 | 474 | location = 0; |
montgojj | 13:8f23699b9c9f | 475 | |
cratliff | 7:e525bfa17136 | 476 | } |
cratliff | 7:e525bfa17136 | 477 | //no page 0 |
montgojj | 13:8f23699b9c9f | 478 | } else if (location >60) { // Do not allow the page screen to go to -1 page |
montgojj | 13:8f23699b9c9f | 479 | velocity = -10; // Change the velocity to return |
cratliff | 7:e525bfa17136 | 480 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 481 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 482 | //no page 4 |
montgojj | 13:8f23699b9c9f | 483 | } else if (location <-1700) { // Do not allow the page screen to go pass top page |
montgojj | 13:8f23699b9c9f | 484 | velocity = 10; // Change the velocity to return |
cratliff | 7:e525bfa17136 | 485 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 486 | paslocation = location; |
cratliff | 7:e525bfa17136 | 487 | //between pages |
montgojj | 13:8f23699b9c9f | 488 | } else if (velocity) { // if the page is not at edge but has velocity |
cratliff | 7:e525bfa17136 | 489 | location += (int16_t) velocity; |
cratliff | 7:e525bfa17136 | 490 | paslocation = location; |
montgojj | 13:8f23699b9c9f | 491 | if (velocity >0) { // acceleration between pages so it does not take forever |
montgojj | 13:8f23699b9c9f | 492 | velocity+= 2; // increase velocity |
montgojj | 13:8f23699b9c9f | 493 | } else { |
cratliff | 7:e525bfa17136 | 494 | velocity-= 2; |
cratliff | 7:e525bfa17136 | 495 | } |
cratliff | 7:e525bfa17136 | 496 | } |
montgojj | 8:886908a6127c | 497 | } |
montgojj | 13:8f23699b9c9f | 498 | SupplyPressure_Check(ITVpressure1_input_scaled, ITVpressure2_input_scaled); // check to see if theres enough supply pressure for the ITVs |
montgojj | 11:f6a146b62579 | 499 | Main_Screen(); // paint new screen |
montgojj | 11:f6a146b62579 | 500 | TFT.Sleep(10); // wait 10ms for next time to repaint the screen |
montgojj | 11:f6a146b62579 | 501 | } // end of display loop |
montgojj | 8:886908a6127c | 502 | } |