control
control
/bin/bash
#
# SPDX-License-Identifier: MIT
#
# This file can and should be sourced by ports for various parameters to
# minimize script customizations and allow for easier future updates
# like adding additional supported devices.
# Thanks to JohnnyonFlame, dhwz, romadu, and shantigilbert for the
# suggestion and assistance with this.
# Source used for gptokeyb available at
# https://github.com/christianhaitian/gptokeyb
# Source used for oga_controls available at
# https://github.com/christianhaitian/oga_controls
if [ -f "/etc/os-release" ]; then
source /etc/os-release
fi
if [ -d "/PortMaster/" ]; then
controlfolder="/PortMaster"
elif [ -d "/opt/system/Tools/PortMaster/" ]; then
controlfolder="/opt/system/Tools/PortMaster"
elif [ -d "/opt/tools/PortMaster/" ]; then
controlfolder="/opt/tools/PortMaster"
else
controlfolder="/$directory/ports/PortMaster"
fi
SDLDBFILE="${SDL_GAMECONTROLLERCONFIG_FILE}"
[ -z "${SDLDBFILE}" ] && SDLDBFILE="${controlfolder}/gamecontrollerdb.txt"
SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/gamecontrollerdb.txt"
[ ! -f "${SDLDBUSERFILE}" ] &&
SDLDBUSERFILE="${controlfolder}/gamecontrollerdb.txt"
get_controls() {
ANALOGSTICKS="2"
LOWRES="N"
if [[ -e "/dev/input/by-path/platform-ff300000.usb-usb-0:1.2:1.0-event-
joystick" ]]; then
DEVICE="03000000091200000031000011010000"
param_device="anbernic"
LOWRES="Y"
if [ -f "/boot/rk3326-rg351v-linux.dtb" ] || [ $(cat
"/storage/.config/.OS_ARCH") == "RG351V" ]; then
ANALOGSTICKS="1"
LOWRES="N"
fi
elif [[ -e "/dev/input/by-path/platform-odroidgo2-joypad-event-joystick" ]]; then
if [[ ! -z $(cat /etc/emulationstation/es_input.cfg | grep
"190000004b4800000010000001010000") ]]; then
DEVICE="190000004b4800000010000001010000"
param_device="oga"
export HOTKEY="l3"
else
if [ -f "/usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0.2600.2" ]; then
DEVICE="19005b284b4800000010000000010000"
else
DEVICE="190000004b4800000010000000010000"
fi
param_device="rk2020"
fi
ANALOGSTICKS=1
LOWRES="Y"
elif [[ -e "/dev/input/by-path/platform-odroidgo3-joypad-event-joystick" ]]; then
DEVICE="190000004b4800000011000000010000"
param_device="ogs"
if [ "$(cat ~/.config/.OS)" == "ArkOS" ] && [ "$(cat ~/.config/.DEVICE)" ==
"RGB10MAX" ]; then
sed -i 's/back:b12,guide:b16,start:b13/back:b14,guide:b12,start:b15/' $
{controlfolder}/gamecontrollerdb.txt
sed -i 's/leftstick:b14,rightstick:b15/leftstick:b16,rightstick:b17/' $
{controlfolder}/gamecontrollerdb.txt
export HOTKEY="guide"
fi
if [[ -e "/opt/.retrooz/device" ]]; then
param_device="$(cat /opt/.retrooz/device)"
if [[ "$param_device" == *"rgb10max2native"* ]]; then
param_device="rgb10maxnative"
elif [[ "$param_device" == *"rgb10max2top"* ]]; then
param_device="rgb10maxtop"
fi
if [[ "$param_device" == *"rgb10maxnative"* ]]; then
sed -i 's/back:b12/back:b14/; s/guide:b16/guide:b12/;
s/guide:b14/guide:b12/; s/start:b13/start:b15/; s/leftstick:b14/leftstick:b16/;
s/rightstick:b15/rightstick:b17/' ${controlfolder}/gamecontrollerdb.txt
elif [[ "$param_device" == *"rgb10maxtop"* ]]; then
sed -i 's/back:b14/back:b12/; s/guide:b12/guide:b14/;
s/guide:b16/guide:b14/; s/start:b15/start:b13/; s/leftstick:b14/leftstick:b16/;
s/rightstick:b15/rightstick:b17/' ${controlfolder}/gamecontrollerdb.txt
elif [[ "$param_device" == *"ogs"* ]]; then
sed -i 's/back:b14/back:b12/; s/guide:b12/guide:b16/;
s/guide:b14/guide:b16/; s/start:b15/start:b13/; s/leftstick:b16/leftstick:b14/;
s/rightstick:b17/rightstick:b15/' ${controlfolder}/gamecontrollerdb.txt
fi
fi
elif [[ -e "/dev/input/by-path/platform-gameforce-gamepad-event-joystick" ]];
then
DEVICE="19000000030000000300000002030000"
param_device="chi"
export HOTKEY="l3"
elif [[ -e "/dev/input/by-path/platform-singleadc-joypad-event-joystick" ]]; then
DEVICE="190000004b4800000111000000010000"
param_device="rg552"
LOWRES="N"
else
DEVICE="${1}"
param_device="${2}"
fi
export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/gamecontrollerdb.txt"
# Spit the controller of the device our heuristics found (if it did).
if [[ ! -z ${DEVICE} ]]; then
grep "${SDLDBUSERFILE}" -e "${DEVICE}" > /tmp/gamecontrollerdb.txt
else
echo "" > /tmp/gamecontrollerdb.txt
fi
SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/gamecontrollerdb.txt"
sdl_controllerconfig="$(< "${SDL_GAMECONTROLLERCONFIG_FILE}")"
}
source $controlfolder/device_info.txt
source $controlfolder/funcs.txt
if [ ! -z "$ESUDO" ]; then
$ESUDO chmod 666 /dev/tty0
$ESUDO chmod 666 /dev/tty1
$ESUDO chmod 666 /dev/uinput
fi