#include "main.h"
int ts_fd;
int ts_x, ts_y;
int old_x = 300;
int flag_x = 0, flag_y = 0, first_press_flag = 0;
int right_left_slide_flag = 0;
int slider_left = 0;
int slider_right = 0;
/*触摸屏初始化*/
void TS_Init()
{
ts_fd = open("/dev/event0", O_RDONLY);
if(ts_fd == -1)
{
perror("open TS error!");
exit(-1);
}
}
/*关闭触摸屏*/
void TS_Close()
{
close(ts_fd);
}
/*获取坐标*/
void get_xy()
{
struct input_event tsevent;
bzero(&tsevent, sizeof(tsevent));
int flag = 0;
while (1)
{
read(ts_fd, &tsevent, sizeof(tsevent));
if(tsevent.type == EV_ABS )//判断是否为触摸屏事件
{
printf("in 1\n");
if(tsevent.code == ABS_X)//判断是否为x轴数据
{
ts_x = tsevent.value;
flag_x= 1;
printf("get x\n");
}
if(tsevent.code == ABS_Y)//判断是否为y轴数据
{
ts_y = tsevent.value;
flag_y = 1;
printf("get y\n");
if (flag_y && flag_x)
break;
}
}
printf("exit 1\n");
if (EV_KEY == tsevent.type)
{
printf("in 2\n");
//刚触碰的坐标/长按时
if (tsevent.code == BTN_TOUCH && tsevent.value == 1)
{
printf("old in\n");
old_x = ts_x;
first_press_flag = 1;
}
}
printf("exit 2\n");
if (EV_KEY == tsevent.type)
{
printf("in 3\n");
//松开
if (tsevent.code == BTN_TOUCH && tsevent.value == 0)
{
//从左到右的滑动
if (((ts_x > old_x) && (ts_x - old_x > 150) && (ts_x < 600)))
{
right_left_slide_flag = 1;
slider_right = 1;
old_x = 300;
}
//从右到左的滑动
else if (((old_x > ts_x) && (old_x - ts_x > 150) && (old_x < 600)))
{
right_left_slide_flag = 1;
slider_left = 1;
old_x = 300;
}
}
}
//if(tsevent.type == EV_KEY && tsevent.code == BTN_TOUCH && tsevent.value == 0 )
//{
// break;
//}
}
}
我想问一下,这是开发板部分获取触摸屏坐标的代码,但是我点击开发板屏幕,不能进去带有 EV_KEY的循环里,这个有办法解决嘛