Libgdx Xbox360 controller mapping

So Libgdx has now official controller support and should work with all controllers.
Of course there is special support for Ouya and its controller by having a mapping already there.

But there are no other mappings currently. Most interesting would be the Xbox360 pad mappings… does anyone have that ?
also: there are some models, at least the wireless and cable models - they dont happen to have different mappings ? would be silly, but you know… microsoft…

Xbox controller is still my champ. But doesn’t Ouya’s controller similiar to this?

sure controllers are similar, but the mapping is always kinda different

I have one lieing around, but not much time atm to constribute.
could you post some little code which reads out all the things you need to know?

well just the button mappings - not sure about stick calibrations, dead zones and whatnot

also I’ll get my pad this week and will probably tackle it then myself. I just thought someone has that mapping already =P

Well, worst case is you have to map by yourself ;D

Here we go


public class Xbox360Pad
{
	/*
	 * It seems there are different versions of gamepads with different ID Strings.
	 * Therefore its IMO a better bet to check for:
	 * if (controller.getName().toLowerCase().contains("xbox") &&
						controller.getName().contains("360"))
	 * 
	 * Controller (Gamepad for Xbox 360)
		Controller (XBOX 360 For Windows)
		Controller (Xbox 360 Wireless Receiver for Windows)
		Controller (Xbox wireless receiver for windows)
		XBOX 360 For Windows (Controller)
		Xbox 360 Wireless Receiver
		Xbox Receiver for Windows (Wireless Controller)
		Xbox wireless receiver for windows (Controller)
	 */
	//public static final String ID = "XBOX 360 For Windows (Controller)";
	public static final int BUTTON_X = 2;
	public static final int BUTTON_Y = 3;
	public static final int BUTTON_A = 0;
	public static final int BUTTON_B = 1;
	public static final int BUTTON_BACK = 6;
	public static final int BUTTON_START = 7;
	public static final PovDirection BUTTON_DPAD_UP = PovDirection.north;
	public static final PovDirection BUTTON_DPAD_DOWN = PovDirection.south;
	public static final PovDirection BUTTON_DPAD_RIGHT = PovDirection.east;
	public static final PovDirection BUTTON_DPAD_LEFT = PovDirection.west;
	public static final int BUTTON_LB = 4;
	public static final int BUTTON_L3 = 8;
	public static final int BUTTON_RB = 5;
	public static final int BUTTON_R3 = 9;
	public static final int AXIS_LEFT_X = 1; //-1 is left | +1 is right
	public static final int AXIS_LEFT_Y = 0; //-1 is up | +1 is down
	public static final int AXIS_LEFT_TRIGGER = 4; //value 0 to 1f
	public static final int AXIS_RIGHT_X = 3; //-1 is left | +1 is right
	public static final int AXIS_RIGHT_Y = 2; //-1 is up | +1 is down
	public static final int AXIS_RIGHT_TRIGGER = 4; //value 0 to -1f
}

Hi

Have you tried to use the Xbox 360 controller pull-based? ex: controller.getButton(buttonCode);

I get everything to work except Start and Back-button. It works in event-based code, but not in pull-based.

I submitted an Issue about it: https://code.google.com/p/libgdx/issues/detail?id=1436 but they Invalid it because they thought I didn’t use the right buttoncode (6 and 7 for back and start).

Any one seen this problem?

/Khazrak

I think you mean POLL based

Yeah I’ve been using ControllerAdapter exclusively actually, so event based…

edit:
No I cannot confirm that. I tested your code:


for (int i = 0; i < 14; i++) {
            System.out.println("Poll "+i+ " " +pad.getButton(i));    
	    }
	    
	    System.out.println("ButtonTest Start: "+pad.getButton(7));
	    System.out.println("ButtonTest Back: "+pad.getButton(6)); 

And yeah:

It works for me.

Intresting, from the code:

@Override
			public boolean buttonDown (Controller controller, int buttonCode)
			{
				System.out.println("code: "+buttonCode);
			   if(buttonCode == 7)
			   {
				   System.out.println("Start button Pressed!");		
			   }
				return true;
			}
			
			@Override
			public boolean buttonUp (Controller controller, int buttonCode) 
			{
				System.out.println("code: "+buttonCode);
			   if(buttonCode == 7)
			   {
				  System.out.println("Start button released!");
			   }
				return true;
			}

and

for (int i = 0; i < 14; i++) {
			System.out.println("Pull "+i+ " " +controller.getButton(i));	
		}
		
		System.out.println("ButtonTest Start: "+controller.getButton(7));
		System.out.println("ButtonTest Back: "+controller.getButton(6));

I get:

I’m trying it with a wired Xbox 360-controll under ubuntu 12.04 64-bit. I will try it on my Windows-pc at work tomorrow to see if it is a linux-specific problem.

The most likely scenario is that the controller variable you are using for polling is not the same / not the right one.
Be 100% sure.

Hi

Have you tried to use the Xbox 360 controller pull-based? ex: controller.getButton(buttonCode);

I get everything to work except Start and Back-button. It works in event-based code, but not in pull-based.

I submitted an Issue about it: https://code.google.com/p/libgdx/issues/detail?id=1436 but they Invalid it because they thought I didn’t use the right buttoncode (6 and 7 for back and start).

Any one seen this problem?

/Khazrak

I think you mean POLL based

Yeah I’ve been using ControllerAdapter exclusively actually, so event based…

edit:
No I cannot confirm that. I tested your code:


for (int i = 0; i < 14; i++) {
            System.out.println("Poll "+i+ " " +pad.getButton(i));    
	    }
	    
	    System.out.println("ButtonTest Start: "+pad.getButton(7));
	    System.out.println("ButtonTest Back: "+pad.getButton(6)); 

And yeah:

It works for me.

Intresting, from the code:

@Override
			public boolean buttonDown (Controller controller, int buttonCode)
			{
				System.out.println("code: "+buttonCode);
			   if(buttonCode == 7)
			   {
				   System.out.println("Start button Pressed!");		
			   }
				return true;
			}
			
			@Override
			public boolean buttonUp (Controller controller, int buttonCode) 
			{
				System.out.println("code: "+buttonCode);
			   if(buttonCode == 7)
			   {
				  System.out.println("Start button released!");
			   }
				return true;
			}

and

for (int i = 0; i < 14; i++) {
			System.out.println("Pull "+i+ " " +controller.getButton(i));	
		}
		
		System.out.println("ButtonTest Start: "+controller.getButton(7));
		System.out.println("ButtonTest Back: "+controller.getButton(6));

I get:

I’m trying it with a wired Xbox 360-controll under ubuntu 12.04 64-bit. I will try it on my Windows-pc at work tomorrow to see if it is a linux-specific problem.

The most likely scenario is that the controller variable you are using for polling is not the same / not the right one.
Be 100% sure.

I get the same problem on my win 7 64 bit laptop?
Weird…

Which version of libgdx are you using?
I’m using 0.9.8 stable version.

I always use nightlies.
But like I said: Make sure you have the right instance when polling. Or post your whole code or sonething.

I get the same problem on my win 7 64 bit laptop?
Weird…

Which version of libgdx are you using?
I’m using 0.9.8 stable version.

I always use nightlies.
But like I said: Make sure you have the right instance when polling. Or post your whole code or sonething.