From 17c556f76ad0e199c5e029ad7777b1f72449284c Mon Sep 17 00:00:00 2001 From: Tovarichtch Date: Thu, 7 Nov 2024 23:19:45 -0500 Subject: [PATCH 1/3] add initial support for OpenFIRE --- .../guns/openfire-guns/99-openfire-guns.rules | 10 +++ .../controllers/guns/openfire-guns/Config.in | 6 ++ .../guns/openfire-guns/openfire-guns.mk | 15 +++++ .../guns/openfire-guns/virtual-openfire-add | 66 +++++++++++++++++++ .../batocera/core/batocera-system/Config.in | 3 +- 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules create mode 100644 package/batocera/controllers/guns/openfire-guns/Config.in create mode 100644 package/batocera/controllers/guns/openfire-guns/openfire-guns.mk create mode 100644 package/batocera/controllers/guns/openfire-guns/virtual-openfire-add diff --git a/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules b/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules new file mode 100644 index 00000000000..354c3d47433 --- /dev/null +++ b/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules @@ -0,0 +1,10 @@ +# Three events at all time: +# Keyboard, Mouse and Gamepad +SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Keyboard", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", RUN+="/usr/bin/virtual-openfire-add" +SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Mouse", ENV{ID_INPUT_MOUSE}="0", RUN+="/usr/bin/virtual-openfire-add" + +# Gamepad event must be disabled, this mode is unsupported for now +SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_JOYSTICK}="0", RUN+="/usr/bin/virtual-openfire-add" + +# Virtual Light Gun +SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE light gun", MODE="0666", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", ENV{ID_INPUT_MOUSE}="1", ENV{ID_INPUT_GUN}="1" diff --git a/package/batocera/controllers/guns/openfire-guns/Config.in b/package/batocera/controllers/guns/openfire-guns/Config.in new file mode 100644 index 00000000000..2ddeedfbd07 --- /dev/null +++ b/package/batocera/controllers/guns/openfire-guns/Config.in @@ -0,0 +1,6 @@ +config BR2_PACKAGE_OPENFIRE_GUNS + bool "openfire-guns" + select BR2_PACKAGE_EVSIEVE + + help + openfire guns support diff --git a/package/batocera/controllers/guns/openfire-guns/openfire-guns.mk b/package/batocera/controllers/guns/openfire-guns/openfire-guns.mk new file mode 100644 index 00000000000..e011da42abf --- /dev/null +++ b/package/batocera/controllers/guns/openfire-guns/openfire-guns.mk @@ -0,0 +1,15 @@ +################################################################################ +# +# OpenFIRE FIRECon light guns +# +################################################################################ +OPENFIRE_GUNS_VERSION = 1 +OPENFIRE_GUNS_LICENSE = GPL +OPENFIRE_GUNS_SOURCE = + +define OPENFIRE_GUNS_INSTALL_TARGET_CMDS + $(INSTALL) -m 0644 -D $(BR2_EXTERNAL_BATOCERA_PATH)/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules $(TARGET_DIR)/etc/udev/rules.d/99-openfire-guns.rules + $(INSTALL) -m 0755 -D $(BR2_EXTERNAL_BATOCERA_PATH)/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add $(TARGET_DIR)/usr/bin/virtual-openfire-add +endef + +$(eval $(generic-package)) diff --git a/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add b/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add new file mode 100644 index 00000000000..a9c353c4fd6 --- /dev/null +++ b/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add @@ -0,0 +1,66 @@ +#!/bin/bash + +test "${ACTION}" = "add" || exit 0 +echo "${DEVNAME}" | grep -E "^/dev/input/event[0-9]+$" || exit 0 + +PARENTHASH=$(evsieve-helper parent "${DEVNAME}" input usb) +BASEFILE="/var/run/virtual-openfire-devices.${PARENTHASH}" +PIDFILE="${BASEFILE}.pid" +LOCKFILE="${BASEFILE}.lock" +LOGFILE="${BASEFILE}.log" + +unlockAndExit() { + rmdir "${LOCKFILE}" + exit "${1}" +} + +checkRunningPIDAndExit1() { + test ! -e "${PIDFILE}" && return 0 + LPID=$(cat "${PIDFILE}") + test ! -d "/proc/${LPID}" && return 0 + unlockAndExit 1 +} + +trylock() { + # lock + N=0 + while ! mkdir "${LOCKFILE}" + do + sleep 1 + let N++ + test "${N}" -gt 30 && exit 1 # give up + done +} + +trylock +checkRunningPIDAndExit1 + +CHILDREN=$(evsieve-helper children "${PARENTHASH}" input usb) +NDEVS=$(echo "${CHILDREN}" | wc -l) + + # Based on the enclosed instruction book from official Github + # + # Trigger : BTN_LEFT + # A / PUMP : BTN_RIGHT + # B : BTN_MIDDLE + # Foot pedal / C : BTN_SIDE + # Alt pedal : BTN_EXTRA + # Start : KEY_1 + # Select : KEY_5 + # D-pad up : KEY_UP + # D-pad down : KEY_DOWN + # D-pad left : KEY_LEFT + # D-pad right : KEY_RIGHT + +if test "${NDEVS}" = 3 +then + DEV1=$(echo "${CHILDREN}" | head -1 | cut -f 1) + DEV2=$(echo "${CHILDREN}" | head -2 | tail -1 | cut -f 1) + DEV3=$(echo "${CHILDREN}" | head -3 | tail -1 | cut -f 1) + nohup evsieve --input "${DEV1}" "${DEV2}" "${DEV3}" persist=exit --map yield btn:middle btn:2 --map yield btn:side btn:right --map yield key:1 btn:middle --map yield key:5 btn:1 --map yield key:up btn:5 --map yield key:down btn:6 --map yield key:left btn:7 --map yield key:right btn:8 --output name="OpenFIRE light gun" >/dev/null 2>"${LOGFILE}" & + echo $! > "${PIDFILE}" +else + unlockAndExit 1 +fi + +unlockAndExit 0 diff --git a/package/batocera/core/batocera-system/Config.in b/package/batocera/core/batocera-system/Config.in index 9a8a4effb0b..c53573a96d4 100644 --- a/package/batocera/core/batocera-system/Config.in +++ b/package/batocera/core/batocera-system/Config.in @@ -243,7 +243,7 @@ config BR2_PACKAGE_BATOCERA_SYSTEM select BR2_PACKAGE_LIBCURL_CURL # download tools select BR2_PACKAGE_NGHTTP2 # required for curl http2 select BR2_PACKAGE_CA_CERTIFICATES # ssl certificates - + # Used for screen rotation (SDL, Retroarch, Moonlight) select BR2_PACKAGE_ROCKCHIP_RGA if BR2_PACKAGE_BATOCERA_TARGET_RK3326 || \ BR2_PACKAGE_BATOCERA_TARGET_RK3128 || \ @@ -1493,6 +1493,7 @@ config BR2_PACKAGE_BATOCERA_GUNS select BR2_PACKAGE_AELIGHTGUN # ae light gun select BR2_PACKAGE_GUN4IR_GUNS # gun4ir guns select BR2_PACKAGE_RETROSHOOTER_GUNS # retroshooter guns + select BR2_PACKAGE_OPENFIRE_GUNS # openfire guns select BR2_PACKAGE_GUNCON if BR2_PACKAGE_BATOCERA_TARGET_X86_64_ANY || BR2_PACKAGE_BATOCERA_TARGET_BCM2711 || BR2_PACKAGE_BATOCERA_TARGET_BCM2837 # guncon select BR2_PACKAGE_GUNCON3 if !BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_4 # guncon3 select BR2_PACKAGE_LIGHTGUNS_GAMES_PRECALIBRATIONS From aa356726b788693e72e1c2a2cdeea046b6edc72a Mon Sep 17 00:00:00 2001 From: Tovarichtch Date: Fri, 8 Nov 2024 15:35:21 -0500 Subject: [PATCH 2/3] Update 99-openfire-guns.rules --- .../controllers/guns/openfire-guns/99-openfire-guns.rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules b/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules index 354c3d47433..8b6ab59a6d8 100644 --- a/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules +++ b/package/batocera/controllers/guns/openfire-guns/99-openfire-guns.rules @@ -4,7 +4,7 @@ SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Keyboard", ENV SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Mouse", ENV{ID_INPUT_MOUSE}="0", RUN+="/usr/bin/virtual-openfire-add" # Gamepad event must be disabled, this mode is unsupported for now -SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_JOYSTICK}="0", RUN+="/usr/bin/virtual-openfire-add" +SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_JOYSTICK}="0" # Virtual Light Gun SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE light gun", MODE="0666", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", ENV{ID_INPUT_MOUSE}="1", ENV{ID_INPUT_GUN}="1" From a5eec3e73290d31ebb9dd8e1108d6b4ce1358418 Mon Sep 17 00:00:00 2001 From: Tovarichtch Date: Fri, 8 Nov 2024 15:46:57 -0500 Subject: [PATCH 3/3] Update virtual-openfire-add --- .../controllers/guns/openfire-guns/virtual-openfire-add | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add b/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add index a9c353c4fd6..34796d2ace6 100644 --- a/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add +++ b/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add @@ -35,7 +35,7 @@ trylock() { trylock checkRunningPIDAndExit1 -CHILDREN=$(evsieve-helper children "${PARENTHASH}" input usb) +CHILDREN=$(evsieve-helper children "${PARENTHASH}" input usb | grep -vE "OpenFIRE FIRECon$") # remove the joystick from the event cause it duplicates events NDEVS=$(echo "${CHILDREN}" | wc -l) # Based on the enclosed instruction book from official Github @@ -52,12 +52,11 @@ NDEVS=$(echo "${CHILDREN}" | wc -l) # D-pad left : KEY_LEFT # D-pad right : KEY_RIGHT -if test "${NDEVS}" = 3 +if test "${NDEVS}" = 2 then DEV1=$(echo "${CHILDREN}" | head -1 | cut -f 1) DEV2=$(echo "${CHILDREN}" | head -2 | tail -1 | cut -f 1) - DEV3=$(echo "${CHILDREN}" | head -3 | tail -1 | cut -f 1) - nohup evsieve --input "${DEV1}" "${DEV2}" "${DEV3}" persist=exit --map yield btn:middle btn:2 --map yield btn:side btn:right --map yield key:1 btn:middle --map yield key:5 btn:1 --map yield key:up btn:5 --map yield key:down btn:6 --map yield key:left btn:7 --map yield key:right btn:8 --output name="OpenFIRE light gun" >/dev/null 2>"${LOGFILE}" & + nohup evsieve --input "${DEV1}" "${DEV2}" persist=exit --map yield btn:middle btn:2 --map yield btn:side btn:right --map yield key:1 btn:middle --map yield key:5 btn:1 --map yield key:up btn:5 --map yield key:down btn:6 --map yield key:left btn:7 --map yield key:right btn:8 --output name="OpenFIRE light gun" >/dev/null 2>"${LOGFILE}" & echo $! > "${PIDFILE}" else unlockAndExit 1