[GLFW] Detect X-box controller or PS controller?

This is pretty much a simple question:
How do you detect the difference between an X-box controller and a PS controller in GLFW?

I can’t use the name because the name comes from the driver, so they are both called the same.
The only other way I can think of is axis and button count, but I can already think of many problems that will come with that…
Is there any other way?

The reason why I need to know is so I can detect which controller the user is using so the game can use the correct ID’s.

Thx in advance.

Have a gander around the net and see if you can find a library that had that functionality, got can learn from that. I’m at work the now so can’t search personally :(.

I have found a library that does this, and they use the NodeJS port of GLFW, so it maybe similar.

https://github.com/floored/node-glfw-joystick

That is that project. I’m looking into this too, but I only have a wireless XBOX controller.

Here is some code on how they are deciding the mapping of the controller.


if (currJoystick.id === "Wireless Controller" && buttonCount === 18) {
    CONTROLLER_TYPE = 'ps4';
    MAPS = ps4Maps;
} else if (currJoystick.id === "PLAYSTATION(R)3 Controller" && buttonCount === 19) {
    CONTROLLER_TYPE = 'ps3';
    MAPS = ps3Maps;
} else if (currJoystick.id === "Controller" && buttonCount === 15) {
    CONTROLLER_TYPE = 'xbox';
    MAPS = xboxMaps;
} else {
    CONTROLLER_TYPE = 'generic';
    MAPS = GC.getMaps();
}

Maybe we could try the same in LWJGL and it may work. I’m still looking on how to use my wireless XBOX controller with Windows 8.1, so if you know that, please say that to me.

[offtopic]
With a wired controller, just plug it in. With a wireless… I think you have to buy some sort of USB dongle. I’ve never used one so I don’t really know. Have a google around.
[/offtopic]

I would try that but I have no idea where they get the ID from. The only thing I can think of is the name which returns “Microsoft PC-joystick driver” for both X-box 360 and PS3 controller. So I’m guessing it is the driver name. I noticed the other day (while messing with bluetooth [did you know you can control your android with a keyboard and mouse?]) that the names in the ‘Devices and Printers’ are actual proper names so maybe if I can just access that…

Could you just add a setting to select between them?

I wrote the xbox 360 pad mapping for libgdx -> Libgdx Xbox360 controller mapping
No idea about GLFW

However, somehow you should be able to get the ID of the device, from the device.
When you have that its simple.
And I like to mention this, since I figured it out: (copy paste)

[quote]It seems there are different versions of gamepads with different ID Strings.
[/quote]
These are the ones I know about, which the last 2 being original xbox controllers, I THINK:


      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)

I guess another valid question is: is the mapping of different models of xbox 360 gamepads the same ?
I would HOPE so, I never actually researched this, but I haven’t gotten any complains from my game using this so should be fine. Maybe.

This is the controller I’m having. This is a PS style gamepad, and it get’s detected as Generic USB Joystick, and the driver name is indeed “Microsoft USB Game Controller”

http://live-tech.in/images/large/lt_game-pad_(dual-vibraton-gamestick).jpg

The driver name will only be changed if the controller is original and having drivers. For example, the original PS controller gets detected as “PLAYSTATION®3 Controller”. Found in screenshots on WikiHow. Never tested an XBOX controller, the wireless adapter is currently out of stock in the local store, but I will purchase it at some point in the future.

So I’m guessing, unless I find a way to get the actual name of the controller, there is no way of detecting if it is X-box or PS?

Could there be some third-party Java API which I could use solely just to access the name and somehow sync it up with GLFW? (So I know which name is for which controller)

I think I got it working, the same code using the name property and button count, is detecting my controller as GENERIC. My controller is now completely working, but I have to test on other controllers as well.


if (name.equalsIgnoreCase("Wireless Controller") && numButtons == 18)
    type = Type.PS4;
else if (name.equalsIgnoreCase("PLAYSTATION(R)3 Controller") && numButtons == 19)
    type = Type.PS3;
else if (name.equalsIgnoreCase("Controller") && numButtons == 15)
    type = Type.XBOX;
else
    type = Type.GENERIC;

Try this, and let’s see what it returns for you, with your XBOX controller.

Make sure it’s the only controller plugged in and try something like this:

public String getJoystick() {
        String stickname;
        int present = GLFW.glfwJoystickPresent(GLFW.GLFW_JOYSTICK_1);
        if (present == 1) {
            stickname = GLFW.glfwGetJoystickName(GLFW.GLFW_JOYSTICK_1);
        } else {
            stickname = "None Detected";
        }
        return stickname; // then just System.out.println(stickname); or whatever you want to do with it.
    }

My XBOX 360 controller for windows(wired) shows as “Microsoft PC-joystick driver”