linux input 设备的测试函数

来源:互联网 发布:brew install php fpm 编辑:程序博客网 时间:2024/06/09 21:00

 为了能够在飞凌的OK6410开发板上,运行这个测试程序,在linux的上位机中,使用cross-4.2.2-eabi的交叉编译工具进行编译,把编译完的程序拷贝到SD卡中,运行飞凌开发板,执行该程序,就可以看到终端能够不断的采集到TP的触摸数据了,完整的源程序如下:

编译命令:arm-linux-gcc -o test  code_name.c

 

/*test code for touch screen */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <linux/input.h>


static struct input_event ev_data;
static int ts_fd=-1;
#define TOUS_DEV  "/dev/input/event3"


static int init_device(char *TS_DEV)
{
    if((ts_fd = open(TS_DEV, O_RDONLY)) < 0)
    {
        printf("Error open %s\n\n", TS_DEV);
        return -1;
    }
    return ts_fd;
}

 

 

static int test_touch_screen()
{
    if(init_device(TOUS_DEV) < 0)
        return -1;
    while(1)
    {
        read(ts_fd, &ev_data, sizeof(ev_data));
        if (ev_data.type == EV_KEY)
        {
            printf(" type: EV_KEY, code = %s, value = %d\n\n",
                ev_data.code == BTN_TOUCH ? “BTN_TOUCH” : "Unkown, ev_data.value);
        }
        else if(ev_data.type == EV_ABS)
        {
            printf(" type: EV_ABS, code = %s, value = %d\n\n",
                ev_data.code == ABS_X ? "ABS_X" :
                ev_data.code == ABS_Y ? "ABS_Y" :
                ev_data.code == ABS_PRESSURE ? "ABS_PRESSURE":
                "Unkown", ev_data.value);
        }
    }
    return 0;
}


int main(void)
{

 test_touch_screen();
 return 0;


}

 

 

 

 

 

 

 

 

 

 

 

 


 

 

原创粉丝点击