2013-03-18, 01:13
So it took me countless hours to get this damned controller working in XBMC in a way that would allow me use it in both XBMC and Advanced Launcher roms.
It took some doing so i figured i would post the process in here as a reference.
Setup:
Updated 03/21/2013
Modified the xboxdrv service script:
- Renamed script to xboxdrv-rc
- Implemented keymap-file flag
- Implemented xboxdrv inline options
- Fixed restart bug by adding a 1 second delay between starting and stopping
- Cleaned up code and added usage function
Configuration Instructions
0 - Update VI [Optional]
The default installation comes with the horrible vim-tiny installation, the first thing i did was upgrade vim so i can edit my files in peace. Install vim-nox using the following commands
1 - Blacklist xpad
xPad is the default Linux USB driver for X-Box gamepads. It has its issues (getting better lately) but is still a no-go if you're using an XBOX DVD remote so we're going to replace it with xboxdrv. To do that we need to disable it.
2 - Install xboxdrv
Install the xboxdrv userspace gampad driver
3 - Test the xboxdrv driver
Start the xboxdrv driver and watch for output, the command here assumes a wireless controller. If you have a wired controller then just substitute --wid with --id
You should see the following output header and then input data when you use the controller
If you see the above output then things are good, if not then please post here or check the forums for solutions.
Don't worry about getting it to work with xbmc just yet - we'll get to that. Just CTRL-C out of the process for now.
4 - Modify xbmc permissions
xboxdrv needs access to USB devices and needs to be able to load uinput but the xbmc user doesn't have the right permissions to do that.
The first thing we're going to do is add xbmc to the root group (there's no other way unfortunately)
Modify uinput permissions to allow xbmc to load it, create the uinput rules file:
5 - Create xboxdrv Service
Create the script xboxdrv-rc in the /etc/init.d/ directory
This script is a modified version of Draggy's script from this post - I modified it because i don't want to have to use screen, wanted the ability to launch it as xbmc, and wanted a cleaner stop/start with the pid files. I plan on modifying it later to load different profiles so i can manage the emulator button assignments using it. Check back for changes. Done! 03.21.2013
Paste the script below into it
Make the script executable
Make the script run at startup
6 - Create xboxdrv Configuration File
xboxdrv comes with an example configuration file for use with xbmc. The file doesn't seem to work right with the latest xbmc build (the up & down dpad buttons don't work).
I modified the original file (/usr/share/doc/xboxdrv/examples/xbmc.xboxdrv) and moved it to my xbmc home folder so it can be backed up during upgrades.
The startup script will point to this file so make sure the pathing is correct or modify the script to point to your path.
Create the file /home/xbmc/.xbmc/userdata/keymaps/MyXBMC.xboxdrv and paste the code below into it.
7 - Test with XBMC
To test we'll need to start the service and restart the xbmc process. You could restart the box or issue these commands:
That's it - should be working smoothly in xbmc
Shameless plea for reputation in my signature
It took some doing so i figured i would post the process in here as a reference.
Setup:
- XBMCbuntu 12.0
- MS Xbox 360 Wireless Gaming Receiver
- An XBOX 360 Controller
Updated 03/21/2013
Modified the xboxdrv service script:
- Renamed script to xboxdrv-rc
- Implemented keymap-file flag
- Implemented xboxdrv inline options
- Fixed restart bug by adding a 1 second delay between starting and stopping
- Cleaned up code and added usage function
Code:
USAGE:
xboxdrvrc [start|stop|restart|status] [OPTIONS]
OPTIONS:
-k [FILE], --keymap-file [FILE]
Provide an alternate xboxdrv key file to use
Full path to the file must be provided
-x [XD-OPTS], --xboxdrv-opts [XD-OPTS]
Provide inline xboxdrv options. Options provided have to be enclosed in quotes
Please refer to the xboxdrv man page for options
-h, --help
Print this usage information
EXAMPLES:
xboxdrvrc start
xboxdrvrc restart --xboxdrv-opts "--ui-buttonmap guide=key::KEY_ESC:2000"
xboxdrvrc start --keymap-file /home/xbmc/zsnes.xboxdrv --xboxdrv-opts "--ui-buttonmap guide=key::KEY_ESC:2000"
Configuration Instructions
0 - Update VI [Optional]
The default installation comes with the horrible vim-tiny installation, the first thing i did was upgrade vim so i can edit my files in peace. Install vim-nox using the following commands
Code:
sudo apt-get update
sudo apt-get -y install vim-nox
1 - Blacklist xpad
xPad is the default Linux USB driver for X-Box gamepads. It has its issues (getting better lately) but is still a no-go if you're using an XBOX DVD remote so we're going to replace it with xboxdrv. To do that we need to disable it.
Code:
sudo echo "blacklist xpad" >> /etc/modprobe.d/blacklist
2 - Install xboxdrv
Install the xboxdrv userspace gampad driver
Code:
sudo apt-get -y install xboxdrv
3 - Test the xboxdrv driver
Start the xboxdrv driver and watch for output, the command here assumes a wireless controller. If you have a wired controller then just substitute --wid with --id
Code:
sudo xboxdrv --wid 0 -c /usr/share/doc/xboxdrv/examples/xbmc.xboxdrv
You should see the following output header and then input data when you use the controller
Code:
xbmc@xbmc:~$ sudo xboxdrv --wid 0 -c /usr/share/doc/xboxdrv/examples/xbmc.xboxdrv
xboxdrv 0.8.4 - http://pingus.seul.org/~grumbel/xboxdrv/
Copyright © 2008-2011 Ingo Ruhnke <[email protected]>
Licensed under GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details.
Controller: Microsoft Xbox 360 Wireless Controller
Vendor/Product: 045e:0291
USB Path: 004:002
Wireless Port: 0
Controller Type: Xbox360 (wireless)
Your Xbox/Xbox360 controller should now be available as:
/dev/input/js0
/dev/input/event9
Press Ctrl-c to quit, use '--silent' to suppress the event output
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:1 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:1 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:1 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:1 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
X1: -3488 Y1: 1924 X2: -1988 Y2: 1688 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
If you see the above output then things are good, if not then please post here or check the forums for solutions.
Don't worry about getting it to work with xbmc just yet - we'll get to that. Just CTRL-C out of the process for now.
4 - Modify xbmc permissions
xboxdrv needs access to USB devices and needs to be able to load uinput but the xbmc user doesn't have the right permissions to do that.
The first thing we're going to do is add xbmc to the root group (there's no other way unfortunately)
Code:
sudo useradd -G root xbmc
Modify uinput permissions to allow xbmc to load it, create the uinput rules file:
Code:
sudo sh -c 'echo KERNEL==\"uinput\", MODE=\"0660\", GROUP=\"root\" >> /etc/udev/rules.d/55-permissions-uinput.rules'
5 - Create xboxdrv Service
Create the script xboxdrv-rc in the /etc/init.d/ directory
This script is a modified version of Draggy's script from this post - I modified it because i don't want to have to use screen, wanted the ability to launch it as xbmc, and wanted a cleaner stop/start with the pid files. I plan on modifying it later to load different profiles so i can manage the emulator button assignments using it. Check back for changes. Done! 03.21.2013
Code:
sudo vi /etc/init.d/xboxdrv-rc
Paste the script below into it
Code:
#! /bin/bash
### BEGIN INIT INFO
# Provides: xboxdrv-rc
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: xboxdrv service script
#
# Description:
# A service script for the xboxdrv controller
# driver.
#
# Changelog:
# v1.1 - Draggy - 04/12/2011
# - Initial Version
#
# v1.2 - Firas AlShafei - 03/17/2013
# - Modified script to not need screen
# - Added ability to run as desired user
# - xbmc can stop/start it if needed
# - Using PID files for process tracking
#
# v1.3 - Firas AlShafei - 03/21/2013
# - Renamed script to xboxdrv-rc
# - Added option flags add ability for
# - keymap file assignment
# - inline xboxdrv options
# - Added a startup delay when using restart|reload
# - Cleaned up code and added usage function
#
### END INIT INFO
#user that xboxdrv will run under
USER="xbmc"
GROUP="xbmc"
# driver binary
DRV=xboxdrv
# wireless controllers
WIRELESS=(0 1)
# Wired Controllers
WIRED=()
# xboxdrv configuration file
KEYMAP_FILE="/home/xbmc/.xbmc/userdata/keymaps/MyXBMC.xboxdrv"
# xboxdrv options
INIT_XD_OPTIONS="--silent --quiet"
# Arguments
function set_args()
{
ARGS="$INIT_XD_OPTIONS -c $KEYMAP_FILE $XD_OPTIONS"
}
# start
start()
{
# Load uinput if it isnt loaded already
if [ -z "$(lsmod | grep uinput)" ]; then
echo "Loading uinput module"
modprobe uinput
fi
# Load joydev if it isnt loaded already
if [ -z "$(lsmod | grep joydev)" ]; then
echo "Loading joydev module"
modprobe joydev
fi
# Unload xpad if its loaded
if [ -n "$(lsmod | grep xpad)" ]; then
echo "Unloading xpad module"
rmmod xpad
fi
for i in ${WIRELESS[@]}
do
ps -p `cat /tmp/.$DRV.WS.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Wireless Controller #$i is already running"
else
echo "Starting Wireless Controller #$i"
if [ $(whoami) = $USER ]; then
$DRV --wid $i $ARGS &
echo $! > /tmp/.$DRV.WS.$i.pid
else
su - $USER -c "$DRV --wid $i $ARGS & echo \$! > /tmp/.$DRV.WS.$i.pid"
bg=$(</tmp/.$DRV.WS.$i.pid)
fi
fi
done
for i in ${WIRED[@]}
do
ps -p `cat /tmp/.$DRV.WD.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Wired Controller #$i is already running"
else
echo "Starting Wired Controller #$i"
if [ $(whoami) = $USER ]; then
$DRV --wid $i $ARGS &
echo $! > /tmp/.$DRV.WD.$i.pid
else
su - $USER -c "$DRV --id $i $ARGS & echo \$! > /tmp/.$DRV.WD.$i.pid"
bg=$(</tmp/.$DRV.WD.$i.pid)
fi
fi
done
}
# stop
stop() {
for i in ${WIRELESS[@]}
do
ps -p `cat /tmp/.$DRV.WS.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Stopping Wireless Controller #$i"
if [ $(whoami) = $USER ]; then
kill -9 `cat /tmp/.$DRV.WS.$i.pid` >& /dev/null
else
su - $USER -c "kill -9 $PID >& /dev/null"
fi
else
echo "Wireless Controller #$i is not running"
fi
done
for i in ${WIRED[@]}
do
ps -p `cat /tmp/.$DRV.WD.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Stopping Wired Controller #$i"
if [ $(whoami) = $USER ]; then
kill -9 `cat /tmp/.$DRV.WD.$i.pid` >& /dev/null
else
su - $USER -c "kill -9 $PID >& /dev/null"
fi
else
echo "Wired Controller #$i is not running"
fi
done
}
# status
status() {
for i in ${WIRELESS[@]}
do
ps -p `cat /tmp/.$DRV.WS.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Wireless Controller #$i is running"
else
echo "Wireless Controller #$i is not running"
fi
done
for i in ${WIRED[@]}
do
ps -p `cat /tmp/.$DRV.WD.$i.pid` >& /dev/null
if [ $? = 0 ];then
echo "Wired Controller #$i is running"
else
echo "Wired Controller #$i is not running"
fi
done
}
function usage()
{
echo "USAGE: "
echo " xboxdrv-rc [start|stop|restart|status] [OPTIONS]"
echo
echo "OPTIONS:"
echo " -k [FILE], --keymap-file [FILE]"
echo " Provide an alternate xboxdrv key file to use"
echo " Full path to the file must be provided"
echo
echo " -x [XD-OPTS], --xboxdrv-opts [XD-OPTS]"
echo " Provide inline xboxdrv options. Options provided have to be enclosed in quotes"
echo " Please refer to the xboxdrv man page for options"
echo
echo " -h, --help"
echo " Print this usage information"
echo
echo "EXAMPLES:"
echo " xboxdrv-rc start"
echo " xboxdrv-rc restart --xboxdrv-opts \"--ui-buttonmap guide=key::KEY_ESC:2000\""
echo " xboxdrv-rc start --keymap-file /home/xbmc/zsnes.xboxdrv --xboxdrv-opts \"--ui-buttonmap guide=key::KEY_ESC:2000\""
echo
}
### main logic ###
# Create Wireless PID files
for i in ${WIRELESS[@]}; do ( touch /tmp/.$DRV.WS.$i.pid && chown $USER:$GROUP /tmp/.$DRV.WS.$i.pid ); done
# Create Wired PID files
for i in ${WIRED[@]}; do ( touch /tmp/.$DRV.WD.$i.pid && chown $USER:$GROUP /tmp/.$DRV.WD.$i.pid ); done
# Get user input
PARAMS=`getopt -o "k:x:h" -l "keymap-file:,xboxdrv-opts:,help" -- "$@"`
# If no input is provided echo usage statement
if [ $? -ne 0 ]; then
usage
exit 1
fi
# A little magic
eval set -- "$PARAMS"
# Go through all the options
while true;
do
case "$1" in
# The keymap-file parameter
# Check if the file exists - print an error message and exit if it doesnt
-k|--keymap-file)
if [ -n "$2" ]; then
KEYMAP_FILE="$2"
if [ ! -f $KEYMAP_FILE ];then
echo Error: Invalid keymap file $KEYMAP_FILE specified.
echo " Ensure the file exists and provide the absolute path." && echo
usage
exit 1
fi
fi
shift 2
;;
# The xboxdrv options parameter
# Cant check this - if the input is bad we'll have to wait for the error from xboxdrv
-x|--xboxdrv-opts)
if [ -n "$2" ]; then
XD_OPTIONS="$2"
fi
shift 2
;;
# Help parameter
# Calls the usage function and exits
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
esac
done
# Set Argument Variable
set_args
# Call action function based on user input
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|reload)
stop
sleep 1
start
;;
*)
echo "Error: Invalid arguments or no arguments provided" && echo
usage
exit 1
;;
esac
exit 0
Make the script executable
Code:
sudo chmod +x /etc/init.d/xboxdrv-rc
Make the script run at startup
Code:
sudo update-rc.d xboxdrv-rc defaults
6 - Create xboxdrv Configuration File
xboxdrv comes with an example configuration file for use with xbmc. The file doesn't seem to work right with the latest xbmc build (the up & down dpad buttons don't work).
I modified the original file (/usr/share/doc/xboxdrv/examples/xbmc.xboxdrv) and moved it to my xbmc home folder so it can be backed up during upgrades.
The startup script will point to this file so make sure the pathing is correct or modify the script to point to your path.
Create the file /home/xbmc/.xbmc/userdata/keymaps/MyXBMC.xboxdrv and paste the code below into it.
Code:
vi /home/xbmc/.xbmc/userdata/keymaps/MyXBMC.xboxdrv
# XBMC Configuration
# ==================
#
# This configuration file that with XBMC by emulating a wireless
# Xbox360 controller connected to the xpad kernel driver. It uses the
# configuration files that come with XBMC, so it should work out of
# the box without any further configuration of XBMC.
#
# This file is identical to 'xpad-wireless.xboxdrv', except the
# workaround for the trigger issue in XBMC.
#
[xboxdrv]
ui-clear = true
extra-devices=false
extra-events=false
deadzone=6000
device-name = "Controller (XBOX 360 For Windows)"
[ui-buttonmap]
A=BTN_A
B=BTN_B
X=BTN_X
Y=BTN_Y
# Modification for frodo
DU=BTN_0
DD=BTN_1
DL=BTN_LEFT
DR=BTN_RIGHT
START=BTN_START
GUIDE=BTN_MODE
BACK=BTN_BACK
LB=BTN_TL
RB=BTN_TR
TL=BTN_THUMBL
TR=BTN_THUMBR
[ui-axismap]
X1=ABS_X
Y1=ABS_Y
X2=ABS_RX
Y2=ABS_RY
# The resp filter moves the neutral position to zero to work around a
# bug in XBMC, that causes bogus events when neutral position is
# elsewhere. It loses a bit of precision in the trigger as result, but
# that isn't noticable.
LT^resp:127:255=ABS_Z
RT^resp:127:255=ABS_RZ
# EOF #
7 - Test with XBMC
To test we'll need to start the service and restart the xbmc process. You could restart the box or issue these commands:
Code:
service xboxdrv-rc restart
sudo killall -HUP xbmc.bin
That's it - should be working smoothly in xbmc
Shameless plea for reputation in my signature