Demo for FT800 lib. Use a dial wheel to select the color and a slider to change the brightness.

Dependencies:   FT800_2 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Demo for mbed Library for FTDI FT800  Enbedded Video Engine "EVE"
00002  * by Peter Drescher, DC2PD 2014
00003  * Released under the MIT License: http://mbed.org/license/mit */
00004 
00005 #include "mbed.h"
00006 #include "FT_Platform.h"
00007 
00008 
00009 FT800 TFT(PA_7,PA_6,PA_5,PC_7,PB_4,PA_9);  // mosi, miso, sck, ss, int, pd     // the FT800 is connected to SPI 11-13
00010 
00011 // global Vars
00012 unsigned int r,b,g;
00013 
00014 // function to convert hue , saturation and  value to RGB
00015 // see http://en.wikipedia.org/wiki/HSL_and_HSV
00016 void hsv2rgb(float H,float S, float V)
00017 {
00018     float f,h,p,q,t;
00019     int i;
00020     if( S == 0.0) {
00021         r = V * 255;  
00022         g = V * 255;
00023         b = V * 255;
00024         return;
00025     }
00026     if(H > 360.0) H = 0.0;   // check values
00027     if(S > 1.0) S = 1.0; 
00028     if(S < 0.0) S = 0.0;
00029     if(V > 1.0) V = 1.0;
00030     if(V < 0.0) V = 0.0;
00031     
00032     h = H / 60.0;
00033     i = (int) h;
00034     f = h - i;
00035     p = V * (1.0 - S);
00036     q = V * (1.0 - (S * f));
00037     t = V * (1.0 - (S * (1.0 - f)));
00038  
00039     switch(i) {
00040         case 0:
00041             r = V * 255;  
00042             g = t * 255;
00043             b = p * 255;
00044             break;
00045         case 1:
00046             r = q * 255;
00047             g = V * 255;
00048             b = p * 255;
00049             break;
00050         case 2:
00051             r = p * 255;
00052             g = V * 255;
00053             b = t * 255;
00054             break;
00055         case 3:
00056             r = p * 255;
00057             g = q * 255;
00058             b = V * 255;
00059             break;
00060         case 4:
00061             r = t * 255;
00062             g = p * 255;
00063             b = V * 255;
00064             break;
00065         case 5:
00066         default:
00067             r = V * 255;
00068             g = p * 255;
00069             b = q * 255;
00070             break;
00071     }  
00072 }
00073 
00074 
00075 /***************************************************************************/
00076 /* Show a Screen with Text for 5 seconds                                   */
00077 /* A spinner shows the delay                                               */
00078 /***************************************************************************/
00079 
00080 ft_void_t Start_Screen(ft_char8_t *str)
00081 {
00082     TFT.DLstart();                                         // start a new display command list
00083     TFT.DL(CLEAR_COLOR_RGB(255,255,255));      // set the clear color to white
00084     TFT.DL(CLEAR(1,1,1));                      // clear buffers -> color buffer,stencil buffer, tag buffer
00085     TFT.DL(COLOR_RGB(0x80,0x80,0x00));         // set current color
00086     TFT.Text((TFT.DispWidth/2), TFT.DispHeight/2, 31, OPT_CENTERX, str); // draw Text with font 31
00087     TFT.DL(COLOR_RGB(0xFF,0x00,0x00));         // change current color
00088     TFT.Spinner((TFT.DispWidth/2),TFT.DispHeight/4, 0,0);  // draw a animated spinner
00089 
00090     TFT.DL(DISPLAY());                         // Display the image
00091     TFT.Swap();                                            // Swap the current display list
00092     TFT.Flush_Co_Buffer();                                 // Download the command list into fifo
00093 
00094     TFT.WaitCmdfifo_empty();                               // Wait till coprocessor completes the operation
00095     TFT.Sleep(5000);                                       // Wait 5 s to show
00096 }
00097 
00098 // construct the screen and downloasd it to the LCD
00099 void screen_1(unsigned int color,unsigned int bright)
00100 {
00101     TFT.DLstart();                         // start a new display command list
00102     TFT.DL(CLEAR(1,1,1));                  // clear buffers -> color buffer,stencil buffer, tag buffer
00103     TFT.DL(COLOR_RGB(0xff,0xff,0xff));     // set current color to white
00104     TFT.DL(TAG(1));                        // assign TAG value 1
00105     //TFT.FgColor(COLOR_RGB(0xff,0,0));      // forground color red
00106     TFT.Dial(249, 86, 55, 0, color);       // dial for color 
00107     TFT.DL(TAG(2));                        // assign TAG value 2
00108     //TFT.FgColor(COLOR_RGB(0,0xff,0));      // forground color green
00109     TFT.Slider(196, 215, 236, 21, 0, bright , 255);       // slider for brightness 
00110     TFT.DL(COLOR_RGB(0xff,0xff,0xff));     // set current color to white
00111     TFT.Text(22, 84, 30, 0, "Color");      // text Color
00112     TFT.Text(22, 208, 30, 0, "Brightness");// text Brightness
00113     
00114     TFT.DL(POINT_SIZE(100));               // color point around the dial 
00115     TFT.DL(BEGIN(POINTS));                  
00116     TFT.DL(COLOR_RGB(0x0,0x0,0xff));       // color of next point 
00117     TFT.DL(VERTEX2II(183,47,0,0));         // set point x,y 
00118     TFT.DL(COLOR_RGB(0xff,0x0,0x0)); 
00119     TFT.DL(VERTEX2II(249,162,0,0));
00120     TFT.DL(COLOR_RGB(0xff,0x0,0xff)); 
00121     TFT.DL(VERTEX2II(183,123,0,0));
00122     TFT.DL(COLOR_RGB(0xff,0xff,0x0)); 
00123     TFT.DL(VERTEX2II(317,123,0,0));
00124     TFT.DL(COLOR_RGB(0x0,0xff,0xff)); 
00125     TFT.DL(VERTEX2II(249,11,0,0));
00126     TFT.DL(COLOR_RGB(0x0,0xff,0x00)); 
00127     TFT.DL(VERTEX2II(317,50,0,0));
00128     TFT.DL(SCISSOR_XY(10,10));             // define sub area starting at 10,10
00129     TFT.DL(SCISSOR_SIZE(50,50));           // size 50,50
00130     hsv2rgb(color /65536.0 * 360,1.0,bright / 255.0);  // calculate rgb color from settings 
00131     TFT.DL(CLEAR_COLOR_RGB(r,b,g));        // set filling color to r,g,b
00132     TFT.DL(CLEAR(1,1,1));                  // fill the area  
00133     
00134     TFT.DL(DISPLAY());                     // Display the image
00135     TFT.Swap();                            // Swap the current display list
00136     TFT.Flush_Co_Buffer();                 // Download the command list into fifo
00137     TFT.WaitCmdfifo_empty();               // Wait till coprocessor completes the operation
00138 }
00139 
00140 int main()
00141 {
00142     unsigned int color = 0,bright = 0;
00143     ft_uint32_t TrackRegisterVal = 0;              // touch track
00144 
00145     Start_Screen("RGB DEMO2 START");                // Show start screen
00146     TFT.Calibrate();                               // calibrate the touch screen
00147 
00148     /* Set the tracker for the dial -  define the Area for touching */
00149     TFT.Track(249, 86, 1, 1, 1);                   // Dial  - dimension 1,1 means rotary
00150     TFT.Track(179, 199, 277, 48, 2);               // Slider
00151     TFT.Flush_Co_Buffer();                         // Download the commands into fifo
00152     TFT.WaitCmdfifo_empty();                       // Wait till coprocessor completes the operation
00153     screen_1(color,bright);                        // paint screen
00154 
00155     /* the demo is updating the screen in a endless loop                                    */
00156     while(1) {
00157         ft_uint8_t tagval = 0;
00158         TrackRegisterVal = TFT.Rd32(REG_TRACKER);    // check if one of the two tracking fields is touched
00159         tagval = TrackRegisterVal & 0xff;
00160         if(0 != tagval) {                            // touch -> get new values
00161             if(1 == tagval) {                        // the dial touched
00162                 color = TrackRegisterVal>>16;        // get the new value
00163             } else if(2 == tagval) {                 // the slider is touched
00164                 bright = TrackRegisterVal>>16;       // get new slider value
00165                 bright = bright * 255/65536;         // scale it down to 255
00166             }
00167             screen_1(color,bright);                  // paint new screen
00168             TFT.Sleep(10);                           // wait 10ms for next check
00169         }
00170 
00171     }  // end of display loop
00172 }
00173 
00174 
00175