scuti/cleanup (#7) general cleanup of code and docs
This commit is contained in:
parent
b9359970c3
commit
a91ca3c296
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "hidapi"]
|
||||
path = hidapi
|
||||
url = https://github.com/libusb/hidapi
|
2
Makefile
2
Makefile
@ -3,7 +3,7 @@
|
||||
obj-m += hanvon.o
|
||||
|
||||
all:
|
||||
gcc hanvon-libusb.c -I/usr/include/libevdev-1.0/ -L/usr/local/lib -lusb-1.0 -ludev -levdev -g
|
||||
gcc hanvon-libusb.c -I/usr/include/libevdev-1.0/ -L/usr/local/lib -lusb-1.0 -ludev -levdev -g -o hvlusb
|
||||
|
||||
archive:
|
||||
tar f - --exclude=.git -C ../ -c hanvon | gzip -c9 > ../hanvon-`date +%Y%m%d`.tgz
|
||||
|
40
README
40
README
@ -1,40 +0,0 @@
|
||||
Hanvon tablet driver
|
||||
====================
|
||||
|
||||
Driver for Linux kernels which supports complete functionality of the tablet:
|
||||
pen coordinates, touch/float/click detection, pressure, x and y tilt, pen
|
||||
button. On Artmaster I four simple tablet buttons (note that the first
|
||||
one works only together with pen activity), and the slider button.
|
||||
|
||||
|
||||
Supported hardware
|
||||
==================
|
||||
|
||||
AM3M, AM0605, AM0806, AM1107, AM1209
|
||||
RL0604, RL0504
|
||||
GP0504, GP0605, GP0605+, GP0806, GP0906
|
||||
NXS1315
|
||||
APPIV0906
|
||||
|
||||
AM - Artmaster I, RL - Rollick, GP - GraphicPal, NXS - Nilox
|
||||
APP - Art Painter Pro
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Type 'make' to compile the module. New file hanvon.ko will be produced in
|
||||
current directory. Load the module with root permissions
|
||||
|
||||
insmod ./hanvon.ko
|
||||
|
||||
If everything goes right the tablet should start working immediately.
|
||||
|
||||
|
||||
Diagnostics
|
||||
===========
|
||||
|
||||
After insmod, check with dmesg, if the module was loaded properly.
|
||||
"USB Hanvon tablet driver" should appear in the listing.
|
||||
|
||||
lsmod should also contain hanvon in its listing: lsmod | grep hanvon
|
33
README.md
Normal file
33
README.md
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
# Hanvon Tablet Drivers
|
||||
|
||||
Userspace driver for Hanvon pen tablets adapted from the original Linux kernel driver. Supports tablet features such as pen coordinates, x and y tilts, proximity and pressure detection.
|
||||
|
||||
## Building
|
||||
make
|
||||
|
||||
## Usage
|
||||
sudo hvlusb
|
||||
|
||||
Run the output executable from a terminal with sudo (preferrably in the background).
|
||||
|
||||
## Supported Hardware
|
||||
|
||||
Currently, only GP0504 is tested and supported.
|
||||
|
||||
The original series of supported hardware:
|
||||
|
||||
Artmaster I: AM3M, AM0605, AM0806, AM1107, AM1209
|
||||
|
||||
Rollick: RL0604, RL0504
|
||||
|
||||
GraphicPal: GP0504, GP0605, GP0605+, GP0806, GP0906
|
||||
|
||||
Nilox: NXS1315
|
||||
|
||||
Art Painter Pro: APPIV0906
|
||||
__________________
|
||||
|
||||
upstream repository: https://git.teknik.io/scuti/hanvon-linux
|
||||
|
||||
forked from: https://github.com/ondrah/hanvon
|
141
hanvon-libusb.c
141
hanvon-libusb.c
@ -10,7 +10,7 @@
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Maintaned by: scuti@teknik.io
|
||||
* Maintained by: scuti@teknik.io
|
||||
* surkeh@protonmail.com
|
||||
*
|
||||
* =====================================================================================
|
||||
@ -24,15 +24,11 @@
|
||||
|
||||
#include <libevdev/libevdev.h>
|
||||
#include <libevdev/libevdev-uinput.h>
|
||||
|
||||
// #include <asm/unaligned.h>
|
||||
|
||||
#define STATE_SUCCESS 0
|
||||
#define STATE_NOT_FOUND 1
|
||||
|
||||
#define UNREF_DEVICE 1
|
||||
#define KEEP_DEVICE_REF 0
|
||||
|
||||
#define VENDOR_ID_HANVON 0x0b57
|
||||
#define PRODUCT_ID_AM3M 0x8528
|
||||
#define PRODUCT_ID_AM0806 0x8502
|
||||
@ -61,8 +57,7 @@
|
||||
#define AM_MAX_TILT_Y 0x7f
|
||||
#define AM_MAX_PRESSURE 0x400
|
||||
|
||||
struct hanvon_message
|
||||
{
|
||||
struct hanvon_message {
|
||||
unsigned char msgtype;
|
||||
unsigned char is_move;
|
||||
unsigned short x_movement;
|
||||
@ -81,9 +76,6 @@ int find_device(libusb_device **list, unsigned int count) {
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
libusb_device *t = list[i];
|
||||
libusb_get_device_descriptor(list[i], &desc);
|
||||
|
||||
// printf( "Dev%u ID %04x:%04x\n", (i), desc.idVendor, desc.idProduct );
|
||||
|
||||
if (desc.idVendor == VENDOR_ID_HANVON) {
|
||||
switch(desc.idProduct) {
|
||||
default:
|
||||
@ -124,7 +116,6 @@ 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(msg->msgtype) {
|
||||
@ -133,42 +124,51 @@ void callback_gp0504 (struct libusb_transfer *tx) { // for callback
|
||||
break;
|
||||
case 0x02:
|
||||
/* is_move values:
|
||||
0x80: near
|
||||
0x10: floating
|
||||
0x02: button press
|
||||
0x01: touching
|
||||
*/
|
||||
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_TOOL_PEN, msg->is_move & (0x80|0x10));
|
||||
0x80: near, 0x02: button press
|
||||
0x10: floating, 0x01: touching */
|
||||
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);
|
||||
//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
|
||||
);
|
||||
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);
|
||||
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_ABS, ABS_PRESSURE, msg->pressure);
|
||||
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_ABS, ABS_TILT_X, msg->y_tilt);
|
||||
err = libevdev_uinput_write_event(
|
||||
ud, EV_ABS, ABS_TILT_X, msg->x_tilt
|
||||
);
|
||||
if(err) { DEBUG("err: %d\n",err); }
|
||||
err = libevdev_uinput_write_event(ud, EV_ABS, ABS_TILT_Y, msg->x_tilt);
|
||||
err = libevdev_uinput_write_event(
|
||||
ud, EV_ABS, ABS_TILT_Y, msg->y_tilt
|
||||
);
|
||||
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); }
|
||||
err = libevdev_uinput_write_event(ud, EV_KEY, BTN_RIGHT, (msg->is_move & 0x02) / 2);
|
||||
err = libevdev_uinput_write_event(
|
||||
ud, EV_KEY, BTN_RIGHT, (msg->is_move & 0x02) / 2
|
||||
);
|
||||
if(err) { DEBUG("err: %d\n",err); }
|
||||
|
||||
// data[1]:
|
||||
// 0x10 = lift, 0x90 = close, 0x91 = press
|
||||
// 0x12 = btn (lift), 0x92 = btn (close), 0x93 = btn (press)
|
||||
{
|
||||
display_packets(data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
display_packets(data);
|
||||
@ -183,13 +183,15 @@ 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) {
|
||||
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) {
|
||||
return is_ok;
|
||||
return -1;
|
||||
}
|
||||
int is_ok = 0;
|
||||
struct libusb_device_descriptor desc;
|
||||
libusb_get_device_descriptor(d, &desc);
|
||||
(*evdev) = libevdev_new();
|
||||
@ -201,8 +203,8 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
|
||||
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_RIGHT, NULL); // pen button
|
||||
libevdev_enable_event_type((*evdev), EV_ABS); // enable absolute position, pressure, tilt
|
||||
|
||||
// enable absolute position, pressure, tilt
|
||||
libevdev_enable_event_type((*evdev), EV_ABS);
|
||||
abs = malloc(sizeof(struct input_absinfo));
|
||||
// set up absolute x coordinate input
|
||||
abs->value = 0x1000;
|
||||
@ -213,24 +215,25 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
|
||||
abs->resolution = 40;
|
||||
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_X, abs)<0) {
|
||||
DEBUG("%s","failed to register absolute x\n");
|
||||
is_ok = -1;
|
||||
}
|
||||
// set up absolute y coordinate input
|
||||
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) {
|
||||
DEBUG("%s","failed to register absolute y\n");
|
||||
is_ok = -1;
|
||||
}
|
||||
// set up pressure input
|
||||
abs -> value = 0;
|
||||
abs -> minimum = 0;
|
||||
abs -> maximum = 0xff;
|
||||
abs -> maximum = AM_MAX_PRESSURE;
|
||||
abs -> resolution = 0;
|
||||
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_PRESSURE, abs)<0) {
|
||||
DEBUG("%s","failed to register pressure\n");
|
||||
is_ok = -1;
|
||||
}
|
||||
// set up tilt x input
|
||||
abs -> value = 0;
|
||||
@ -239,6 +242,7 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
|
||||
abs -> resolution = 0;
|
||||
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_TILT_X, abs)<0) {
|
||||
DEBUG("%s","failed to register x tilt\n");
|
||||
is_ok = -1;
|
||||
}
|
||||
// set up tilt y input
|
||||
abs -> value = 0;
|
||||
@ -247,8 +251,8 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
|
||||
abs -> resolution = 0;
|
||||
if(libevdev_enable_event_code((*evdev), EV_ABS, ABS_TILT_Y, abs)<0) {
|
||||
DEBUG("%s","failed to register y tilt\n");
|
||||
is_ok = -1;
|
||||
}
|
||||
|
||||
switch(desc.idProduct) {
|
||||
case PRODUCT_ID_GP0504:
|
||||
libevdev_set_name((*evdev), "Hanvon Graphicpal GP0504");
|
||||
@ -258,7 +262,9 @@ int init_ctrl(struct libusb_device * const d, struct libevdev **evdev, struct li
|
||||
case PRODUCT_ID_APPIV0906:
|
||||
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);
|
||||
free(abs);
|
||||
return is_ok;
|
||||
@ -274,12 +280,13 @@ int handle_device_lusb(libusb_device *d) {
|
||||
struct libevdev *evdev = NULL;
|
||||
struct libevdev_uinput *uidev = NULL;
|
||||
printf("handle_device: %x\n", uidev);
|
||||
init_ctrl(d, &evdev, &uidev);
|
||||
if (init_ctrl(d, &evdev, &uidev) < 0) {
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
//AM_PACKET_LEN = 10; // wMaxPacketSize from lsusb -v
|
||||
@ -298,7 +305,7 @@ int handle_device_lusb(libusb_device *d) {
|
||||
do {
|
||||
status = libusb_submit_transfer(tx);
|
||||
if (status < 0 ) {
|
||||
//return status;
|
||||
printf("warning: usb transfer status = %i\n", status);
|
||||
//continue;
|
||||
}
|
||||
libusb_handle_events(NULL);
|
||||
@ -307,12 +314,7 @@ int handle_device_lusb(libusb_device *d) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
libusb_device *FindHanvon( libusb_context **context);
|
||||
int HandleData( void );
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
#define UNREF_DEVICE 1
|
||||
#define KEEP_DEVICE_REF 0
|
||||
|
||||
@ -338,48 +340,3 @@ int main()
|
||||
libusb_exit(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
libusb_device *FindHanvon( libusb_context **context)
|
||||
{
|
||||
libusb_device **deviceList;
|
||||
libusb_device *found = NULL;
|
||||
ssize_t nDevices = libusb_get_device_list( context[0], &deviceList);
|
||||
if( nDevices > 0 )
|
||||
{
|
||||
struct libusb_device_descriptor description;
|
||||
|
||||
for( ssize_t i = 0; i < nDevices; i++ )
|
||||
{
|
||||
libusb_device *device = deviceList[i];
|
||||
libusb_get_device_descriptor(device, &description);
|
||||
//printf( "Dev%u ID %04x:%04x\n", (i + 1), description.idVendor, description.idProduct );
|
||||
if( description.idVendor == VENDOR_ID_HANVON )
|
||||
{
|
||||
switch( description.idProduct )
|
||||
case PRODUCT_ID_AM0806:
|
||||
case PRODUCT_ID_AM0605:
|
||||
case PRODUCT_ID_AM1107:
|
||||
case PRODUCT_ID_AM1209:
|
||||
case PRODUCT_ID_RL0604:
|
||||
case PRODUCT_ID_RL0504:
|
||||
case PRODUCT_ID_GP0806:
|
||||
case PRODUCT_ID_GP0806B:
|
||||
case PRODUCT_ID_GP0605:
|
||||
case PRODUCT_ID_GP0605A:
|
||||
case PRODUCT_ID_GP0504:
|
||||
case PRODUCT_ID_NXS1513:
|
||||
case PRODUCT_ID_GP0906:
|
||||
case PRODUCT_ID_APPIV0906:
|
||||
found = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf( "\n\n" );
|
||||
}
|
||||
|
||||
libusb_free_device_list( deviceList, UNREF_DEVICE );
|
||||
return found;
|
||||
}
|
||||
|
||||
|
1
hidapi
1
hidapi
@ -1 +0,0 @@
|
||||
Subproject commit cdc473dfe43f6432dda7ad53d7656b8ae8ff968b
|
Loading…
Reference in New Issue
Block a user