📄 tp.c
字号:
/*** $Id: tp.c,v 1.2 2005/02/06 04:54:17 zxh Exp $**** tp.c: Touch panel calibration module of FHAS.**** Copyright (C) 2002, 2003 Feynman Software, all rights reserved.**** Use of this source package is subject to specific license terms** from Beijing Feynman Software Technology Co., Ltd.**** URL: http://www.minigui.com**** Current maintainer: Chen Lei (leon@minigui.org).***/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <fcntl.h>#include <sys/time.h>#include <sys/types.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "tp.h"/*---------------------------------------------------------------------------*/#define DEV_NODE "/dev/tsc2101/touchscreen"#define TP_CONF "tp.cfg"#define TP_SECTION "TPINFO"typedef struct { short header; short x; short y; short pad; struct timeval stamp;} TS_EVENT;typedef struct { ushort x; ushort y;} TS_POINT;/*static TS_POINT screenCalPos[5] = { { OFF1, OFF1 }, { SCREEN_WIDTH - OFF1 - 1, SCREEN_HEIGHT - OFF1 - 1 }, { SCREEN_WIDTH - OFF2 - 1, OFF2 }, { OFF2, SCREEN_HEIGHT - OFF2 - 1 }, { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 }};*/static HWND hDlgTp;static const char config[] = "[TPINFO]\nTX0=\nTY0=\nTX1=\nTY1=\n";//static int xa[5], ya[5];//static int k = 0, xsum, ysum, cnt = 0;//static char tpkey[10], tpvalue[10];#define fh_data_path "/home/fhas2/data/"static POINT src_pts [5] = { { OFF1, OFF1 }, { SCREEN_WIDTH - OFF2 - 1, OFF2 }, { SCREEN_WIDTH - OFF1 - 1, SCREEN_HEIGHT - OFF1 - 1 }, { OFF2, SCREEN_HEIGHT - OFF2 - 1 }, { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 }};static POINT dst_pts [5] = {}; /*---------------------------------------------------------------------------*//*static int SetTPConf (const char *key, char* value){ char buf[PATH_MAX + NAME_MAX + 1]; strcpy (buf, fh_data_path); strcat (buf, TP_CONF); if (SetValueToEtcFile (buf, TP_SECTION, key, value) < 0) return -1; else return 0;}*//* Draw the x-hair to stated coordinates */static void drawPlus (HDC hdc, int x_coord, int y_coord,int delete){ int xcoord, ycoord; int screen_w, screen_h;#ifdef _COOR_TRANS#if _ROT_DIR_CCW /* swap coord 90 degree -- from 320x240 to 240x320*/ xcoord = y_coord; ycoord = SCREEN_WIDTH - 1 -x_coord; screen_w = SCREEN_HEIGHT; screen_h = SCREEN_WIDTH;#else /* swap coord 90 degree -- from 320x240 to 240x320*/ xcoord = SCREEN_HEIGHT -1 - y_coord; ycoord = x_coord; screen_w = SCREEN_HEIGHT; screen_h = SCREEN_WIDTH;#endif#else xcoord = x_coord; ycoord = y_coord; screen_w = SCREEN_WIDTH; screen_h = SCREEN_HEIGHT;#endif if (delete ) SetPenColor(hdc, PIXEL_lightgray); else SetPenColor(hdc, PIXEL_black);printf("xcoord = %d, ycoord = %d\n", xcoord, ycoord); ScreenToClient(hDlgTp, &xcoord, &ycoord); /* draw horizontal line */ MoveTo(hdc, xcoord - SZ_XHAIR/2, ycoord); LineTo(hdc, xcoord + SZ_XHAIR/2, ycoord); /* draw vertical line */ MoveTo(hdc, xcoord, ycoord - SZ_XHAIR/2); LineTo(hdc, xcoord, ycoord + SZ_XHAIR/2);}/*static int tp_init (void){ if ((tsfd = open (DEV_NODE, O_RDWR)) < 0) { printf ("ERROR: unable to open %s", DEV_NODE); return -1; } return 0;}static void tp_close (void){ close (tsfd);}*/#if 0static int do_calibration(HDC hdc){ int k, xsum, ysum, cnt, rv; char tpkey0[10], tpvalue0[10]; char tpkey1[10], tpvalue1[10]; char tpkey2[10], tpvalue2[10]; char tpkey3[10], tpvalue3[10]; TS_EVENT ts_ev; for (k = 0; k < MAX_CAL_POINTS; k++) { /* for each screen position take the average of 5 points. */ drawPlus (hdc, screenCalPos[k].x, screenCalPos[k].y,0); cnt = xsum = ysum = 0; while (1) { if ((rv = read(tsfd, &ts_ev, sizeof(TS_EVENT))) == -1) { usleep(100); continue; } else if (rv != sizeof(TS_EVENT)) { usleep(100); continue; } if (ts_ev.header <= 0 || cnt > 5) //if (cnt > 5) { drawPlus(hdc, screenCalPos[k].x, screenCalPos[k].y, 1); break; } else { /* accumulate the x coords */ xsum += ts_ev.x; ysum += ts_ev.y; /* increment the event counter */ cnt++; } } /* take the average of the x & y points */ xa[k] = xsum/cnt; ya[k] = ysum/cnt; printf("k=%d AveX=%3d AveY=%3d (cnt=%3d)\n", k, xa[k], ya[k], cnt); if (k == 0) { sprintf (tpkey0, "TX%d", k); sprintf (tpvalue0, "%d", xa[k]); sprintf (tpkey1, "TY%d", k); sprintf (tpvalue1, "%d", ya[k]); } else { sprintf (tpkey2, "TX%d", k); sprintf (tpvalue2, "%d", xa[k]); sprintf (tpkey3, "TY%d", k); sprintf (tpvalue3, "%d", ya[k]); } } SetTPConf (tpkey0, tpvalue0); SetTPConf (tpkey1, tpvalue1); SetTPConf (tpkey2, tpvalue2); SetTPConf (tpkey3, tpvalue3); return 0;}#endif/*---------------------------------------------------------------------------*/int TpWinProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; static int nClickCount = 0; int x, y; int i; switch (message) { case MSG_INITDIALOG: hDlgTp = hDlg; break; case MSG_LBUTTONDOWN: x = LOWORD (lParam); y = HIWORD (lParam); dst_pts [nClickCount].x = x; dst_pts [nClickCount].y = y; nClickCount ++; if (nClickCount >= 5) { SendNotifyMessage(hDlg, MSG_CLOSE, 0, 0); } InvalidateRect (hDlg, NULL, TRUE); break; case MSG_PAINT: hdc = BeginPaint (hDlg); drawPlus (hdc, src_pts [nClickCount].x, src_pts [nClickCount].y, 0); EndPaint (hDlg, hdc); return 0;/* case MSG_IDLE: hdc = GetClientDC(hDlg); do_calibration(hdc); ReleaseDC(hdc); SendNotifyMessage(hDlg, MSG_CLOSE, 0, 0); break;*/ case MSG_CLOSE: //tp_close(); for (i = 0; i < 5; i++) { printf ("---------dst_pts[%d].x=%d\n", i, dst_pts [i].x); printf ("---------dst_pts[%d].y=%d\n", i, dst_pts [i].y); } SetMouseCalibrationParameters (dst_pts, src_pts); EndDialog (hDlg, 0); return 0; } return DefaultDialogProc (hDlg, message, wParam, lParam);}/*---------------------------------------------------------------------------*/DLGTEMPLATE DlgTp={ WS_BORDER, WS_EX_NONE, MAINWINDOW_LX, MAINWINDOW_TY, MAINWINDOW_RX-MAINWINDOW_LX, MAINWINDOW_YY-MAINWINDOW_TY, "", 0, 0, 1, NULL, 0};CTRLDATA CtrlTp[] ={ { "static", WS_CHILD | SS_CENTER | WS_VISIBLE, INFO_X,INFO_Y, INFO_W, INFO_H, IDC_INFO, "请点击目标中心", 0 }};//static void InitDialogBox (HWND hWnd)void OpenTpDialogBox (HWND hWnd){ DlgTp.controls = CtrlTp; DialogBoxIndirectParam (&DlgTp, hWnd, TpWinProc, 0L);}/*int MiniGUIMain (int argc, const char* argv[]){#ifdef _LITE_VERSION SetDesktopRect (0, 0, 1024, 768);#endif InitDialogBox (HWND_DESKTOP); return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -