Skip to contentSkip to conversation

HID: wacom: set stylus_in_proximity before checking touch_down

PATCH In review Ping Cheng 2 participants 2 messages Mar 20, 2015 – Apr 1, 2015

Subsystems (2)
lore
Share & tools
lore

Ping Cheng

author
#0 lore raw

PATCH 3/3 HID: wacom: set stylus_in_proximity before checking touch_down

In wacom_bpt_pen, we checked touch_down before assigning new stylus_in_proximity value. This would cause stylus_in_proximity not updated properly if touch is down before pen is in proximity.

---
 drivers/hid/wacom_wac.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)
drivers/hid/wacom_wac.c +16 -19
index 60d9ccb..63e767e 100644
@@ -1752,9 +1752,6 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
 		return 0;
 	}
 
-	if (wacom->shared->touch_down)
-		return 0;
-
 	prox = (data[1] & 0x20) == 0x20;
 
 	/*
@@ -1767,17 +1764,21 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
 	 *
 	 * Hardware does report zero in most out-of-prox cases but not all.
 	 */
-	if (prox) {
-		if (!wacom->shared->stylus_in_proximity) {
-			if (data[1] & 0x08) {
-				wacom->tool[0] = BTN_TOOL_RUBBER;
-				wacom->id[0] = ERASER_DEVICE_ID;
-			} else {
-				wacom->tool[0] = BTN_TOOL_PEN;
-				wacom->id[0] = STYLUS_DEVICE_ID;
-			}
-			wacom->shared->stylus_in_proximity = true;
+	if (!wacom->shared->stylus_in_proximity) {
+		if (data[1] & 0x08) {
+			wacom->tool[0] = BTN_TOOL_RUBBER;
+			wacom->id[0] = ERASER_DEVICE_ID;
+		} else {
+			wacom->tool[0] = BTN_TOOL_PEN;
+			wacom->id[0] = STYLUS_DEVICE_ID;
 		}
+	}
+
+	wacom->shared->stylus_in_proximity = prox;
+	if (wacom->shared->touch_down)
+		return 0;
+
+	if (prox) {
 		x = le16_to_cpup((__le16 *)&data[2]);
 		y = le16_to_cpup((__le16 *)&data[4]);
 		p = le16_to_cpup((__le16 *)&data[6]);
@@ -1793,7 +1794,8 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
 		pen = data[1] & 0x01;
 		btn1 = data[1] & 0x02;
 		btn2 = data[1] & 0x04;
-	}
+	} else
+		wacom->id[0] = 0;
 
 	input_report_key(input, BTN_TOUCH, pen);
 	input_report_key(input, BTN_STYLUS, btn1);
@@ -1804,11 +1806,6 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
 	input_report_abs(input, ABS_PRESSURE, p);
 	input_report_abs(input, ABS_DISTANCE, d);
 
-	if (!prox) {
-		wacom->id[0] = 0;
-		wacom->shared->stylus_in_proximity = false;
-	}
-
 	input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
 	input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
 
Signature · 1 line
1.9.1
Reviewed-by on v1 3/3
#1 lore raw
Quoted 56 lines · Ping Cheng

In wacom_bpt_pen, we checked touch_down before assigning new stylus_in_proximity value. This would cause stylus_in_proximity not updated properly if touch is down before pen is in proximity.

---
  drivers/hid/wacom_wac.c | 35 ++++++++++++++++-------------------
  1 file changed, 16 insertions(+), 19 deletions(-)
drivers/hid/wacom_wac.c +14 -13
index 60d9ccb..63e767e 100644
@@ -1752,9 +1752,6 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
  		return 0;
  	}
 
-	if (wacom->shared->touch_down)
-		return 0;
-
  	prox = (data[1] & 0x20) == 0x20;
 
  	/*
@@ -1767,17 +1764,21 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
  	 *
  	 * Hardware does report zero in most out-of-prox cases but not all.
  	 */
-	if (prox) {
-		if (!wacom->shared->stylus_in_proximity) {
-			if (data[1] & 0x08) {
-				wacom->tool[0] = BTN_TOOL_RUBBER;
-				wacom->id[0] = ERASER_DEVICE_ID;
-			} else {
-				wacom->tool[0] = BTN_TOOL_PEN;
-				wacom->id[0] = STYLUS_DEVICE_ID;
-			}
-			wacom->shared->stylus_in_proximity = true;
+	if (!wacom->shared->stylus_in_proximity) {
+		if (data[1] & 0x08) {
+			wacom->tool[0] = BTN_TOOL_RUBBER;
+			wacom->id[0] = ERASER_DEVICE_ID;
+		} else {
+			wacom->tool[0] = BTN_TOOL_PEN;
+			wacom->id[0] = STYLUS_DEVICE_ID;
  		}
+	}
+
+	wacom->shared->stylus_in_proximity = prox;
+	if (wacom->shared->touch_down)
+		return 0;
+
+	if (prox) {
  		x = le16_to_cpup((__le16 *)&data[2]);
  		y = le16_to_cpup((__le16 *)&data[4]);
  		p = le16_to_cpup((__le16 *)&data[6]);

drivers/hid/wacom_wac.c static int wacom_bpt_pen(struct wacom_wac *wacom) · line 1798

Quoted 6 lines
drivers/hid/wacom_wac.c +2 -1
@@ -1793,7 +1794,8 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
  		pen = data[1] & 0x01;
  		btn1 = data[1] & 0x02;
  		btn2 = data[1] & 0x04;
-	}
+	} else
+		wacom->id[0] = 0;

Nitpick: Add braces around this final block. Otherwise:

---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one /
(That is to say, eight) to the two, /
But you can’t take seven from three, /
So you look at the sixty-fours....

Quoted 6 lines
drivers/hid/wacom_wac.c +0 -0
  	input_report_key(input, BTN_TOUCH, pen);
  	input_report_key(input, BTN_STYLUS, btn1);
@@ -1804,11 +1806,6 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
  	input_report_abs(input, ABS_PRESSURE, p);

drivers/hid/wacom_wac.c static int wacom_bpt_pen(struct wacom_wac *wacom) · line 1811

Quoted 10 lines
drivers/hid/wacom_wac.c +0 -5
  	input_report_abs(input, ABS_DISTANCE, d);
 
-	if (!prox) {
-		wacom->id[0] = 0;
-		wacom->shared->stylus_in_proximity = false;
-	}
-
  	input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
  	input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
 

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html