Howto: fix broken 360 Controller mapping in Moonlight
-
tl;dr: My Xbox 360 Controller (wireless, connected via original USB receiver bundled with the controller) had a wrong config for Moonlight. Here's how to fix it. This post has been updated (marked with UPD).
Setup: Official retropie image installed on a Raspberry Pi 4. (Currently 4.8/Buster).
Controller: Xbox 360 Controller connected wirelessly and showing up inlsusb
as follows:
Bus 001 Device 005: ID 045e:0719 Microsoft Corp. Xbox 360 Wireless Adapter
Driver (UPD): Retropie's default out-of-the-box patched(!)xpad
driver is in use.
Issue: The controller works fine in various libretro emulators (after initial config in EmluationStation, not sure if needed), but it is messed up in Moonlight. Among others the dpad axes are interchanged....(UPD) The reason is that retropie uses a patched
xpad
driver instead of the kernel's defaultxpad
. The proper solution to my problem is to simply remove the patchedxpad
via the retropie-setup menu.Below you'll find my first "solution". I leave it here because it may still be useful for other controllers.
The reason is that Moonlight has its own controller database in
/opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt
. There are mappings for various revisions of the controller:# Game Controller DB for SDL in 2.0.16 format # Source: https://github.com/gabomdq/SDL_GameControllerDB (...) 030000005e0400009102000007010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000005e040000a102000000010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, (...)
The first field is an SDL-generated (supposedly) unique identifier (guid).
In order to find out my controller's guid and actually remap it in a userfriendly GUI I compiled SDL's
controllermap
utility. I can't thank @isrnick enough for his tutorial for PPSSPP controller mapping. I just had to adapt it to the SDL version currently installed on my system. (The 2.0.16 mentioned in the config threw me of here at first. It wouldn't compile.) There is also this thread, but I'm not sure if this ever got solved and I'm wondering about the location of the controller database which differs from the one here.Step-by-step:
- Either quit EmulationStation or connect via SSH as
pi
. - Check your currently installed libsdl version:
apt search libsdl2-dev | grep installed
(2.0.10 in my case.) wget http://libsdl.org/release/SDL2-2.0.10.tar.gz
tar -zxvf SDL2-2.0.10.tar.gz
cd SDL2-2.0.10/test
./configure
make controllermap
I was pleasantly surprised that I didn't have to do any dependency hunting for the compilation process, it's just a teeny tiny compilation that won't take long either.
- If you did the steps above via ssh, now is the time to actually quit EmulationStation... (Still no physical keyboard needed if you're using ssh.)
- Still in /home/pi/SDL2-2.0.10/test launch the GUI app to map the buttons and store the config string in /home/pi/my360.txt.
./controllermap >> ~/my360.txt
- Show the generated config:
cat ~/my360.txt
. Here's my output:
030000005e040000a102000000010000,Xbox 360 Wireless Receiver,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:b15,dpdown:b16,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,
- It's probably best to check if an entry for this guid already exists in the database. I'm not sure what happens if there are duplicate entries...
grep 030000005e040000a102000000010000 /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt
- In my case there was already an existing entry for this guid, so I commented it out (adding an
#
at the beginning of that line) and added my new config line. You may usenano
or some other text editor of your liking to do this:nano /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt
. Here's the result:
# wrong config 030000005e040000a102000000010000,Xbox 360 Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Linux, 030000005e040000a102000000010000,Xbox 360 Wireless Receiver,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b5,dpup:b15,dpdown:b16,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,
That should be all. Just restart emulationstation and have fun. :-)
- (optional) Clean up:
rm -rf /home/pi/SDL2-2.0.10*
- Either quit EmulationStation or connect via SSH as
-
Oh well, I did some more reading on controller support in linux. Lots of reading. Until I found this bug report:
https://github.com/RetroPie/RetroPie-Setup/issues/3379It seems that my issues are well known and due to an incorrectly patched xpad (for historic reasons). Removing retropie's xpad driver via retropie's package management menu should be all that's needed to fix it! It would then revert to the kernel's default xpad driver. It must be remapped though in EmulationStation.
I'll try that later and update the initial post if this indeed solves the issue in a cleaner way. -
And just now I've found that a note has even been added to the FAQ:
https://retropie.org.uk/docs/FAQ/?h=faq#my-xbox-controller-is-not-working-properly-with-moonlight-embeddedppsspp
But there is no word on this issue in the actual documentation for the 360 controller: https://retropie.org.uk/docs/Xbox-360-Controller/The wording in the FAQ is also suboptimal:
RetroPie's xpad Xbox controller driver is configured to map the controller's LT/RT as buttons - insteads of axis - and this option makes the controller not working properly in applications that use SDL gamepad mappings.
This sounds as if only the triggers were concerned. But it's the whole controller that is messed up!
I'd kindly like to suggest to:
- Move the warning from the FAQ to the 360 Controller page and link to it from the FAQ or the Moonlight and ppsspp docs.
- Change the warning text to insist that it completely messes up the controller in sdl games.
- Add a link to the github bug.
- Suggest to remove the 'xpad' driver. (I'll test to confirm)
- In the next major release or so fix this once and for all by dropping the patch that breaks xpad.
Let me just say that I learned a lot over the last hours...
-
Just a heads-up: removing
xpad
might break the controller inemulationstation
and elsewhere. In my case, the triggers weren't being properly parsed, and as such they couldn't be properly mapped. Hence, I wasn't able to simply remove said driver. That being said, the original solution by @tuxophil DOES work properly, and as such I would still recommend it. Keep in mind, though, that the command at step "8" requires a declaration about which controller you want to map. As such, a correct command might be./controllermap 0 >> ~/my360.txt
, if your X360 gamepad is in slot0
. Running just./controllermap
will show which controllers are connected, so use your gamepad's slot from that list.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.