⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guidemo_touch.c

📁 基于3SC44B0的移植代码,包括UCOSII、UCGUI、触模屏、摄像头的程序
💻 C
字号:
/***********************************************************************************************************                                                uC/GUI*                        Universal graphic software for embedded applications**                       (c) Copyright 2002, Micrium Inc., Weston, FL*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH**              礐/GUI is protected by international copyright laws. Knowledge of the*              source code may not be used to write a similar product. This file may*              only be used in accordance with a license and should not be redistributed*              in any way. We appreciate your understanding and fairness.*----------------------------------------------------------------------File        : GUIDEMO_TouchPurpose     : Touch demo---------------------------END-OF-HEADER------------------------------*/#include "GUI.h"//#include "LCD_ConfDefaults.h"      /* valid LCD configuration */#include "GUIDEMO.h"#include "Button.h"#include "Edit.h"#include "44b.h"#if (GUI_WINSUPPORT && GUI_SUPPORT_TOUCH)#define countof(Obj) (sizeof(Obj)/sizeof(Obj[0]))/***********************************************************************       Static functions************************************************************************/static int _Log2Phys(int l, I32 l0, I32 l1, I32 p0, I32 p1) {  return p0 + ((p1 - p0) * (l - l0)) / (l1 - l0);}static void _Calibrate(int Coord, int Log0, int Log1, int Phys0, int Phys1, int *p0, int *p1) {  int l0 = 0;  int l1 = (Coord == GUI_COORD_X) ? LCD_XSIZE - 1 : LCD_YSIZE - 1;  *p0 = _Log2Phys(l0, Log0, Log1, Phys0, Phys1);  *p1 = _Log2Phys(l1, Log0, Log1, Phys0, Phys1);}/***********************************************************************       Static functions************************************************************************//********************************************************************       _ExecCalibration************************************************************************/void _ExecCalibration(void) {  int ax_Phys[2],ay_Phys[2],po,flag;/* calculate log. Positions */  int ax[2] = { 10, LCD_XSIZE -1-10};// int ay[2] = { 15, LCD_YSIZE-1-15};int ay[2] = { LCD_YSIZE-1-10, 10};  GUI_TOUCH_SetDefaultCalibration();/* _Calibrate upper left */  GUI_SetBkColor(GUI_RED);    GUI_Clear();   GUI_SetColor(GUI_YELLOW);  GUI_DrawHLine(0, 0, LCD_XSIZE-1);  GUI_DrawHLine(LCD_YSIZE-1, 0, LCD_XSIZE-1);  GUI_DrawVLine(0, 0, LCD_YSIZE-1);  GUI_DrawVLine(LCD_XSIZE-1, 0, LCD_YSIZE-1);   GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[0], ay[0], 10);  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[0], ay[0], 5);  GUI_SetColor(GUI_WHITE);  GUI_DispStringAt("Press here", ax[0]+20, ay[0]);  while(1){      rPUPE=0x00;							/*不使用上拉						*/       rPCONE=(rPCONE & 0x300ff) | 0x0500; /*pe45(touch_yh)out, pe67 input		*/       rPDATE=(rPDATE & 0xCF) ;       /* data low 6,7 ( 4.5= low out )	*/       for(po=0 ; po<30; po++ ) ;       flag= rPDATE&0x80;      for(po=0 ; po<30; po++ ) ;     if(flag==0)      {        TOUCH_X_ActivateY();        ay_Phys[0] =TOUCH_X_MeasureY();        TOUCH_X_ActivateX();        ax_Phys[0] =TOUCH_X_MeasureX();        break;       }}  #if 0   GUI_DispStringAt("Analog input:  X ,Y\n", 0, 40);    GUI_DispDec(ax_Phys[0] ,8);    GUI_DispString(",");    GUI_DispDec(ay_Phys[0] ,8);//    OSTimeDlyHMSM(0,0,4,0);	#endif  //GUI_Delay (100);/* Tell user to release *///  GUI_Clear();  GUI_DispStringAt("OK", ax[0]+20, ay[0]);  do{      rPUPE=0x00;							/*不使用上拉						*/      rPCONE=(rPCONE & 0x300ff) | 0x0500; /*pe45(touch_yh)out, pe67 input		*/      rPDATE=(rPDATE & 0xCF) ;       /* data low 6,7 ( 4.5= low out )	*/     for(po=0 ; po<30; po++ ) ;      flag= rPDATE&0x80;     for(po=0 ; po<30; po++ ) ;    }while(flag==0);  //GUI_Delay (500);/* _Calibrate lower right */  GUI_SetBkColor(GUI_RED);    GUI_Clear();   GUI_SetColor(GUI_YELLOW);  GUI_DrawHLine(0, 0, LCD_XSIZE-1);  GUI_DrawHLine(LCD_YSIZE-1, 0, LCD_XSIZE-1);  GUI_DrawVLine(0, 0, LCD_YSIZE-1);  GUI_DrawVLine(LCD_XSIZE-1, 0, LCD_YSIZE-1);  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[1], ay[1], 10);  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[1], ay[1], 5);  GUI_SetColor(GUI_WHITE);  GUI_SetTextAlign(GUI_TA_RIGHT);  GUI_DispStringAt("Press here", ax[1]-20, ay[1]);  while(1){     rPUPE=0x00;							/*不使用上拉						*/      rPCONE=(rPCONE & 0x300ff) | 0x0500; /*pe45(touch_yh)out, pe67 input		*/      rPDATE=(rPDATE & 0xCF) ;       /* data low 6,7 ( 4.5= low out )	*/      for(po=0 ; po<30; po++ ) ;      flag= rPDATE&0x80;     for(po=0 ; po<30; po++ ) ;      if(flag==0)	{	 TOUCH_X_ActivateY();	ay_Phys[1] =TOUCH_X_MeasureY();	 TOUCH_X_ActivateX();	ax_Phys[1] =TOUCH_X_MeasureX();	break;	}    }  #if 0     GUI_DispStringAt("Analog input:  X ,Y\n", 0, 40);    GUI_DispDec(ax_Phys[0] ,8);    GUI_DispString(",");    GUI_DispDec(ay_Phys[0] ,8);   //OSTimeDlyHMSM(0,0,4,0);#endif   GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);   //GUI_Delay (10);   } /***********************************************************************       _TestCalibration************************************************************************/void _TestCalibration(void) {  #define  but_id   0x900    #define  but_ida   0x901  int IdleCnt=0,Key;  BUTTON_Handle hButton1,hButton2; GUI_CURSOR_Hide();  GUI_SetBkColor(GUI_WHITE);    GUI_SetColor(GUI_BLACK);    GUI_Clear();  GUI_SetFont(&GUI_Font16B_1);  hButton1 =  BUTTON_Create( 5, 3, 40, 20, but_id, BUTTON_CF_SHOW );  hButton2=  BUTTON_Create( 100, 3, 40, 20, but_ida, BUTTON_CF_SHOW );    BUTTON_SetFont (hButton1, &GUI_Font16B_1);   BUTTON_SetText (hButton1, "ESE");   BUTTON_SetFont (hButton2, &GUI_Font16B_1);   BUTTON_SetText (hButton2, "CLR");  GUI_SetPenSize( 5 );  while( 1){	  GUI_TOUCH_tState State;	Key=GUI_GetKey();	if(Key==but_id)       break;	if(Key==but_ida)	 GUI_Clear();	      GUI_TOUCH_GetState(&State);      if (State.Pressed) {      GUI_DrawPoint(State.x, State.y);      }     GUI_Delay (8);  }  BUTTON_Delete(hButton1);   BUTTON_Delete(hButton2);}/***********************************************************************       _ExecKeyboard***********************************************************************This creates a sample keyboard.The routine returns after ENTER or ESC has been pressed.*/#if 1//(LCD_XSIZE == 320) && (LCD_YSIZE == 240)static char _acText[] = { '1', '2', '3', '4', '5', '6',                                        '7', '8', '9', '0', '=','Q', 					    'W', 'E', 'R', 'T', 'Y', 'U', 					     'I', 'O', 'P', 'A', 'S', 'D', 					     'F', 'G', 'H', 'J', 'K', 'L',					    'Q', 'Z', 'X', 'C', 'V', 'B', 0};int _ExecKeyboard(void) {  int i;  int Key;  BUTTON_Handle ahButton[36];  BUTTON_Handle hButtonESC,hButtonESE;  EDIT_Handle   hEdit;  //GUI_RECT rText = {0,0, LCD_XSIZE, 20};    GUI_CURSOR_Show();  GUI_SetBkColor(GUI_RED);    GUI_Clear();  //GUI_DrawBitmap(&bmMicriumLogo, 5, 5);  // GUI_SetFont(&GUI_Font16B_1);  //GUI_SetColor(GUI_WHITE);  //GUI_DispStringInRect("BILLOW", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER); // rText.y0 +=20; // rText.y1 +=20; // GUI_DispStringInRect("Touch screen demo", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER);  /* Create Keyboard Buttons */    for (i=0; i< 36; i++) {    int x0 = 5  + 28*(i%6);    int y0 = 50 + 28*(i/6);    char c = _acText[i];    int Id = c ? c : 1;    char ac[2] = {0};    char *s= ac;    ac[0] = c;    ahButton[i] = BUTTON_Create( x0, y0, 25, 25, Id,BUTTON_CF_SHOW ); 	BUTTON_SetText (ahButton[i], s);    #if GUI_SUPPORT_MEMDEV      BUTTON_EnableMemdev(ahButton[i]);    #endif  }    hButtonESE = BUTTON_Create( 5, 5, 60, 20, GUI_ID_ESE,BUTTON_CF_SHOW );  BUTTON_SetText   (hButtonESE, "CLR");  //hEdit = EDIT_Create( 3, 30, 170, 20, ' ', 80, 0 );   hButtonESC = BUTTON_Create( 80, 5, 80, 20, GUI_ID_CANCEL,BUTTON_CF_SHOW );  BUTTON_SetText   (hButtonESC, "ESC");  hEdit = EDIT_Create( 3, 30, 170, 20, ' ', 80, 0 );  EDIT_SetFont(hEdit, &GUI_Font8x16);  /* Handle Keyboard until ESC or ENTER is pressed */  do {    Key = GUIDEMO_WaitKey1();  if(Key==GUI_ID_CANCEL)   break;      switch (Key) {    case 0:  break;    case GUI_ID_ESE:     BUTTON_Delete(hEdit);     hEdit = EDIT_Create( 3, 30, 170, 20, ' ', 80, 0 );     EDIT_SetFont(hEdit, &GUI_Font8x16);     break;    default:      EDIT_AddKey(hEdit, Key);    }  }  while(1);// ((Key != 'N') && (Key!=GUI_ID_CANCEL) && (Key!=0));  /* Cleanup */  for (i=0; i< countof(ahButton); i++) {    BUTTON_Delete(ahButton[i]);  }  BUTTON_Delete(hButtonESC);  BUTTON_Delete(hButtonESE);  BUTTON_Delete(hEdit);  return Key;}#elsestatic char _acText[] = {  '7','8','9','/',  '4','5','6','*',  '1','2','3','-',  '0',',','+','=',0};int _ExecKeyboard(void) {  int y0 = 75;  int XSize = LCD_GetXSize();  int YSize = LCD_GetYSize();  int XStep = XSize / 4;  int YStep = (YSize - y0) / 4;  int i;  int Key;  BUTTON_Handle ahButton[16];  BUTTON_Handle hButtonESC;  EDIT_Handle   hEdit;  GUI_RECT rText = {0};  rText.x1 = LCD_GetXSize() - 3;  rText.y1 = 15;  GUI_SetBkColor(GUI_RED);    GUI_Clear();  GUI_SetFont(&GUI_Font16B_1);  GUI_SetColor(GUI_WHITE);  GUI_DispStringInRect("礐/GUI", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER);  rText.y0 +=20;  rText.y1 +=20;  GUI_DispStringInRect("Touch screen demo", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER);  /* Create Keyboard Buttons */  for (i=0; _acText[i]; i++) {    int XPos = (i%4) * XStep + 3;    int YPos = (i/4) * YStep + 3 + y0;    char c = _acText[i];    int Id = c ? c : 1;    char ac[2] = {0};    char *s= ac;    ac[0] = c;    ahButton[i] = BUTTON_Create( XPos, YPos, XStep - 5, YStep - 5, Id, BUTTON_CF_SHOW );    BUTTON_SetText(ahButton[i], s);    BUTTON_EnableMemdev(ahButton[i]);  }  hButtonESC = BUTTON_Create( 3, 3, 80, 25, GUI_ID_CANCEL, BUTTON_CF_SHOW );  BUTTON_SetText(hButtonESC, "ESC");  hEdit = EDIT_Create( 5, y0 - 30, XSize - 10, 25, ' ', 80, 0 );  EDIT_SetFont(hEdit, &GUI_Font8x16);  /* Handle Keyboard until ESC or ENTER is pressed */  do {    Key = GUIDEMO_WaitKey();    switch (Key) {    case 0: break;    case GUI_ID_CANCEL:     break;    default:      EDIT_AddKey(hEdit, Key);    }  } while ((Key != 'N') && (Key!=GUI_ID_CANCEL) && (Key!=0));  /* Cleanup */  for (i=0; i< countof(ahButton); i++) {    BUTTON_Delete(ahButton[i]);  }  BUTTON_Delete(hButtonESC);  EDIT_Delete(hEdit);  return Key;}#endif/*************************************************************************              USER_Task************************************************************************/#if 1//GUIDEMO_LARGEvoid GUIDEMO_Touch(void) {  #define ID_KEYBOARD  0X805  #define ID_TESTCAL     0X806  #define ID_CALIBRATE 0X807   #define ID_DEMO         0X808    #define   ID_LCD        0X809  int i, r;  int XSize = LCD_GetXSize();  int YSize = LCD_GetYSize();  int XMid = XSize / 2;  int YMid = YSize / 2-40;  GUI_CURSOR_Show();  GUIDEMO_NotifyStartNext();  GUIDEMO_HideInfoWin();  do {    GUI_RECT rText;/*= {0, 80, XSize, 120};*/    BUTTON_Handle ahButton[5];    rText.x0=0;    rText.y0=10;    rText.x1=XSize;    rText.y1=40;    GUI_SetBkColor(GUI_BLUE);    GUI_Clear();    //GUI_DrawBitmap(&bmMicriumLogo, (XSize - 1 - bmMicriumLogo.XSize) / 2, 15);    GUI_SetFont(&GUI_Font8x16);    GUI_DispStringInRect("BILLOW Touch TEST V0", &rText, GUI_TA_HCENTER | GUI_TA_VCENTER); GUI_SetFont(&GUI_Font16B_1);ahButton[0] =  BUTTON_Create( XMid - 50, YMid - 20, 100, 50, ID_CALIBRATE,BUTTON_CF_SHOW );    ahButton[1] =  BUTTON_Create( XMid - 90, YMid + 40, 80, 30, ID_KEYBOARD, BUTTON_CF_SHOW );    ahButton[2] =  BUTTON_Create( XMid + 10, YMid + 40, 80, 30, ID_TESTCAL,BUTTON_CF_SHOW );  ahButton[3] =  BUTTON_Create( XMid - 90, YMid + 100, 80, 30, ID_DEMO,BUTTON_CF_SHOW );  ahButton[4] =  BUTTON_Create( XMid +10 , YMid + 100, 80, 30, ID_LCD,BUTTON_CF_SHOW );      BUTTON_SetText (ahButton[0], "Calibrate");    BUTTON_SetBkColor(ahButton[0], 0, GUI_RED);    BUTTON_SetText (ahButton[1], "Keyboard");    BUTTON_SetText (ahButton[2], "GUI draw");   BUTTON_SetText (ahButton[3], "GUI DEMOD");   BUTTON_SetText (ahButton[4], "LCD OFF");	    BUTTON_SetFont(ahButton[0], &GUI_FontComic18B_ASCII);    r = GUIDEMO_WaitKey1();    if (r==0) {      r = ID_CALIBRATE;      BUTTON_SetState(ahButton[0],BUTTON_STATE_PRESSED);      GUIDEMO_Delay(500);    }    for (i=0; i< countof(ahButton); i++) {      BUTTON_Delete(ahButton[i]);    }   switch (r) {   case ID_KEYBOARD:  r= _ExecKeyboard(); break;    case ID_CALIBRATE: _ExecCalibration(); break;    case ID_TESTCAL:   _TestCalibration(); break;    case ID_DEMO:   GUIDEMO_main(); break;    case ID_LCD:   GUI_LCD_OFF(); break;	    }  } while (r && (r!='n') && (r!='N'));}#elsevoid GUIDEMO_Touch(void) {}#endif#elsevoid GUIDEMO_Touch(void) {} /* avoid empty object files */#endif /* #if GUI_WINSUPPORT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -