Linux Input/HID development
 help / color / mirror / Atom feed
From: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
To: Jan Kratochvil <honza@jikos.cz>
Cc: linux-input@atrey.karlin.mff.cuni.cz,
	Brian Magnuson <bdmagnuson@gmail.com>
Subject: Re: [PATCH 4/4] xpad.c - fixed report for dpad and inverted Y and RY axes
Date: Mon, 11 Jun 2007 10:36:43 -0400	[thread overview]
Message-ID: <d120d5000706110736g3a15f86bg75ff57e3170819f1@mail.gmail.com> (raw)
In-Reply-To: <alpine.LRH.0.98.0706031610380.22353@twin.jikos.cz>

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

Hi,

Sorry for disappearmign on you guys...

On 6/3/07, Jan Kratochvil <honza@jikos.cz> wrote:
> Fixed input report handling for xbox 360 controller.
> Y/RY up is now positive and down negative.
> DPAD report fixed.

I have some concerns over this patch - when mapping dpad to buttons
your new mapping follows mapping for classic xbox; however it is still
different when mapping dpad to axes so this is suspicious. Could you
please try the attached patch and tell me if it works for you?

Also, please avoid constructs like this:

> +               input_report_abs(dev, ABS_HAT0Y, !!((data[2] & 0x08) >> 3) - !!((data[2] & 0x04) >> 2));

Doing shift is meaningles if you convert result to 0/1. I.e. it is
exactly the same as !!(data[2] & 0x08) - !!(data[2] &0x04).

Thank you.

-- 
Dmitry

[-- Attachment #2: xpad-fix-mapping-for-360.patch --]
[-- Type: text/plain, Size: 3726 bytes --]

---
 drivers/input/joystick/xpad.c |   40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

Index: linux/drivers/input/joystick/xpad.c
===================================================================
--- linux.orig/drivers/input/joystick/xpad.c
+++ linux/drivers/input/joystick/xpad.c
@@ -236,8 +236,8 @@ static void xpad_process_packet(struct u
 	} else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ {
 		input_report_key(dev, BTN_LEFT,  data[2] & 0x04);
 		input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
-		input_report_key(dev, BTN_0,     data[2] & 0x01); // up
-		input_report_key(dev, BTN_1,     data[2] & 0x02); // down
+		input_report_key(dev, BTN_0,     data[2] & 0x01); /* up */
+		input_report_key(dev, BTN_1,     data[2] & 0x02); /* down */
 	}
 
 	/* start/back buttons and stick press left/right */
@@ -275,40 +275,40 @@ static void xpad360_process_packet(struc
 
 	/* digital pad */
 	if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) {
-		input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x01) - !!((data[2] & 0x08) >> 3));
-		input_report_abs(dev, ABS_HAT0Y, !!((data[2] & 0x02) >> 1) - !!((data[2] & 0x04) >> 2));
-	} else if ( xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS ) {
+		input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04));
+		input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01));
+	} else if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) {
 		/* dpad as buttons (right, left, down, up) */
-		input_report_key(dev, BTN_RIGHT, (data[2] & 0x01));
-		input_report_key(dev, BTN_LEFT, (data[2] & 0x08) >> 3);
-		input_report_key(dev, BTN_0, (data[2] & 0x02) >> 1);
-		input_report_key(dev, BTN_1, (data[2] & 0x04) >> 2);
+		input_report_key(dev, BTN_LEFT, data[2] & 0x04);
+		input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
+		input_report_key(dev, BTN_0, data[2] & 0x01);	/* up */
+		input_report_key(dev, BTN_1, data[2] & 0x02);	/* down */
 	}
 
 	/* start/back buttons */
-	input_report_key(dev, BTN_START,  (data[2] & 0x10) >> 4);
-	input_report_key(dev, BTN_BACK,   (data[2] & 0x20) >> 5);
+	input_report_key(dev, BTN_START,  data[2] & 0x10);
+	input_report_key(dev, BTN_BACK,   data[2] & 0x20);
 
 	/* stick press left/right */
 	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
 	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
 
 	/* buttons A,B,X,Y,TL,TR and MODE */
-	input_report_key(dev, BTN_A, (data[3] & 0x10) >> 4);
-	input_report_key(dev, BTN_B, (data[3] & 0x20) >> 5);
-	input_report_key(dev, BTN_X, (data[3] & 0x40) >> 6);
-	input_report_key(dev, BTN_Y, (data[3] & 0x80) >> 7);
-	input_report_key(dev, BTN_TL, data[3] & 0x01 );
-	input_report_key(dev, BTN_TR, (data[3] & 0x02) >> 1);
-	input_report_key(dev, BTN_MODE, (data[3] & 0x04) >> 2);
+	input_report_key(dev, BTN_A,	data[3] & 0x10);
+	input_report_key(dev, BTN_B,	data[3] & 0x20);
+	input_report_key(dev, BTN_X,	data[3] & 0x40);
+	input_report_key(dev, BTN_Y,	data[3] & 0x80);
+	input_report_key(dev, BTN_TL,	data[3] & 0x01);
+	input_report_key(dev, BTN_TR,	data[3] & 0x02);
+	input_report_key(dev, BTN_MODE,	data[3] & 0x04);
 
 	/* left stick */
 	input_report_abs(dev, ABS_X, (__s16) (((__s16)data[7] << 8) | (__s16)data[6]));
-	input_report_abs(dev, ABS_Y, ~(__s16) (((__s16)data[9] << 8) | (__s16)data[8]));
+	input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[9] << 8) | (__s16)data[8]));
 
 	/* right stick */
-	input_report_abs(dev, ABS_RY, ~(__s16) (((__s16)data[13] << 8) | (__s16)data[12]));
 	input_report_abs(dev, ABS_RX, (__s16) (((__s16)data[11] << 8) | (__s16)data[10]));
+	input_report_abs(dev, ABS_RY, (__s16) (((__s16)data[13] << 8) | (__s16)data[12]));
 
 	/* triggers left/right */
 	input_report_abs(dev, ABS_Z, data[4]);

  reply	other threads:[~2007-06-11 14:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-03 14:14 [PATCH 4/4] xpad.c - fixed report for dpad and inverted Y and RY axes Jan Kratochvil
2007-06-11 14:36 ` Dmitry Torokhov [this message]
2007-06-13  1:13   ` Brian Magnuson
2007-06-13  6:26   ` Jan Kratochvil
2007-06-15  5:05     ` 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=d120d5000706110736g3a15f86bg75ff57e3170819f1@mail.gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=bdmagnuson@gmail.com \
    --cc=honza@jikos.cz \
    --cc=linux-input@atrey.karlin.mff.cuni.cz \
    /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