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..8b6ab59a6d8 --- /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" + +# 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..7292a56c306 --- /dev/null +++ b/package/batocera/controllers/guns/openfire-guns/virtual-openfire-add @@ -0,0 +1,65 @@ +#!/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}" = 2 +then + DEV1=$(echo "${CHILDREN}" | head -1 | cut -f 1) + DEV2=$(echo "${CHILDREN}" | head -2 | tail -1 | cut -f 1) + 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 +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