这是基于arm开发板的简单划屏算法;原理:记录下第一次按下去的坐标值,然后判断是左滑还是右滑
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <dirent.h>
#include <time.h>
#include <linux/input.h>
struct X_Y
{
int x1;
int y1;
};
int get_xy(int* x,int *y,int *p,struct X_Y *before);
int main(int argc, char const **argv)
{
struct X_Y before;
bzero(&before,sizeof(struct X_Y));
int x, y, p;
get_xy(&x,&y,&p,&before);
printf("x: %d y:%d\n",x,y);
printf("struct :x :%d y:%d\n",before.x1,before.y1);
if(x - before.x1>0)
{
printf("right\n");
}
else if(x - before.x1<0)
{
printf("left\n");
}
return 0;
}
int get_xy(int* x,int *y,int *p,struct X_Y *before)
{
int ts_fd = open("/dev/input/event0", O_RDONLY);
if(ts_fd == -1)
{
perror("open /dev/input/event0 failed!");
return -1;
}
struct input_event ts_buf;
bzero(&ts_buf, sizeof(ts_buf));
int falg=0;
while(1)
{
read(ts_fd, &ts_buf, sizeof(ts_buf));
if(ts_buf.type == EV_ABS)
{
if(ts_buf.code == ABS_X)
{
*x = ts_buf.value;
if(falg == 0)
{
before->x1 = *x;
falg++;
}
printf("x:%d\n", *x);
}
else if(ts_buf.code == ABS_Y)
{
*y = ts_buf.value;
printf("y:%d\n", *y);
}
}
else if(ts_buf.type == EV_KEY)
{
if(ts_buf.code == BTN_TOUCH)
{
*p = ts_buf.value;
printf("pressure:%d\n", p);
if(*p==0)
{
break;
}
}
}
}
close(ts_fd);
return 0;
}
函数已经封装好了的,需要的可以直接拷过去用;也可以在这个基础上加上判断是往上滑还是往下滑