编写Linux下Input设备的检测程序(2)

static int test_touch_pancel()
{
    if(init_device(TOUP_DEV) < 0)
        return -1;
    while(1)
    {
        read(ts_fd, &data, sizeof(data));
        if (data.type == EV_KEY)
        {
            printf(" type = EV_KEY, code = %s, value = %d\n",
                data.code == BTN_LEFT ? "MOUSE_LEFT" :
                data.code == BTN_RIGHT ? "MOUSE_RIGHT" :
                data.code == BTN_MIDDLE ? "MOUSE_MIDDLE" :
                data.code == BTN_SIDE ? "MOUSE_SIDE" :
                "Unkonw", data.value);
        }
        else if(data.type == EV_REL)
        {
            printf(" type = EV_ABS, code = %s, value = %d\n",
                data.code == REL_X ? "ABS_X" :
                data.code == REL_Y ? "ABS_Y" :
                data.code == ABS_WHEEL ? "MOUSE_WHEEL" :
                data.code == ABS_PRESSURE ? "ABS_PRESSURE" :
                "Unkown", data.value);
        }
    }
    return 0;
}

int main()
{
    static int i;
select:    printf("Please select device:\n0.KeyBoard\n1.Mouse\n2.TouchScreen\n3.TouchPancel\n");
    scanf("%d",&i);
    switch(i){
        case 0:
            test_key();
            break;
        case 1:
            test_mouse();
            break;
        case 2:
            test_touch_screen();
            break;
        case 3:
            test_touch_pancel();
            break;
        default:
            printf("Wrong device, Please select again!\n\n");
            break;       
    }
    goto select;
        return 0;
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwszgs.html