scuti/pressure (#2)

Pen pressure working.
This commit is contained in:
scuti 2021-07-13 21:19:49 -07:00 committed by Gitea
parent 2d0c200b95
commit f6cd7e70cb

View File

@ -112,7 +112,7 @@ void display_packets(const unsigned char* buf) {
for(int i = 0; i < AM_PACKET_LEN; i++) { for(int i = 0; i < AM_PACKET_LEN; i++) {
fprintf(stderr,"0x%x, ", buf[i]); fprintf(stderr,"0x%x, ", buf[i]);
} }
fprintf(stderr,"\n"); fprintf(stderr,"\r");
} }
void callback(struct libusb_transfer *transfer) { void callback(struct libusb_transfer *transfer) {
@ -137,8 +137,10 @@ void callback_gp0504 (struct libusb_transfer *tx) { // for callback
0x02: button press 0x02: button press
0x01: touching 0x01: touching
*/ */
if(msg->is_move & (0x80|0x10)) err = libevdev_uinput_write_event(
{ ud, EV_KEY, BTN_TOOL_PEN, msg->is_move & (0x80|0x10));
if(err) { DEBUG("err: %d\n",err); }
if(msg->is_move & (0x80|0x10)) {
msg->x_movement = htobe16(msg->x_movement); msg->x_movement = htobe16(msg->x_movement);
//DEBUG("Set X to %x\n",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); err = libevdev_uinput_write_event(ud, EV_ABS, ABS_X, msg->x_movement);
@ -148,29 +150,17 @@ void callback_gp0504 (struct libusb_transfer *tx) { // for callback
err = libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, msg->y_movement); err = libevdev_uinput_write_event(ud, EV_ABS, ABS_Y, msg->y_movement);
if(err) { DEBUG("err: %d\n",err); } if(err) { DEBUG("err: %d\n",err); }
} }
err = libevdev_uinput_write_event(
ud, EV_ABS, ABS_PRESSURE, msg->pressure);
if(err) { DEBUG("err: %d\n",err); }
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, msg->is_move & 0x01); err = libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, msg->is_move & 0x01);
if(err) { DEBUG("err: %d\n",err); } if(err) { DEBUG("err: %d\n",err); }
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, msg->is_move & 0x02); err = libevdev_uinput_write_event(
ud, EV_KEY, BTN_RIGHT, (msg->is_move & 0x02) / 2);
if(err) { DEBUG("err: %d\n",err); } if(err) { DEBUG("err: %d\n",err); }
// pen touches surface
//err += libevdev_uinput_write_event(ud, EV_KEY, BTN_LEFT, data[6] > 68);
// data[1]: // data[1]:
// 0x10 = lift, 0x90 = close, 0x91 = press // 0x10 = lift, 0x90 = close, 0x91 = press
// 0x12 = btn (lift), 0x92 = btn (close), 0x93 = btn (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);
// }
//else
{ {
display_packets(data); display_packets(data);
} }
@ -198,10 +188,12 @@ 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_property((*evdev), INPUT_PROP_DIRECT);
libevdev_enable_event_type((*evdev), EV_SYN); libevdev_enable_event_type((*evdev), EV_SYN);
libevdev_enable_event_code((*evdev), EV_SYN, SYN_REPORT, NULL); libevdev_enable_event_code((*evdev), EV_SYN, SYN_REPORT, NULL);
// every tablet has these features // every tablet has these features
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_TOOL_PEN, NULL);
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
@ -228,6 +220,13 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
{ {
DEBUG("%s","failed to register absolute x\n"); DEBUG("%s","failed to register absolute x\n");
} }
abs -> value = 0;
abs -> minimum = 0;
abs -> maximum = 0xff;
abs -> resolution = 0;
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_PRESSURE, abs)<0) {
DEBUG("%s","failed to register pressure\n");
}
switch(desc.idProduct) { switch(desc.idProduct) {
case PRODUCT_ID_GP0504: case PRODUCT_ID_GP0504:
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504"); libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");