📄 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 + -