Curtis Mattull
/
PANEL_GUI_hello_world
basic functional test of FT810 LCD via SPI
Diff: main.cpp
- Revision:
- 8:886908a6127c
- Parent:
- 7:e525bfa17136
- Child:
- 9:bf787d41b645
--- a/main.cpp Thu Mar 31 17:17:30 2016 +0000 +++ b/main.cpp Fri Apr 01 18:32:03 2016 +0000 @@ -11,12 +11,7 @@ ** ** ** Todo : - - - */ - - #include "mbed.h" #include "FT_Platform.h" #include "FT_color.h" @@ -33,7 +28,7 @@ #define K20 // used add easy way to reprogram without using the phsyical button. #define Program_Button -#define Debug_Swipe +//#define Debug_Swipe #ifdef Nucleo_F303K8 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 @@ -45,8 +40,8 @@ MCP4725 dac1(D18, D19, MCP4725::ADDRESS_2); MCP4725 dac2(D18, D19, MCP4725::ADDRESS_3); -AnalogIn ISEpressure_raw(A9); -AnalogIn PFMflowrate_raw(A8); +AnalogIn PSEpressure_raw(A9); +AnalogIn PFWflowrate_raw(A8); AnalogIn ITVpressure1_feedback_raw(A3); AnalogIn ITVpressure2_feedback_raw(A2); DigitalIn card_present(D7); @@ -54,72 +49,16 @@ // global Vars unsigned int r, b, g, CalVal0, CalVal1, CalVal2, CalVal3, CalVal4, curX, curY, pasX, pasY; -float ISEpressure, PFMflowrate = 0.0; +float PSEpressure, PFWflowrate = 0.0; float ITVpressure1_feedback, ITVpressure2_feedback, ITVpressure1_user_input, ITVpressure2_user_input = 0.0; uint16_t ITVpressure1_input_raw, ITVpressure2_input_raw, test = 0; int16_t velocity, distance, touched, location, paslocation ; char buffer[50]; uint8_t tcal[24]; //Touch screen Calibration char tstr[40]; // Temp location for Touch Screen Calibration - -void hsv2rgb(double H,double S, double V) -{ - double f,h,p,q,t; - int i; - if( S == 0.0) { - r = V * 255; - g = V * 255; - b = V * 255; - return; - } - if(H > 480.0) H = 0.0; // check values - if(S > 1.0) S = 1.0; - if(S < 0.0) S = 0.0; - if(V > 1.0) V = 1.0; - if(V < 0.0) V = 0.0; - - h = H / 60.0; - i = (int) h; - f = h - i; - p = V * (1.0 - S); - q = V * (1.0 - (S * f)); - t = V * (1.0 - (S * (1.0 - f))); +ft_int16_t x_size,y_size; - switch(i) { - case 0: - r = V * 255; - g = t * 255; - b = p * 255; - break; - case 1: - r = q * 255; - g = V * 255; - b = p * 255; - break; - case 2: - r = p * 255; - g = V * 255; - b = t * 255; - break; - case 3: - r = p * 255; - g = q * 255; - b = V * 255; - break; - case 4: - r = t * 255; - g = p * 255; - b = V * 255; - break; - case 5: - default: - r = V * 255; - g = p * 255; - b = q * 255; - break; - } -} - +unsigned int err[7]; /***************************************************************************/ /* Show a Screen with Text for 5 seconds */ @@ -149,7 +88,7 @@ TFT.DL(VERTEX2F(0*16,0*16)); TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31 - TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel!"); // draw Text with font 31 + TFT.Text((TFT.DispWidth/2), 350, 31, OPT_CENTERX, "Brew Panel"); // draw Text with font 31 TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); // change current color TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0); // draw a animated spinner @@ -165,25 +104,24 @@ void screen_1() { TFT.DLstart(); // start a new display command list - TFT.DL(CLEAR_COLOR_RGB(0,0,0)); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); TFT.DL(CLEAR(1,1,1)); // clear buffers -> color buffer,stencil buffer, tag buffer - + #ifdef Program_Button + TFT.DL(TAG(200)); // assign TAG value 200 + TFT.Button(710, 10, 76, 22, 26, 0, "Reprogram"); + TFT.DL(TAG(3)); + #endif /***************************************************************************************************/ - - // some temp location holder for each page showing the transitions - TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800)); + // some temp location holder for each page showing the transitions + /*TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800)); TFT.Text(300, 200, 31, 0, "Page 2"); - TFT.DL(VERTEX_TRANSLATE_X(location* 16+25600)); TFT.Text(300, 200, 31, 0, "Page 3"); - TFT.DL(VERTEX_TRANSLATE_X(location* 16+38400)); TFT.Text(300, 200, 31, 0, "Page 4"); - TFT.DL(CLEAR_COLOR_RGB(255,255,255)); - - TFT.DL(VERTEX_TRANSLATE_X(location* 16)); - + TFT.DL(VERTEX_TRANSLATE_X(location* 16));*/ + /*Border Creation*/ TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); TFT.DL(BEGIN(LINES)); @@ -200,74 +138,130 @@ /***************************************************************************************************/ /***************************************************************************************************/ - - /*ISE Screen Display*/ - TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); - TFT.Text(90, 20, 31, 0, "ISE Pressure"); - TFT.DL(BEGIN(RECTS)); - TFT.DL(VERTEX2F(110*16,85*16)); - TFT.DL(VERTEX2F(315*16,150*16)); + /*ITV 1 Screen Display*/ + TFT.DL(COLOR_RGB(255,255,255)); + TFT.DL(VERTEX_TRANSLATE_X(location* 16)); + + TFT.DL(BEGIN(BITMAPS)); + TFT.DL(VERTEX2II(265,50,0,0)); + TFT.DL(VERTEX2II(75,50,1,0)); + TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)); + TFT.DL(VERTEX2II(511,50,2,0)); + TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)); TFT.DL(END()); - ISEpressure = (ISEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0;; + + TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); + TFT.Text(265, 200, 31, 0, "ITV 1 Pressure"); + TFT.DL(BEGIN(RECTS)); + TFT.DL(VERTEX2F(300*16,265*16)); + TFT.DL(VERTEX2F(505*16,330*16)); + TFT.DL(END()); TFT.DL(COLOR_RGB(255,255,255)); - sprintf(buffer, "%.2f", ISEpressure); - //test = ISEpressure_raw.read_u16(); - //sprintf(buffer, "%d", test); - TFT.Text(135,95,31,0,buffer); - TFT.Text(225, 95, 31, 0, " MPa"); + sprintf(buffer, "%.1f", ITVpressure1_feedback); + TFT.Text(325,275,31,0,buffer); + TFT.Text(415, 275, 31, 0, " PSI"); + ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0; + TFT.DL(COLOR_RGB(255,255,255)); + TFT.FgColor(COLOR_RGB(0,124,196)); + TFT.BgColor(COLOR_RGB(0,124,196)); + TFT.DL(TAG(1)); // assign TAG value 1 + TFT.Slider(225,375,350,30,0,ITVpressure1_user_input,2355); + TFT.DL(TAG(3)); /***************************************************************************************************/ /***************************************************************************************************/ - - /*PFM Screen Display*/ + /*ITV 2 and PF3W Screen Display*/ + TFT.DL(COLOR_RGB(255,255,255)); + TFT.DL(VERTEX_TRANSLATE_X(location* 16)+12800); + TFT.DL(BEGIN(BITMAPS)); + //TFT.DL(VERTEX2II(265,50,0,0)); + TFT.DL(VERTEX2II(30,75,3,0)); + TFT.DL(VERTEX_TRANSLATE_X((149+location)*16)+12800); + TFT.DL(VERTEX2II(411,75,4,0)); + TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+12800); + TFT.DL(END()); + + TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800)); + // Slide + TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); + TFT.Text(265, 200, 31, 0, "ITV 2 Pressure"); + TFT.DL(BEGIN(RECTS)); + TFT.DL(VERTEX2F(300*16,265*16)); + TFT.DL(VERTEX2F(505*16,330*16)); + TFT.DL(END()); + TFT.DL(COLOR_RGB(255,255,255)); + sprintf(buffer, "%.1f", ITVpressure2_feedback); + TFT.Text(325,275,31,0,buffer); + TFT.Text(415, 275, 31, 0, " PSI"); + ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0; + TFT.DL(COLOR_RGB(255,255,255)); + TFT.FgColor(COLOR_RGB(0,124,196)); + TFT.BgColor(COLOR_RGB(0,124,196)); + TFT.DL(TAG(2)); // assign TAG value 2 + TFT.Slider(225,375,350,30,0,ITVpressure2_user_input,2387); + TFT.DL(TAG(3)); + + TFT.DL(VERTEX_TRANSLATE_X(location* 16+12800)); TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); - TFT.Text(455, 20, 31, 0, "PFM Flow Rate"); + TFT.Text(250, 20, 31, 0, "PF3W Flow Rate"); TFT.DL(BEGIN(RECTS)); - TFT.DL(VERTEX2F(465*16,85*16)); - TFT.DL(VERTEX2F(720*16,150*16)); + TFT.DL(VERTEX2F(300*16,85*16)); + TFT.DL(VERTEX2F(505*16,150*16)); + PFWflowrate = (PFWflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0; + TFT.DL(COLOR_RGB(255,255,255)); + sprintf(buffer, "%.1f", PFWflowrate); + TFT.Text(285,95,31,0,buffer); + TFT.Text(385, 95, 31, 0, " L/min"); + /***************************************************************************************************/ + + /***************************************************************************************************/ + /*ISE Screen Display*/ + TFT.DL(COLOR_RGB(255,255,255)); + TFT.DL(VERTEX_TRANSLATE_X(location* 16)+25600); + TFT.DL(BEGIN(BITMAPS)); + TFT.DL(TAG(3)); + TFT.DL(VERTEX2II(265,50,0,0)); + TFT.DL(VERTEX2II(75,50,5,0)); + TFT.DL(VERTEX_TRANSLATE_X((99+location)*16)+25600); + TFT.DL(VERTEX2II(511,85,6,0)); + TFT.DL(VERTEX_TRANSLATE_X((0+location)*16)+25600); + TFT.DL(END()); + + TFT.DL(VERTEX_TRANSLATE_X(location* 16+25600)); //page 3 + TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); + TFT.Text(280, 200, 31, 0, "PSE Pressure"); + TFT.DL(BEGIN(RECTS)); + TFT.DL(VERTEX2F(295*16,265*16)); + TFT.DL(VERTEX2F(505*16,330*16)); + TFT.DL(END()); + PSEpressure = (PSEpressure_raw.read_u16() - 10440) * (1.0) / (52350 - 10440) + 0;; + TFT.DL(COLOR_RGB(255,255,255)); + sprintf(buffer, "%.2f", PSEpressure); + //test = ISEpressure_raw.read_u16(); + //sprintf(buffer, "%d", test); + TFT.Text(300,275,31,0,buffer); + TFT.Text(405, 275, 31, 0, " MPa"); + /***************************************************************************************************/ + + /***************************************************************************************************/ + /*PFM Screen Display*/ + /*TFT.DL(VERTEX_TRANSLATE_X(location* 16+38400)); // page 4 + TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); + TFT.Text(265, 200, 31, 0, "PFW Flow Rate"); + TFT.DL(BEGIN(RECTS)); + TFT.DL(VERTEX2F(300*16,265*16)); + TFT.DL(VERTEX2F(505*16,330*16)); TFT.DL(END()); PFMflowrate = (PFMflowrate_raw.read_u16() - 10355) * (40.0) / (51920 - 10355) + 0; TFT.DL(COLOR_RGB(255,255,255)); sprintf(buffer, "%.1f", PFMflowrate); - TFT.Text(485,95,31,0,buffer); - TFT.Text(575, 95, 31, 0, " L/min"); - /***************************************************************************************************/ - + TFT.Text(295,275,31,0,buffer); + TFT.Text(385, 275, 31, 0, " L/min");*/ /***************************************************************************************************/ - /*ITV Screen Display*/ - TFT.DL(COLOR_RGB(0x00,0x7C,0xC4)); - TFT.Text(75, 200, 31, 0, "ITV 1 Pressure"); - TFT.Text(455, 200, 31, 0, "ITV 2 Pressure"); - TFT.DL(BEGIN(RECTS)); - TFT.DL(VERTEX2F(110*16,265*16)); - TFT.DL(VERTEX2F(315*16,330*16)); - TFT.DL(VERTEX2F(485*16,265*16)); - TFT.DL(VERTEX2F(690*16,330*16)); - TFT.DL(END()); - TFT.DL(COLOR_RGB(255,255,255)); - sprintf(buffer, "%.1f", ITVpressure1_feedback); - TFT.Text(135,275,31,0,buffer); - TFT.Text(225, 275, 31, 0, " PSI"); - sprintf(buffer, "%.1f", ITVpressure2_feedback); - TFT.Text(515,275,31,0,buffer); - TFT.Text(605, 275, 31, 0, " PSI"); - ITVpressure1_feedback = (ITVpressure1_feedback_raw.read_u16() - 9430) * (70.0) / (48430 - 9430) + 0; - ITVpressure2_feedback = (ITVpressure2_feedback_raw.read_u16()- 9365) * (70.0) / (48420 - 9365) + 0; - TFT.DL(COLOR_RGB(255,255,255)); - TFT.FgColor(COLOR_RGB(0,124,196)); - TFT.BgColor(COLOR_RGB(0,124,196)); - TFT.DL(TAG(1)); // assign TAG value 1 - TFT.Slider(70,375,280,30,0,ITVpressure1_user_input,2355); - TFT.DL(TAG(2)); // assign TAG value 2 - TFT.Slider(450,375,280,30,0,ITVpressure2_user_input,2387); - /***************************************************************************************************/ -// add button to make for easy reprogramming -#ifdef Program_Button - TFT.DL(TAG(200)); // assign TAG value 200 - TFT.Button(720, 1, 76, 22, 26, 0, "Reprogram"); -#endif + // add button to make for easy reprogramming + #ifdef Debug_Swipe TFT.DL(COLOR_RGB(0,0,0)); @@ -286,7 +280,6 @@ } #endif - TFT.DL(DISPLAY()); // Display the image TFT.Swap(); // Swap the current display list TFT.Flush_Co_Buffer(); // Download the command list into fifo @@ -320,26 +313,9 @@ TFT.Sleep(1000); } -int main() +void touchscreen_Calibration() { - // dac1.wakeup(); - // dac2.wakeup(); - // dac1.write_u12(0); -// dac2.write_u12(0); - ft_uint32_t TrackRegisterVal = 0; // touch track int i = 0; - - TFT.MemWrite(REG_ROTATE, 1); - TFT.Rotate(1); - - Start_Screen("3"); // Show start screen - Start_Screen("2"); // Show start screen - Start_Screen("1"); // Show start screen - - while(card_present.read()) { - error_screen_SD(); - } - FILE *fp = fopen("/sd/TCal/TCalData.txt", "a"); fp= fopen("/sd/TCal/TCalData.txt", "r"); if(!fp) { @@ -369,15 +345,59 @@ } TFT.write_calibrate(tcal); // write cal data to screen } +} - /* Set the tracker for the dial - define the Area for touching */ - //TFT.Track(0, 0, 800, 480, 201); - TFT.Track(70, 375, 280, 30, 1); - TFT.Track(450, 375, 280, 30, 2); // Slider +void initialize_Images() +{ + TFT.DLstart(); + TFT.DL(CLEAR_COLOR_RGB(255,255,255)); + TFT.DL(CLEAR(1,1,1)); + + TFT.DL(BITMAP_HANDLE(0)); + err[0] = TFT.Load_jpg("/sd/Logo.jpg",& x_size,& y_size, 0); + TFT.DL(BITMAP_HANDLE(1)); + err[1] = TFT.Load_jpg("/sd/ITV_1.jpg",& x_size,& y_size, 45000); + TFT.DL(BITMAP_HANDLE(2)); + err[2] = TFT.Load_jpg("/sd/ITV_2.jpg",& x_size,& y_size, 60000); + TFT.DL(BITMAP_HANDLE(3)); + err[3] = TFT.Load_jpg("/sd/PF3W_1.jpg",& x_size,& y_size, 85000); + TFT.DL(BITMAP_HANDLE(4)); + err[4] = TFT.Load_jpg("/sd/PF3W_2.jpg",& x_size,& y_size, 150000); + TFT.DL(BITMAP_HANDLE(5)); + err[5] = TFT.Load_jpg("/sd/PSE_1.jpg",& x_size,& y_size, 230000); + TFT.DL(BITMAP_HANDLE(6)); + err[6] = TFT.Load_jpg("/sd/PSE_2.jpg",& x_size,& y_size, 260000); + + TFT.DL(DISPLAY()); // Display the image + TFT.Swap(); // Swap the current display list + TFT.Flush_Co_Buffer(); // Download the command list into fifo + TFT.WaitCmdfifo_empty(); +} + +int main() +{ + dac1.wakeup(); + dac2.wakeup(); + dac1.write_u12(0); + dac2.write_u12(0); + ft_uint32_t TrackRegisterVal = 0; // touch track + + TFT.MemWrite(REG_ROTATE, 1); + TFT.Rotate(1); + + Start_Screen("Starting..."); // Show start screen + + while(card_present.read()) { + error_screen_SD(); + } + + touchscreen_Calibration(); + + initialize_Images(); + TFT.Track(200, 400, 375, 30, 1); + TFT.Track(200, 400, 375, 30, 2); TFT.Flush_Co_Buffer(); // Download the commands into fifo - TFT.WaitCmdfifo_empty(); // Wait till coprocessor completes the operation - screen_1(); // paint screen - + TFT.WaitCmdfifo_empty(); /* the demo is updating the screen in a endless loop*/ while(1) { // Touch position @@ -386,18 +406,16 @@ ft_uint8_t tagval = 0; TrackRegisterVal = TFT.Rd32(REG_TRACKER); // check if one of the two tracking fields is touched tagval = TrackRegisterVal & 0xff; - if(0 != tagval) { // touch -> get new values - if(1 == tagval) { - ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095); - ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590; - //dac1.write_u12(ITVpressure1_input_raw); - } else if(2 == tagval) { // the slider is touched - ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095); - ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585; - //dac2.write_u12(ITVpressure2_input_raw); - } else if (200 == tagval) { - break; - } + if(1 == tagval) { + ITVpressure1_user_input = (TrackRegisterVal>>20) * (2356.0/4095); + ITVpressure1_input_raw = (TrackRegisterVal>>20) * (2356.0/4095) + 590; + dac1.write_u12(ITVpressure1_input_raw); + } else if(2 == tagval) { // the slider is touched + ITVpressure2_user_input = (TrackRegisterVal>>20) * (2386.0/4095); + ITVpressure2_input_raw = (TrackRegisterVal>>20) * (2386.0/4095) + 585; + dac2.write_u12(ITVpressure2_input_raw); + } else if (200 == tagval) { + break; } else if(curX !=0x8000 && touched>0) { touched++; distance = curX - pasX; @@ -463,7 +481,7 @@ location += (int16_t) velocity; paslocation = location; //no page 5 - } else if (location <-2500) { + } else if (location <-1700) { velocity = 10; location += (int16_t) velocity; paslocation = location; @@ -478,9 +496,9 @@ velocity-= 2; } } - } + } - screen_1(); // paint new screen - TFT.Sleep(10); // wait 10ms for next time to repaint the screen - } // end of display loop - } \ No newline at end of file + screen_1(); // paint new screen + TFT.Sleep(10); // wait 10ms for next time to repaint the screen + } // end of display loop +} \ No newline at end of file