Skip to contentSkip to conversation

input: wacom: Report correct touch contact size for I5/Bamboo

PATCH In review Jason Gerecke 3 participants 3 messages Sep 24, 2012 – Sep 25, 2012 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CAGzDe_Y6RUs7Y29zNEFdf7Oja_wmQtNijY09qSctf9hVzm9pig@mail.gmail.com

#1 lore raw

PATCH v3 1/1 input: wacom: Report correct touch contact size for I5/Bamboo

This changes how the touch packets for Intuos5 and 3rd-gen Bamboo are interpreted, so that proper values for the MAJOR and MINOR axes are reported. Instead of using the amplitude field (data[6]), we use the size field (data[5]) and do some calculation to transform it from a scaled-down area into axis lengths.

Note that even though we assume a circular contact, both MAJOR and MINOR are reported since the resolution of the X and Y axes differ.

---
Changes from v2:
* Modified WACOM_CONTACT_AREA_SCALE so that we can calculate the width directly, rather than going through an intermediate logical_diameter and physical_diameter.

 drivers/input/tablet/wacom_wac.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/input/tablet/wacom_wac.c +22 -4
index 532d067..2543169 100644
@@ -25,6 +25,11 @@
 #define WACOM_INTUOS_RES	100
 #define WACOM_INTUOS3_RES	200
 
+/* Scale factor relating reported contact size to logical contact area.
+ * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
+ */
+#define WACOM_CONTACT_AREA_SCALE 2607
+
 static int wacom_penpartner_irq(struct wacom_wac *wacom)
 {
 	unsigned char *data = wacom->data;
@@ -1043,11 +1048,19 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
 	if (touch) {
 		int x = (data[2] << 4) | (data[4] >> 4);
 		int y = (data[3] << 4) | (data[4] & 0x0f);
-		int w = data[6];
+		int a = data[5];
+
+		// "a" is a scaled-down area which we assume is roughly
+		// circular and which can be described as: a=(pi*r^2)/C.
+		int x_res  = input_abs_get_res(input, ABS_X);
+		int y_res  = input_abs_get_res(input, ABS_Y);
+		int width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
+		int height = width * y_res / x_res;
 
 		input_report_abs(input, ABS_MT_POSITION_X, x);
 		input_report_abs(input, ABS_MT_POSITION_Y, y);
-		input_report_abs(input, ABS_MT_TOUCH_MAJOR, w);
+		input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
+		input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
 	}
 }
 
@@ -1533,7 +1546,9 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
 			input_mt_init_slots(input_dev, features->touch_max);
 
 			input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
-			                     0, 255, 0, 0);
+			                     0, features->x_max, 0, 0);
+			input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
+			                     0, features->y_max, 0, 0);
 
 			input_set_abs_params(input_dev, ABS_MT_POSITION_X,
 					     0, features->x_max,
@@ -1641,7 +1656,10 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
 
 				input_set_abs_params(input_dev,
 						     ABS_MT_TOUCH_MAJOR,
-						     0, 255, 0, 0);
+						     0, features->x_max, 0, 0);
+				input_set_abs_params(input_dev,
+						     ABS_MT_TOUCH_MINOR,
+						     0, features->y_max, 0, 0);
 			}
 
 			input_set_abs_params(input_dev, ABS_MT_POSITION_X,
Signature · 1 line
1.7.12
Reviewed-by on v3 1/1
#2 lore raw
Quoted 9 lines · Jason Gerecke

This changes how the touch packets for Intuos5 and 3rd-gen Bamboo are interpreted, so that proper values for the MAJOR and MINOR axes are reported. Instead of using the amplitude field (data[6]), we use the size field (data[5]) and do some calculation to transform it from a scaled-down area into axis lengths.

Note that even though we assume a circular contact, both MAJOR and MINOR are reported since the resolution of the X and Y axes differ.

Quoted 6 lines

---
Changes from v2:
* Modified WACOM_CONTACT_AREA_SCALE so that we can calculate the width directly, rather than going through an intermediate logical_diameter and physical_diameter.

This version does read easier with the simplified steps.

Quoted 68 lines
 drivers/input/tablet/wacom_wac.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/input/tablet/wacom_wac.c +22 -5
index 532d067..2543169 100644
@@ -25,6 +25,11 @@
 #define WACOM_INTUOS_RES       100
 #define WACOM_INTUOS3_RES      200
 
+/* Scale factor relating reported contact size to logical contact area.
+ * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
+ */
+#define WACOM_CONTACT_AREA_SCALE 2607
+
 static int wacom_penpartner_irq(struct wacom_wac *wacom)
 {
        unsigned char *data = wacom->data;
@@ -1043,11 +1048,19 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
        if (touch) {
                int x = (data[2] << 4) | (data[4] >> 4);
                int y = (data[3] << 4) | (data[4] & 0x0f);
-               int w = data[6];
+               int a = data[5];
+
+               // "a" is a scaled-down area which we assume is roughly
+               // circular and which can be described as: a=(pi*r^2)/C.
+               int x_res  = input_abs_get_res(input, ABS_X);
+               int y_res  = input_abs_get_res(input, ABS_Y);
+               int width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
+               int height = width * y_res / x_res;
 
                input_report_abs(input, ABS_MT_POSITION_X, x);
                input_report_abs(input, ABS_MT_POSITION_Y, y);
-               input_report_abs(input, ABS_MT_TOUCH_MAJOR, w);
+               input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
+               input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
        }
 }
 
@@ -1533,7 +1546,9 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
                        input_mt_init_slots(input_dev, features->touch_max);
 
                        input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
-                                            0, 255, 0, 0);
+                                            0, features->x_max, 0, 0);
+                       input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
+                                            0, features->y_max, 0, 0);
 
                        input_set_abs_params(input_dev, ABS_MT_POSITION_X,
                                             0, features->x_max,
@@ -1641,7 +1656,10 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
 
                                input_set_abs_params(input_dev,
                                                     ABS_MT_TOUCH_MAJOR,
-                                                    0, 255, 0, 0);
+                                                    0, features->x_max, 0, 0);
+                               input_set_abs_params(input_dev,
+                                                    ABS_MT_TOUCH_MINOR,
+                                                    0, features->y_max, 0, 0);
                        }
 
                        input_set_abs_params(input_dev, ABS_MT_POSITION_X,
--

1.7.12

Acked-by on v3 1/1
#3 lore raw
In reply to Jason Gerecke
Quoted 10 lines · Jason Gerecke

This changes how the touch packets for Intuos5 and 3rd-gen Bamboo are interpreted, so that proper values for the MAJOR and MINOR axes are reported. Instead of using the amplitude field (data[6]), we use the size field (data[5]) and do some calculation to transform it from a scaled-down area into axis lengths.

Note that even though we assume a circular contact, both MAJOR and MINOR are reported since the resolution of the X and Y axes differ.

Ping

Quoted 73 lines

---
Changes from v2:
* Modified WACOM_CONTACT_AREA_SCALE so that we can calculate the width directly, rather than going through an intermediate logical_diameter and physical_diameter.

 drivers/input/tablet/wacom_wac.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/input/tablet/wacom_wac.c +22 -5
index 532d067..2543169 100644
@@ -25,6 +25,11 @@
 #define WACOM_INTUOS_RES       100
 #define WACOM_INTUOS3_RES      200
 
+/* Scale factor relating reported contact size to logical contact area.
+ * 2^14/pi is a good approximation on Intuos5 and 3rd-gen Bamboo
+ */
+#define WACOM_CONTACT_AREA_SCALE 2607
+
 static int wacom_penpartner_irq(struct wacom_wac *wacom)
 {
        unsigned char *data = wacom->data;
@@ -1043,11 +1048,19 @@ static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
        if (touch) {
                int x = (data[2] << 4) | (data[4] >> 4);
                int y = (data[3] << 4) | (data[4] & 0x0f);
-               int w = data[6];
+               int a = data[5];
+
+               // "a" is a scaled-down area which we assume is roughly
+               // circular and which can be described as: a=(pi*r^2)/C.
+               int x_res  = input_abs_get_res(input, ABS_X);
+               int y_res  = input_abs_get_res(input, ABS_Y);
+               int width  = 2 * int_sqrt(a * WACOM_CONTACT_AREA_SCALE);
+               int height = width * y_res / x_res;
 
                input_report_abs(input, ABS_MT_POSITION_X, x);
                input_report_abs(input, ABS_MT_POSITION_Y, y);
-               input_report_abs(input, ABS_MT_TOUCH_MAJOR, w);
+               input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
+               input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
        }
 }
 
@@ -1533,7 +1546,9 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
                        input_mt_init_slots(input_dev, features->touch_max);
 
                        input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR,
-                                            0, 255, 0, 0);
+                                            0, features->x_max, 0, 0);
+                       input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR,
+                                            0, features->y_max, 0, 0);
 
                        input_set_abs_params(input_dev, ABS_MT_POSITION_X,
                                             0, features->x_max,
@@ -1641,7 +1656,10 @@ int wacom_setup_input_capabilities(struct input_dev *input_dev,
 
                                input_set_abs_params(input_dev,
                                                     ABS_MT_TOUCH_MAJOR,
-                                                    0, 255, 0, 0);
+                                                    0, features->x_max, 0, 0);
+                               input_set_abs_params(input_dev,
+                                                    ABS_MT_TOUCH_MINOR,
+                                                    0, features->y_max, 0, 0);
                        }
 
                        input_set_abs_params(input_dev, ABS_MT_POSITION_X,
--

1.7.12