?? ads.c
字號:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
#ifdef _ADS_IAL
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/kd.h>
#include "44b.h"#include "misc.h"
#include "ial.h"
#include "ads.h"typedef struct {
int pressure;
int x;
int y;
} TS_EVENT;static TS_EVENT ts_event;static int ts = -1;
static int mousex = 0;
static int mousey = 0;
/************************ Low Level Input Operations **********************/
/*
* Mouse operations -- Event
*/
static int mouse_update(void) //更新鼠標狀態
{
return 1;
}
static void mouse_getxy(int *x, int* y)
{
*x = mousex; //最上層通過該函數取得最終的坐標值
*y = mousey;
}
static int mouse_getbutton(void) //最上層通過該函數,就知道是否有點擊
{
return ts_event.pressure;
}
static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,
struct timeval *timeout)
{ fd_set rfds;
int retvalue = 0;
int e;
if (!in) {
in = &rfds;
FD_ZERO (in);
}
if ((which & IAL_MOUSEEVENT) && ts >= 0) {
FD_SET (ts, in);
}
ioctl(ts,0,0); //調用驅動程序
e = select (FD_SETSIZE, in, out, except, timeout) ;
if (e > 0) {
if (ts >= 0 && FD_ISSET (ts, in)) {
FD_CLR (ts, in);
ts_event.x=0;
ts_event.y=0;
ts_event.pressure=0; read (ts, &ts_event, sizeof (TS_EVENT)); //從緩沖區讀取點擊狀態和坐標值 if (ts_event.pressure == 1 && ts_event.x > 0 && ts_event.y > 0) { //坐標變換,初始為:右下腳(0,0),左上腳(255,255),因為是八位A/D;轉換后的坐標為:左上腳(0,0),右下腳(640,480),符合LCD標準 mousex=(242-ts_event.x)*640/228; mousey=(235-ts_event.y)*480/218; // printf("mousex = %d\n",mousex); // printf("mousey = %d\n",mousey); // printf("ts_event.pressure = %d\n",ts_event.pressure); ts_event.pressure = 4; //相當于鼠標左鍵按下,最上層的應用程序會作出判斷,以便決定是否讀取坐標
} else
ts_event.pressure = 0; //無點擊
retvalue |= IAL_MOUSEEVENT;
}
}
else if (e < 0) {
return -1;
}
return retvalue;
}
BOOL InitADSInput (INPUT* input, const char* mdev, const char* mtype)
{
ts = open ("/dev/touch", O_RDONLY);
if (ts < 0) {
fprintf (stderr, "IAL: Can not open touch screen!\n");
return FALSE;
}
input->update_mouse = mouse_update;
input->get_mouse_xy = mouse_getxy;
input->set_mouse_xy = NULL;
input->get_mouse_button = mouse_getbutton;
input->set_mouse_range = NULL;
input->wait_event = wait_event;
mousex = 0;
mousey = 0;
ts_event.x = ts_event.y = ts_event.pressure = 0;
return TRUE;
}
void TermADSInput(void)
{
if (ts >= 0)
close(ts);
}
#endif /* _ADS_IAL */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -