From 535ea39e39169cb3937be36db6bf880f34044599 Mon Sep 17 00:00:00 2001 From: ond Date: Thu, 10 Mar 2011 20:40:16 +0100 Subject: [PATCH] absolute wheel implementation --- hanvon.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hanvon.c b/hanvon.c index c941a63..2056814 100644 --- a/hanvon.c +++ b/hanvon.c @@ -20,6 +20,8 @@ MODULE_LICENSE(DRIVER_LICENSE); #define B1 BTN_TOOL_FINGER #define B2 BTN_TOOL_PENCIL #define B3 BTN_TOOL_AIRBRUSH +#define TOTAL_WHEEL_ABS 0x40 +#define WHEEL_THRESHOLD 10 struct hanvon { unsigned char *data; @@ -32,7 +34,7 @@ struct hanvon { unsigned b1:1; unsigned b2:1; unsigned b3:1; - int b_wheel; + int wheel_pos, old_wheel_pos; int pressure; char phys[32]; }; @@ -70,9 +72,21 @@ static void hanvon_irq(struct urb *urb) input_report_key(dev, B2, hanvon->b2); input_report_key(dev, B3, hanvon->b3); } else { - hanvon->b_wheel = data[2]; // FIXME: calculate position 0 .. 255 + if(data[2] <= 0x3f) { // slider area active + int diff = hanvon->old_wheel_pos - data[2]; + if(abs(diff) < WHEEL_THRESHOLD) { + hanvon->wheel_pos += diff; - input_report_key(dev, BTN_WHEEL, hanvon->b_wheel); + if(hanvon->wheel_pos < -TOTAL_WHEEL_ABS) + hanvon->wheel_pos += TOTAL_WHEEL_ABS; + else if(hanvon->wheel_pos > TOTAL_WHEEL_ABS) + hanvon->wheel_pos -= TOTAL_WHEEL_ABS; + + input_report_key(dev, ABS_WHEEL, hanvon->wheel_pos); + } + + hanvon->old_wheel_pos = data[2]; + } } break; @@ -120,6 +134,7 @@ static int hanvon_open(struct input_dev *dev) { struct hanvon *hanvon = input_get_drvdata(dev); + hanvon->old_wheel_pos = -TOTAL_WHEEL_ABS-1; hanvon->irq->dev = hanvon->usbdev; if (usb_submit_urb(hanvon->irq, GFP_KERNEL)) return -EIO; @@ -182,6 +197,7 @@ static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id * input_set_abs_params(input_dev, ABS_X, 0, 0x27de, 4, 0); input_set_abs_params(input_dev, ABS_Y, 0, 0x1cfe, 4, 0); input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xffffffff, 4, 0); + input_set_abs_params(input_dev, ABS_WHEEL, 0, TOTAL_WHEEL_ABS, 4, 0); endpoint = &intf->cur_altsetting->endpoint[0].desc;