Joysticks - Controller ID?

Started by
14 comments, last by irbaboon 10 years, 9 months ago

Hello! This is a bit long thread about a little issue I've encountered.

Yesterday I started looking at joysticks, and how to use them in my games. I found this to be fairly easy. I made an input system so I could register new controllers fairly easy. However, a problem has come up!

In the settings in my game, you get a list of all controllers connected to your computer. So you basically just choose one, and you can play with that controller.

Right now, I have configured an XBOX360 controller and an Nintendo 64 controller. After adding the N64, I realised the problem.

I needed to know which controller was which. So I added an "id" property to my joystick class. The game would then set an "id" to each controller, so it would know which action to do.

The code to add an input looks like this, pseudocodeishly:


int ACTION_PAUSE = joystick->add_input();
joystick->add_trigger(ACTION_PAUSE, new button_press(XBOX360_BUTTON_START, CONTROLLER_XBOX360, input_state::pressed));
joystick->add_trigger(ACTION_PAUSE, new button_press(N64_BUTTON_START, CONTROLLER_N64, input_state::pressed));
joystick->add_trigger(ACTION_PAUSE, new key_press(key_return, input_state::pressed));

So it's all fine, until I realise I have to actually idenfity the controller.

What I thought first I could do was


joystick->open(controller_index, CONTROLLER_XBOX360);

Then I realised... I have no idea which controller is which.

I know I can call SDL_JoystickName for the name of the controller, but the Nintendo 64 controller, which I can use through an adapter, names the controller for "USB Controller". I have two of those, as there are two ports in the adapter. So what if I get, let's say, a GC adapter, and use a GC controller. Then I get possibly another "USB Controller" name. So I can't just use that name to identify the controller.

Also, I noticed that an XBOX360 controller of a friend of mine was a special one with a unique name. So I can't even see which is which of the same type.

So I'm wondering if there is a way to figure it out?

I thought of making a function that checks how many buttons, axes, hats and balls the controller has - but what if it's a special-made N64 controller? I saw one online that had special buttons on it. Regardless of that, it's a stupid idea anyway, lol.

So yeah, any thoughts?

Thanks in advance.

Advertisement
Well, I would probably have the game do the best it can to map input based on the number of buttons and the name of the device name but then allow the user to customize the input. You could try to have a good layout for the most common input devices but you will never be able to have the perfect layout for all input devices because new devices hit the market all the time.
My current game project Platform RPG

Yeah, I know.

I guess I can try to make a function that tries its best to recognise a controller by its name and amount of buttons.

However, it would be so much better if there is some sort of signature in the controller...

I have another question by the way. Why does SDL say there are 16 buttons on the n64 controller when there's only 10.

Is there a logical explanation for this? The B button has ID 2, and then the left shoulder button comes next at ID 6.


I have another question by the way. Why does SDL say there are 16 buttons on the n64 controller when there's only 10.
Is there a logical explanation for this? The B button has ID 2, and then the left shoulder button comes next at ID 6.

Is the D-pad mapped to the 4 missing buttons?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


I have another question by the way. Why does SDL say there are 16 buttons on the n64 controller when there's only 10.
Is there a logical explanation for this? The B button has ID 2, and then the left shoulder button comes next at ID 6.

Is the D-pad mapped to the 4 missing buttons?

There are 6 missing buttons in total.

The D-pad is button 12, 13, 14 and 15. It's also a hat which has the dpad sum.

Here's the list of the IDs I have figured out:


// Buttons
static const int N64_BUTTON_A          = 1;
static const int N64_BUTTON_B          = 2;
static const int N64_BUTTON_LEFT       = 6;
static const int N64_BUTTON_RIGHT      = 7;
static const int N64_BUTTON_Z          = 8;
static const int N64_BUTTON_START      = 9;
static const int N64_BUTTON_DPAD_UP    = 12;
static const int N64_BUTTON_DPAD_RIGHT = 13;
static const int N64_BUTTON_DPAD_DOWN  = 14;
static const int N64_BUTTON_DPAD_LEFT  = 15;
// Axes
static const int N64_AXIS_X            = 0;
static const int N64_AXIS_Y            = 1;
static const int N64_AXIS_C_VERTICAL   = 2;
static const int N64_AXIS_C_HORIZONTAL = 3;
// Hats
static const int N64_HAT_DPAD          = 0;

Did they leave extra space for the attachments (rumblepack and such) that fit in the bottom of the controller?

The memory card I had for mine had a "Page up" and "page down" button for the four pages/memory-blocks of the card. I also had another card that had a four-position slider.


I have another question by the way. Why does SDL say there are 16 buttons on the n64 controller when there's only 10.

You must have a non-standard controller. The stock n64 controller has:

- a start button

- an A button

- a B button

- a central trigger

- 4 directional buttons

- 2 shoulder buttons

- a 4-way D-pad

For a total of 14 buttons.

Additionally, some controllers have Turbo and Slow buttons, which brings you up to 16.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


I have another question by the way. Why does SDL say there are 16 buttons on the n64 controller when there's only 10.

You must have a non-standard controller. The stock n64 controller has:

- a start button

- an A button

- a B button

- a central trigger

- 4 directional buttons

- 2 shoulder buttons

- a 4-way D-pad

For a total of 14 buttons.

Additionally, some controllers have Turbo and Slow buttons, which brings you up to 16.

I have a normal N64 controller.

What's a "central trigger"? I don't have anything like that...

Also, the 4 C buttons doesn't work as buttons for me, I can only use the axes.

I guess it'd make sense what you explain though. Are you 100% certain the C buttons are buttons?

Did they leave extra space for the attachments (rumblepack and such) that fit in the bottom of the controller?

The memory card I had for mine had a "Page up" and "page down" button for the four pages/memory-blocks of the card. I also had another card that had a four-position slider.

I suppose what you and swiftcoder says about that might be correct. As I explain above, it still doesn't quite make sense for my controller though...

Or maybe this controller explains it? If the C-pad are axes instead of buttons, I count 16 there. Though that's not actually plugged into an N64, so maybe not. This implies that the C-pad are actually buttons, and that there are two unused spaces (that is, two spaces that the author of the article left blank, so maybe they are used but he just didn't know about it).

I suppose the LodgeNet controller could explain it. Maybe Nintendo made support for 16 buttons on the original controller to make the LodgeNet controller easier to make. I don't know, is it a modified Nintendo 64 or just a TV that can play N64 games... I got a bit confused.

Anyway, the link you sent me doesn't really say the C-pad buttons are 'buttons', or am I missing something?

Even if they were, it's still not a better explanation than the LodgeNet controller, as that has 16 buttons in total.

This topic is closed to new replies.

Advertisement