How SDL controller mapping works?

Started by
4 comments, last by thd79 3 years ago

I have this problem, the game (SDL2, C++) correctly handles XInput Controller but when I try to connect PS3 Controller everything is a mess.

I'm not sure I understand how the controller mappings is supposed to work… I mean, when I tried SDL_GameControllerMapping() it returns “030000004c0500006802000000000000,PS3 Controller,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b10,lefttrigger:a3~,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:a4~,rightx:a2,righty:a5,start:b8,x:b3,y:b0,” so it seems the mapping for this controller is available and it should work?

How exactly it's supposed to work (feel free to copy/paste related links, tried to google it but found nothing)? Where the problem might be? The mapping is not “activated”? Something needs to be initialized? Etc.

Stellar Monarch (4X, turn based, released): GDN forum topic - Twitter - Facebook - YouTube

Advertisement

yes that comes from: http://hg.libsdl.org/SDL/file/e52d96ea04fc/src/joystick/SDL_gamecontrollerdb.h​ at LINE 234 ?

so a few more pointers (some of them are test programs, so u can see how to use it):

(if a link doesn't work, just copy-paste it manually into your address bar…)

it historically started here: https://bugzilla.libsdl.org/show_bug.cgi?id=2181​​ or here http://forums.libsdl.org/viewtopic.php?p=40677

anyway this should get u goin'

that's it …. all the best ?

@Acharis

I found the same problem with the same controller. I don't know if the mapping is wrong inside SDL, or it's the fault of the controller (mine is a fake PS3 controller, - sold as genuine on ebay, but actually a fake). This fixed things for me:

const char* fakePS3Mapping = "030000004c0500006802000000000000,Fake PS3 Controller,a:b14,"
"b:b13,y:b12,x:b15,start:b3,guide:b12,back:b0,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,"
"leftshoulder:b10,rightshoulder:b11,leftstick:b1,rightstick:b2,leftx:a0,lefty:a1,"
"rightx:a2,righty:a3,lefttrigger:b8,right trigger:b9";

SDL_GameControllerAddMapping(fakePS3Mapping);

I don't know about SDL (as I never ever worked with it) but XInput and generic low-level HID input handling is accessing the USB specifications of the HID device. This is usually a binary template of the controller you want to get input from which is used to map the input message send from the device to some sane results like Button, DPad or Axis states.

Those controller templates come from the corresponding device driver and may or may not be available to ge from the driver API in Windows for example. I already had the problem that a PS4 controller doesn't return a template data pack and so grabbing input wasn't possible.

You have to either install a driver which grants support for those templates or generate the template on your own and post that to the driver API

@Shaarigan SDL has a bunch of pre-canned controller mappings for known controllers (http://hg.libsdl.org/SDL/file/e52d96ea04fc/src/joystick/SDL_gamecontrollerdb.h​).​ The issue here is that the controller mapping for this controller seems to be wrong.

This topic is closed to new replies.

Advertisement