Helloworld program for TFT320_QVT Touchscreen module

Dependencies:   TFTLCD UTouch mbed

Fork of TFT_320QVT_Window_Drag_Demo by Dmitry Shtatnov

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /** \file main.cpp
00002  *  \brief mbed Hello World demo for TFT-320QVT module with SSD1289 and XPT2046 touchscreen.
00003  *   
00004  *  \copyright GNU Public License, v2. or later
00005  *  Creates a window, which can be dragged within the screen, and can be closed
00006  *  with the standard WIndows-style "x"-button.
00007  *  Window appearance: initial position, size and colors can be changed via defines
00008  *  Window in this demo can not be moved beyond the screen area except of the right side.
00009  *  May require a touchscreen calibration procedure using UTouchCD.h
00010  *
00011  *  Made by Dmitry Shtatnov, SSSR Labs
00012  *  http://modularsynth.ru/
00013  ***************************************************************************************/
00014 
00015 #include "mbed.h"
00016 #include "ssd1289.h"
00017 #include "UTouch.h"
00018 
00019 #define C_WINDOW_BODY       0xCCCCCC
00020 #define C_WINDOW_HIGHLIGHT  0xDDDDDD
00021 #define C_WINDOW_SHADOW     0xBBBBBB
00022 #define C_WINDOW_TITLE_BAR  0x0066DD
00023 #define C_DESKTOP_BG        0x000000
00024 
00025 #define WINDOW_WIDTH 150
00026 #define WINDOW_HEIGHT 100
00027 
00028 PortOut LCDPA(PortA,0xFF00);
00029 PortOut LCDPC(PortC,0x00FF);
00030 //                 CS,   REST, RS,   WR,   DATA,      BL, RD
00031 SSD1289_LCD myGLCD(PB_3, PB_4, PB_0, PB_1, &LCDPA, &LCDPC, NC, PB_2);
00032 
00033 UTouch  myTouch(PB_9, PB_8, PB_7, PB_6, PB_5);
00034   long x, y, oldx, oldy, wx, wy;
00035   float p;
00036   uint8_t av_cnt;
00037     int16_t rx, ry, rz1, rz2, pressure;
00038   char xc[10], yc[10], z1c[10], z2c[10], str[15];
00039   bool drag = false;
00040   bool loop = true;
00041     
00042 bool title(uint16_t xcur, uint16_t ycur, uint16_t xwin, uint16_t ywin) {
00043     if((xcur>xwin+2)&&(xcur<xwin+WINDOW_WIDTH-18)&&(ycur>ywin+2)&&(ycur<ywin+22)) return true;
00044     else return false;
00045 }
00046 
00047 bool close(uint16_t xcur, uint16_t ycur, uint16_t xwin, uint16_t ywin) {
00048     if((xcur>xwin+WINDOW_WIDTH-19)&&(xcur<xwin+WINDOW_WIDTH-1)&&(ycur>ywin+2)&&(ycur<ywin+21)) return true;
00049     else return false;
00050 }
00051 
00052 void drawBox(uint16_t xpos, uint16_t ypos, uint16_t xsize, uint16_t ysize) {
00053     myGLCD.FillRect(xpos,ypos,xpos+xsize-1,ypos+ysize-1,C_WINDOW_BODY);
00054     myGLCD.DrawHLine(xpos,ypos,xsize,C_WINDOW_HIGHLIGHT);
00055     myGLCD.DrawHLine(xpos+1,ypos+ysize-1,xsize-1,C_WINDOW_SHADOW);
00056     myGLCD.DrawVLine(xpos,ypos,ysize,C_WINDOW_HIGHLIGHT);
00057     myGLCD.DrawVLine(xpos+xsize-1,ypos,ysize-1,C_WINDOW_SHADOW);
00058 }    
00059 
00060 void drawWindow(uint16_t xpos, uint16_t ypos, uint16_t xsize, uint16_t ysize) {
00061     drawBox(xpos, ypos, xsize, ysize);
00062     myGLCD.FillRect(xpos+2,ypos+2,xpos+xsize-3,ypos+21,C_WINDOW_TITLE_BAR);
00063     drawBox(xpos+xsize-21,ypos+3,18,18);
00064     myGLCD.DrawLine(xpos+xsize-18,ypos+6,xpos+xsize-7,ypos+17,COLOR_BLACK);
00065     myGLCD.DrawLine(xpos+xsize-18,ypos+17,xpos+xsize-7,ypos+6,COLOR_BLACK);
00066     myGLCD.SetBackground(C_WINDOW_TITLE_BAR);
00067     myGLCD.SetForeground(COLOR_WHITE);
00068     myGLCD.Print("Hello World", xpos+6,ypos+6);
00069 }
00070 int main() {
00071   myGLCD.Initialize();
00072   myGLCD.SetBackground(COLOR_WHITE);
00073   myGLCD.SetForeground(COLOR_BLACK);
00074   myGLCD.FillScreen(C_DESKTOP_BG);
00075   
00076 while(1==1)
00077 {
00078   wx = 85;
00079   wy = 70;
00080   loop = true;
00081   myGLCD.SetFont(&TerminusFont);
00082   myTouch.InitTouch();
00083   myTouch.SetPrecision(PREC_HI);
00084   drawWindow(wx,wy,WINDOW_WIDTH,WINDOW_HEIGHT);
00085   while(loop)
00086   {
00087     if (myTouch.DataAvailable() == true)
00088     {
00089       if(myTouch.Read()) {
00090         x = myTouch.GetX();
00091         y = myTouch.GetY();
00092         if((oldx!=x)&&(oldy!=y)) {
00093             if(drag) {
00094                 myGLCD.FillRect(wx, wy, wx+WINDOW_WIDTH-1, wy+WINDOW_HEIGHT-1, C_DESKTOP_BG);
00095                 wx=wx+x-oldx;
00096                 wy=wy+y-oldy;
00097                 drawWindow(wx,wy,WINDOW_WIDTH,WINDOW_HEIGHT);
00098             }
00099             if(title(x, y, wx, wy)) {
00100                 drag = true;
00101                 }
00102             if(close(x, y, wx, wy)) {
00103                 myGLCD.FillRect(wx, wy, wx+WINDOW_WIDTH-1, wy+WINDOW_HEIGHT-1, C_DESKTOP_BG);
00104                 loop = false;
00105             }
00106             oldx = x;
00107             oldy = y;
00108         }
00109       }
00110     }
00111     else {
00112       drag = false;
00113     }
00114   }
00115 }
00116 }