Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # AUTHOR: Frash Pikass
- # DESCRIPTION:
- # This script does the following
- # 0. Writes the correct script to use the Classic Controller in /tmp/gamepad
- # 1. Starts the kernel module 'uinput' in order to accept joysticks
- # 2. Starts wminput Wiimote driver to use classic controller as a driver
- # 3. Check if wiimotes are connected
- # 4.1 If a wiimote is connected start zsnes
- # 4.2 If a wiimote is not connected tell the user
- # 5. Make sure wiimote processes are killed after zsnes stopped running
- #
- # DEPENDENCIES:
- # wminput
- # zsnes
- # bluez
- #
- # 0. Creates the gamepad script
- cat <<EOF > /tmp/gamepad
- # gameport
- Classic.Dpad.X = ABS_HAT0X
- Classic.Dpad.Y = ABS_HAT0Y
- Classic.LStick.X = ABS_X
- Classic.LStick.Y = ABS_Y
- Classic.RStick.X = ABS_RX
- Classic.RStick.Y = ABS_RY
- Classic.A = BTN_A
- Classic.B = BTN_B
- Classic.X = BTN_X
- Classic.Y = BTN_Y
- Classic.Minus = BTN_SELECT
- Classic.Plus = BTN_START
- Classic.Home = BTN_MODE
- Classic.L = BTN_TL
- Classic.R = BTN_TR
- Classic.ZL = BTN_TL2
- Classic.ZR = BTN_TR2
- EOF
- # 1. Starts uinput
- sudo modprobe uinput
- echo "This script\'s PID is $$"
- echo Push 1 and 2 on the Wiimote
- sleep 1
- # 2. Waits for wiimote connection and starts wminput
- sudo wminput -c /tmp/gamepad > /dev/null 2>&1 &
- # Saves the PID of sudo
- PIDsudo=$!
- # Saves the PID of wminput
- # (which is the only PID shown by ps with parent PID==$PIDsudo)
- sleep 1
- PIDwminput=$(ps --ppid $PIDsudo -o pid=)
- echo "PID numbers: sudo=$PIDsudo; wminput=$PIDwminput"
- # Waits for connection
- sleep 8
- # 3. Tests wminput to see if it's alive (which means a wiimote is connected)
- sudo kill -0 $PIDwminput
- if [ $? -eq 0 ]
- then
- # 4.1 If wminput is alive start zsnes
- echo wminput process $PIDwminput is alive and running ':)'
- sudo zsnes -ad sdl -r 5
- # Kill wiimote processes for memory/battery saving
- sleep 1
- $(sudo kill -9 $PIDsudo $PIDwminput) > /dev/null 2>&1
- exit 0
- else
- # 4.2 If wminput is dead, exit with status 1
- echo wminput process $PIDwminput could not be run ':('
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement