Got tablet to report button events.
This commit is contained in:
@ -124,31 +124,44 @@ void callback(struct libusb_transfer *transfer) {
|
|||||||
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
|
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
|
||||||
unsigned char *data = tx -> buffer;
|
unsigned char *data = tx -> buffer;
|
||||||
unsigned short temp;
|
unsigned short temp;
|
||||||
|
int err = 0;
|
||||||
struct libevdev_uinput *ud = tx -> user_data;
|
struct libevdev_uinput *ud = tx -> user_data;
|
||||||
switch(data[0]) {
|
switch(data[0]) {
|
||||||
case 0x01:
|
case 0x01:
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02:
|
||||||
if((data[1] & 0xf0) != 0) {
|
// pen touches surface
|
||||||
//absolute x
|
err += libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, data[6] > 68);
|
||||||
temp = data[2];
|
// data[1]:
|
||||||
temp <<= 8;
|
// 0x10 = lift, 0x90 = close, 0x91 = press
|
||||||
temp += data[3];
|
// 0x12 = btn (lift), 0x92 = btn (close), 0x93 = btn (press)
|
||||||
libevdev_uinput_write_event(ud, EV_ABS, ABS_X, temp);
|
err += libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, data[1] & 0x02);
|
||||||
//absolute y
|
// if((data[1] & 0xf0) != 0) {
|
||||||
temp = data[4];
|
// //absolute x
|
||||||
temp <<= 8;
|
// temp = data[2];
|
||||||
temp += data[5];
|
// temp <<= 8;
|
||||||
libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, temp);
|
// temp += data[3];
|
||||||
}
|
// err += libevdev_uinput_write_event(ud, EV_ABS, ABS_X, temp);
|
||||||
break;
|
// //absolute y
|
||||||
default:
|
// temp = data[4];
|
||||||
|
// temp <<= 8;
|
||||||
|
// temp += data[5];
|
||||||
|
// err += libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, temp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
default:
|
||||||
display_packets(data);
|
display_packets(data);
|
||||||
break;
|
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) {
|
int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct libevdev_uinput **uidev) {
|
||||||
printf("init_ctrl: %x\n", uidev);
|
printf("init_ctrl: %x\n", uidev);
|
||||||
int is_ok = 0;
|
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;
|
struct libusb_device_descriptor desc;
|
||||||
libusb_get_device_descriptor(d, &desc);
|
libusb_get_device_descriptor(d, &desc);
|
||||||
(*evdev) = libevdev_new();
|
(*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) {
|
switch(desc.idProduct) {
|
||||||
default: // every tablet has these features - allow fall through
|
case PRODUCT_ID_GP0504:
|
||||||
libevdev_enable_event_type((*evdev), EV_ABS); // enable absolute position
|
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
|
||||||
libevdev_enable_event_type((*evdev), EV_KEY); // enable pen button
|
break;
|
||||||
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_GP0906:
|
case PRODUCT_ID_GP0906:
|
||||||
break;
|
break;
|
||||||
case PRODUCT_ID_APPIV0906:
|
case PRODUCT_ID_APPIV0906:
|
||||||
break;
|
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);
|
int err = libevdev_uinput_create_from_device((*evdev), LIBEVDEV_UINPUT_OPEN_MANAGED, uidev);
|
||||||
printf("Initializing controls status: %x, \n", uidev);
|
printf("Initializing controls status: %x, \n", uidev);
|
||||||
|
Reference in New Issue
Block a user