dudleydesParticipant09/22/2015 at 13:09Post count: 139
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 binary
Download the source from the following link:
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:
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"
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 map
The 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:
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.
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.jonnygallParticipant10/06/2015 at 19:38Post count: 7
I 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.
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).dudleydesParticipant10/07/2015 at 11:47Post count: 139
I 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"jonnygallParticipant10/08/2015 at 02:05Post count: 7
# 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.MRKaneParticipant10/08/2015 at 02:49Post count: 58
Could 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? :DdudleydesParticipant10/08/2015 at 14:19Post count: 139
I 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.MRKaneParticipant10/08/2015 at 23:57Post count: 58
Saying it here also: Thanks a heap for that dudelydes!MRKaneParticipant10/14/2015 at 11:58Post count: 58
Right, 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!hypersonicParticipant11/18/2015 at 00:06Post count: 3
This 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.dudleydesParticipant11/19/2015 at 17:41Post count: 139
I’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:
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.hypersonicParticipant11/19/2015 at 23:16Post count: 3
You 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 keyshypersonicParticipant11/19/2015 at 23:29Post count: 3
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.OmnijaParticipant01/04/2016 at 17:52Post count: 155
Any 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?shades42Participant01/05/2016 at 00:37Post count: 16
I 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 :
#!/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
# 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 loadmapshades42Participant01/05/2016 at 06:46Post count: 16
The 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
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 appreciateddudleydesParticipant01/05/2016 at 13:40Post count: 139
You could try entering 0000 as your product code in your mapper file. Alternatively, you could use xboxdrv. Instructions below:
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.shades42Participant01/05/2016 at 18:34Post count: 16
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!dudleydesParticipant01/05/2016 at 18:55Post count: 139
You 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.shades42Participant01/05/2016 at 20:51Post count: 16
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.2
When 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"OmnijaParticipant01/05/2016 at 21:50Post count: 155shades42Participant01/06/2016 at 07:17Post count: 16
@dudleydes I noticed with the link you provided there is a type for the permissions
sudo groupdadd -f uinputthere is an extra d groupdadd
once you remove it and put
sudo groupadd -f uinputit works and if you are C/P’ing the
KERNEL==”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 itshades42Participant01/10/2016 at 23:45Post count: 16
I 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.shades42Participant01/11/2016 at 03:59Post count: 16
I 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 advancedudleydesParticipant01/11/2016 at 11:18Post count: 139
Thanks 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.shades42Participant01/11/2016 at 15:34Post count: 16
Thanks 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.shades42Participant01/12/2016 at 19:01Post count: 16
Just 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 :)Computer NinjaParticipant01/16/2016 at 00:10Post count: 22
Any updates on getting a USB Gamepad (like my Logitech F310) working with Kodi?noratioParticipant02/18/2016 at 03:37Post count: 1
Alright @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.
- You must be logged in to reply to this topic.