Guest User

Untitled

a guest
Oct 21st, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # This file is part of The RetroPie Project
  4. #
  5. # The RetroPie Project is the legal property of its developers, whose names are
  6. # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
  7. #
  8. # See the LICENSE.md file at the top-level directory of this distribution and
  9. # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
  10. #
  11.  
  12. function onstart_dolphin_joystick() {
  13. # write a temp file that will become the Controller Profile
  14. cat <<EOF > /tmp/gctempconfig.cfg
  15. [Profile]
  16. Device = evdev/0/${DEVICE_NAME}
  17. Main Stick/Calibration = 100.00 141.42 100.00 141.42 100.00 141.42 100.00 141.42
  18. C-Stick/Calibration = 100.00 141.42 100.00 141.42 100.00 141.42 100.00 141.42
  19. EOF
  20. }
  21.  
  22.  
  23. function map_dolphin_joystick() {
  24. local input_name="$1"
  25. local input_type="$2"
  26. local input_id="$3"
  27. local input_value="$4"
  28.  
  29. local keys
  30. local dir
  31. case "$input_name" in
  32. up)
  33. keys=("D-Pad/Up")
  34. dir=("Up")
  35. ;;
  36. down)
  37. keys=("D-Pad/Down")
  38. dir=("Down")
  39. ;;
  40. left)
  41. keys=("D-Pad/Left")
  42. dir=("Left")
  43. ;;
  44. right)
  45. keys=("D-Pad/Right")
  46. dir=("Right")
  47. ;;
  48. b)
  49. keys=("Buttons/B")
  50. ;;
  51. y)
  52. keys=("Buttons/Y")
  53. ;;
  54. a)
  55. keys=("Buttons/A")
  56. ;;
  57. x)
  58. keys=("Buttons/X")
  59. ;;
  60. leftbottom|leftshoulder)
  61. keys=("Triggers/L")
  62. ;;
  63. rightbottom|rightshoulder)
  64. keys=("Triggers/R")
  65. ;;
  66. righttop|righttrigger)
  67. keys=("Buttons/Z")
  68. ;;
  69. start)
  70. keys=("Buttons/Start")
  71. ;;
  72. leftanalogleft)
  73. keys=("Main Stick/Left")
  74. dir=("Left")
  75. ;;
  76. leftanalogright)
  77. keys=("Main Stick/Right")
  78. dir=("Right")
  79. ;;
  80. leftanalogup)
  81. keys=("Main Stick/Up")
  82. dir=("Up")
  83. ;;
  84. leftanalogdown)
  85. keys=("Main Stick/Down")
  86. dir=("Down")
  87. ;;
  88. rightanalogleft)
  89. keys=("C-Stick/Left")
  90. dir=("Left")
  91. ;;
  92. rightanalogright)
  93. keys=("C-Stick/Right")
  94. dir=("Right")
  95. ;;
  96. rightanalogup)
  97. keys=("C-Stick/Up")
  98. dir=("Up")
  99. ;;
  100. rightanalogdown)
  101. keys=("C-Stick/Down")
  102. dir=("Down")
  103. ;;
  104. *)
  105. return
  106. ;;
  107. esac
  108.  
  109. local key
  110. local value
  111. #iniConfig " = " "" "/tmp/gckeys.cfg"
  112. for key in "${keys[@]}"; do
  113. # read key value. Axis takes two key/axis values.
  114. iniGet "$key"
  115. case "$input_type" in
  116. axis)
  117. # key "X/Y Axis" needs different button naming
  118. if [[ "$key" == *Axis* ]]; then
  119. # if there is already a "-" axis add "+" axis value
  120. if [[ "$ini_value" == *\(* ]]; then
  121. value="${ini_value}\`Axis ${input_id}+\`"
  122. # if there is already a "+" axis add "-" axis value
  123. elif [[ "$ini_value" == *\)* ]]; then
  124. value="\`Axis ${input_id}-\`, ${ini_value}"
  125. # if there is no ini_value add "+" axis value
  126. elif [[ "$input_value" == "1" ]]; then
  127. value="\`Axis ${input_id}+\`"
  128. else
  129. value="\`Axis ${input_id}-\`"
  130. fi
  131. elif [[ "$input_value" == "1" ]]; then
  132. value="\`Axis ${input_id}+\` ${ini_value}"
  133. else
  134. value="\`Axis ${input_id}-\` ${ini_value}"
  135. fi
  136. ;;
  137. hat)
  138. if [[ "$key" == *Axis* ]]; then
  139. if [[ "$ini_value" == *\(* ]]; then
  140. value="${ini_value}\`Hat ${input_id} ${dir}\`"
  141. elif [[ "$ini_value" == *\)* ]]; then
  142. value="\`Hat ${input_id} ${dir}\`, ${ini_value}"
  143. elif [[ "$dir" == "Up" || "$dir" == "Left" ]]; then
  144. value="\`Hat ${input_id} ${dir}\`"
  145. elif [[ "$dir" == "Right" || "$dir" == "Down" ]]; then
  146. value="\`${dir}\`"
  147. fi
  148. else
  149. if [[ -n "$dir" ]]; then
  150. value="\`Hat ${input_id} ${dir}\` ${ini_value}"
  151. fi
  152. fi
  153. ;;
  154. *)
  155. if [[ "$key" == *Axis* ]]; then
  156. if [[ "$ini_value" == *\(* ]]; then
  157. value="${ini_value}\`Button ${input_id}\`"
  158. elif [[ "$ini_value" == *\)* ]]; then
  159. value="\`Button ${input_id}\`, ${ini_value}"
  160. elif [[ "$dir" == "Up" || "$dir" == "Left" ]]; then
  161. value="\`Button ${input_id}\`"
  162. elif [[ "$dir" == "Right" || "$dir" == "Down" ]]; then
  163. value="\`${input_id}\`"
  164. fi
  165. else
  166. value="\`Button ${input_id}\` ${ini_value}"
  167. fi
  168. ;;
  169. esac
  170.  
  171. iniSet "$key" "$value"
  172. done
  173. }
  174.  
  175. function onend_dolphin_joystick() {
  176. local bind
  177. local axis
  178. local axis_neg
  179. local axis_pos
  180. for axis in "X Axis" "Y Axis"; do
  181. if [[ "$axis" == *X* ]]; then
  182. axis_neg="D-Pad/Left"
  183. axis_pos="D-Pad/Right"
  184. else
  185. axis_neg="D-Pad/Up"
  186. axis_pos="D-Pad/Down"
  187. fi
  188.  
  189. # analog stick sanity check
  190. # replace Axis values with DPAD values if there is no Axis
  191. # device setup
  192. if ! grep -q "$axis" /tmp/gctempconfig.cfg ; then
  193. iniGet "${axis_neg}"
  194. bind=${ini_value//)/,}
  195. iniGet "${axis_pos}"
  196. ini_value=${ini_value//axis(/}
  197. ini_value=${ini_value//hat(/}
  198. ini_value=${ini_value//button(/}
  199. bind="${bind}${ini_value}"
  200. iniSet "$axis" "$bind"
  201. iniDel "${axis_neg}"
  202. iniDel "${axis_pos}"
  203. fi
  204. done
  205.  
  206. # disable any auto configs for the same device to avoid duplicates
  207. local file
  208. local dir="$configdir/gc/Config/Profiles/GCpad"
  209. while read -r file; do
  210. mv "$file" "$file.bak"
  211. done < <(grep -Fl "\"$DEVICE_NAME\"" "$dir/"*.ini 2>/dev/null)
  212.  
  213. # sanitise filename
  214. file="${DEVICE_NAME//[:><?\"\/\\|*]/}.ini"
  215.  
  216. if [[ -f "$dir/$file" ]]; then
  217. mv "$dir/$file" "$dir/$file.bak"
  218. fi
  219. mv "/tmp/gctempconfig.cfg" "$dir/$file"
  220. }
  221.  
Advertisement
Add Comment
Please, Sign In to add comment