Skip to content

Commit

Permalink
Merge pull request #183 from kloptops/main
Browse files Browse the repository at this point in the history
Fixed some stuff with Batocera/Knulli, fixed device_info.txt
  • Loading branch information
kloptops authored Nov 10, 2024
2 parents 261ff0f + 4ffc92d commit 6a5cd55
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 60 deletions.
6 changes: 3 additions & 3 deletions PortMaster/PortMaster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ elif [ -f "${controlfolder}/.emulationstation-refresh" ]; then
$ESUDO systemctl restart emulationstation
elif [ -f "${controlfolder}/.batocera-es-refresh" ]; then
$ESUDO rm -f "${controlfolder}/.batocera-es-refresh"
if [ ! -e "/lib/ld-linux-x86-64.so.2" ]; then
batocera-es-swissknife --restart
fi
# BROKEN :(
# batocera-es-swissknife --restart
curl http://localhost:1234/reloadgames
fi
34 changes: 18 additions & 16 deletions PortMaster/batocera/control.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ directory="userdata/roms"
ESUDO=""
ESUDOKILL="-1" # for 351Elec and EmuELEC use "-1" (numeric one) or "-k"

# Install our own shGenerator.py
if ! grep 'gamecontrollerdb.txt' /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py; then
cp -f /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py.bak

if ! grep 'from generators.Generator import Generator' /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py; then
# New style relative imports
cp -f $controlfolder/batocera/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py
else
# Old style absolute imports
cp -f $controlfolder/knulli/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py
fi

batocera-save-overlay
fi

if [ -f "$HOME/.config/gamecontrollerdb.txt" ]; then
export SDL_GAMECONTROLLERCONFIG_FILE="$HOME/.config/gamecontrollerdb.txt"
# elif [ -f "/usr/share/sdl-jstest/gamecontrollerdb.txt" ]; then
# export SDL_GAMECONTROLLERCONFIG_FILE="/usr/share/sdl-jstest/gamecontrollerdb.txt"
elif [ -f "/tmp/gamecontrollerdb.txt" ]; then
export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/gamecontrollerdb.txt"
else
export SDL_GAMECONTROLLERCONFIG_FILE="/$controlfolder/batocera/gamecontrollerdb.txt"
fi
Expand All @@ -22,24 +37,11 @@ SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/gamecontrollerdb.txt"

get_controls() {
# TODO: figure out SDL_GAMECONTROLLERCONFIG
ANALOGSTICKS="2"
ANALOGSTICKS="${ANALOG_STICKS:-2}"
LOWRES="N"

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

if [ -f "$controlfolder/cwtbe_flag" ]; then
if [ -f "${HOME}/configs/emulationstation/es_input.cfg" ]; then
$controlfolder/mapper.py /tmp/gamecontrollerdb.txt > /dev/null 2>&1
fi
fi

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

Expand Down
39 changes: 39 additions & 0 deletions PortMaster/batocera/shGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

from ... import Command
from ...controller import generate_sdl_game_controller_config, write_sdl_controller_db
from ..Generator import Generator

if TYPE_CHECKING:
from ...types import HotkeysContext


class ShGenerator(Generator):

def getHotkeysContext(self) -> HotkeysContext:
return {
"name": "shell",
"keys": { "exit": ["KEY_LEFTALT", "KEY_F4"] }
}

def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):
rom_path = Path(rom)

# in case of squashfs, the root directory is passed
runsh = rom_path / "run.sh"
shrom = runsh if runsh.exists() else rom_path

# Fixes stuff on PortMaster
dbfile = "/tmp/gamecontrollerdb.txt"
write_sdl_controller_db(playersControllers, dbfile)

commandArray = ["/bin/bash", shrom]
return Command.Command(array=commandArray,env={
"SDL_GAMECONTROLLERCONFIG": generate_sdl_game_controller_config(playersControllers)
})

def getMouseMode(self, config, rom):
return True
82 changes: 65 additions & 17 deletions PortMaster/device_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if [ ! -z "$DEVICE_INFO_VERSION" ]; then
return
fi

DEVICE_INFO_VERSION="0.1.11"
DEVICE_INFO_VERSION="0.1.12"

if [ -z "$controlfolder" ]; then
SCRIPT_DIR="$(dirname "$0")"
Expand Down Expand Up @@ -121,21 +121,23 @@ elif [ -f "/sys/firmware/devicetree/base/model" ]; then
if [[ "${DEVICE_NAME}" == "RGB10" ]]; then
# This one is tricky :D
DEVICE_NAME=$(cat "/sys/firmware/devicetree/base/model" 2>/dev/null)
fi

if [[ "${DEVICE_NAME}" == "" ]]; then
elif [[ "${DEVICE_NAME}" == "Pocket" ]]; then
# Retroid Pocket 5/Mini
DEVICE_NAME=$(cat "/sys/firmware/devicetree/base/model" 2>/dev/null)

elif [[ "${DEVICE_NAME}" == "" ]]; then
DEVICE_NAME=$(cat "/sys/firmware/devicetree/base/model" 2>/dev/null)
fi

if [[ "$CFW_NAME" == "AmberELEC" ]] && [[ -f "/storage/.config/device" ]]; then
elif [[ "$CFW_NAME" == "AmberELEC" ]] && [[ -f "/storage/.config/device" ]]; then
DEVICE_NAME=$(cat /storage/.config/device)
fi
else
DEVICE_NAME="Unknown"
fi

ANALOG_STICKS=2
DEVICE_CPU=$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1')
DEVICE_CPU=$(lscpu | grep '^Model name' | cut -f 2 -d ":" | awk 'NR==1{print $1}')
DISPLAY_ORIENTATION=0

DEVICE_ARCH="aarch64"
Expand Down Expand Up @@ -194,6 +196,20 @@ case "$(echo "$DEVICE_NAME" | tr '[:upper:]' '[:lower:]')" in
fi
;;

"rp5")
DEVICE_NAME="Retroid Pocket 5"
DEVICE_CPU="SD865"
;;

"rpmini")
DEVICE_NAME="Retroid Pocket Mini"
DEVICE_CPU="SD865"
;;

"retroid pocket 5"|"retroid pocket mini")
DEVICE_CPU="SD865"
;;

"rk3326")
DEVICE_CPU="RK3326"
if [[ "${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}" == "854x480" ]]; then
Expand Down Expand Up @@ -272,25 +288,57 @@ case "$(echo "$DEVICE_NAME" | tr '[:upper:]' '[:lower:]')" in
DEVICE_CPU="a133plus"
;;

"rg-cubexx")
DEVICE_NAME="RGCUBEXX-H"
DEVICE_CPU="h700"
;;

"rg28xx")
ANALOG_STICKS=0
DEVICE_CPU="h700"
;;

"rg35xx-h")
DEVICE_CPU="h700"
;;

"rg35xx-plus")
ANALOG_STICKS=0
DEVICE_CPU="h700"
;;

"rg35xx-sp")
ANALOG_STICKS=0
DEVICE_CPU="h700"
;;

"rg40xx-h")
DEVICE_CPU="h700"
;;

"rg40xx-v")
ANALOG_STICKS=1
DEVICE_CPU="h700"
;;

"sun50iw9")
if [ -f "/opt/muos/config/device.txt" ]; then
if [[ "$(cat /opt/muos/config/device.txt)" == "RG35XX-PLUS" ]]; then
DEVICE_NAME="$(cat /opt/muos/config/device.txt | tr '[:lower:]' '[:upper:]')"
if [[ "$DEVICE_NAME" == "RG35XX-2024" ]]; then
ANALOG_STICKS=0
elif [[ "$DEVICE_NAME" == "RG35XX-PLUS" ]]; then
ANALOG_STICKS=0
DEVICE_NAME="RG35XX PLUS"
elif [[ "$(cat /opt/muos/config/device.txt)" == "RG35XX-SP" ]]; then
elif [[ "$DEVICE_NAME" == "RG35XX-SP" ]]; then
ANALOG_STICKS=0
DEVICE_NAME="RG35XX SP"
elif [[ "$(cat /opt/muos/config/device.txt)" == "RG28XX" ]]; then
elif [[ "$DEVICE_NAME" == "RG28XX" ]]; then
ANALOG_STICKS=0
DEVICE_NAME="RG28XX"
DISPLAY_ORIENTATION=1
elif [[ "$(cat /opt/muos/config/device.txt)" == "RG40XX" ]]; then
DEVICE_NAME="RG40XX"
else
DEVICE_NAME="RG35XX H"
elif [[ "$DEVICE_NAME" == "RG40XX-V" ]]; then
DEVICE_NAME="RG40XX-V"
ANALOG_STICKS=1
fi
else
DEVICE_NAME="RG35XX H"
DEVICE_NAME="RG35XX-H"
fi

DEVICE_CPU="H700"
Expand Down
35 changes: 19 additions & 16 deletions PortMaster/knulli/control.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@ directory="userdata/roms"

ESUDO=""
ESUDOKILL="-1" # for 351Elec and EmuELEC use "-1" (numeric one) or "-k"

# Install our own shGenerator.py
if ! grep 'gamecontrollerdb.txt' /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py; then
cp -f /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py.bak

if ! grep 'from generators.Generator import Generator' /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py; then
# New style relative imports
cp -f $controlfolder/batocera/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py
else
# Old style absolute imports
cp -f $controlfolder/knulli/shGenerator.py /usr/lib/python3.11/site-packages/configgen/generators/sh/shGenerator.py
fi

batocera-save-overlay
fi

if [ -f "$HOME/.config/gamecontrollerdb.txt" ]; then
export SDL_GAMECONTROLLERCONFIG_FILE="$HOME/.config/gamecontrollerdb.txt"
elif [ -f "/tmp/gamecontrollerdb.txt" ]; then
export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/gamecontrollerdb.txt"
else
export SDL_GAMECONTROLLERCONFIG_FILE="/$controlfolder/batocera/gamecontrollerdb.txt"
fi
Expand All @@ -19,26 +37,11 @@ SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/gamecontrollerdb.txt"

get_controls() {
# TODO: figure out SDL_GAMECONTROLLERCONFIG
ANALOGSTICKS="2"
ANALOGSTICKS="${ANALOG_STICKS:-2}"
LOWRES="N"

DEVICE="Deeplay-keys"

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

if [ -f "$controlfolder/cwtbe_flag" ]; then
if [ -f "${HOME}/configs/emulationstation/es_input.cfg" ]; then
$controlfolder/mapper.py /tmp/gamecontrollerdb.txt > /dev/null 2>&1
fi
fi

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

Expand Down
29 changes: 29 additions & 0 deletions PortMaster/knulli/shGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

from generators.Generator import Generator
import Command
import controllersConfig
import glob

class ShGenerator(Generator):

def generate(self, system, rom, playersControllers, metadata, guns, wheels, gameResolution):

# in case of squashfs, the root directory is passed
shInDir = glob.glob(rom + "/run.sh")
if len(shInDir) == 1:
shrom = shInDir[0]
else:
shrom = rom

# Fixes stuff on PortMaster
dbfile = "/tmp/gamecontrollerdb.txt"
controllersConfig.writeSDLGameDBAllControllers(playersControllers, dbfile)

commandArray = ["/bin/bash", shrom]
return Command.Command(array=commandArray,env={
"SDL_GAMECONTROLLERCONFIG": controllersConfig.generateSdlGameControllerConfig(playersControllers)
})

def getMouseMode(self, config, rom):
return True
5 changes: 3 additions & 2 deletions PortMaster/pugwash
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,14 @@ class PortMasterGUI(pySDL2gui.GUI, harbourmaster.Callback):
capabilities = harbourmaster.device_info()

if sdl2.video.SDL_GetCurrentDisplayMode(0, display_mode) != 0:
print("Failed to get display mode:", sdl2.SDL_GetError())
logger.error("Failed to get display mode:", sdl2.SDL_GetError())
self.display_width, self.display_height = capabilities['resolution']

else:
self.display_width = display_mode.w
self.display_height = display_mode.h
# Print the display width and height
print(f"Display size: {self.display_width}x{self.display_height}")
logger.info(f"Display size: {self.display_width}x{self.display_height}")

if harbourmaster.HM_TESTING:
capabilities = harbourmaster.device_info()
Expand Down Expand Up @@ -781,6 +781,7 @@ class PortMasterGUI(pySDL2gui.GUI, harbourmaster.Callback):
Path("/sys/class/power_supply/battery/capacity"),
Path("/sys/class/power_supply/axp2202-battery/capacity"),
Path("/sys/class/power_supply/BAT1/capacity"),
Path("/sys/class/power_supply/qcom-battery/capacity"),
]

for battery_file in battery_paths:
Expand Down
15 changes: 13 additions & 2 deletions PortMaster/pylibs/harbourmaster/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
# TrimUI
"TrimUI Smart Pro": {"device": "trimui-smart-pro", "manufacturer": "TrimUI", "cfw": ["TrimUI"]},

# Retroid Pocket
"Retroid Pocket 5": {"device": "rp5", "manufacturer": "Retroid Pocket", "cfw": ["ROCKNIX", "Batocera"]},
"Retroid Pocket Mini": {"device": "rpmini", "manufacturer": "Retroid Pocket", "cfw": ["ROCKNIX", "Batocera"]},

# Generic
"XU10 Retro Handheld": {"device": "xu10", "manufacturer": "MagicX", "cfw": ["ArkOS", "AmberELEC", "JELOS", "ROCKNIX"]},
"R33S Retro Handheld": {"device": "r33s", "manufacturer": "Game Console", "cfw": ["ArkOS", "AmberELEC", "JELOS", "ROCKNIX"]},
Expand Down Expand Up @@ -110,7 +114,11 @@

# Gameforce Chi / Ace
"chi": {"resolution": ( 640, 480), "analogsticks": 2, "cpu": "rk3326", "capabilities": [], "ram": 1024},
"ace": {"resolution": (1920, 1080), "analogsticks": 2, "cpu": "rk3588", "capabilities": ["power"], "ram": 8192},
"ace": {"resolution": (1920, 1080), "analogsticks": 2, "cpu": "rk3588", "capabilities": ["power", "ultra"], "ram": 8192},

# Retroid Pocket
"rpmini": {"resolution": (1280, 960), "analogsticks": 2, "cpu": "sd865", "capabilities": ["power", "ultra"], "ram": 6144},
"rp5": {"resolution": (1920, 1080), "analogsticks": 2, "cpu": "sd865", "capabilities": ["power", "ultra"], "ram": 8192},

# Generic
"xu10": {"resolution": ( 640, 480), "analogsticks": 2, "cpu": "rk3326", "capabilities": [], "ram": 1024},
Expand Down Expand Up @@ -245,6 +253,9 @@ def nice_device_to_device(raw_device):
('GameForce ACE', 'ace'),

('MagicX XU10', 'xu10'),

('retroid pocket 5', 'rp5'),
('retroid pocket mini', 'rpmini'),
)

for pattern, device in pattern_to_device:
Expand Down Expand Up @@ -289,7 +300,7 @@ def new_device_info():

muos_device = safe_cat('/opt/muos/config/device.txt')
if muos_device != '':
info['device'] = muos_device.lower().replace(' ', '-')
info['device'] = muos_device.lower().replace(' ', '-').split('\n')[0]

# Works on TrimUI Smart Pro
if Path('/usr/trimui').is_dir():
Expand Down
Loading

0 comments on commit 6a5cd55

Please sign in to comment.