Little Joystick-Configuration Script

Welcome Page Forums RetroPie Project Everything else related to the RetroPie Project Little Joystick-Configuration Script

This topic contains 1 reply, has 0 voices, and was last updated by  Naurandir 3 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #68382

    Naurandir

    Hello Guys!

    Because of the sometimes painfull usage of joyconfig (how do i start it, how do i copy settings into other emulators? and so on)
    i wrote a little script if anyone is interested.
    It is optimized for EmulationStation 2!

    what does it do?
    It shows you your usb devices (is the joystick recognized?)
    It shows your dev/input (js0, js1 to know where the joystick is).

    After that you can choose what platforms you want to create your input (default all).

    Next it asks which player you would like to edit.
    After that it starts the normal joyconfig script but with correct parameters and copies it into the correct retroarch.cfg.

    What you need to do:
    1. make copies of retroarch.cfg as retroarch_original.cfg WITHOUT any player input (because the script will refer always to retroarch_original.cfg, copies it into retroarch.cfg and append the joystick-input) in every config folder like all, nes, snes, mame,…
    [retroarch.cfg are located in /opt/retropie/configs/*/]

    2. make a file called Joystick.sh (or any other name you want) and copy following code into it:

    #!/bin/sh
    #First Show USB Devices and Inputs inside dev that user knows what pi recognizes.
    echo Initialising Joystick Configuration...
    echo Showing all USB-Devices:
    sudo lsusb
    sleep 6
    echo " "
    echo " "
    echo Showing Devices in dev:
    sudo ls /dev/input
    echo Joysticks should be shown as js0, js1, js2 and so on.
    sleep 6s
    echo " "
    echo " "
    echo Remember your shown Devices for further configuration...
    sleep 3s
    echo Script will start in 5 Seconds...
    sleep 5s
    
    #Create Temp Data
    #Tempdata for Platform
    platformtemp="/home/pi/platformtjs.tmp"
    #Make Sure file is empty
    >$platformtemp
    
    #Tempdata for Joystick
    joysticktemp="/home/pi/joyconfig.tmp"
    #Make Sure file is empty
    >$joysticktemp
    
    #Tempdata for player
    playertemp="/home/pi/playerconfig.tmp"
    #Make Sure file is empty
    >$playertemp
    
    dialog --backtitle "Joystick-Configuration" \
    --title "Joystick-Configuration" \
    --msgbox 'Welcome to Joystick-Configuration' 6 60
    
    dialog --backtitle "Joystick-Configuration" \
    --title "Joystick-Configuration" \
    --yesno 'Would you like to Configure your Joystick?' 6 60
    response=$?
    case $response in
       0) starting=1;;
       1) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
       255) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    esac
    
    #While Loop to configure more than one Player.
    while [ "$starting" = "1" ]
    do
    	#---------Platform-Index------------
    	dialog --backtitle "Joystick-Configuration: Platform Selection" \
    	--radiolist "Select a Platform to configure (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	all "All" on \
    	gb "Game Boy" off \
    	gbc "Game Boy Advanced" off \
    	nes "Nintendo" off \
    	snes "Super Nintendo" off \
    	mastersystem "Sega Master System" off \
    	megadrive "Sega Mega Drive" off \
    	mame "M.A.M.E" off \
    	psx "Playstation 1" off 2> $platformtemp
    	
    	#Platform Type
    	platform=$(cat $platformtemp)
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Platform Selection" \
    	--title "Selected Platform" \
    	--msgbox "Platform -${platform}- was selected." 6 60
    	
    	#---------Joystick-Index------------
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
    	--radiolist "Select Joystick-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	0 "Joystick #0" on \
    	1 "Joystick #1" off \
    	2 "Joystick #2" off \
    	3 "Joystick #3" off \
    	4 "Joystick #4" off \
    	5 "Joystick #5" off \
    	6 "Joystick #6" off \
    	7 "Joystick #7" off \
    	8 "Joystick #8" off 2> $joysticktemp
    	
    	#Joystick-Index
    	joystickindex=$(cat $joysticktemp)
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
    	--title "Selected Joystick" \
    	--msgbox "Joystick-Index Number ${joystickindex} was selected." 6 60
    	
    	#--------Player-Index-------------
    	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
    	--radiolist "Select Player-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	1 "Player #1" on \
    	2 "Player #2" off \
    	3 "Player #3" off \
    	4 "Player #4" off \
    	5 "Player #5" off \
    	6 "Player #6" off \
    	7 "Player #7" off \
    	8 "Player #8" off 2> $playertemp
    	
    	#Player-Index
    	playerindex=$(cat $playertemp)
    	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
    	--title "Selected Player" \
    	--msgbox "Player-Number ${playerindex} was selected." 6 60
    	
    	#---------Start Joypad Configuration Script
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Starting Input" \
    	--title "Starting Input Configuration" \
    	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} will start on Platform -${platform}- shortly. Before the Configuration starts it is recommended that all Buttons are used now to calibrate them." 8 60
    	
    	#Start known Joystick Script with correct Parameters.
    	sudo /opt/retropie/emulators/RetroArch/installdir/bin/retroarch-joyconfig -p $playerindex -j $joystickindex > /opt/retropie/configs/${platform}/p${playerindex}.cfg
    	#Finished
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Finished Config" \
    	--title "Configuration Finished" \
    	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} is finished." 6 60
    	
    	#Ask if another Player should be configured.
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." \
    	--title "Joystick-Configuration" \
    	--yesno 'Would you like to Configure another Joystick?' 6 60
    	response=$?
    	case $response in
    		0) 	starting=1;;
    		1) 	starting=0
    			dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    		255) starting=0
    			 dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    	esac
    	
    #Remove all Temp Files
    rm $platformtemp
    rm $joysticktemp
    rm $playertemp
    done #Ende der While Schleife
    
    #After Configuration is finished all files have to be copied into retroarch.cfg
    sudo cp -f /opt/retropie/configs/${platform}/retroarch_original.cfg /opt/retropie/configs/${platform}/retroarch.cfg
    sudo cat /opt/retropie/configs/${platform}/p*.cfg >> /opt/retropie/configs/${platform}/retroarch.cfg
    

    Save it and start your script!

    If you played around with the RaspberryPi like me and you have an Section called Applications at EmulationStation you can run this script directly from ES like i do.

    Hope it helps somebody ^^

    greetings Naurandir

    #68392

    Naurandir

    Little change to prevent problems with tmp Files, sorry ^^

    #!/bin/sh
    #First Show USB Devices and Inputs inside dev that user knows what pi recognizes.
    echo Initialising Joystick Configuration...
    echo Showing all USB-Devices:
    sudo lsusb
    sleep 6
    echo " "
    echo " "
    echo Showing Devices in dev:
    sudo ls /dev/input
    echo Joysticks should be shown as js0, js1, js2 and so on.
    sleep 6s
    echo " "
    echo " "
    echo Remember your shown Devices for further configuration...
    sleep 3s
    echo Script will start in 5 Seconds...
    sleep 5s
    
    #Create Temp Data
    #Tempdata for Platform
    platformtemp="/home/pi/platformtjs.tmp"
    #Make Sure file is empty
    >$platformtemp
    
    #Tempdata for Joystick
    joysticktemp="/home/pi/joyconfig.tmp"
    #Make Sure file is empty
    >$joysticktemp
    
    #Tempdata for player
    playertemp="/home/pi/playerconfig.tmp"
    #Make Sure file is empty
    >$playertemp
    
    dialog --backtitle "Joystick-Configuration" \
    --title "Joystick-Configuration" \
    --msgbox 'Welcome to Joystick-Configuration' 6 60
    
    dialog --backtitle "Joystick-Configuration" \
    --title "Joystick-Configuration" \
    --yesno 'Would you like to Configure your Joystick?' 6 60
    response=$?
    case $response in
       0) starting=1;;
       1) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
       255) dialog --backtitle "Joystick-Configuration" --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    esac
    
    #While Loop to configure more than one Player.
    while [ "$starting" = "1" ]
    do
    	#---------Platform-Index------------
    	dialog --backtitle "Joystick-Configuration: Platform Selection" \
    	--radiolist "Select a Platform to configure (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	all "All" on \
    	gb "Game Boy" off \
    	gbc "Game Boy Advanced" off \
    	nes "Nintendo" off \
    	snes "Super Nintendo" off \
    	mastersystem "Sega Master System" off \
    	megadrive "Sega Mega Drive" off \
    	mame "M.A.M.E" off \
    	psx "Playstation 1" off 2> $platformtemp
    	
    	#Platform Type
    	platform=$(cat $platformtemp)
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Platform Selection" \
    	--title "Selected Platform" \
    	--msgbox "Platform -${platform}- was selected." 6 60
    	
    	#---------Joystick-Index------------
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
    	--radiolist "Select Joystick-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	0 "Joystick #0" on \
    	1 "Joystick #1" off \
    	2 "Joystick #2" off \
    	3 "Joystick #3" off \
    	4 "Joystick #4" off \
    	5 "Joystick #5" off \
    	6 "Joystick #6" off \
    	7 "Joystick #7" off \
    	8 "Joystick #8" off 2> $joysticktemp
    	
    	#Joystick-Index
    	joystickindex=$(cat $joysticktemp)
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Joystick-Index Selection" \
    	--title "Selected Joystick" \
    	--msgbox "Joystick-Index Number ${joystickindex} was selected." 6 60
    	
    	#--------Player-Index-------------
    	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
    	--radiolist "Select Player-Number (Use SPACEBAR to select and ENTER to confirm):" 18 45 9 \
    	1 "Player #1" on \
    	2 "Player #2" off \
    	3 "Player #3" off \
    	4 "Player #4" off \
    	5 "Player #5" off \
    	6 "Player #6" off \
    	7 "Player #7" off \
    	8 "Player #8" off 2> $playertemp
    	
    	#Player-Index
    	playerindex=$(cat $playertemp)
    	dialog --backtitle "Player-Configuration for -${platform}- Platforms: Player-Number Selection" \
    	--title "Selected Player" \
    	--msgbox "Player-Number ${playerindex} was selected." 6 60
    	
    	#---------Start Joypad Configuration Script
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Starting Input" \
    	--title "Starting Input Configuration" \
    	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} will start on Platform -${platform}- shortly. Before the Configuration starts it is recommended that all Buttons are used now to calibrate them." 8 60
    	
    	#Start known Joystick Script with correct Parameters.
    	sudo /opt/retropie/emulators/RetroArch/installdir/bin/retroarch-joyconfig -p $playerindex -j $joystickindex > /opt/retropie/configs/${platform}/p${playerindex}.cfg
    	#Finished
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms: Finished Config" \
    	--title "Configuration Finished" \
    	--msgbox "Configuration of Joystick ${joystickindex} for Player ${playerindex} is finished." 6 60
    	
    	#Ask if another Player should be configured.
    	dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." \
    	--title "Joystick-Configuration" \
    	--yesno 'Would you like to Configure another Joystick?' 6 60
    	response=$?
    	case $response in
    		0) 	starting=1;;
    		1) 	starting=0
    			dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    		255) starting=0
    			 dialog --backtitle "Joystick-Configuration for -${platform}- Platforms." --title "Configuration Finished" --msgbox 'Joystick-Configuration will now end.' 6 60;;
    	esac
    	>$platformtemp
    	>$joysticktemp
    	>$playertemp
    done #Ende der While Schleife
    
    #After Configuration is finished all files have to be copied into retroarch.cfg
    sudo cp -f /opt/retropie/configs/${platform}/retroarch_original.cfg /opt/retropie/configs/${platform}/retroarch.cfg
    sudo cat /opt/retropie/configs/${platform}/p*.cfg >> /opt/retropie/configs/${platform}/retroarch.cfg
    
    #Remove all Temp Files
    rm $platformtemp
    rm $joysticktemp
    rm $playertemp
    
Viewing 2 posts - 1 through 2 (of 2 total)

Forums are currently read only - please visit the new RetroPie forums at https://retropie.org.uk/forums/