From: Chase Douglas <chase.douglas@canonical.com>
To: Ping Cheng <pinglinux@gmail.com>
Cc: Michael Poole <mdpoole@troilus.org>,
Jiri Kosina <jkosina@suse.cz>,
linux-input@vger.kernel.org
Subject: Re: [PATCH] hid-magicmouse: Correct parsing of large X and Y motions.
Date: Mon, 05 Jul 2010 16:02:00 -0400 [thread overview]
Message-ID: <1278360120.2425.97.camel@cndougla> (raw)
In-Reply-To: <AANLkTim9R0ur7r2Y3r3bOMIRSM7JYVcZdGZ0QMaYvK4X@mail.gmail.com>
On Tue, 2010-07-06 at 03:54 +0800, Ping Cheng wrote:
> On Mon, Jul 5, 2010 at 10:50 PM, Michael Poole <mdpoole@troilus.org> wrote:
> > The X and Y values have two more significant bits in the same byte
> > that contains click status. Include these in the reported value.
> > Thanks to Iain Hibbert of NetBSD for pointing this out.
> >
> > Signed-off-by: Michael Poole <mdpoole@troilus.org>
> > ---
> > drivers/hid/hid-magicmouse.c | 4 ++--
> > 1 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> > index 0b89c1c..7cdda23 100644
> > --- a/drivers/hid/hid-magicmouse.c
> > +++ b/drivers/hid/hid-magicmouse.c
> > @@ -267,8 +267,8 @@ static int magicmouse_raw_event(struct hid_device *hdev,
> > * to have the current touch information before
> > * generating a click event.
> > */
> > - x = (signed char)data[1];
> > - y = (signed char)data[2];
> > + x = (int)(((data[3] & 0x0c) << 28) | (data[1] << 22)) >> 22;
> > + y = (int)(((data[3] & 0x30) << 26) | (data[2] << 22)) >> 22;
>
> Will the following give us the same result?
>
> + x = (int)(((data[3] & 0x0c) << 6) | data[1]);
> + y = (int)(((data[3] & 0x30) << 4) | data[2]);
I thought about this too, but there's a sign extension issue. If the X
coordinate is -1 (these are relative coordinates), then you will end up
with (int)(1023), which is no longer -1.
When you shift to the right, the bits are sign-extended. Thus, shifting
everything to the most significant bit of an integer, and then shifting
everything back to the least significant will properly sign extend.
(I actually wrote a test program just to verify this)
That's just a reason for the shifts. There very well could be a more
elegant solution.
-- Chase
next prev parent reply other threads:[~2010-07-05 20:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-05 14:50 [PATCH] hid-magicmouse: Correct parsing of large X and Y motions Michael Poole
2010-07-05 16:28 ` Chase Douglas
2010-07-11 21:07 ` Jiri Kosina
2010-07-05 19:54 ` Ping Cheng
2010-07-05 20:02 ` Chase Douglas [this message]
2010-07-05 20:33 ` Michael Poole
2010-07-05 20:51 ` Chase Douglas
2010-07-05 22:08 ` Michael Poole
2010-07-05 22:25 ` Chase Douglas
2010-07-06 11:23 ` ext-phil.2.carmody
2010-07-06 11:38 ` Datta, Shubhrajyoti
2010-07-06 11:55 ` Michael Poole
2010-07-06 13:05 ` ext-phil.2.carmody
2010-07-05 22:51 ` Dmitry Torokhov
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=1278360120.2425.97.camel@cndougla \
--to=chase.douglas@canonical.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=mdpoole@troilus.org \
--cc=pinglinux@gmail.com \
/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).