linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Henrik Rydberg" <rydberg@euromail.se>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Stephane Chatty <chatty@enac.fr>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Henrik Rydberg <rydberg@euromail.se>
Subject: [PATCH 3/3] hid: 3m: Correct touchscreen emulation
Date: Sat, 28 Aug 2010 16:29:08 +0200	[thread overview]
Message-ID: <1283005748-3293-3-git-send-email-rydberg@euromail.se> (raw)
In-Reply-To: <1283005748-3293-1-git-send-email-rydberg@euromail.se>

The current code sometimes misses to report the last BTN_TOUCH event
when multiple fingers are lifted simultaneously.  With the
introduction of MT slots, the tracking id is available to determine
the oldest active contact. Use this information to simplify and
correct the touchscreen emulation logic.

Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
 drivers/hid/hid-3m-pct.c |   41 +++++------------------------------------
 1 files changed, 5 insertions(+), 36 deletions(-)

diff --git a/drivers/hid/hid-3m-pct.c b/drivers/hid/hid-3m-pct.c
index 9a3b047..65441e0 100644
--- a/drivers/hid/hid-3m-pct.c
+++ b/drivers/hid/hid-3m-pct.c
@@ -33,7 +33,6 @@ MODULE_LICENSE("GPL");
 struct mmm_finger {
 	__s32 x, y, w, h;
 	__u16 id;
-	__u8 rank;
 	bool prev_touch;
 	bool touch, valid;
 };
@@ -41,7 +40,7 @@ struct mmm_finger {
 struct mmm_data {
 	struct mmm_finger f[MAX_SLOTS];
 	__u16 id;
-	__u8 curid, num;
+	__u8 curid;
 	__u8 nexp, nreal;
 	bool touch, valid;
 };
@@ -152,13 +151,7 @@ static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi,
 static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
 {
 	struct mmm_finger *oldest = 0;
-	bool pressed = false, released = false;
 	int i;
-
-	/*
-	 * we need to iterate on all fingers to decide if we have a press
-	 * or a release event in our touchscreen emulation.
-	 */
 	for (i = 0; i < MAX_SLOTS; ++i) {
 		struct mmm_finger *f = &md->f[i];
 		if (!f->valid) {
@@ -179,34 +172,11 @@ static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
 						wide ? f->w : f->h);
 			input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR,
 						wide ? f->h : f->w);
-			/*
-			 * touchscreen emulation: maintain the age rank
-			 * of this finger, decide if we have a press
-			 */
-			if (f->rank == 0) {
-				f->rank = ++(md->num);
-				if (f->rank == 1)
-					pressed = true;
-			}
-			if (f->rank == 1)
+			/* touchscreen emulation: pick the oldest contact */
+			if (!oldest || ((f->id - oldest->id) & (SHRT_MAX + 1)))
 				oldest = f;
 		} else {
 			/* this finger took off the screen */
-			/* touchscreen emulation: maintain age rank of others */
-			int j;
-
-			for (j = 0; j < 10; ++j) {
-				struct mmm_finger *g = &md->f[j];
-				if (g->rank > f->rank) {
-					g->rank--;
-					if (g->rank == 1)
-						oldest = g;
-				}
-			}
-			f->rank = 0;
-			--(md->num);
-			if (md->num == 0)
-				released = true;
 			input_event(input, EV_ABS, ABS_MT_TRACKING_ID, -1);
 		}
 		f->prev_touch = f->touch;
@@ -215,11 +185,10 @@ static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
 
 	/* touchscreen emulation */
 	if (oldest) {
-		if (pressed)
-			input_event(input, EV_KEY, BTN_TOUCH, 1);
+		input_event(input, EV_KEY, BTN_TOUCH, 1);
 		input_event(input, EV_ABS, ABS_X, oldest->x);
 		input_event(input, EV_ABS, ABS_Y, oldest->y);
-	} else if (released) {
+	} else {
 		input_event(input, EV_KEY, BTN_TOUCH, 0);
 	}
 	input_sync(input);
-- 
1.7.1

  parent reply	other threads:[~2010-08-28 14:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-28 14:29 [PATCH 1/3] hid: 3m: Adjust to sequential MT HID protocol Henrik Rydberg
2010-08-28 14:29 ` [PATCH 2/3] hid: 3m: Convert to MT slots Henrik Rydberg
2010-09-20 19:43   ` Stéphane Chatty
2010-09-20 19:48     ` Henrik Rydberg
2010-09-20 19:53       ` Stéphane Chatty
2010-09-20 19:46   ` Stéphane Chatty
2010-09-20 19:51     ` Henrik Rydberg
2010-09-20 20:01       ` Stéphane Chatty
2010-09-20 20:04         ` Henrik Rydberg
2010-09-20 20:23           ` Stéphane Chatty
2010-09-21 17:37             ` Henrik Rydberg
2010-09-21 19:21               ` Stéphane Chatty
2010-09-21 19:34                 ` Henrik Rydberg
2010-09-21 21:24                 ` Jiri Kosina
2010-08-28 14:29 ` Henrik Rydberg [this message]
2010-08-28 15:56   ` [PATCH 3/3] hid: 3m: Correct touchscreen emulation Stéphane Chatty
2010-08-28 16:08     ` Henrik Rydberg
2010-08-28 17:07       ` Stéphane Chatty
2010-08-30 13:36         ` Jiri Kosina
2010-09-21 17:00   ` Stéphane Chatty
2010-09-21 17:05     ` Jiri Kosina
2010-09-21 19:20       ` Stéphane Chatty
2010-09-21 21:23         ` Jiri Kosina
2010-09-20 18:21 ` [PATCH 1/3] hid: 3m: Adjust to sequential MT HID protocol Stéphane Chatty
2010-09-21 14:12   ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283005748-3293-3-git-send-email-rydberg@euromail.se \
    --to=rydberg@euromail.se \
    --cc=chatty@enac.fr \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).