Recognizes pen tablet interaction, but does not move cursor

This commit is contained in:
2020-10-02 22:31:39 -07:00
parent 158dde5351
commit 90108aabdc

View File

@ -21,6 +21,7 @@
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
// #include <asm/unaligned.h>
#define STATE_SUCCESS 0
@ -120,16 +121,25 @@ void callback(struct libusb_transfer *transfer) {
display_packets(data);
}
void callback_gp0504 (struct libusb_transfer *transfer) { // for callback
unsigned char *data = transfer -> buffer;
struct libevdev_uinput *ud = transfer -> user_data;
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
unsigned char *data = tx -> buffer;
unsigned short temp;
struct libevdev_uinput *ud = tx -> user_data;
switch(data[0]) {
case 0x01:
break;
case 0x02:
if((data[1] & 0xf0) != 0) {
;
// libevdev_uinput_write_event(ud, ABS_X, )
//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:
@ -139,32 +149,31 @@ void callback_gp0504 (struct libusb_transfer *transfer) { // for callback
}
// determine which callback devices to use and how to initialize libevdev
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);
int is_ok = 0;
if (d == NULL) {
return is_ok;
}
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(d, &desc);
evdev = libevdev_new();
(*evdev) = libevdev_new();
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
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_GP0906:
break;
case PRODUCT_ID_APPIV0906:
break;
case PRODUCT_ID_GP0504:
libevdev_set_name(evdev, "Hanvon Graphicpal GP0504");
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
break;
}
int err = libevdev_uinput_create_from_device(evdev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uidev);
if (err == 0) {
is_ok = 1;
}
int err = libevdev_uinput_create_from_device((*evdev), LIBEVDEV_UINPUT_OPEN_MANAGED, uidev);
printf("Initializing controls status: %x, \n", uidev);
return is_ok;
}
@ -173,13 +182,16 @@ int handle_device_lusb(libusb_device *d) {
int status = libusb_open(d, &h);
if (status < 0 || h == NULL) {
printf("Error opening device, %i.\n", status);
libusb_exit(NULL);
return 0;
}
struct libevdev *evdev = NULL;
struct libevdev_uinput *uidev = NULL;
init_ctrl(d, evdev, uidev);
printf("handle_device: %x\n", uidev);
init_ctrl(d, &evdev, &uidev);
if (evdev == NULL || uidev == NULL) {
printf("Error initializing controls, %x, %x.\n", evdev, uidev);
return 0;
}
struct libusb_transfer *tx;
const int ENDPOINT_ADDR = 0x81; // bEndpointAddress from lsusb -v
@ -193,7 +205,7 @@ int handle_device_lusb(libusb_device *d) {
ENDPOINT_ADDR,
buffer,
AM_PACKET_LEN,
callback,
callback_gp0504,
uidev, // extra data to send in tx
130); // timeout in milliseconds
do {