Make the logic for reading X, Y, distance, and pressure a bit more
clear. An additional bit was stuffed into the packet format many
models back, and /most/ devices in use will use it. If we happen
to be dealing with a particularly old tablet, just shift it off
the end to pretend we never read it.

Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
Signed-off-by: Jiri Kosina <jkos...@suse.cz>
[jason.gere...@wacom.com: Imported into input-wacom repository (5f33f43)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
[jason.gere...@wacom.com: backported from input-wacom 6425413]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
---
 2.6.38/wacom_wac.c | 27 ++++++++++++++-------------
 3.7/wacom_wac.c    | 27 ++++++++++++++-------------
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/2.6.38/wacom_wac.c b/2.6.38/wacom_wac.c
index f960c4a..9b37c01 100644
--- a/2.6.38/wacom_wac.c
+++ b/2.6.38/wacom_wac.c
@@ -831,21 +831,23 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        struct input_dev *input = wacom->input;
        int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
        unsigned char type = (data[1] >> 1) & 0x0F;
-       unsigned int t;
+       unsigned int x, y, distance, t;
 
        if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ 
&&
                data[0] != WACOM_REPORT_INTUOS_PEN)
                return 0;
 
-       if (features->type >= INTUOS3S) {
-               input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) 
| ((data[9] >> 1) & 1));
-               input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) 
| (data[9] & 1));
-               input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
-       } else {
-               input_report_abs(input, ABS_X, be16_to_cpup((__be16 
*)&data[2]));
-               input_report_abs(input, ABS_Y, be16_to_cpup((__be16 
*)&data[4]));
-               input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
+       x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
+       y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
+       distance = data[9] >> 2;
+       if (features->type < INTUOS3S) {
+               x >>= 1;
+               y >>= 1;
+               distance >>= 1;
        }
+       input_report_abs(input, ABS_X, x);
+       input_report_abs(input, ABS_Y, y);
+       input_report_abs(input, ABS_DISTANCE, distance);
 
        switch (type) {
        case 0x00:
@@ -853,10 +855,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        case 0x02:
        case 0x03:
                /* general pen packet */
-               t = (data[6] << 2) | ((data[7] >> 6) & 3);
-               if (features->pressure_max == 2047) {
-                       t = (t << 1) | (data[1] & 1);
-               }
+               t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
+               if (features->pressure_max < 2047)
+                       t >>= 1;
                input_report_abs(input, ABS_PRESSURE, t);
                if (features->type != INTUOSHT2) {
                        input_report_abs(input, ABS_TILT_X,
diff --git a/3.7/wacom_wac.c b/3.7/wacom_wac.c
index 613855a..3644634 100644
--- a/3.7/wacom_wac.c
+++ b/3.7/wacom_wac.c
@@ -833,21 +833,23 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        struct input_dev *input = wacom->input;
        int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
        unsigned char type = (data[1] >> 1) & 0x0F;
-       unsigned int t;
+       unsigned int x, y, distance, t;
 
        if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ 
&&
                data[0] != WACOM_REPORT_INTUOS_PEN)
                return 0;
 
-       if (features->type >= INTUOS3S) {
-               input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) 
| ((data[9] >> 1) & 1));
-               input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) 
| (data[9] & 1));
-               input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
-       } else {
-               input_report_abs(input, ABS_X, be16_to_cpup((__be16 
*)&data[2]));
-               input_report_abs(input, ABS_Y, be16_to_cpup((__be16 
*)&data[4]));
-               input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
+       x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
+       y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
+       distance = data[9] >> 2;
+       if (features->type < INTUOS3S) {
+               x >>= 1;
+               y >>= 1;
+               distance >>= 1;
        }
+       input_report_abs(input, ABS_X, x);
+       input_report_abs(input, ABS_Y, y);
+       input_report_abs(input, ABS_DISTANCE, distance);
 
        switch (type) {
        case 0x00:
@@ -855,10 +857,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        case 0x02:
        case 0x03:
                /* general pen packet */
-               t = (data[6] << 2) | ((data[7] >> 6) & 3);
-               if (features->pressure_max == 2047) {
-                       t = (t << 1) | (data[1] & 1);
-               }
+               t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
+               if (features->pressure_max < 2047)
+                       t >>= 1;
                input_report_abs(input, ABS_PRESSURE, t);
                if (features->type != INTUOSHT2) {
                        input_report_abs(input, ABS_TILT_X,
-- 
2.7.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to