Miss Papaya got position input working

This commit is contained in:
surkhe 2021-07-08 13:30:01 -07:00
parent af84249d34
commit 2d0c200b95

View File

@ -15,6 +15,8 @@
* =====================================================================================
*/
#define DEBUG(msg,...) fprintf(stderr,"%s(%d): " msg , __FILE__,__LINE__,__VA_ARGS__)
#include <stdlib.h>
#include <stdio.h>
#include <libusb-1.0/libusb.h>
@ -58,20 +60,17 @@
#define AM_MAX_TILT_Y 0x7f
#define AM_MAX_PRESSURE 0x400
struct hanvon {
unsigned char *data;
//dma_addr_t data_dma;
struct input_dev *dev;
struct usb_device *usbdev;
struct urb *irq;
int old_wheel_pos;
char phys[32];
struct hanvon_message
{
unsigned char msgtype;
unsigned char is_move;
unsigned short x_movement;
unsigned short y_movement;
unsigned char pressure;
unsigned char x_tilt;
unsigned char y_tilt;
};
int find_device(libusb_device **list, unsigned int count) {
if (count < 0) {
return -1;
@ -111,9 +110,9 @@ int find_device(libusb_device **list, unsigned int count) {
void display_packets(const unsigned char* buf) {
for(int i = 0; i < AM_PACKET_LEN; i++) {
printf("0x%x, ", buf[i]);
fprintf(stderr,"0x%x, ", buf[i]);
}
printf("\n");
fprintf(stderr,"\n");
}
void callback(struct libusb_transfer *transfer) {
@ -123,19 +122,42 @@ void callback(struct libusb_transfer *transfer) {
void callback_gp0504 (struct libusb_transfer *tx) { // for callback
unsigned char *data = tx -> buffer;
struct hanvon_message *msg = (struct hanvon_message *)tx -> buffer;
unsigned short temp;
int err = 0;
struct libevdev_uinput *ud = tx -> user_data;
switch(data[0]) {
switch(msg->msgtype) {
case 0x01:
display_packets(data);
break;
case 0x02:
/*is_move values:
0x80: near
0x10: floating
0x02: button press
0x01: touching
*/
if(msg->is_move & (0x80|0x10))
{
msg->x_movement = htobe16(msg->x_movement);
//DEBUG("Set X to %x\n",msg->x_movement);
err = libevdev_uinput_write_event(ud, EV_ABS, ABS_X, msg->x_movement);
if(err) { DEBUG("err: %d\n",err); }
msg->y_movement = htobe16(msg->y_movement);
//DEBUG("Set Y to %x\n",msg->y_movement);
err = libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, msg->y_movement);
if(err) { DEBUG("err: %d\n",err); }
}
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, msg->is_move & 0x01);
if(err) { DEBUG("err: %d\n",err); }
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, msg->is_move & 0x02);
if(err) { DEBUG("err: %d\n",err); }
// pen touches surface
err += libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, data[6] > 68);
//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);
//err += libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, data[1] & 0x02);
// if((data[1] & 0xf0) != 0) {
// //absolute x
// temp = data[2];
@ -148,7 +170,11 @@ void callback_gp0504 (struct libusb_transfer *tx) { // for callback
// temp += data[5];
// err += libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, temp);
// }
//else
{
display_packets(data);
}
break;
default:
display_packets(data);
break;
@ -163,6 +189,7 @@ void callback_gp0504 (struct libusb_transfer *tx) { // for callback
// 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) {
struct input_absinfo *abs;
printf("init_ctrl: %x\n", uidev);
int is_ok = 0;
if (d == NULL) {
@ -175,9 +202,32 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
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
libevdev_enable_event_type((*evdev), EV_ABS); // enable absolute position
abs = malloc(sizeof(struct input_absinfo));
abs->value = 0x1000;
abs->minimum = 0;
abs->maximum = 0x27DE;
abs->fuzz = 0;
abs->flat = 0;
abs->resolution = 40;
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_X, abs)<0) // pen button
{
DEBUG("%s","failed to register absolute x\n");
}
abs = malloc(sizeof(struct input_absinfo));
abs->value = 0x1000;
abs->minimum = 0;
abs->maximum = 0x1cfe;
abs->fuzz = 0;
abs->flat = 0;
abs->resolution = 40;
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_Y, abs)<0) // pen button
{
DEBUG("%s","failed to register absolute x\n");
}
switch(desc.idProduct) {
case PRODUCT_ID_GP0504:
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
@ -226,7 +276,8 @@ int handle_device_lusb(libusb_device *d) {
do {
status = libusb_submit_transfer(tx);
if (status < 0 ) {
return status;
//return status;
//continue;
}
libusb_handle_events(NULL);
} while (1);