Re: [PATCH 6/6] hid: egalax: Convert to MT slots

From: Chase Douglas
Date: Wed Oct 13 2010 - 13:35:27 EST


On Wed, 2010-10-13 at 15:58 +0200, Henrik Rydberg wrote:
> The joojoo reports touches sequentially, one per report, which
> confuses the current driver. Convert to the MT slots protocol and use
> the stored slot information to emulate pointer movement in a stable
> manner.
>
> Tested-by: Philipp Merkel <mail@xxxxxxxxxxx>
> Signed-off-by: Henrik Rydberg <rydberg@xxxxxxxxxxx>

[...]

> @@ -122,64 +133,61 @@ static int egalax_input_mapped(struct hid_device *hdev, struct hid_input *hi,
> return -1;
> }
>
> +static void emulate_pointer(struct egalax_data *td, struct input_dev *input)
> +{
> + struct egalax_contact *s = &td->single;
> + struct egalax_contact *best = 0;
> + int dbest, i;
> +
> + for (i = 0; i < MAX_SLOTS; i++) {
> + struct egalax_contact *f = &td->contact[i];
> + if (f->touch) {
> + int d = abs(f->x - s->x) + abs(f->y - s->y);
> + if (!best || d < dbest) {
> + best = f;
> + dbest = d;
> + }

Wouldn't it be better to do a real distance comparison:

int d = (f->x - s->x) * (f->x - s->x) + (f->y - s->y) * (f->y - s->y)

That should be the square of the actual distance between two contacts.

The rest looks ok to me.

-- Chase

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/