[HowTo] Scripts for using Xbox Controller in RetrOSMC

Can’t believe I didn’t see your tutorial for a whole week. Thumbs up for putting this together noob-friendly. :slight_smile: I’ll give it a go this weekend. Looks promising so far. Again, kudos to you!

interesting tidbit… for some reason my scripts to kill and restart xboxdrv when retrosmc starts no longer work. I can SSH in and run the command and it works fine though…

sudo kill -9 ps -ef | grep xboxdrv | grep -v grep | awk '{print $2}'
sudo xboxdrv --wid 0 --led 3 --alt-config /home/osmc/buttonswap.ini & sleep 2

but as soon as ssh connection is lost it’s dead again.
But it will kill xboxdrv and restart it with proper key mapping when osmc starts up again. The “switchtoxpad.sh” script was made executable and the transition script is set up. I have literally made no changes and it was working last week. Any ideas?

Try
sudo kill -9 $(pidof xboxdrv)

i’m slightly noobish. I’m assuming by (pidof xboxdrv) you mean the process id of xboxdrv when it’s running is osmc? Is there a command i can run to find that information?

edit/update: command line - How to find the Process ID (PID) of a running terminal program? - Ask Ubuntu The internet is a wonderful thing. Correctly identified the process ID. Still won’t run

Seems as though it just isn’t running the launch script. If i run the script via command it runs fine.

What could be the reason for it not to load when booting emulation station when just a few days ago it ran that way no problem?

pidof is a program. Type exactly as I wrote it.
$(…) will give back the value a command between the braces will produce.
So this will automatically find the process id of xboxdrv and give it as a parameter to the kill command to kill it.

Thanks man…that looks much simpler than my method

thanks for clarifying.

Still doesn’t seem to run the script. i can run it via command prompt once emulation station is running and everything works fine though.

What does /home/osmc/RetroPie/scripts/retropie.sh look like…this is where switchtoxpad.sh is being called.

it has the line
sudo su osmc -c “sh /home/osmc/switchtoxpad.sh &” &

do you think it’s possible that somehow the retropie version switched so it’s feeding off the scripts in the /opt/retrosmc/home/pi/RetroPie/scripts folder?

whats scripts are in that folder…sorry don’t have my pi with me

chroot.sh, retropie.sh, retropie_watchdog.sh are all in the /opt/retrosmc/home/pi/RetroPie/scripts folder for me.

to clarify they are also in the /home/osmc/RetroPie/scripts/ folder as well

then you’d have to change it there

Already did, but still no go.

the retropie.sh script in the /opt/retrosmc/home/pi/RetroPie/scripts folder looks like this:

#!/bin/bash
# This scripts starts the emulationstation watchdog deamon and
# emulationstation itself while stopping KODI afterwards.
# Script by mcobit
sudo openvt -c 7 -s -f clear
sudo openvt -c 7 -s -f echo "Running emulationstation from KODI"
sudo su osmc -c "sh /home/osmc/RetroPie/scripts/retropie_watchdog.sh &" &
#run controller
sudo su osmc -c "sh /home/osmc/switchtoxpad.sh &" &
sudo su osmc -c "nohup openvt -c 7 -f -s /home/osmc/RetroPie/scripts/chroot.sh >/dev/null 2>&1 &" &
sudo openvt -c 7 -s -f clear
sleep 2
sudo su -c "systemctl stop mediacenter &" &

exit

If i actually just open an SSH connection and enter the command “sudo su osmc -c “sh /home/osmc/switchtoxpad.sh &” &” the controllers all work as intended.

If i don’t enter that the controller works in emulationstation, and even if a press any button for settings as an emulator loads, but then once a game is fully loaded it stops working unless i run that script.

add a second controller below this line…
sudo xboxdrv --wid 1 --led 4 --alt-config /home/osmc/buttonswap.ini & sleep 2

currently my switchtoxpad.sh looks like this

#!/bin/bash
sudo kill -9 $(pidof xboxdrv)
sudo xboxdrv --wid 0 --led 6 --trigger-as-button --alt-config /home/osmc/buttonswap.ini & sleep 2
sudo xboxdrv --wid 1 --led 3 --trigger-as-button --alt-config /home/osmc/buttonswap.ini & sleep 2
sudo xboxdrv --wid 2 --led 4 --trigger-as-button --alt-config /home/osmc/buttonswap.ini & sleep 2
sudo xboxdrv --wid 3 --led 5 --trigger-as-button --alt-config /home/osmc/buttonswap.ini & sleep 2
exit

I changed the first to led6 just to see if it would cause anything different to happen when retropie booted. It seems like the script just isn’t launching at boot for some reason

did you add the other instances before or after the issue started? We need to establish whether this script is being called or not. Pipe the output to a text file and check if the result

before. They were working fine running xmen on MAME with 4 players no prob. I’m not sure exactly how to pipe the output to a text file. Can you point me in the direction of how to do that?

Please modify the scripts in your home folder. Not in /opt.

at first the only modified scripts were in the home folder. I only modified the ones in /opt in an attempt to get them to work again

Just want to confirm that the scripts are still working with the current 0.007 installer procedure, which is not based on a CHROOT environment anymore:

The retropie.sh script has changed, but insert the call for the switchtoxpad.sh script one line before calling the retropie_watchdog.sh script
In the retropie_watchdog.sh script (also changed versus the description above) insert the switchtoxboxdrv.sh call just one line above the line restarting the mediacenter