📄 calibrate.c
字号:
/*--------------------------------------------------------------------------------------------------------------------
用于触摸屏的校准 08-8-6
-----------------------------------------------------------------------------------------------------------------------*/
#include "sysincludes.h"
#include "GUIDEMO.H"
#include "graph.h"
#include "Calibrate.h"
#include "GUI.h"
#include "GUI_X.h"
#include "WIDGET.h"
#include "../menu_item/Menu_item.h"
#include "../menu_widget/Menu_common.h"
#include "../menu_widget/ListMenu.h"
#include "string.h"
#include "g_data.h"
#define blank_h2p(h) (blank_obj *) WM_HMEM2Ptr(h)
static const char * _acPos[] = {
"(upper left position)",
"(lower right position)"
};
static void _WaitForPressedState(int Pressed);
static void _DispStringCentered(const char * pString);
static void _GetPhysValues(int LogX, int LogY, const char * pString);
static void _Explain(void);
static void blank_callback(WM_MESSAGE *);
static void _WaitForPressedState(int Pressed) {
GUI_HID_STATE State;
do {
GUI_TOUCH_GetState(&State);
if (State.Pressed == Pressed) {
break;
}
GUI_Delay (100);
} while (1);
}
static void _DispStringCentered(const char * pString) {
GUI_RECT Rect;
Rect.x0 = Rect.y0 = 0;
Rect.x1 = LCD_GetXSize() - 1;
Rect.y1 = LCD_GetYSize() - 1;
GUI_DispStringInRect(pString, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
}
static void _GetPhysValues(int LogX, int LogY, const char * pString) {
char acText[] = "Press here";
GUI_RECT Rect;
int FontSizeY, Align;
FontSizeY = GUI_GetFontSizeY();
GUI_Clear();
GUI_SetColor(GUI_BLACK);
_DispStringCentered("Runtime calibration,\n"
"please touch the screen\n"
"at the center of the ring."); /* Ask user to press the touch */
/* Calculate the rectangle for the string */
Rect.y0 = LogY - FontSizeY;
Rect.y1 = LogY + FontSizeY;
if (LogX < LCD_GetXSize() / 2) {
Rect.x0 = LogX + 15;
Rect.x1 = LCD_GetXSize();
Align = GUI_TA_LEFT;
} else {
Rect.x0 = 0;
Rect.x1 = LogX - 15;
Align = GUI_TA_RIGHT;
}
/* Show the text nearby the ring */
GUI_DispStringInRect(acText, &Rect, Align | GUI_TA_TOP);
GUI_DispStringInRect(pString, &Rect, Align | GUI_TA_BOTTOM);
/* Draw the ring */
GUI_FillCircle(LogX, LogY, 10);
GUI_SetColor(GUI_WHITE);
GUI_FillCircle(LogX, LogY, 5);
GUI_SetColor(GUI_BLACK);
/* Wait until touch is pressed */
}
static void _Explain(void) {
_DispStringCentered("This sample shows how\n"
"a touch screen can be\n"
"calibrated at run time.\n"
"Please press the touch\n"
"screen to continue...");
GUI_DispStringHCenterAt("TOUCH_Calibrate", LCD_GetXSize() / 2, 5);
}
void Calibrate(void)
{
WM_HWIN h;
blank_obj *p;
if (memdev == 0)
memdev = GUI_MEMDEV_Create(0, 0, 320, 240);
h = WM_CreateWindowAsChild(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW,
blank_callback, sizeof(blank_obj) - sizeof(WM_Obj));
p = blank_h2p(h);
/* Disable上一层窗口(并没有隐藏)。*/
WM_HideWindow(p->widget.Win.hNextLin);
WM_Paint(h);
go_prev(h, (WM_Obj *)p);
if (menu_main_window == 0) {
GUI_MEMDEV_Delete(memdev);
memdev = 0;
}
}
static void blank_callback(WM_MESSAGE *msg)
{
int aLogX = 15;int aLogY = 15;
int aPhysX ;int aPhysY ;
int aLogX2 = LCD_GetXSize() - 20;int aLogY2 = LCD_GetYSize() - 20;
int aPhysX2 ;int aPhysY2 ;
int calx0, calx1;int caly0, caly1;
WM_HWIN h = msg->hWin;
blank_obj *p = blank_h2p(h);
GUI_HID_STATE *state;
switch (msg->MsgId) {
case WM_PAINT:
GUI_MEMDEV_Select(memdev);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font13B_ASCII);
GUI_MEMDEV_CopyToLCD(memdev);
_Explain();
GUI_MEMDEV_CopyToLCD(memdev);
_WaitForPressedState(1);
_WaitForPressedState(0);
_GetPhysValues(aLogX, aLogY,_acPos[0]);
GUI_MEMDEV_CopyToLCD(memdev);
_WaitForPressedState(1);
aPhysX = GUI_TOUCH_GetxPhys();
aPhysY = GUI_TOUCH_GetyPhys();
_WaitForPressedState(0);
_GetPhysValues(aLogX2, aLogY2,_acPos[1]);
GUI_MEMDEV_CopyToLCD(memdev);
_WaitForPressedState(1);
aPhysX2 = GUI_TOUCH_GetxPhys();
aPhysY2 = GUI_TOUCH_GetyPhys();
_WaitForPressedState(0);
GUI_Clear();
GUI_MEMDEV_CopyToLCD(memdev);
GUI_TOUCH_Calibrate(0, aLogX, aLogX2, aPhysX, aPhysX2);
GUI_TOUCH_Calibrate(1, aLogY, aLogY2, aPhysY, aPhysY2);
GUI_TOUCH_GetCalData(GUI_COORD_X, &calx0, &calx1);
GUI_TOUCH_GetCalData(GUI_COORD_Y, &caly0, &caly1);
g_calx0=calx0;g_calx1=calx1;g_caly0=caly0;g_caly1=caly1;
GUI_DispStringAt("calX0: ", 0, 0); GUI_DispDec(calx0, 4); GUI_DispNextLine();
GUI_DispString ("calX1: "); GUI_DispDec(calx1, 4); GUI_DispNextLine();
GUI_DispString ("calY0: "); GUI_DispDec(caly0, 4); GUI_DispNextLine();
GUI_DispString ("calY1: "); GUI_DispDec(caly1, 4);
GUI_DispStringAt("lcdx0: ", 0, 100); GUI_DispDec(aLogX, 4); GUI_DispNextLine();
GUI_DispString ("lcdx1: "); GUI_DispDec(aLogX2, 4); GUI_DispNextLine();
GUI_DispString ("lcdy0: "); GUI_DispDec(aLogY, 4); GUI_DispNextLine();
GUI_DispString ("lcdy1: "); GUI_DispDec(aLogY2, 4); GUI_DispNextLine();
GUI_DispString ("tscX0: "); GUI_DispDec(aPhysX, 4); GUI_DispNextLine();
GUI_DispString ("tscX1: "); GUI_DispDec(aPhysX2, 4); GUI_DispNextLine();
GUI_DispString ("tscY0: "); GUI_DispDec(aPhysY, 4); GUI_DispNextLine();
GUI_DispString ("tscY1: "); GUI_DispDec(aPhysY2, 4); GUI_DispNextLine();
GUI_DispString ("Please touch display to continue...");
GUI_Delay(1000);
GUI_MEMDEV_CopyToLCD(memdev);
_WaitForPressedState(1);
_WaitForPressedState(0);
break;
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -