Why is SDL Cannot Open JoyStick for PS2 Controller
I am using the psx/usb connecter to play this game i made in SDL using the psx controller the thing tell me it find one controller connected. but when i try to open it it cannot open it also if i try to get the name of the controller it returns a bunch of jiberish. So does it support it or not i want to make sure.
Wrong forum, but anyway.
Does the system (like, directx?) recognize the controller as a joystick?
Does the system (like, directx?) recognize the controller as a joystick?
And what platform are you running SDL on? I'm running Linux and my current SDL code fails to recognize my USB Logitech Wingman Gamepad, but on my older linux system the exact same gamepad was recognized (and worked with no tweaking) on SNES9x, which I believe uses SDL.
I am sorry for not repplying for so long. The way that i fixed what that when i try to get the joystick name. it was not returning it to me so what i did since to Initialize the Joystick you have to pass and data type int so it know which port is open i just pass the whatever SDL_NumJoystickOpen() returns -1 this will set the correct port because the thing is that SDL will return 1 when you Querry for the controller if it is in port 1, so you migh think that to Initialize it you have to set it to 1 but don't forget that everything starts at 0 so if SDl returns 1 the port you have to Open then is 0 so the Best way to do it is Set SDL_OpenJoystick(SDL_NumJoystickOpen()-1); This will defintely work. If it doens't then your controller is not supported. Also when you Initialize SDL make sure you pass SDL_INIT_JOYSTICK as one of the parameters otherwise this whole thing will fail.
So it was just an off-by-one error then. Well that's no fun. By the way calling SDL_JoystickOpen(SDL_NumJoysticks()-1); is not a good idea, because if there are no joysticks on your system then you're going to be passing -1 to the SDL_JoystickOpen function, which is a very bad thing. :P Here's some joystick debug code I wrote up for my project. It just prints out info about all the joysticks that SDL has recognized on the system, nothing special.
SDL_Joystick *js_test; int js_num = SDL_NumJoysticks(); // Get the number of joysticks available cout << "SDL has recognized " << js_num << " joystick(s) on this system." << endl; for (int i = 0; i < js_num; i++) { // Print out information about each joystick js_test = SDL_JoystickOpen(i); if (js_test == NULL) cout << "ERROR: SDL was unable to open joystick #" << i << endl; else { cout << "Joystick #" << i << endl; cout << ">Name: " << SDL_JoystickName(i) << endl; cout << ">Axes: " << SDL_JoystickNumAxes(js_test) << endl; cout << ">Buttons: " << SDL_JoystickNumButtons(js_test) << endl; cout << ">Trackballs: " << SDL_JoystickNumBalls(js_test) << endl; cout << ">Hat Switches: " << SDL_JoystickNumHats(js_test) << endl; SDL_JoystickClose(js_test); } }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement