Got tablet to report button events.

This commit is contained in:
- 2020-10-04 10:44:54 -07:00
parent 90108aabdc
commit af84249d34

View File

@ -124,31 +124,44 @@ void callback(struct libusb_transfer *transfer) {
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
unsigned char *data = tx -> buffer;
unsigned short temp;
int err = 0;
struct libevdev_uinput *ud = tx -> user_data;
switch(data[0]) {
case 0x01:
break;
case 0x02:
if((data[1] & 0xf0) != 0) {
//absolute x
temp = data[2];
temp <<= 8;
temp += data[3];
libevdev_uinput_write_event(ud, EV_ABS, ABS_X, temp);
//absolute y
temp = data[4];
temp <<= 8;
temp += data[5];
libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, temp);
}
break;
default:
// pen touches surface
err += libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, data[6] > 68);
// data[1]:
// 0x10 = lift, 0x90 = close, 0x91 = press
// 0x12 = btn (lift), 0x92 = btn (close), 0x93 = btn (press)
err += libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, data[1] & 0x02);
// if((data[1] & 0xf0) != 0) {
// //absolute x
// temp = data[2];
// temp <<= 8;
// temp += data[3];
// err += libevdev_uinput_write_event(ud, EV_ABS, ABS_X, temp);
// //absolute y
// temp = data[4];
// temp <<= 8;
// temp += data[5];
// err += libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, temp);
// }
default:
display_packets(data);
break;
}
err += libevdev_uinput_write_event(ud, EV_SYN, SYN_REPORT, 0);
if (err != 0) {
printf("error : gp0504, %i\n", err);
}
return;
}
// determine which callback devices to use and how to initialize libevdev
// https://www.freedesktop.org/software/libevdev/doc/latest/group__kernel.html
int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct libevdev_uinput **uidev) {
printf("init_ctrl: %x\n", uidev);
int is_ok = 0;
@ -158,19 +171,21 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(d, &desc);
(*evdev) = libevdev_new();
libevdev_enable_event_type((*evdev), EV_SYN);
libevdev_enable_event_code((*evdev), EV_SYN, SYN_REPORT, NULL);
// every tablet has these features
libevdev_enable_event_type((*evdev), EV_KEY); // enable pen button
libevdev_enable_event_type((*evdev), EV_ABS); // enable absolute position
libevdev_enable_event_code((*evdev), EV_KEY, BTN_LEFT, NULL); // pen tap
libevdev_enable_event_code((*evdev), EV_KEY, BTN_RIGHT, NULL); // pen button
switch(desc.idProduct) {
default: // every tablet has these features - allow fall through
libevdev_enable_event_type((*evdev), EV_ABS); // enable absolute position
libevdev_enable_event_type((*evdev), EV_KEY); // enable pen button
libevdev_enable_event_code((*evdev), EV_KEY, BTN_LEFT, NULL); // pen tap
libevdev_enable_event_code((*evdev), EV_KEY, BTN_RIGHT, NULL); // pen button
case PRODUCT_ID_GP0504:
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
break;
case PRODUCT_ID_GP0906:
break;
case PRODUCT_ID_APPIV0906:
break;
case PRODUCT_ID_GP0504:
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
break;
}
int err = libevdev_uinput_create_from_device((*evdev), LIBEVDEV_UINPUT_OPEN_MANAGED, uidev);
printf("Initializing controls status: %x, \n", uidev);