Reasoning through the conditions under which a particular block of code
in 'wacom_intuos_general' will be reached is not at all easy due to the
sheer number of magic masks and comparisons. Remove these and replace
them with a switch statement over the various 'types' of packets that
will be encountered.

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 (a8a09c8)]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
[jason.gere...@wacom.com: backported from input-wacom cf5e2de]
Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
---
 2.6.38/wacom_wac.c | 79 +++++++++++++++++++++++++++++++++---------------------
 3.7/wacom_wac.c    | 79 +++++++++++++++++++++++++++++++++---------------------
 2 files changed, 98 insertions(+), 60 deletions(-)

diff --git a/2.6.38/wacom_wac.c b/2.6.38/wacom_wac.c
index 2a1dfbb..ee636e9 100644
--- a/2.6.38/wacom_wac.c
+++ b/2.6.38/wacom_wac.c
@@ -830,6 +830,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        unsigned char *data = wacom->data;
        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;
 
        if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ 
&&
@@ -846,8 +847,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
        }
 
-       /* general pen packet */
-       if ((data[1] & 0xb8) == 0xa0) {
+       switch (type) {
+       case 0x00:
+       case 0x01:
+       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);
@@ -861,36 +866,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                input_report_key(input, BTN_STYLUS, data[1] & 2);
                input_report_key(input, BTN_STYLUS2, data[1] & 4);
                input_report_key(input, BTN_TOUCH, t > 10);
-       }
+               break;
 
-       /* airbrush second packet */
-       if ((data[1] & 0xbc) == 0xb4) {
+       case 0x0a:
+       case 0x0b:
+               /* airbrush second packet */
                input_report_abs(input, ABS_WHEEL,
                                (data[6] << 2) | ((data[7] >> 6) & 3));
                input_report_abs(input, ABS_TILT_X,
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
                input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
-       }
+               break;
 
-       /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor 
packets */
-       if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 
0xbc) == 0xac) {
-
-               if (data[1] & 0x02) {
-                       /* Rotation packet */
-                       if (features->type >= INTUOS3S) {
-                               /* I3 marker pen rotation */
-                               t = (data[6] << 3) | ((data[7] >> 5) & 7);
-                               t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 
- 1350) :
-                                       ((t-1) / 2 + 450)) : (450 - t / 2) ;
-                               input_report_abs(input, ABS_Z, t);
-                       } else {
-                               /* 4D mouse rotation packet */
-                               t = (data[6] << 3) | ((data[7] >> 5) & 7);
-                               input_report_abs(input, ABS_RZ, (data[7] & 
0x20) ?
-                                       ((t - 1) / 2) : -t / 2);
-                       }
+       case 0x05:
+       case 0x07:
+               /* Rotation packet */
+               if (features->type >= INTUOS3S) {
+                       /* I3 marker pen rotation */
+                       t = (data[6] << 3) | ((data[7] >> 5) & 7);
+                       t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
+                               ((t-1) / 2 + 450)) : (450 - t / 2) ;
+                       input_report_abs(input, ABS_Z, t);
+               } else {
+                       /* 4D mouse rotation packet */
+                       t = (data[6] << 3) | ((data[7] >> 5) & 7);
+                       input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
+                               ((t - 1) / 2) : -t / 2);
+               }
+               break;
 
-               } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
+       /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor 
packets */
+       case 0x04:
+       case 0x06:
+       case 0x08:
+               if (features->type < INTUOS3S && type != 0x08) {
                        /* 4D mouse packet */
                        input_report_key(input, BTN_LEFT,   data[8] & 0x01);
                        input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -900,8 +909,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                        input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
                        t = (data[6] << 2) | ((data[7] >> 6) & 3);
                        input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) 
? -t : t);
-
-               } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
+               }
+               else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
                        /* I4 mouse */
                        if (features->type >= INTUOS4S && features->type <= 
INTUOSPL) {
                                input_report_key(input, BTN_LEFT,   data[6] & 
0x01);
@@ -929,10 +938,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                                        input_report_key(input, BTN_EXTRA,  
data[8] & 0x20);
                                }
                        }
-               } else if ((features->type < INTUOS3S || features->type == 
INTUOS3L ||
-                               features->type == INTUOS4L || features->type == 
INTUOS5L ||
-                               features->type == INTUOSPL) &&
-                          wacom->tool[idx] == BTN_TOOL_LENS) {
+               }
+               else if ((features->type < INTUOS3S || features->type == 
INTUOS3L ||
+                         features->type == INTUOS4L || features->type == 
INTUOS5L ||
+                         features->type == INTUOSPL) &&
+                        wacom->tool[idx] == BTN_TOOL_LENS) {
                        /* Lens cursor packets */
                        input_report_key(input, BTN_LEFT,   data[8] & 0x01);
                        input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -940,6 +950,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                        input_report_key(input, BTN_SIDE,   data[8] & 0x10);
                        input_report_key(input, BTN_EXTRA,  data[8] & 0x08);
                }
+               break;
+
+       case 0x09:
+       case 0x0c:
+       case 0x0d:
+       case 0x0e:
+       case 0x0f:
+               /* unhandled */
+               break;
        }
 
        input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
diff --git a/3.7/wacom_wac.c b/3.7/wacom_wac.c
index a04b9c7..c85ddd0 100644
--- a/3.7/wacom_wac.c
+++ b/3.7/wacom_wac.c
@@ -832,6 +832,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
        unsigned char *data = wacom->data;
        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;
 
        if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ 
&&
@@ -848,8 +849,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
        }
 
-       /* general pen packet */
-       if ((data[1] & 0xb8) == 0xa0) {
+       switch (type) {
+       case 0x00:
+       case 0x01:
+       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);
@@ -863,36 +868,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                input_report_key(input, BTN_STYLUS, data[1] & 2);
                input_report_key(input, BTN_STYLUS2, data[1] & 4);
                input_report_key(input, BTN_TOUCH, t > 10);
-       }
+               break;
 
-       /* airbrush second packet */
-       if ((data[1] & 0xbc) == 0xb4) {
+       case 0x0a:
+       case 0x0b:
+               /* airbrush second packet */
                input_report_abs(input, ABS_WHEEL,
                                (data[6] << 2) | ((data[7] >> 6) & 3));
                input_report_abs(input, ABS_TILT_X,
                                ((data[7] << 1) & 0x7e) | (data[8] >> 7));
                input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
-       }
+               break;
 
-       /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor 
packets */
-       if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 
0xbc) == 0xac) {
-
-               if (data[1] & 0x02) {
-                       /* Rotation packet */
-                       if (features->type >= INTUOS3S) {
-                               /* I3 marker pen rotation */
-                               t = (data[6] << 3) | ((data[7] >> 5) & 7);
-                               t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 
- 1350) :
-                                       ((t-1) / 2 + 450)) : (450 - t / 2) ;
-                               input_report_abs(input, ABS_Z, t);
-                       } else {
-                               /* 4D mouse rotation packet */
-                               t = (data[6] << 3) | ((data[7] >> 5) & 7);
-                               input_report_abs(input, ABS_RZ, (data[7] & 
0x20) ?
-                                       ((t - 1) / 2) : -t / 2);
-                       }
+       case 0x05:
+       case 0x07:
+               /* Rotation packet */
+               if (features->type >= INTUOS3S) {
+                       /* I3 marker pen rotation */
+                       t = (data[6] << 3) | ((data[7] >> 5) & 7);
+                       t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
+                               ((t-1) / 2 + 450)) : (450 - t / 2) ;
+                       input_report_abs(input, ABS_Z, t);
+               } else {
+                       /* 4D mouse rotation packet */
+                       t = (data[6] << 3) | ((data[7] >> 5) & 7);
+                       input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
+                               ((t - 1) / 2) : -t / 2);
+               }
+               break;
 
-               } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
+       /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor 
packets */
+       case 0x04:
+       case 0x06:
+       case 0x08:
+               if (features->type < INTUOS3S && type != 0x08) {
                        /* 4D mouse packet */
                        input_report_key(input, BTN_LEFT,   data[8] & 0x01);
                        input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -902,8 +911,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                        input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
                        t = (data[6] << 2) | ((data[7] >> 6) & 3);
                        input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) 
? -t : t);
-
-               } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
+               }
+               else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
                        /* I4 mouse */
                        if (features->type >= INTUOS4S && features->type <= 
INTUOSPL) {
                                input_report_key(input, BTN_LEFT,   data[6] & 
0x01);
@@ -931,10 +940,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                                        input_report_key(input, BTN_EXTRA,  
data[8] & 0x20);
                                }
                        }
-               } else if ((features->type < INTUOS3S || features->type == 
INTUOS3L ||
-                               features->type == INTUOS4L || features->type == 
INTUOS5L ||
-                               features->type == INTUOSPL) &&
-                          wacom->tool[idx] == BTN_TOOL_LENS) {
+               }
+               else if ((features->type < INTUOS3S || features->type == 
INTUOS3L ||
+                         features->type == INTUOS4L || features->type == 
INTUOS5L ||
+                         features->type == INTUOSPL) &&
+                        wacom->tool[idx] == BTN_TOOL_LENS) {
                        /* Lens cursor packets */
                        input_report_key(input, BTN_LEFT,   data[8] & 0x01);
                        input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -942,6 +952,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
                        input_report_key(input, BTN_SIDE,   data[8] & 0x10);
                        input_report_key(input, BTN_EXTRA,  data[8] & 0x08);
                }
+               break;
+
+       case 0x09:
+       case 0x0c:
+       case 0x0d:
+       case 0x0e:
+       case 0x0f:
+               /* unhandled */
+               break;
        }
 
        input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
-- 
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