input事件解析:
##################### type = 3 code = 0 value = 724 //读取的X坐标的值
type = 3 code = 1 value = 328 //读取的Y坐标的值
type = 1 code = 330 value = 1 //330 是触摸屏的按键值
##################### type = 3 code = 24 value = 1 //24 表示压力值,驱动值定义的压力值范围是 0 到 1
type = 0 code = 0 value = 0 //同步信号
type = 1 code = 330 value = 0
##################### type = 3 code = 24 value = 0 //表示弹起
type = 0 code = 0 value = 0 // 下面连续发送9次同步信息,作为结束发送
type = 0 code = 2 value = 0
##################### type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
##################### type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
##################### type = 0 code = 0 value = 0
在inut.h中
/*
* Event types
*/
#define EV_SYN 0x00 //表示支持所有事件
#define EV_KEY 0x01 //键盘或者按键,表示一个键码
#define EV_REL 0x02 //鼠标设备,表示一个相对的光标位置结果
#define EV_ABS 0x03 //手写板产生的值,其是一个绝对整数值
#define EV_MSC 0x04 //其他类型
#define EV_SW 0x05 //转换
#define EV_LED 0x11 //led
#define EV_SND 0x12 //声音设备
#define EV_REP 0x14 //允许重复输入按键类型
#define EV_FF 0x15
#define EV_PWR 0x16 //电源管理
#define EV_FF_STATUS 0x17
#define EV_MAX 0x1f
#define EV_CNT (EV_MAX+1)
操作定义:
/* 触摸屏的操作模式 */
enum to_operating_mode
{
up_switchover = 1, /* 向上翻页 */
down_switchover, /* 向下翻页 */
left_switchover, /* 向左翻页 */
right_switchover, /* 向右翻页 */
add_file, /* 添加文件 */
delete_file, /* 删除文件 */
};
信息结构体:
struct read_info
{
unsigned int x_coordinate; /* x坐标*/
unsigned int y_coordinate; /* y坐标*/
long event_timr; /* 触发时间 */
};
全局变量和宏定义:
/* 触摸屏文件 */
#define DEVICE_KEY "/dev/input/event1"
struct input_event env1; /* input 事件 */
struct read_info read_arry[READ_MAX_NUM] = {{0}}; /*把从触摸屏读到的有效数据保存到这里 */
int now_num = 0; /* 现在读取了多少个数据 */
核心处理函数:用来做总的管理
/* 核心处理函数 */
int tu_core(void)
{
int ret = -1;
tu_read_touch();
ret = tu_is_judge();
return ret;
}
读取触摸屏信息并转化为相应的可用信息:
/* 读取触摸屏信息 */
int tu_read_touch(void)
{
int fd1 = -1;
int ret = -1;
int i = 0;
int arry_num = 0;
int end_num = 4; /* 读取结束标志,因为结束时会发送4次type = 0,code = 2*/
/* 结束信息
type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
type = 0 code = 2 value = 0
type = 0 code = 0 value = 0
*/
fd1 = open(DEVICE_KEY, O_RDONLY);
if(fd1 < 0){
DERROR("open1\n");
return -1;
}
for(;i < READ_MAX_NUM; i++)
{
ret = read(fd1, &env1, sizeof(struct input_event));
if(ret <= 0){
return -1;
}
if(end_num == 0)
break;
if((env1.type == 3) && (env1.code == 0)){
read_arry[arry_num].x_coordinate = env1.value;
}else if((env1.type == 3) && (env1.code == 1)){
read_arry[arry_num].y_coordinate = env1.value;
read_arry[arry_num].event_timr = env1.value;
++arry_num;
}else if((env1.type == 0) && (env1.code == 2)){
--end_num;
}
memset(&env1, 0, sizeof(struct input_event));
}
/* 作为结束标志 */
read_arry[arry_num].x_coordinate = read_arry[arry_num].y_coordinate = read_arry[arry_num].event_timr = 0;
now_num = arry_num;
DEBUG("ok-------------\n");
close(fd1);
return 0;
}
判断是哪种操作:
/* 判断是哪种操作 */
int tu_is_judge(void)
{
int x_add = 0;
int y_add = 0;
int i = 0;
for(; i<now_num - 1; i++)
{
x_add += read_arry[i].x_coordinate - read_arry[i + 1].x_coordinate;
y_add += read_arry[i].y_coordinate - read_arry[i + 1].y_coordinate;
//DEBUG("x = %d , y = %d \n", read_arry[i].x_coordinate, read_arry[i].y_coordinate);
}
DEBUG("x_add = %d , y_add = %d \n", x_add, y_add);
if((x_add > 0) && (abs(x_add) > abs(y_add))){ /* 向左翻页 */
return left_switchover;
}else if((x_add < 0) && (abs(x_add) > abs(y_add))){ /* 向右翻页 */
return right_switchover;
}else if((y_add < 0) && (abs(x_add) < abs(y_add))){ /* 向下翻页 */
return down_switchover;
}else if((y_add > 0) && (abs(x_add) < abs(y_add))){ /* 向上翻页 */
return up_switchover;
}
return 0;
}