distribution/packages/emulators/standalone/retroarch/scripts/mkcontroller
2023-04-22 20:55:24 +00:00

84 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2020-present Fewtarius
TMPFILE=$(uuidgen)
OUTFILE=$(uuidgen)
CONTROLLER=$(grep -b4 js0 /proc/bus/input/devices | awk 'BEGIN {FS="\""}; /Name/ {printf $2}')
xmlstarlet sel -t \
-m "/inputList/inputConfig[@deviceName='${CONTROLLER}']/input" \
-v "concat(@name,'|',@type,'|',@id,'|',@value)" \
-n /storage/.config/emulationstation/es_input.cfg >/tmp/${TMPFILE}
while read -r line
do
BTN=$(echo ${line} | awk 'BEGIN { FS="|" } {print $1}')
TYPE=$(echo ${line} | awk 'BEGIN { FS="|" } {print $2}')
ID=$(echo ${line} | awk 'BEGIN {FS="|" } {print $3}')
VALUE=$(echo ${line} | awk 'BEGIN { FS="|" } {print $4}')
if [ "${TYPE}" == "axis" ]
then
if [[ "${VALUE}" =~ ^[0-9] ]]
then
ID="+${ID}"
else
ID="-${ID}"
fi
elif [ "${TYPE}" == "hat" ]
then
ID="h${ID}${BTN}"
fi
if [[ ${BTN} == "pagedown" ]]
then
BTN="leftshoulder"
elif [[ ${BTN} == "pageup" ]]
then
BTN="rightshoulder"
elif [[ ${BTN} == "l2" ]]
then
BTN="lefttrigger"
elif [[ ${BTN} == "r2" ]]
then
BTN="righttrigger"
elif [[ ${BTN} == "l3" ]]
then
BTN="leftthumb"
elif [[ ${BTN} == "r3" ]]
then
BTN="rightthumb"
fi
echo "${BTN}=${ID}" >>/tmp/${OUTFILE}
done < /tmp/${TMPFILE}
rm -f /tmp/${TMPFILE}
source /tmp/${OUTFILE}
echo "${CONTROLLER}" >/storage/.controller
cat <<EOF >/storage/.config/profile.d/98-controller
DEVICE_BTN_SOUTH="${b}"
DEVICE_BTN_EAST="${a}"
DEVICE_BTN_NORTH="${x}"
DEVICE_BTN_WEST="${y}"
DEVICE_BTN_TL="${leftshoulder}"
DEVICE_BTN_TR="${rightshoulder}"
DEVICE_BTN_TL2="${lefttrigger}"
DEVICE_BTN_TR2="${righttrigger}"
DEVICE_BTN_SELECT="${select}"
DEVICE_BTN_START="${start}"
DEVICE_BTN_MODE="${hotkeyenable}"
DEVICE_BTN_THUMBL="${leftthumb}"
DEVICE_BTN_THUMBR="${rightthumb}"
DEVICE_BTN_DPAD_UP="${up}"
DEVICE_BTN_DPAD_DOWN="${down}"
DEVICE_BTN_DPAD_LEFT="${left}"
DEVICE_BTN_DPAD_RIGHT="${right}"
EOF
### Link jslisten to load after mkcontroller
ln -sf /usr/config/jslisten_profile /storage/.config/profile.d/99-jslisten
rm /tmp/${OUTFILE}