Tag: gamepad

Success with gamepad mappings

Success with gamepad mappings

SNES Gamepad
Image by Marco Sberveglieri from Pixabay

My ploy with running gamepad-tool on the Linux laptop worked and I was able to get the correct mappings to use in my game. Though weirdly it seems to have X and Y buttons mixed up as well as A and B.

In the end I hard-coded the mapping string and set it up with this code:

	if (SDL_GameControllerAddMapping("030000001008000001e5000010010000,NEXT SNES Controller2,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,dpup:-a1,dpdown:+a1,dpleft:-a0,dpright:+a0")==-1){
		LogError("Unable to load gamepad mappings from gamepad.txt");
	}

Then in my ProcessEvents() function which handles I/O events, I added this code:

			case SDL_CONTROLLERBUTTONDOWN:
			if (event.cbutton.state== SDL_PRESSED){
				switch(event.cbutton.button){
					case SDL_CONTROLLER_BUTTON_A:
					    fireFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_B:						
					    jumpFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_X:
					    shieldFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_Y:						
					    thrustFlag =1;
					    break;						
					case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
					    rotateFlag = 1;
					    break;
					case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
					    rotateFlag= 2;				
					    break;
					}
				}

There’s similar code for the SDL_CONTROLLERBUTTONUP except it checks for the state = SDL_RELEASED and in the switch statement it sets each flag to 0. So inspite of the code, it’s the Y button that does shields and the X button does thrust, B button fires and A button does the hyper space jump.

More on Raspberry Pi Gamepad

More on Raspberry Pi Gamepad

jstest-gtkUnfortunately there’s no gamepad-tool for the PI, but there is a program called jstest and in particular a visual one called jstest-gtk. That’s it on the left. You install it on any Linux system, including Raspbian on the Pi with the command

sudo apt install jstest-gtk

Then run it with a jstest-gtk command from a terminal.

It then detects your game pad and responds to button presses and joystick movements.

The weird thing is although my gamepad identifies it as a NEXT SNES but so far attempts to load that have not been successful in the Asteroids game. It loads but doesn’t seem to work and its not recognising the right shoulder button and has A and B buttons muddled up. Yet in jstest, it is clearly able to identify them.

Time I think to create a mapping under Linux with gamepadtool. Unfortunately it doesn’t work on the Hyper-V Ubuntu so it’s time to fetch my Linux laptop and try it on that.