diff --git a/config.sh b/config.sh new file mode 100755 index 0000000000000000000000000000000000000000..79106bc46b839fe68805bdf6871d20c20e423dbc --- /dev/null +++ b/config.sh @@ -0,0 +1,4 @@ +#!/bin/bash +#configure working directories +export workingDirectory="/where/gamepad-switcher/is" +export killProcessesScript="a/shell/file/that/will/be/created/and/erased/in/working/directory" \ No newline at end of file diff --git a/game.sh b/game.sh index 90a077e4fbc83bffd5ab0b238493bebaee24dac9..4f75039ff5d22c6c615abd75f0a1665865c9ff9b 100755 --- a/game.sh +++ b/game.sh @@ -3,6 +3,21 @@ # 2 parameters can be used : 1 → x for xbox controller, p for ps3 # 2 → name of the game as suggested in menu +#configuration +. ./config.sh +cd $workingDirectory +if [ -e "$killProcessesScript" ] +then + echo "There seems to be (a) running instance(s) of the game controller, do you want to brutally kill the processes? (Y/n)\nI'm not sure what it does if you don't…" + read userinput + if [ "$userinput" = "Y" ] + then + sh $killProcessesScript + rm $killProcessesScript + sleep 1 + fi +fi + if [ $# = 0 ] then echo "(X)box or (P)S3 ?" @@ -33,11 +48,12 @@ else echo What game would you like to play? echo 1\) vvvvvv echo 2\) Braid - echo 3\) Limbo - echo 4\) Lone Survivor - echo 5\) Minecraft - echo 6\) Psychonauts - echo 7\) Amnesia + echo 3\) Eggnogg + echo 93\) Limbo + echo 94\) Lone Survivor + echo 95\) Minecraft + echo 96\) Psychonauts + echo 97\) Amnesia echo "99) None, give me my gamepad mode back." read userinput fi @@ -55,31 +71,38 @@ then echo cd modules ./braid.sh -elif [ "$userinput" = 3 -o "$userinput" = "Limbo" -o "$userinput" = "limbo" ] +elif [ "$userinput" = 3 -o "$userinput" = "Eggnogg" -o "$userinput" = "eggnogg" -o "$userinput" = "egg" -o "$userinput" = "E" -o "$userinput" = "e" ] +then + echo "Your controllerS will now be configured for eggnogg." +#Different types of controllers could be configured, but it's not my case so I won't do it ;) + echo + cd modules + ./eggnogg.sh +elif [ "$userinput" = 93 -o "$userinput" = "Limbo" -o "$userinput" = "limbo" ] then echo "Your controller will now be configured for Limbo." echo cd modules ./limbo.sh -elif [ "$userinput" = 4 -o "$userinput" = "Lone Survivor" -o "$userinput" = "lone survivor" ] +elif [ "$userinput" = 94 -o "$userinput" = "Lone Survivor" -o "$userinput" = "lone survivor" ] then echo "Your controller will now be configured for Lone Survivor" echo cd modules ./lonesurvivor.sh -elif [ "$userinput" = 5 -o "$userinput" = "Minecraft" -o "$userinput" = "minecraft" ] +elif [ "$userinput" = 95 -o "$userinput" = "Minecraft" -o "$userinput" = "minecraft" ] then echo "Your controller will now be configured for Minecraft." echo cd modules ./minecraft.sh -elif [ "$userinput" = 6 -o "$userinput" = "Psychonauts" -o "$userinput" = "psychonauts" ] +elif [ "$userinput" = 96 -o "$userinput" = "Psychonauts" -o "$userinput" = "psychonauts" ] then echo "Your controller will now be configured for Psychonauts." echo cd modules ./psychonauts.sh -elif [ "$userinput" = 7 -o "$userinput" = "Amnesia" -o "$userinput" = "amnesia" ] +elif [ "$userinput" = 97 -o "$userinput" = "Amnesia" -o "$userinput" = "amnesia" ] then echo "Your controller will now be configured for Amnesia." echo diff --git a/modules/amnesia.sh b/modules/amnesia.sh index 675e703e42306c6a5c07f3d4432ab6591a1d317c..37abf82234c835d127ef30c9d42a6283fdd8d5c4 100755 --- a/modules/amnesia.sh +++ b/modules/amnesia.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c amnesia.xboxdrv -s +sudo xboxdrv$pad -c amnesia.xboxdrv -s --led 2 diff --git a/modules/braid.sh b/modules/braid.sh index 68466080daeedf7e3dbe1b4eea02c0a8d67bd3ca..06ba98da93bb93e16c8115551e86b76941011404 100755 --- a/modules/braid.sh +++ b/modules/braid.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c braid.xboxdrv -s +sudo xboxdrv$pad -c braid.xboxdrv -s --led 2 diff --git a/modules/eggnogg.sh b/modules/eggnogg.sh new file mode 100755 index 0000000000000000000000000000000000000000..276891c8fa97d7659e2eb789754fc912adea3a0b --- /dev/null +++ b/modules/eggnogg.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Define the default gamepad module name +module=xpad + +# Check if the module is already loaded, if so, remove it and run the xboxdrv module +if lsmod | grep -q "^$module " +then sudo rmmod xpad +fi + +if [ ! -e "$workingDirectory$killProcessesScript" ] +then + touch "$workingDirectory$killProcessesScript" +fi +sudo xboxdrv$pad -s -i 0 --led 2 & +echo "controller1 is being handled by process number $!" +if [ -f "$workingDirectory$killProcessesScript" ] +then + echo "sudo kill $!" > "$workingDirectory$killProcessesScript" +fi +sudo xboxdrv$pad -s -i 1 --led 3 & +echo "controller2 is being handled by process number $!" +if [ -f "$workingDirectory$killProcessesScript" ] +then + echo "sudo kill $!" >> "$workingDirectory$killProcessesScript" +fi \ No newline at end of file diff --git a/modules/limbo.sh b/modules/limbo.sh index 2aa5e1addabfaac681267a6eaacbcd5c5a0cecdd..016551ba2cf8c876d2c60636219bfa2a6abe3bbf 100755 --- a/modules/limbo.sh +++ b/modules/limbo.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c limbo.xboxdrv -s +sudo xboxdrv$pad -c limbo.xboxdrv -s --led 2 diff --git a/modules/lonesurvivor.sh b/modules/lonesurvivor.sh index bcb4984964b725adde7d3e0670a5dca95a151837..bbdbeb1bf4d5603f44e04c38de25717eb60811f0 100755 --- a/modules/lonesurvivor.sh +++ b/modules/lonesurvivor.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c lonesurvivor.xboxdrv -s +sudo xboxdrv$pad -c lonesurvivor.xboxdrv -s --led 2 diff --git a/modules/minecraft.sh b/modules/minecraft.sh index 58d8fdee17ab092e14da90df91f5c0009b51e552..31a8ba21e0f2435a41ac518c17f3ceb5e4dcd092 100755 --- a/modules/minecraft.sh +++ b/modules/minecraft.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c minecraft.xboxdrv -s +sudo xboxdrv$pad -c minecraft.xboxdrv -s --led 2 diff --git a/modules/psychonauts.sh b/modules/psychonauts.sh index 3a77bdb4851c11fa087a13b72b95db433f2042ee..a5288025e5c61e7e341fe0c3a56a54d600a8f470 100755 --- a/modules/psychonauts.sh +++ b/modules/psychonauts.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c psychonauts.xboxdrv -s +sudo xboxdrv$pad -c psychonauts.xboxdrv -s --led 2 diff --git a/modules/vvvvvv.sh b/modules/vvvvvv.sh index d04973620e3de20d1839ccd3a0fd6df861787764..5134dc4824e4dff6250fe0da30a31b562f3096e4 100755 --- a/modules/vvvvvv.sh +++ b/modules/vvvvvv.sh @@ -8,4 +8,4 @@ if lsmod | grep -q "^$module " then sudo rmmod xpad fi -sudo xboxdrv$pad -c vvvvvv.xboxdrv -s +sudo xboxdrv$pad --led 2 -c vvvvvv.xboxdrv -s diff --git a/modules/xpad.sh b/modules/xpad.sh index ed73b190a608d7977851eb1e6a785ec1db003302..d3309e0024feb7be55d29703009047fc13559b9a 100755 --- a/modules/xpad.sh +++ b/modules/xpad.sh @@ -4,7 +4,7 @@ module=xpad if lsmod | grep -q "^$module " then echo "Xpad already loaded." -else echo "Controller has been returned to normal function." -sudo modprobe xpad +else sudo modprobe xpad +echo "Controller has been returned to normal function." echo fi