分类: LINUX
2011-01-14 20:11:10
#include
#include
#include
#include
#include
#define TS_DEV "/dev/input/event7"
static int ts_fd = -1;
static int init_device()
{
if((ts_fd = open(TS_DEV, O_RDONLY)) < 0)
{
printf("Error open %s\n", TS_DEV);
return -1;
}
return ts_fd;
}
int main()
{
int i;
struct input_event da
if(init_device() < 0)
return -1;
while(1)
{
read(ts_fd, &da
printf("da
if (da
{
printf("type: EV_KEY, event = %s, value = %d\n\n",
da
}
else if(da
{
printf("type: EV_ABS, event = %s, value = %d\n\n",
da
da
da
"Unkown", da
}
else if (da
{
printf("type: EV_SYN, event = %s, value = %d\n\n",
da
}
else
{
printf("type: 0x%x, event = 0x%x, value = %d\n\n", da
}
}
return 0;
}
交叉编译:arm-linux-gcc -o ts_test ts_test.c -static
运行应用程序就可以了,这里需要确定自己的
TS_DEV "/dev/input/event7"
我的touch 是 event0。。。。注意修改了,
测试结果如下:
data.type = 3, data.code = 0, data.value = 329
type: EV_ABS, event = ABS_X, value = 329
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 328
type: EV_ABS, event = ABS_X, value = 328
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 329
type: EV_ABS, event = ABS_X, value = 329
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 328
type: EV_ABS, event = ABS_X, value = 328
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 329
type: EV_ABS, event = ABS_X, value = 329
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 1, data.value = 310
type: EV_ABS, event = ABS_Y, value = 310
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 330
type: EV_ABS, event = ABS_X, value = 330
data.type = 3, data.code = 1, data.value = 311
type: EV_ABS, event = ABS_Y, value = 311
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 332
type: EV_ABS, event = ABS_X, value = 332
data.type = 3, data.code = 1, data.value = 312
type: EV_ABS, event = ABS_Y, value = 312
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 3, data.code = 0, data.value = 335
type: EV_ABS, event = ABS_X, value = 335
data.type = 3, data.code = 1, data.value = 323
type: EV_ABS, event = ABS_Y, value = 323
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
data.type = 1, data.code = 330, data.value = 0
type: EV_KEY, event = BTN_TOUCH, value = 0
data.type = 3, data.code = 24, data.value = 0
type: EV_ABS, event = ABS_PRESSURE, value = 0
data.type = 0, data.code = 0, data.value = 0
type: EV_SYN, event = SYN_REPORT, value = 0
chinaunix网友2011-03-09 14:01:23
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com