Advertisement
Frash

Wii Classic Controller with ZSNES on Linux

Jan 20th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.03 KB | None | 0 0
  1. #!/bin/bash
  2. # AUTHOR: Frash Pikass
  3. # DESCRIPTION:
  4. #   This script does the following
  5. #   0. Writes the correct script to use the Classic Controller in /tmp/gamepad
  6. #   1. Starts the kernel module 'uinput' in order to accept joysticks
  7. #   2. Starts wminput Wiimote driver to use classic controller as a driver
  8. #   3. Check if wiimotes are connected
  9. #   4.1 If a wiimote is connected start zsnes
  10. #   4.2 If a wiimote is not connected tell the user
  11. #   5. Make sure wiimote processes are killed after zsnes stopped running
  12. #      
  13. # DEPENDENCIES:
  14. #   wminput
  15. #   zsnes
  16. #   bluez
  17. #
  18.  
  19. # 0. Creates the gamepad script
  20. cat <<EOF > /tmp/gamepad
  21. # gameport
  22. Classic.Dpad.X = ABS_HAT0X
  23. Classic.Dpad.Y = ABS_HAT0Y
  24. Classic.LStick.X = ABS_X
  25. Classic.LStick.Y = ABS_Y
  26. Classic.RStick.X = ABS_RX
  27. Classic.RStick.Y = ABS_RY
  28. Classic.A = BTN_A
  29. Classic.B = BTN_B
  30. Classic.X = BTN_X
  31. Classic.Y = BTN_Y
  32. Classic.Minus = BTN_SELECT
  33. Classic.Plus  = BTN_START
  34. Classic.Home  = BTN_MODE
  35. Classic.L  = BTN_TL
  36. Classic.R  = BTN_TR
  37. Classic.ZL = BTN_TL2
  38. Classic.ZR = BTN_TR2
  39. EOF
  40.  
  41. # 1. Starts uinput
  42. sudo modprobe uinput
  43. echo "This script\'s PID is $$"
  44. echo Push 1 and 2 on the Wiimote
  45. sleep 1
  46.  
  47. # 2. Waits for wiimote connection and starts wminput
  48. sudo wminput -c /tmp/gamepad > /dev/null 2>&1 &
  49.  
  50. # Saves the PID of sudo
  51. PIDsudo=$!
  52. # Saves the PID of wminput
  53. # (which is the only PID shown by ps with parent PID==$PIDsudo)
  54. sleep 1
  55. PIDwminput=$(ps --ppid $PIDsudo -o pid=)
  56. echo "PID numbers: sudo=$PIDsudo; wminput=$PIDwminput"
  57.  
  58. # Waits for connection
  59. sleep 8
  60.  
  61. # 3. Tests wminput to see if it's alive (which means a wiimote is connected)
  62. sudo kill -0 $PIDwminput
  63.  
  64. if [ $? -eq 0 ]
  65.     then
  66.         # 4.1 If wminput is alive start zsnes
  67.         echo wminput process $PIDwminput is alive and running ':)'
  68.         sudo zsnes -ad sdl -r 5
  69.        
  70.         # Kill wiimote processes for memory/battery saving     
  71.         sleep 1    
  72.         $(sudo kill -9 $PIDsudo $PIDwminput) > /dev/null 2>&1
  73.         exit 0
  74.     else
  75.         # 4.2 If wminput is dead, exit with status 1       
  76.         echo wminput process $PIDwminput could not be run ':('
  77.         exit 1
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement