Recognizes pen tablet interaction, but does not move cursor
This commit is contained in:
parent
158dde5351
commit
90108aabdc
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
#include <libevdev/libevdev-uinput.h>
|
#include <libevdev/libevdev-uinput.h>
|
||||||
|
|
||||||
// #include <asm/unaligned.h>
|
// #include <asm/unaligned.h>
|
||||||
|
|
||||||
#define STATE_SUCCESS 0
|
#define STATE_SUCCESS 0
|
||||||
@ -120,16 +121,25 @@ void callback(struct libusb_transfer *transfer) {
|
|||||||
display_packets(data);
|
display_packets(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void callback_gp0504 (struct libusb_transfer *transfer) { // for callback
|
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
|
||||||
unsigned char *data = transfer -> buffer;
|
unsigned char *data = tx -> buffer;
|
||||||
struct libevdev_uinput *ud = transfer -> user_data;
|
unsigned short temp;
|
||||||
|
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) {
|
if((data[1] & 0xf0) != 0) {
|
||||||
;
|
//absolute x
|
||||||
// libevdev_uinput_write_event(ud, ABS_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;
|
break;
|
||||||
default:
|
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
|
// 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;
|
int is_ok = 0;
|
||||||
if (d == NULL) {
|
if (d == NULL) {
|
||||||
return is_ok;
|
return is_ok;
|
||||||
}
|
}
|
||||||
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();
|
||||||
switch(desc.idProduct) {
|
switch(desc.idProduct) {
|
||||||
default: // every tablet has these features - allow fall through
|
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_ABS); // enable absolute position
|
||||||
libevdev_enable_event_type(evdev, EV_KEY); // enable pen button
|
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_LEFT, NULL); // pen tap
|
||||||
libevdev_enable_event_code(evdev, EV_KEY, BTN_RIGHT, NULL); // pen button
|
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:
|
case PRODUCT_ID_GP0504:
|
||||||
libevdev_set_name(evdev, "Hanvon Graphicpal GP0504");
|
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
|
||||||
break;
|
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);
|
||||||
if (err == 0) {
|
printf("Initializing controls status: %x, \n", uidev);
|
||||||
is_ok = 1;
|
|
||||||
}
|
|
||||||
return is_ok;
|
return is_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,13 +182,16 @@ int handle_device_lusb(libusb_device *d) {
|
|||||||
int status = libusb_open(d, &h);
|
int status = libusb_open(d, &h);
|
||||||
if (status < 0 || h == NULL) {
|
if (status < 0 || h == NULL) {
|
||||||
printf("Error opening device, %i.\n", status);
|
printf("Error opening device, %i.\n", status);
|
||||||
libusb_exit(NULL);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct libevdev *evdev = NULL;
|
struct libevdev *evdev = NULL;
|
||||||
struct libevdev_uinput *uidev = 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;
|
struct libusb_transfer *tx;
|
||||||
const int ENDPOINT_ADDR = 0x81; // bEndpointAddress from lsusb -v
|
const int ENDPOINT_ADDR = 0x81; // bEndpointAddress from lsusb -v
|
||||||
@ -193,7 +205,7 @@ int handle_device_lusb(libusb_device *d) {
|
|||||||
ENDPOINT_ADDR,
|
ENDPOINT_ADDR,
|
||||||
buffer,
|
buffer,
|
||||||
AM_PACKET_LEN,
|
AM_PACKET_LEN,
|
||||||
callback,
|
callback_gp0504,
|
||||||
uidev, // extra data to send in tx
|
uidev, // extra data to send in tx
|
||||||
130); // timeout in milliseconds
|
130); // timeout in milliseconds
|
||||||
do {
|
do {
|
||||||
|
Loading…
Reference in New Issue
Block a user