프로그램 사용/uinput2024. 3. 12. 11:03

아래와 같이 설정하면 BTN_LEFT, BTN_RIGHT 때문에, udev에서 Mouse Touchscreen으로 인식된다.

    int keys[] = {BTN_LEFT, BTN_RIGHT, BTN_TOUCH};

    fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

    //Custom key events init
    ioctl(fd, UI_SET_EVBIT, EV_KEY);
    for(int i = 0; i < sizeof(keys) / sizeof(int); i++){
        ioctl(fd, UI_SET_KEYBIT, keys[i]);
    }
[01:49:49.721] event5  - virtual touch driver: is tagged by udev as: Mouse Touchscreen
[01:49:49.722] event5  - virtual touch driver: kernel bug: device has min == max on ABS_MT_POSITION_X
[01:49:49.722] event5  - virtual touch driver: was rejected
[01:49:49.722] event5  - using input device '/dev/input/event5'

 

그래서 BTN_TOUCH만 넣으면 Mouse는 빠지고 Touchscreen만 뜨는데, 도대체 커널 버그 쪽은 어떻게 해결해야 할까?

    int keys[] = {BTN_TOUCH}; // BTN_LEFT, BTN_RIGHT

    fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);

    //Custom key events init
    ioctl(fd, UI_SET_EVBIT, EV_KEY);
    for(int i = 0; i < sizeof(keys) / sizeof(int); i++){
        ioctl(fd, UI_SET_KEYBIT, keys[i]);
    }
[01:50:22.720] event5  - virtual touch driver: is tagged by udev as: Touchscreen
[01:50:22.720] event5  - virtual touch driver: kernel bug: device has min == max on ABS_MT_POSITION_X
[01:50:22.720] event5  - virtual touch driver: was rejected
[01:50:22.720] event5  - not using input device '/dev/input/event5'

 

+

chatGPT 응답해준 것을 조합하면 아래와 같이 하면

일단 터치 장비로 인식은 되는데.. 커서도 안되고 터치 이동, 클릭을 어떻게 구현해야 하나...

void initializeTouchEvent(int fd) {
    struct uinput_setup usetup;
    int keys[] = {BTN_TOUCH}; // BTN_LEFT, BTN_RIGHT, 

    fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
    ioctl(fd, UI_SET_EVBIT, EV_KEY);

    // 사용할 키 등록(터치니까 BTN_TOUCH 만, BTN_LEFT 나 BTN_RIGHT가 등록되면 마우스로 인식됨)
    for(int i = 0; i < sizeof(keys) / sizeof(int); i++){
       ioctl(fd, UI_SET_KEYBIT, keys[i]);
    }

    ioctl(fd, UI_SET_EVBIT, EV_ABS);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_SLOT);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);  // 요건 없어도 되는 듯
    ioctl(fd, UI_SET_EVBIT, EV_SYN);

    struct uinput_abs_setup abs_setup_x;
    struct uinput_abs_setup abs_setup_y;
    memset(&abs_setup_x, 0, sizeof(abs_setup_x));
    memset(&abs_setup_y, 0, sizeof(abs_setup_y));
    abs_setup_x.code = ABS_MT_POSITION_X;
    abs_setup_x.absinfo.minimum = 0; // 최솟값
    abs_setup_x.absinfo.maximum = 1024; // 최댓값
    abs_setup_y.code = ABS_MT_POSITION_Y;
    abs_setup_y.absinfo.minimum = 0; // 최솟값
    abs_setup_y.absinfo.maximum = 1024; // 최댓값

    ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
    ioctl(fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
    ioctl(fd, UI_ABS_SETUP, &abs_setup_x);
    ioctl(fd, UI_ABS_SETUP, &abs_setup_y);

    // 가상 디바이스를 생성
    memset(&usetup, 0, sizeof(usetup));
    usetup.id.bustype = BUS_USB;
    usetup.id.vendor = 0x1;
    usetup.id.product = 0x1;
    strcpy(usetup.name, "Virtual Touch Device");

    ioctl(fd, UI_DEV_SETUP, &usetup);
    ioctl(fd, UI_DEV_CREATE);
}
Posted by 구차니