📄 guidemo_touch.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_Touch
Purpose : Touch demo
---------------------------END-OF-HEADER------------------------------
*/
#include "GUI.h"
#include "LCD_ConfDefaults.h" /* valid LCD configuration */
#include "GUIDEMO.h"
#if (GUI_WINSUPPORT && GUI_SUPPORT_TOUCH)
#include "BUTTON.h"
#include "EDIT.h"
#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);
}
/*********************************************************************
*
* _ExecCalibration
*
**********************************************************************
*/
static void _ExecCalibration(void) {
int ax_Phys[2],ay_Phys[2];
/* calculate log. Positions */
int ax[2] = { 15, LCD_XSIZE -1-15};
// const int ay[2] = { 15, LCD_YSIZE-1-15};
int ay[2] = { LCD_YSIZE-1-15, 15};
GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
GUI_SetBkColor(GUI_RED);
GUI_Clear();
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]);
do {
GUI_PID_STATE State;
GUI_TOUCH_GetState(&State);
if (State.Pressed) {
ax_Phys[0] = GUI_TOUCH_GetxPhys();
ay_Phys[0] = GUI_TOUCH_GetyPhys();
break;
}
GUI_Delay (100);
} while (1);
/* Tell user to release */
GUI_Clear();
GUI_DispStringAt("OK", ax[0]+20, ay[0]);
do {
GUI_PID_STATE State;
GUI_TOUCH_GetState(&State);
if (State.Pressed == 0) {
break;
}
GUI_Delay (100);
} while (1);
/* _Calibrate lower right */
GUI_SetBkColor(GUI_RED);
GUI_Clear();
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]);
do {
GUI_PID_STATE State;
GUI_TOUCH_GetState(&State);
if (State.Pressed) {
ax_Phys[1] = GUI_TOUCH_GetxPhys();
ay_Phys[1] = GUI_TOUCH_GetyPhys();
break;
}
GUI_Delay (100);
} while (1);
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]);
{ /* calculate and display values for configuration file */
int x0, x1;
int y0, y1;
GUI_Clear();
_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1);
_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1);
GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine();
GUI_DispString ("x1: "); GUI_DispDec(x1, 4); GUI_DispNextLine();
GUI_DispString ("y0: "); GUI_DispDec(y0, 4); GUI_DispNextLine();
GUI_DispString ("y1: "); GUI_DispDec(y1, 4); GUI_DispNextLine();
GUI_DispString ("Please touch display to continue...");
GUI_Delay(1000);
do {
GUI_PID_STATE State;
GUI_TOUCH_GetState(&State);
if (State.Pressed)
break;
GUI_Delay (10);
} while (1);
}
}
/*********************************************************************
*
* _TestCalibration
*
**********************************************************************
*/
static void _TestCalibration(void) {
int IdleCnt=0;
BUTTON_Handle hButton;
GUI_SetBkColor(GUI_RED);
GUI_SetColor(GUI_WHITE);
GUI_Clear();
hButton = BUTTON_Create( 225, 15, 80, 40, 1, BUTTON_CF_SHOW );
BUTTON_SetText (hButton, "ABORT");
BUTTON_SetFont (hButton, &GUI_FontComic18B_ASCII);
while ((IdleCnt<50) && (GUI_GetKey()==0)) {
static GUI_PID_STATE StateLast;
GUI_PID_STATE State;
GUI_TOUCH_GetState(&State);
if ((StateLast.Pressed != State.Pressed) && (State.Pressed == 0)) {
GUI_Clear();
}
if ((StateLast.x != State.x) || ((StateLast.y != State.y))) {
if (State.Pressed) {
GUI_FillCircle(State.x, State.y, 5);
}
StateLast = State;
}
if (State.Pressed) {
IdleCnt =0;
} else {
IdleCnt++;
}
GUI_Delay (100);
}
EDIT_Delete(hButton);
}
/*********************************************************************
*
* _ExecKeyboard
*
**********************************************************************
This creates a sample keyboard.
The routine returns after ENTER or ESC has been pressed.
*/
#if (LCD_XSIZE == 320) && (LCD_YSIZE == 240)
static char _acText[] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '='
,0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'
,0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Q'
,0, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -