Skip to content

Commit

Permalink
Added EmuELEC support, updated gptokeyb, fixed bug in port requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
kloptops authored Nov 11, 2023
2 parents 8255faa + 697d3b1 commit 46ea038
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ config/


ports/
ports_scripts/
themes/
*.squashfs
*.squashfs.md5
Expand Down
15 changes: 12 additions & 3 deletions PortMaster/control.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,19 @@ else
DEVICE="${1}"
param_device="${2}"
fi
export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/gamecontrollerdb.txt"

CONTROLS=`grep "${SDLDBUSERFILE}" -e "${DEVICE}"`
[ -z "${CONTROLS}" ] && CONTROLS=`grep "${SDLDBFILE}" -e "${DEVICE}"`
sdl_controllerconfig="${CONTROLS}"
# 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

$controlfolder/mapper.txt /tmp/gamecontrollerdb.txt > /dev/null 2>&1
SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/gamecontrollerdb.txt"

sdl_controllerconfig="$(< "${SDL_GAMECONTROLLERCONFIG_FILE}")"
}

GPTOKEYB="$ESUDO $controlfolder/gptokeyb $ESUDOKILL"
Binary file modified PortMaster/gptokeyb
Binary file not shown.
135 changes: 135 additions & 0 deletions PortMaster/mapper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

# -- Config & Setup --
# Destination file
if [[ -z "$1" ]]; then
echo "Usage: mapper [gamecontrollerdb.txt]"
exit -1
fi

CONTROLLER_DB="$1"
if [[ ! -f "${CONTROLLER_DB}" ]]; then
echo "File ${CONTROLLER_DB} does not exist."
exit -1
fi

# Where the emulationstation configuration file is
ES_CONFIG="${HOME}/.config/emulationstation/es_input.cfg"

# -- Helper function --
# Map the actual button/hat/axis
function map {
INPUT_NAME=$1
TYPE=$2
ID=$3
VALUE=$4

map_x_result=""
case "${INPUT_NAME}" in
"b") TR_NAME="a";;
"a") TR_NAME="b";;
"y") TR_NAME="x";;
"x") TR_NAME="y";;
"hotkeyenable") TR_NAME="guide";;
"up") TR_NAME="dpup";;
"down") TR_NAME="dpdown";;
"left") TR_NAME="dpleft";;
"right") TR_NAME="dpright";;
"leftshoulder") TR_NAME="leftshoulder";;
"leftthumb") TR_NAME="leftstick";;
"lefttrigger") TR_NAME="lefttrigger";;
"rightshoulder") TR_NAME="rightshoulder";;
"rightthumb") TR_NAME="rightstick";;
"righttrigger") TR_NAME="righttrigger";;
"select") TR_NAME="back";;
"start") TR_NAME="start";;
"leftanalogup") TR_NAME="-lefty";;
"leftanalogleft") TR_NAME="-leftx";;
"leftanalogdown") TR_NAME="+lefty";;
"leftanalogright") TR_NAME="+leftx";;
"rightanalogup") TR_NAME="-righty";;
"rightanalogleft") TR_NAME="-rightx";;
"rightanalogdown") TR_NAME="+righty";;
"rightanalogright") TR_NAME="+rightx";;
*)
echo "Invalid mapping ${INPUT_NAME}."
return
;;
esac

case "${TYPE}" in
"axis")
if (( $VALUE < 0 )); then
map_x_result="${TR_NAME}:${map_x_result}-a${ID},"
else
# Most (save for a few misbehaved children...) triggers are [0, 1] instead of [-1, 1]
# Shitty workaround for an emulationstation issue
if [[ $INPUT_NAME =~ .*"trigger" ]]; then
map_x_result="${TR_NAME}:${map_x_result}a${ID},"
else
map_x_result="${TR_NAME}:${map_x_result}+a${ID},"
fi
fi
;;
"button")
map_x_result="${TR_NAME}:${map_x_result}b${ID},"
;;
"hat")
map_x_result="${TR_NAME}:${map_x_result}h${ID}.${VALUE},"
;;
*)
echo "Invalid entry ${TYPE}"
;;
esac
}

function get_map_suffix {
map_suffix="platform:Linux,"
}

function get_map_prefix {
map_prefix="${GUID},${NAME},"
}

# query controllers mapped in emulationstation, ignore devices without a GUID
ES_QUERY="$(xmlstarlet sel -T -t -m "inputList/inputConfig[@deviceGUID!='']" -n -v "concat(@deviceName,';',@deviceGUID)" $ES_CONFIG)"
printf "\n# Custom Entries\n" >> "${CONTROLLER_DB}"

echo "## ES Dev Mapper ##"
while IFS=";" read -r NAME GUID; do
echo "$NAME :: $GUID"
# Ignore keyboards
if [[ "${GUID}" == -1 ]]; then
continue
fi

# Check if GUID exists in gamecontrollerdb.txt
if [ -z "$(fgrep -- ${GUID} "${CONTROLLER_DB}")" ]; then
# Query this specific GUID on the mappings
MAPPING_CFG=$(xmlstarlet sel -T -t -m "//inputConfig[@deviceGUID = '${GUID}']/input" -n -v "concat(@name,';',@type,';',@id,';',@value)" $ES_CONFIG)

MAPPING=""
while IFS=";" read -r -e INPUT_NAME TYPE ID VALUE; do
# Map the controller
map "${INPUT_NAME}" "${TYPE}" "${ID}" "${VALUE}"

# Only concatenate valid mappings
if [[ ! -z ${map_x_result} ]]; then
MAPPING="${MAPPING}${map_x_result}"
fi
done <<< ${MAPPING_CFG:1}

get_map_prefix
get_map_suffix
if [[ ! -z "${MAPPING}" ]]; then
echo "${map_prefix}${MAPPING}${map_suffix}" >> "${CONTROLLER_DB}"
echo "${map_prefix}${MAPPING}${map_suffix}"
echo ""
else
echo "Failed to map anything."
echo ""
fi
else
echo "Already mapped..."
fi
done <<< ${ES_QUERY:1}
2 changes: 1 addition & 1 deletion PortMaster/pugwash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

## -- BEGIN PORTMASTER INFO --
PORTMASTER_VERSION = '8.5.4'
PORTMASTER_VERSION = '8.5.5'
PORTMASTER_RELEASE_CHANNEL = 'beta'
## -- END PORTMASTER INFO --

Expand Down
2 changes: 2 additions & 0 deletions PortMaster/pylibs/harbourmaster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from .config import (
HM_DEFAULT_PORTS_DIR,
HM_DEFAULT_SCRIPTS_DIR,
HM_DEFAULT_TOOLS_DIR,
HM_GENRES,
HM_PORTS_DIR,
HM_SCRIPTS_DIR,
HM_SORT_ORDER,
HM_SOURCE_DEFAULTS,
HM_TESTING,
Expand Down
26 changes: 26 additions & 0 deletions PortMaster/pylibs/harbourmaster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

HM_TOOLS_DIR=None
HM_PORTS_DIR=None
HM_SCRIPTS_DIR=None
HM_UPDATE_FREQUENCY=(60 * 60 * 1) # Only check automatically once per hour.

HM_TESTING=False
Expand All @@ -25,6 +26,7 @@
################################################################################
## The following code is a simplification of the PortMaster toolsloc and whichsd code.
HM_DEFAULT_PORTS_DIR = Path("/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/roms/ports")
HM_DEFAULT_TOOLS_DIR = Path("/roms/ports")

if (Path().cwd() / '..' / '.git').is_dir():
Expand All @@ -34,19 +36,26 @@
## For testing
HM_DEFAULT_TOOLS_DIR = Path('.').absolute()
HM_DEFAULT_PORTS_DIR = Path('ports/').absolute()
HM_DEFAULT_SCRIPTS_DIR = Path('ports_scripts/').absolute()
HM_TESTING=True
elif Path("/opt/tools/PortMaster/").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/opt/tools")
elif Path("/opt/system/Tools/PortMaster/").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/opt/system/Tools")
elif Path("/storage/roms/ports_scripts").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_PORTS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/storage/roms/ports_scripts")
elif Path("/storage/roms/ports").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_PORTS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/storage/roms/ports")
else:
HM_DEFAULT_TOOLS_DIR = Path("/roms/ports")

if Path("/roms2/ports").is_dir():
HM_DEFAULT_PORTS_DIR = Path("/roms2/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/roms2/ports")

## Default TOOLS_DIR
if HM_TOOLS_DIR is None:
Expand Down Expand Up @@ -79,6 +88,21 @@
logger.error(f"{HM_PORTS_DIR!r} is set to something weird.")
exit(255)

## Default TOOLS_DIR
if HM_SCRIPTS_DIR is None:
if 'HM_SCRIPTS_DIR' in os.environ:
HM_SCRIPTS_DIR = Path(os.environ['HM_SCRIPTS_DIR'])
else:
HM_SCRIPTS_DIR = HM_DEFAULT_SCRIPTS_DIR
elif isinstance(HM_SCRIPTS_DIR, str):
HM_SCRIPTS_DIR = Path(HM_SCRIPTS_DIR).resolve()
elif isinstance(HM_SCRIPTS_DIR, pathlib.PurePath):
# This is good.
pass
else:
logger.error(f"{HM_SCRIPTS_DIR!r} is set to something weird.")
exit(255)


if 'HM_PERFTEST' in os.environ:
HM_PERFTEST=True
Expand Down Expand Up @@ -139,9 +163,11 @@
__all__ = (
'HM_DEFAULT_PORTS_DIR',
'HM_DEFAULT_TOOLS_DIR',
'HM_DEFAULT_SCRIPTS_DIR',
'HM_GENRES',
'HM_PERFTEST',
'HM_PORTS_DIR',
'HM_SCRIPTS_DIR',
'HM_SORT_ORDER',
'HM_SOURCE_DEFAULTS',
'HM_TESTING',
Expand Down
Loading

0 comments on commit 46ea038

Please sign in to comment.