Chinaunix首页 | 论坛 | 博客
  • 博客访问: 276903
  • 博文数量: 91
  • 博客积分: 2105
  • 博客等级: 大尉
  • 技术积分: 1050
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-14 19:30
文章分类
文章存档

2011年(11)

2010年(64)

2009年(16)

我的朋友

分类: 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 data;
        if(init_device() < 0)
                return -1;
        while(1)
        {
                read(ts_fd, &data, sizeof(data));
  printf("data.type = %d, data.code = %d, data.value = %d\n",data.type,data.code,data.value);
                if (data.type == EV_KEY)
                {
                        printf("type: EV_KEY, event = %s, value = %d\n\n",
                                data.code == BTN_TOUCH ? "BTN_TOUCH" : "Unkown", data.value);
                }
                else if(data.type == EV_ABS)
                {
                        printf("type: EV_ABS, event = %s, value = %d\n\n",
                                data.code == ABS_X ? "ABS_X" :
                                data.code == ABS_Y ? "ABS_Y" :
                                data.code == ABS_PRESSURE ? "ABS_PRESSURE" :
                                "Unkown", data.value);
                }
                else if (data.type == EV_SYN)
                {
                        printf("type: EV_SYN, event = %s, value = %d\n\n",
                                data.code == SYN_REPORT ? "SYN_REPORT" : "Unkown", data.value);
                }
                else
                {
                        printf("type: 0x%x, event = 0x%x, value = %d\n\n", data.type, data.code, data.value);
                }
        }
        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



阅读(2640) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-04-13 15:59:53

学习了,多谢楼主分享哦!也欢迎广大linux爱好者来我们的论坛一起讨论arm哦!www.lt-net.cn

chinaunix网友2011-03-09 14:01:23

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com