Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # This file is part of The RetroPie Project
- #
- # The RetroPie Project is the legal property of its developers, whose names are
- # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
- #
- # See the LICENSE.md file at the top-level directory of this distribution and
- # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
- #
- function onstart_dolphin_joystick() {
- # write a temp file that will become the Controller Profile
- cat <<EOF > /tmp/gctempconfig.cfg
- [Profile]
- Device = evdev/0/${DEVICE_NAME}
- Main Stick/Calibration = 100.00 141.42 100.00 141.42 100.00 141.42 100.00 141.42
- C-Stick/Calibration = 100.00 141.42 100.00 141.42 100.00 141.42 100.00 141.42
- EOF
- }
- function map_dolphin_joystick() {
- local input_name="$1"
- local input_type="$2"
- local input_id="$3"
- local input_value="$4"
- local keys
- local dir
- case "$input_name" in
- up)
- keys=("D-Pad/Up")
- dir=("Up")
- ;;
- down)
- keys=("D-Pad/Down")
- dir=("Down")
- ;;
- left)
- keys=("D-Pad/Left")
- dir=("Left")
- ;;
- right)
- keys=("D-Pad/Right")
- dir=("Right")
- ;;
- b)
- keys=("Buttons/B")
- ;;
- y)
- keys=("Buttons/Y")
- ;;
- a)
- keys=("Buttons/A")
- ;;
- x)
- keys=("Buttons/X")
- ;;
- leftbottom|leftshoulder)
- keys=("Triggers/L")
- ;;
- rightbottom|rightshoulder)
- keys=("Triggers/R")
- ;;
- righttop|righttrigger)
- keys=("Buttons/Z")
- ;;
- start)
- keys=("Buttons/Start")
- ;;
- leftanalogleft)
- keys=("Main Stick/Left")
- dir=("Left")
- ;;
- leftanalogright)
- keys=("Main Stick/Right")
- dir=("Right")
- ;;
- leftanalogup)
- keys=("Main Stick/Up")
- dir=("Up")
- ;;
- leftanalogdown)
- keys=("Main Stick/Down")
- dir=("Down")
- ;;
- rightanalogleft)
- keys=("C-Stick/Left")
- dir=("Left")
- ;;
- rightanalogright)
- keys=("C-Stick/Right")
- dir=("Right")
- ;;
- rightanalogup)
- keys=("C-Stick/Up")
- dir=("Up")
- ;;
- rightanalogdown)
- keys=("C-Stick/Down")
- dir=("Down")
- ;;
- *)
- return
- ;;
- esac
- local key
- local value
- #iniConfig " = " "" "/tmp/gckeys.cfg"
- for key in "${keys[@]}"; do
- # read key value. Axis takes two key/axis values.
- iniGet "$key"
- case "$input_type" in
- axis)
- # key "X/Y Axis" needs different button naming
- if [[ "$key" == *Axis* ]]; then
- # if there is already a "-" axis add "+" axis value
- if [[ "$ini_value" == *\(* ]]; then
- value="${ini_value}\`Axis ${input_id}+\`"
- # if there is already a "+" axis add "-" axis value
- elif [[ "$ini_value" == *\)* ]]; then
- value="\`Axis ${input_id}-\`, ${ini_value}"
- # if there is no ini_value add "+" axis value
- elif [[ "$input_value" == "1" ]]; then
- value="\`Axis ${input_id}+\`"
- else
- value="\`Axis ${input_id}-\`"
- fi
- elif [[ "$input_value" == "1" ]]; then
- value="\`Axis ${input_id}+\` ${ini_value}"
- else
- value="\`Axis ${input_id}-\` ${ini_value}"
- fi
- ;;
- hat)
- if [[ "$key" == *Axis* ]]; then
- if [[ "$ini_value" == *\(* ]]; then
- value="${ini_value}\`Hat ${input_id} ${dir}\`"
- elif [[ "$ini_value" == *\)* ]]; then
- value="\`Hat ${input_id} ${dir}\`, ${ini_value}"
- elif [[ "$dir" == "Up" || "$dir" == "Left" ]]; then
- value="\`Hat ${input_id} ${dir}\`"
- elif [[ "$dir" == "Right" || "$dir" == "Down" ]]; then
- value="\`${dir}\`"
- fi
- else
- if [[ -n "$dir" ]]; then
- value="\`Hat ${input_id} ${dir}\` ${ini_value}"
- fi
- fi
- ;;
- *)
- if [[ "$key" == *Axis* ]]; then
- if [[ "$ini_value" == *\(* ]]; then
- value="${ini_value}\`Button ${input_id}\`"
- elif [[ "$ini_value" == *\)* ]]; then
- value="\`Button ${input_id}\`, ${ini_value}"
- elif [[ "$dir" == "Up" || "$dir" == "Left" ]]; then
- value="\`Button ${input_id}\`"
- elif [[ "$dir" == "Right" || "$dir" == "Down" ]]; then
- value="\`${input_id}\`"
- fi
- else
- value="\`Button ${input_id}\` ${ini_value}"
- fi
- ;;
- esac
- iniSet "$key" "$value"
- done
- }
- function onend_dolphin_joystick() {
- local bind
- local axis
- local axis_neg
- local axis_pos
- for axis in "X Axis" "Y Axis"; do
- if [[ "$axis" == *X* ]]; then
- axis_neg="D-Pad/Left"
- axis_pos="D-Pad/Right"
- else
- axis_neg="D-Pad/Up"
- axis_pos="D-Pad/Down"
- fi
- # analog stick sanity check
- # replace Axis values with DPAD values if there is no Axis
- # device setup
- if ! grep -q "$axis" /tmp/gctempconfig.cfg ; then
- iniGet "${axis_neg}"
- bind=${ini_value//)/,}
- iniGet "${axis_pos}"
- ini_value=${ini_value//axis(/}
- ini_value=${ini_value//hat(/}
- ini_value=${ini_value//button(/}
- bind="${bind}${ini_value}"
- iniSet "$axis" "$bind"
- iniDel "${axis_neg}"
- iniDel "${axis_pos}"
- fi
- done
- # disable any auto configs for the same device to avoid duplicates
- local file
- local dir="$configdir/gc/Config/Profiles/GCpad"
- while read -r file; do
- mv "$file" "$file.bak"
- done < <(grep -Fl "\"$DEVICE_NAME\"" "$dir/"*.ini 2>/dev/null)
- # sanitise filename
- file="${DEVICE_NAME//[:><?\"\/\\|*]/}.ini"
- if [[ -f "$dir/$file" ]]; then
- mv "$dir/$file" "$dir/$file.bak"
- fi
- mv "/tmp/gctempconfig.cfg" "$dir/$file"
- }
Advertisement
Add Comment
Please, Sign In to add comment