RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Guide: Advanced Controller Mappings

    Scheduled Pinned Locked Moved Help and Support
    joystickcontrollermappingxboxdrvscummvm
    626 Posts 35 Posters 464.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Pyjamarama
      last edited by

      You guys are making wonders here. You take ES to next level of functionality

      1 Reply Last reply Reply Quote 1
      • M
        MadHorse
        last edited by MadHorse

        Hello everybody,

        i made some more test and it seems to work very well.
        All the xboxdrv parameters are assigned to variables, this way the case statement is more readable.
        Create the runcommand-onstart.sh

        nano /opt/retropie/configs/all/runcommand-onstart.sh
        

        This is my configuration used for test

        #!/bin/sh
        ## Uncomment one or all of the following if you need to find some information about the emulator or roms
        ## Name of the emulator
        #echo $1 >> /dev/shm/runcommand.log
        
        ## Name of the software used for running the emulation
        #echo $2 >> /dev/shm/runcommand.log
        
        ## Name of the rom
        #echo $3 >> /dev/shm/runcommand.log
        
        ##Executed command line
        #echo $4 >> /dev/shm/runcommand.log
        
        
        ### The FUN begins
        #Get ROM name striping full path
        rom="${3##*/}"
        
        ### Set variables for your joypad and emulator
        ### Basic Configuraions - Standard controller mappings 
        basicPS3="/opt/retropie/supplementary/xboxdrv/bin/xboxdrv >/dev/null \
        	--evdev /dev/input/event2 \
        	--silent \
        	--detach-kernel-driver \
        	--force-feedback \
        	--mimic-xpad \
        	--dpad-as-button \
        	--trigger-as-button \
        	--evdev-absmap ABS_X=x1,ABS_Y=y1,ABS_Z=x2,ABS_RX=y2 \
        	--evdev-keymap KEY_#302=a,KEY_#301=b,BTN_DEAD=x,KEY_#300=y,BTN_THUMB=tl,BTN_THUMB2=tr,BTN_BASE5=lb,BTN_BASE6=rb,BTN_BASE3=lt,BTN_BASE4=rt,BTN_TRIGGER=back,BTN_TOP=start,BTN_SOUTH=guide,BTN_TOP2=du,BTN_PINKIE=dr,BTN_BASE=dd,BTN_BASE2=dl
        	--calibration x1=-32767:0:32767,y1=-32767:0:32767,x2=-32767:0:32767,y2=-32767:0:32767"
        
        
        ### Extended Configurations
        ### Specific emulator configuration or any other parameters you will need only for some emulators
        scummVM="--axismap -Y1=Y1,-Y2=Y2 \
        	--ui-axismap x1=REL_X:10,y1=REL_Y:10 \
        	--ui-buttonmap a=BTN_LEFT,b=BTN_RIGHT,start=KEY_F5,back=KEY_ESC \
        	--ui-buttonmap guide=void,x=void,y=void,lb=void,rb=void,tl=void,tr=void,lt=void,rt=void,back=void \
        	--ui-axismap x2=void"
        
        amiga="--axismap -Y1=Y1,-Y2=Y2 \
        	--ui-axismap x2=REL_X:1,y2=REL_Y:1 \
        	--ui-axismap x1=KEY_LEFT:KEY_RIGHT,y1=KEY_DOWN:KEY_UP \
        	--ui-buttonmap du=KEY_UP,dd=KEY_DOWN,dl=KEY_LEFT,dr=KEY_RIGHT \
        	--ui-buttonmap lt=BTN_LEFT,rt=BTN_RIGHT,start=KEY_ESC,back=KEY_LEFTCTRL,y=KEY_SPACE,a=KEY_LEFTCTRL,b=KEY_LEFTALT,x=KEY_LEFTSHIFT \
        	--ui-buttonmap guide=void,tl=void,lt=void,rt=void,back=void \
        	--ui-axismap x2=void"
        
        fourway="--four-way-restrictor"
        
        invert="--ui-buttonmap du=KEY_DOWN,dd=KEY_UP"
        
        ### Kill Command
        xboxkill="sudo killall >/dev/null xboxdrv"
        
        ### Execute the driver with the configuration you need
        # $1 is the name of the emulation, not the name of the software used
        # it is intellivision not jzintv
        case $1 in
        
        	mame-libretro)
        	;;
        
        	fba)
        		case $rom in
        			"amidar.zip"|"atetris.zip"|"puckman.zip") # Configuration used only for these ROMs
        				$xboxkill
        				joycommand="$basicPS3 $fourway &"
        				eval $joycommand
        			;;
        			*) # Configuration for every other ROMs on this emulator
        				$xboxkill
        				joycommand="$basicPS3 &"
        				eval $joycommand
        			;;
        		esac
        	;;
        
        	daphne)
        	;;
        
        	scummvm)
        		$xboxkill
        		joycommand="$basicPS3 $scummVM &"
        		eval $joycommand
        	;;
        
        	amiga)
        		$xboxkill
        		joycommand="$basicPS3 $amiga &"
        		eval $joycommand
        	;;
        
        	intellivision)
        	;;
        esac
        

        We assign to the joycommand variable, the list of variables that contains the parameters we need for example joycommand="BasicVAR var1 var2 var3 $". The Basic variables must be the first, and & must be the last.
        Make the script executable

        sudo chmod +x /opt/retropie/configs/all/runcommand-onstart.sh
        

        For some emulators we could face some problem, i have a PS3 controller recognized as input device event2, when i execute xboxdrv the controller is recognized as input device event3. The system now see 2 controller device, the PS3 as controller with id 0 and an Xbox360 controller with id 1, for the emulator you are now using the controller for player2 and this will cause some problem, for example you can only start a 2 players game, you can't quit the emulation pushing select+start. To solve the problem we have to specify on retroarch.cfg the id of the controller used by player1 and player2.
        This is the configuration for Final Burn Alpha, we have to add input_playerx_joypad_index = "x" for every controller between input_remapping_directory = "/opt/retropie/configs/fba/" and #include "/opt/retropie/configs/all/retroarch.cfg" where the first X is the player number, and the secon X is the controller ID

        
        # Settings made here will only override settings in the global retroarch.cfg if placed above the #include line
        
        input_remapping_directory = "/opt/retropie/configs/fba/"
        
        input_player1_joypad_index = "1"
        input_player2_joypad_index = "0"
        input_player2_analog_dpad_mode = 1
        
        #include "/opt/retropie/configs/all/retroarch.cfg"
        

        If you want this configuration for every retroarch emulators, you have to edit nano /opt/retropie/configs/all/retroarch.cfg

        Now we need to kill xboxdrv when we exit from the emulator, we do this with the onend script

        nano /opt/retropie/configs/all/runcommand-onend.sh
        
        #!/bin/sh
        sudo killall >/dev/null xboxdrv
        

        and make it executable

        sudo chmod +x /opt/retropie/configs/all/runcommand-onend.sh
        

        Sorry for my english, let me know if something is unclear, i will try to explain better, and if you are trying it, please let me know if it's working.
        Hope you find it usefull.

        @mediamogul
        If you think it could be of help, maybe you could add it to the first post.

        mediamogulM meleuM J 4 Replies Last reply Reply Quote 3
        • mediamogulM
          mediamogul Global Moderator @MadHorse
          last edited by

          @MadHorse

          This is fantastic! I added an introduction and link in section 3 that directs right to your post. This way you can maintain control if anything needs to be changed or you think of any other improvements. Again, this is really streets ahead!

          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

          meleuM 1 Reply Last reply Reply Quote 0
          • meleuM
            meleu @MadHorse
            last edited by

            @MadHorse just sharing a runcommand-onstart.sh info to simplify your script:

            All the error messages from these scripts (onstart and onend) will be logged in runcommand.log. If you want to log something more you just have to redirect the output to the standard error. This way:

            echo "message to log" >&2
            

            I've just updated the runcommand wiki with this info. ;-)

            • Useful topics
            • joystick-selection tool
            • rpie-art tool
            • achievements I made
            1 Reply Last reply Reply Quote 1
            • meleuM
              meleu @MadHorse
              last edited by meleu

              @MadHorse
              Oh! I've just realized that you suggest the use of runcommand.log to get infos about emulator/roms. But all these infos are already available at /dev/shm/runcommand.info.

              This file has the following structure:

              • line #1 - the system (eg: atari2600, nes, snes, megadrive, fba, etc).
              • line #2 - the emulator (eg: lr-stella, lr-fceumm, lr-picodrive, pifba, etc).
              • line #3 - the full path to the rom file.
              • line #4 - the full command line used to launch the emulator.

              To get a specific line from a file I'm used to use this sed trick:

              sed '1!d' file # to get the 1st line
              sed '2!d' file # 2nd line
              sed '3!d' file # 3rd line
              sed '4!d' file # 4th line
              
              • Useful topics
              • joystick-selection tool
              • rpie-art tool
              • achievements I made
              1 Reply Last reply Reply Quote 0
              • meleuM
                meleu @mediamogul
                last edited by

                @mediamogul This guide would be really nice on the wiki, huh? ;-)

                • Useful topics
                • joystick-selection tool
                • rpie-art tool
                • achievements I made
                mediamogulM 1 Reply Last reply Reply Quote 0
                • mediamogulM
                  mediamogul Global Moderator @meleu
                  last edited by

                  @meleu

                  I originally thought it might be a bit too long and involved for a wiki entry, but maybe it should go there.

                  RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                  meleuM 1 Reply Last reply Reply Quote 0
                  • meleuM
                    meleu @mediamogul
                    last edited by meleu

                    @mediamogul I think it is a bit too long and involved for a forum topic. LOL! :D

                    I think it fits nice in the "Advanced Configuration" section.

                    • Useful topics
                    • joystick-selection tool
                    • rpie-art tool
                    • achievements I made
                    mediamogulM 1 Reply Last reply Reply Quote 0
                    • mediamogulM
                      mediamogul Global Moderator @meleu
                      last edited by

                      @meleu

                      I might try to pair it down to something more manageable at some point and post it as a wiki.

                      RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                      RionR 1 Reply Last reply Reply Quote 3
                      • J
                        jrmymllr
                        last edited by

                        Great guide. I'm getting more comfortable with xboxdrv and it should work well.

                        I'll have two different types of controllers, either one (not both) may be connected. How will xboxdrv and ES handle this? I'm hoping that when the controller mapped to xboxdrv is attached, xboxdrv will run, and ES will see the virtual Xbox controller and use that, and when the other controller is attached, xboxdrv will fail, and ES will see the non-Xbox controller and use that. Is that basically accurate?

                        mediamogulM 1 Reply Last reply Reply Quote 1
                        • mediamogulM
                          mediamogul Global Moderator @jrmymllr
                          last edited by

                          @jrmymllr

                          xboxdrv can't detect when a controller is connected when used in the way this guide details, so the command must be executed after the controller is connected. Even when the configuration command is added to /etc/rc.local, your controller must be connected at startup or it will fail. Provided that you've mapped both your xboxdrv controller and the secondary controller you mentioned, Emulation Station should have no problem reading either.

                          RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                          J 1 Reply Last reply Reply Quote 1
                          • J
                            jrmymllr @mediamogul
                            last edited by

                            @mediamogul
                            Right, I'd have to reboot then immediately change controllers. That was my thought too.

                            mediamogulM 1 Reply Last reply Reply Quote 1
                            • mediamogulM
                              mediamogul Global Moderator @jrmymllr
                              last edited by

                              @jrmymllr

                              There are ways to create a daemon that would see when a controller is connected and execute a command like you would need for xboxdrv, but all information I've found on the subject is either conflicting or outdated. If successfully implemented, it could also tell when a controller is disconnected and stop xboxdrv.

                              RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                              J 1 Reply Last reply Reply Quote 1
                              • J
                                jrmymllr @mediamogul
                                last edited by

                                @mediamogul

                                I'm getting close. I want to map the D-pad to arrow keys, but it's not working. Just for testing, if I run this (how do you display text as code???):

                                /opt/retropie/supplementary/xboxdrv/bin/xboxdrv
                                --evdev /dev/input/by-id/usb-0079_USB_Gamepad-event-joystick
                                --silent
                                --detach-kernel-driver
                                --force-feedback
                                --deadzone-trigger 15%
                                --deadzone 4000
                                --mimic-xpad
                                --evdev-absmap ABS_X=dpad_x,ABS_Y=dpad_y
                                --evdev-keymap BTN_THUMB=a,BTN_THUMB2=b,BTN_BASE3=back,BTN_BASE4=start
                                --dpad-only
                                --ui-axismap lt=void,rt=void
                                --ui-buttonmap tl=void,tr=void,guide=void,x=void,y=void,lb=void,rb=void,back=KEY_ESC,a=KEY_1,b=KEY_2 &

                                Then run "evtest", the D-pad responds as ABS_X and ABS_Y with values -1 to 1. But if I add this to --ui-axismap:

                                dpad_x=KEY_LEFT:KEY_RIGHT,dpad_y=KEY_UP:KEY_DOWN

                                it runs with no errors, but now in "evtest" the D-pad causes no response at all. If instead I use:

                                X1=KEY_LEFT:KEY_RIGHT,Y1=KEY_UP:KEY_DOWN

                                The D-pad in "evtest" responds not with arrow keys, but the same ABS_X and ABS_Y. Any ideas?

                                mediamogulM 1 Reply Last reply Reply Quote 0
                                • mediamogulM
                                  mediamogul Global Moderator @jrmymllr
                                  last edited by

                                  @jrmymllr said in Guide: Advanced Controller Mappings:

                                  how do you display text as code?

                                  https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting

                                  Everything looks to be correct. You say you're running evtest a second time, but which controller event are you testing at that point? Is it the original physical controller event, or the new virtual controller event? If it's the prior, that event is rendered inert while xboxdrv is running to avoid conflicts. If it's the latter, xboxdrv creates both a new virtualized joystick event, along with a virtualized keyboard event. If your looking to see if the keyboard is being activated with button presses, you'll want to look at the new keyboard event. However, if it's running without errors as you say, it's probably fine. You may just want to fire up an emulator that supports arrow keys and see what shakes loose.

                                  RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                                  J 1 Reply Last reply Reply Quote 1
                                  • RionR
                                    Rion @mediamogul
                                    last edited by Rion

                                    @mediamogul said in Guide: Advanced Controller Mappings:

                                    @meleu

                                    I originally thought it might be a bit too long and involved for a wiki entry, but maybe it should go there.

                                    Yes please :)

                                    And while where on the topic. This should be built in to the retropie setup. With a gui.

                                    Edit:

                                    Something like this.

                                    Configuration / Tools / Advanced Controller Configuration.

                                    From here you can choose device using
                                    cat /proc/bus/input/devices from a list.

                                    Event Location

                                    ls /dev/input/by-id/

                                    Event codes for each button

                                    And so on all in the gui.

                                    FBNeo rom filtering
                                    Mame2003 Arcade Bezels
                                    Fba Arcade Bezels
                                    Fba NeoGeo Bezels

                                    1 Reply Last reply Reply Quote 2
                                    • J
                                      jrmymllr @mediamogul
                                      last edited by

                                      @mediamogul

                                      I am definitely testing the new virtual Xbox event with evtest. With no xboxdrv running here's the response direct from the controller (USB NES type controller):

                                      Event: time 1475321474.481703, type 3 (EV_ABS), code 1 (ABS_Y), value 255
                                      Event: time 1475321474.481703, -------------- EV_SYN ------------
                                      Event: time 1475321474.593717, type 3 (EV_ABS), code 1 (ABS_Y), value 127
                                      Event: time 1475321474.593717, -------------- EV_SYN ------------
                                      Event: time 1475321475.369820, type 3 (EV_ABS), code 1 (ABS_Y), value 0
                                      Event: time 1475321475.369820, -------------- EV_SYN ------------
                                      Event: time 1475321475.473841, type 3 (EV_ABS), code 1 (ABS_Y), value 127
                                      Event: time 1475321475.473841, -------------- EV_SYN ------------
                                      Event: time 1475321476.417955, type 3 (EV_ABS), code 0 (ABS_X), value 255
                                      Event: time 1475321476.417955, -------------- EV_SYN ------------
                                      Event: time 1475321476.481967, type 3 (EV_ABS), code 0 (ABS_X), value 127
                                      Event: time 1475321476.481967, -------------- EV_SYN ------------
                                      Event: time 1475321477.058044, type 3 (EV_ABS), code 0 (ABS_X), value 0
                                      Event: time 1475321477.058044, -------------- EV_SYN ------------
                                      Event: time 1475321477.122050, type 3 (EV_ABS), code 0 (ABS_X), value 127
                                      Event: time 1475321477.122050, -------------- EV_SYN ------------
                                      

                                      Then if I run this:

                                              --evdev /dev/input/by-id/usb-0079_USB_Gamepad-event-joystick \
                                              --silent \
                                              --detach-kernel-driver \
                                              --force-feedback \
                                              --deadzone-trigger 15% \
                                              --deadzone 4000 \
                                              --mimic-xpad \
                                              --evdev-absmap ABS_X=dpad_x,ABS_Y=dpad_y \
                                              --evdev-keymap BTN_THUMB=a,BTN_THUMB2=b,BTN_BASE3=back,BTN_BASE4=start \
                                              --dpad-only \
                                              --ui-axismap lt=void,rt=void,X1=KEY_LEFT:KEY_RIGHT,Y1=KEY_UP:KEY_DOWN \
                                              --ui-buttonmap tl=void,tr=void,guide=void,x=void,y=void,lb=void,rb=void,back=KEY_ESC,a=KEY_1,b=KEY_2 &
                                      

                                      the response from evtest from the Dpad through the virtual xboxdrv device is:

                                      Event: time 1475321774.129436, type 3 (EV_ABS), code 1 (ABS_Y), value -1
                                      Event: time 1475321774.129436, -------------- EV_SYN ------------
                                      Event: time 1475321774.265388, type 3 (EV_ABS), code 1 (ABS_Y), value 0
                                      Event: time 1475321774.265388, -------------- EV_SYN ------------
                                      Event: time 1475321775.169519, type 3 (EV_ABS), code 1 (ABS_Y), value 1
                                      Event: time 1475321775.169519, -------------- EV_SYN ------------
                                      Event: time 1475321775.297536, type 3 (EV_ABS), code 1 (ABS_Y), value 0
                                      Event: time 1475321775.297536, -------------- EV_SYN ------------
                                      Event: time 1475321775.889574, type 3 (EV_ABS), code 0 (ABS_X), value -1
                                      Event: time 1475321775.889574, -------------- EV_SYN ------------
                                      Event: time 1475321775.953608, type 3 (EV_ABS), code 0 (ABS_X), value 0
                                      Event: time 1475321775.953608, -------------- EV_SYN ------------
                                      Event: time 1475321776.401679, type 3 (EV_ABS), code 0 (ABS_X), value 1
                                      Event: time 1475321776.401679, -------------- EV_SYN ------------
                                      Event: time 1475321776.489683, type 3 (EV_ABS), code 0 (ABS_X), value 0
                                      Event: time 1475321776.489683, -------------- EV_SYN ------------
                                      

                                      However if I press the other buttons during evtest they appear as KEY_ESC,KEY_1, etc. as they should. And, those buttons really behave like I'm pressing the associated keyboard buttons in an emulator.

                                      I've ensured no other xboxdrv processes are running, and tried rebooting. So, no problem emulating the keyboard with controller buttons. The problem is emulating keyboard presses with the Dpad. Should be simple but I must be missing something!

                                      mediamogulM 1 Reply Last reply Reply Quote 0
                                      • mediamogulM
                                        mediamogul Global Moderator @jrmymllr
                                        last edited by

                                        @jrmymllr

                                        Try adding --dpad-as-button and configuring each direction separately in a --ui-buttonmap line using du=KEY_*,dd=KEY_*,dl=KEY_*,dr=KEY_* entries to see if that makes a difference.

                                        RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                                        J 1 Reply Last reply Reply Quote 1
                                        • J
                                          jrmymllr @mediamogul
                                          last edited by

                                          @mediamogul

                                          Success! I previously tried the --dpad-as-button but must not have figured out du,dd,etc.

                                          Thanks a million!

                                          1 Reply Last reply Reply Quote 1
                                          • mediamogulM
                                            mediamogul Global Moderator
                                            last edited by mediamogul

                                            I have now added this guide to the wiki along with @MadHorse's additions. It can be found here. As it doesn't make sense to maintain the same information in two places, I'll leave the first post as is, adding only a notation at the beginning. Of course, anyone can continue to ask questions and trade configurations here if need be.

                                            Thanks guys!

                                            RetroPie v4.5 • RPi3 Model B • 5.1V 2.5A PSU • 16GB SanDisk microSD • 512GB External Drive

                                            1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            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.