Homepage › Forums › RetroPie Project › Everything else related to the RetroPie Project › Mapping a Game Controller in Kodi
Tagged: Game Controller, kodi
- This topic has 27 replies, 8 voices, and was last updated 8 years, 8 months ago by noratio.
-
AuthorPosts
-
09/22/2015 at 13:09 #106586dudleydesParticipant
After posts here and at Reddit, I thought I’d share a method for mapping your game controller to use in Kodi without the need to recompile.
Build Linux Joystick Mapper binaryDownload the source from the following link:
http://sourceforge.net/projects/linuxjoymap/
Copy the joymap-0.2 folder to the home directory of your pi and build the binary with the following commands:
cd joymap-0.2 make
This will create a binary called loadmap.
Get Joystick Information
Joystick selection by number (jsX) is broken in Linux Joystick Mapper so the vendor and product identifier must be used. This info can be found by running the command:
cat /proc/bus/input/devices
The output for my PS3 controller was:I: Bus=0003 Vendor=054c Product=0268 Version=0111 N: Name="Sony PLAYSTATION(R)3 Controller" P: Phys=usb-bcm2708_usb-1.3.2/input0 S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/0003:054C:0268.0001/input/input2 U: Uniq= H: Handlers=js0 event2 B: PROP=0 B: EV=1b B: KEY=7 0 0 0 0 0 0 0 0 0 0 0 0 ffff 0 0 0 0 0 0 0 0 0 B: ABS=7fffff00 27 B: MSC=10
The information required is in the first line. For the PS3 controller, the vendor code is 054c and the product code is 0268.
Create the Mapper File
Documentation for creating a mapper file can be found in /doc/config.pdf.
To map a joystick button to a key press, a line needs to added for each mapping as below:
button vendor=0xXXXX product=0xYYYY src=joy_button_num target=kbd button="key_press"
where
XXXX is the vendor code
YYYY is the product code
joy_button_num is the joystick button number as defined in jstest
“key_press” is the key press to mapThe values for key presses can be found in the keys.txt in the source code folder.
The default keyboard controls for Kodi can be found at the link below:
http://kodi.wiki/view/Keyboard_controls
To keep things tidy, I created a new folder, joymap, in the home directory. I copied the loadmap binary built earlier to the joymap folder. I then created a text file, kodi.map, with the following contents:
# PS3 controller mapper file for Kodi # Navigation # D-pad to navigate; X to select and circle to go to previous menu button vendor=0x054c product=0x0268 src=4 target=kbd button="up" button vendor=0x054c product=0x0268 src=5 target=kbd button="right" button vendor=0x054c product=0x0268 src=6 target=kbd button="down" button vendor=0x054c product=0x0268 src=7 target=kbd button="left" button vendor=0x054c product=0x0268 src=14 target=kbd button="enter" button vendor=0x054c product=0x0268 src=13 target=kbd button="esc" # Triangle to bring up conextual menu button vendor=0x054c product=0x0268 src=12 target=kbd button="c" # Play Media # R1 to play/pause and L1 to stop button vendor=0x054c product=0x0268 src=11 target=kbd button="space" button vendor=0x054c product=0x0268 src=10 target=kbd button="x" # Exit Kodi by pressing Select and Start button vendor=0x054c product=0x0268 src=0 target=kbd button="leftctrl" button vendor=0x054c product=0x0268 src=3 target=kbd button="end"
Please note this mapping may not be complete for your needs. Also I have not found a way to map analogue sticks to key presses.
Execute Mapper with Kodi
To load the mapper file with Kodi, I edited kodi.sh in the /roms/ports folder as follows:
#!/bin/bash sudo /home/pi/joymap/loadmap /home/pi/joymap/kodi.map & /opt/retropie/supplementary/runcommand/runcommand.sh 0 "kodi-standalone" "kodi" sudo killall loadmap sleep 1
Permissions on /dev/uinput are required to run the mapper program. I tried the instructions below to set the permissions to pi but they did not work so I ran the mapper program as sudo to get round this.
https://tkcheng.wordpress.com/2013/11/11/changing-uinput-device-permission/
The killall command (run as sudo) will stop the mapper program before returning to ES.
The sleep command is to prevent a ES error which I guess was occurring because of a conflict of joystick control between the mapper program and ES.
When you launch Kodi, you will get failed to grab device/failed to lock device messages. You can ignore these – Kodi and your mapping will work fine.
10/06/2015 at 19:38 #107375jonnygallParticipantI have not tried this with Kodi yet, but I tried it out on a game called lbreakout2 and works great with a controller. I was always frustrated I had to play with a keyboard. Thanks for telling me about this.
One thing is trying to get the mouse portion to work. I have a nintendo 64 controller and I was trying to map the mouse to the analog stick. I did get the mouse to work but what happened was the cursor would re calibrate itself to the upper left corner of the screen, and I wished it wouldn’t do that. I looked at the example map in the joymap folder but I’m still stumped.
EDIT:
Mouse is working, left and right clicks work. Still have the same problem of the cursor re-calibrating. Also, regular button keys work but as soon as I move with the analog stick the buttons stop (excluding the left and right click).10/07/2015 at 11:47 #107423dudleydesParticipantI have tried lbreakout2 (built from http://lgames.sourceforge.net/index.php?project=LBreakout2) and have not observed any of the behaviour you mention in your post.
Here is the mapping file I used for a PS3 controller
# Mapping for lbreakout2 for PS3 Controller # Map mouse axis vendor=0x054c product=0x0268 src=0 target=mouse axis=0 axis vendor=0x054c product=0x0268 src=1 target=mouse axis=1 button vendor=0x054c product=0x0268 src=14 target=mouse button=0 button vendor=0x054c product=0x0268 src=15 target=mouse button=1 # Actions button vendor=0x054c product=0x0268 src=0 target=kbd button="esc" button vendor=0x054c product=0x0268 src=3 target=kbd button="enter" button vendor=0x054c product=0x0268 src=10 target=kbd button="x" button vendor=0x054c product=0x0268 src=11 target=kbd button="c" button vendor=0x054c product=0x0268 src=12 target=kbd button="y"
10/08/2015 at 02:05 #107445jonnygallParticipant# mapper file for lbreakout2 # navigation button vendor=0x06f7 product=0x0001 src=10 target=kbd button="up" button vendor=0x06f7 product=0x0001 src=11 target=kbd button="down" button vendor=0x06f7 product=0x0001 src=12 target=kbd button="left" button vendor=0x06f7 product=0x0001 src=13 target=kbd button="right" button vendor=0x06f7 product=0x0001 src=6 target=kbd button="y" button vendor=0x06f7 product=0x0001 src=7 target=kbd button="n" button vendor=0x06f7 product=0x0001 src=4 target=kbd button="y" button vendor=0x06f7 product=0x0001 src=1 target=kbd button="space" button vendor=0x06f7 product=0x0001 src=8 target=kbd button="enter" button vendor=0x06f7 product=0x0001 src=9 target=kbd button="esc" axis vendor=0x06f7 product=0x0001 src=0 target=mouse axis=0 axis vendor=0x06f7 product=0x0001 src=1 target=mouse axis=1 button vendor=0x06f7 product=0x0001 src=5 target=mouse button=0 button vendor=0x06f7 product=0x0001 src=2 target=mouse button=1
I’m wondering if some process is conflicting. I tried my brother’s N64 controller as well, and it’s the same behavior. I even made a Kodi map with the same axis lines, and the cursor behaved the exact same way.
10/08/2015 at 02:49 #107448MRKaneParticipantCould this method be used with the likes of DosBox to map controller input to keyboard for all of those four player games where we use to be clustered around one keyboard? :D
10/08/2015 at 14:19 #107457dudleydesParticipantI think I may know what you are referring to. In Kodi, it is possible to remove the mouse pointer by going to System > Settings > System > Input Devices and unchecking the Enable Mouse and touch screen support. After doing this, when you launch Kodi, the mouse pointer will appear momentarily, then disappear and you will see the Kodi logo.
I have not found a way to do the same with lbreakout2. I don’t find it a problem as the mouse pointer disappears as soon as I press fire. You could contact the developer.
Yes, you can use the Linux Joystick Mapper program to map DOS games. I mapped mouse and keyboard controls to my PS3 controller for Ultima Underworld: Stygian Abyss. Before you try, please check your post on mapping multiple controllers in DOSBox as I have posted a link that may be helpful.
10/08/2015 at 23:57 #107485MRKaneParticipantSaying it here also: Thanks a heap for that dudelydes!
10/14/2015 at 11:58 #107848MRKaneParticipantRight, finally had the time to sit down and try this and just want to say thanks so much for writing this guide! I’m still having a little trouble getting the buttons sorted out, and don’t seem to have any success myself with the axis stuff either.
But again: THANK YOU!! I’m a total noob and well on the way!
11/18/2015 at 00:06 #110149hypersonicParticipantThis looked so easy on paper…
I’m trying to set up a buffalo 8 axis snes style pad in kodi using the following but nothing works.
# SNES Pad mapper file for Kodi # Navigation # D-pad to navigate; X to select and circle to go to previous menu axis vendor=0x054c product=0x0268 src=-1 target=kbd button="up" axis vendor=0x054c product=0x0268 src=-0 target=kbd button="right" axis vendor=0x054c product=0x0268 src=1 target=kbd button="down" axis vendor=0x054c product=0x0268 src=0 target=kbd button="left" button vendor=0x054c product=0x0268 src=1 target=kbd button="enter" button vendor=0x054c product=0x0268 src=0 target=kbd button="esc" # Triangle to bring up conextual menu button vendor=0x054c product=0x0268 src=2 target=kbd button="c" # Play Media # R1 to play/pause and L1 to stop button vendor=0x054c product=0x0268 src=4 target=kbd button="space" button vendor=0x054c product=0x0268 src=5 target=kbd button="x" # Exit Kodi by pressing Select and Start button vendor=0x054c product=0x0268 src=6 target=kbd button="leftctrl" button vendor=0x054c product=0x0268 src=7 target=kbd button="end"
FWIW when i run jstest, i have names for my joypad buttons like ‘trigger’ or ‘thumbbtn’. Should i be using these or just the numbers as displayed in the testing lines at the bottom?
What seems to be causing the problem is that the d-pad shows as an x and y axis, whereas it’d be a lot easier if it showed as 4 separate buttons.
11/19/2015 at 17:41 #110252dudleydesParticipantI’ve noticed you have the vendor and product identifiers for a PS3 controller in your mapper file. You need the identifiers for your SNES pad which you can find by running the command:
cat /proc/bus/input/devices
AFAIK, the arrow keys cannot be mapped to the axes. You could try mapping the mouse to the axes, which I have done for a number of mouse-driven DOS games. The lines to add would look like below:
axis vendor=0xXXXX product=0xYYYY src=0 target=mouse axis=0 axis vendor=0xXXXX product=0xYYYY src=1 target=mouse axis=1
where XXXX is the vendor code for your SNES controller and YYYY the product code.
11/19/2015 at 23:16 #110278hypersonicParticipantYou know, the ps3 product/vendor codes might be what’s wrong with my setup – i recall that i just copied your file and changed the buttons to suit.
It never occurred to me that i’d have to change the ids too :$
Let’s see if i can select +tive and -tive axis and map them to kbd keys
11/19/2015 at 23:29 #110283hypersonicParticipantDamn
It doesn’t like the +tive and -tive axis lines and when i set the axes to mouse axes, it shows some promising lines in the console before loading kodi but doesn’t give me a mouse pointer.
Also none of the controller buttons work, i’m wondering if i need to sort out a usb keyboard to go in and turn on the mouse pointer in kodi settings to make this work.
01/04/2016 at 17:52 #113115OmnijaParticipantAny idea on how to set up an xbox 360 controller when the vendor and product ID comes out as 0000 after using cat /proc/bus/input/devices
also tried lsusb but it didn’t seem to map anything?
01/05/2016 at 00:37 #113130shades42ParticipantI have tried this but seem to be stuck somewhere..
output for joystick
pi@retropie ~ $ cat /proc/bus/input/devices I: Bus=0003 Vendor=11c0 Product=5500 Version=0111 N: Name="Tronsmart" P: Phys=usb-3f980000.usb-1.4/input0 S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:11C0:5500.0001/input/input0 U: Uniq= H: Handlers=js0 event0 B: PROP=0 B: EV=1b B: KEY=fff0000 0 0 0 0 0 0 0 0 0 B: ABS=30027 B: MSC=10
I installed the package into :
/home/pi/MyJoy
my kodi.sh
#!/bin/bash sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map & /opt/retropie/supplementary/runcommand/runcommand.sh 0 "kodi-standalone" "kodi" sudo killall loadmap sleep 1
my kodi.map
# Navigation # D-pad to navigate; X to select and circle to go to previous menu #axis vendor=0x11c0 product=0x5500 src=5 target=kbd button="up" #axis vendor=0x11c0 product=0x5500 src=4 target=kbd button="right" #axis vendor=0x11c0 product=0x5500 src=5 target=kbd button="down" #axis vendor=0x11c0 product=0x5500 src=4 target=kbd button="left" button vendor=0x11c0 product=0x5500 src=2 target=kbd button="enter" button vendor=0x11c0 product=0x5500 src=1 target=kbd button="esc" # Triangle to bring up conextual menu button vendor=0x11c0 product=0x5500 src=0 target=kbd button="c" # Play Media # R1 to play/pause and L1 to stop button vendor=0x11c0 product=0x5500 src=11 target=kbd button="space" button vendor=0x11c0 product=0x5500 src=10 target=kbd button="x" # Exit Kodi by pressing Select and Start button vendor=0x11c0 product=0x5500 src=9 target=kbd button="leftctrl" button vendor=0x11c0 product=0x5500 src=8 target=kbd button="end"
The reason the axis are commented out is because I was just testing to see if any buttons would work. I did get the “failed to grab device/failed to lock device messages.” with or without the axis in the .map file, but nothing would work.
I did notice that once I was loaded into Kodi, the jstest would no longer register any of my joystick presses/movements. Could it be that I am losing my joystick when Kodi loads and that is why I am not registering anything within Kodi?
When I do exit Kodi via the keyboard my joystick functionality comes back for ES, so I assume it has something to do with the loadmap
01/05/2016 at 06:46 #113140shades42ParticipantThe Tronsmart has the option of switching which type of “joystick” it is, I tried it as an xbox 360 controller and the vendor and product #’s changed when I re ran the
cat /proc/bus/input/devices
so I tried that as well and I get nothing in Kodi, I’ve re read a few times and hunted around on the googles and can’t figure out what is wrong.
Any help muchly appreciated
01/05/2016 at 13:40 #113158dudleydesParticipantYou could try entering 0000 as your product code in your mapper file. Alternatively, you could use xboxdrv. Instructions below:
https://www.reddit.com/r/RetroPie/comments/3mcf4y/kodi_with_xbox_360_controller/
Have you tried running the loadmap program from a terminal on the pi? You should see key presses written to the terminal (you may want to change the key presses to letters rather than esc/ctrl for this).
Alternatively, you can use your controller as a xbox 360 controller and try the link above.
01/05/2016 at 18:34 #113192shades42Participant@dudleydues
Hey man appreciate you taking the time to respond, half the fun for me is fighting with stuff to get it to work when I can’t but this is a little different because all of it is so new.
I putty’d in with just the pi/raspberry credentials.
pi@retropie /dev/input $ sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map 0 joysticks. Found device Tronsmart (vendor=0x11c0, product=0x5500) Found device JOYMAP Code Device (vendor=0x00ff, product=0x0000) 10 button assignments. Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... Failed to grab device: Device or resource busy Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway... 0 axes assignments.
I do not know if it states “0 joysticks” is normal or not but that is what I see when trying to just run the map ( assuming I did that right lol ) and nothing on the screen when I press the buttons in a putty window.
I’ll report back when I try it as an xbox controller via the link you provided, thanks again!
01/05/2016 at 18:55 #113196dudleydesParticipantYou need to run the loadmap program from a terminal on the pi itself. I found that I didn’t see any key presses when I tried in a SSH session.
01/05/2016 at 20:51 #113205shades42ParticipantHey dudleydes,
With the link you provided I was able to get joystick control in kodi no problems, but once I leave kodi a few things happen.
#1. The joystick no longer works
#2. If I quit ES afterwards to get to the terminal screen its just black and eventually goes back to ES. If I hit a key while its black it just stays black. I already upgraded to Kodi 15.2When I run
sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map
from the terminal I get the same output I listed above ( with the inclusion of the xbox gamepad from trying the other link ) but again nothing being written on the screen.
I also changed all the button presses to letters in the map file
button vendor=0x11c0 product=0x5500 src=2 target=kbd button="a" button vendor=0x11c0 product=0x5500 src=1 target=kbd button="b" # Triangle to bring up conextual menu button vendor=0x11c0 product=0x5500 src=0 target=kbd button="c" # Play Media # R1 to play/pause and L1 to stop #utton vendor=0x11c0 product=0x5500 src=11 target=kbd button="d" #utton vendor=0x11c0 product=0x5500 src=10 target=kbd button="e" # Exit Kodi by pressing Select and Start button vendor=0x11c0 product=0x5500 src=9 target=kbd button="f" button vendor=0x11c0 product=0x5500 src=8 target=kbd button="g"
01/05/2016 at 21:50 #113210OmnijaParticipant@dudleydes I actually tried that before this one, after quitting kodi it would screw up my ES controller settings. I also tried 0000 and did lsusb using the logic3 vender/product id and it still didn’t work
01/06/2016 at 07:17 #113240shades42Participant@dudleydes I noticed with the link you provided there is a type for the permissions
sudo groupdadd -f uinput
there is an extra d groupdaddonce you remove it and put
sudo groupadd -f uinput
it works and if you are C/P’ing theKERNEL==”uinput”, GROUP=”uinput”, MODE:=”0660″
you will need to change the quotes.I can run the loadmap without the sudo now ( i worked on this incase that was the issue ) but still no button presses.
I am wondering if installing the Virtual Gamepad is messing some of this up.
Do you have it installed? if not I need to figure out how to uninstall it
01/10/2016 at 23:45 #113629shades42ParticipantI think I am going to have to toss in the towel with my controller and this option, I’ve go so far as fresh install and only the joymap and never get anything registering.
It was an exciting possibility and fun messing with it but no luck and out of ideas :)
Thanks though and thanks for the direction.
01/11/2016 at 03:59 #113640shades42ParticipantI lied I can’t toss the towel in lol…
I grabbed a wired xbox controller and hooked that up and tried giving it ago and I couldn’t register any button presses with that either..
Any suggestions are welcome, it isn’t for KODI so much anymore its wanting to map key presses to the joystick for other things now so I need to figure out what is wrong.
Thanks in advance
01/11/2016 at 11:18 #113652dudleydesParticipantThanks for tidying up the changing uInput device permission issue. It was the quotes in the udev rule that was causing the problem.
I’m sorry to hear that you’ve had no luck using the loadmap program with your controllers. All I can suggest is that you try the attached binary that works for me.
01/11/2016 at 15:34 #113668shades42ParticipantThanks for the effort, first did a comparison yours and mine are the same, tried it anyway still no success.
Seems lot of people use this option, even read some SteamOS threads about people using it successfully, so it has to be me somewhere some way :)
At least this endeavor cleaned things up a little for you, and I learned a bunch of stuff along the way. Now I am trying to write my own code to see if I can get something working.
01/12/2016 at 19:01 #113818shades42ParticipantJust an update on this for anyone else looking and reading.
If I run jstest in putty on another system, and presses buttons while Kodi it loading, as soon as it is up and running, all my buttons stop registering. I have tried this with both wheezy and jessie running Kodi 15.2 on fresh installs.
As soon as Kodi exits, my buttons start function again (before it goes back in ES).
I wish I thought of this before, because I wrote/stole/borrowed/modified some code that will take inputs from js0 (buttons and axis) and map them to key presses and they show up in the terminal window of the pi, but its useless if Kodi “kills” the joystick :)
01/16/2016 at 00:10 #114071Computer NinjaParticipantAny updates on getting a USB Gamepad (like my Logitech F310) working with Kodi?
02/18/2016 at 03:37 #117421noratioParticipantAlright @shades42, after hours of having the same issue as you, I finally found out the problem.. it’s easy you will see.
Just unplug your keyboard
0- Turn off your PI
1- Make sure you only have your PS3 or Xbox controller plugged in with instructions from @dudleydes
2- Start Kodi and enjoy!!Hope that works for you. It looks like the cause of the problem the mapping in changed because of what ever Raspbian detected for your keyboard. So the region changed for the mapping. I was using a Apple Keyboard, and with another keyboard when I was pressing buttons it was different characters. As soon I rebooted without a keyboard, everything worked and man, it’s now a complete solution that Retropie/Emulationstation/Kodi. I must say that I have cloned my SD card and it will be some Christmas gift next year.
Cheers!
-
AuthorPosts
- The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.