Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial support for OpenFIRE light gun #12880

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions package/batocera/controllers/guns/openfire-guns/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config BR2_PACKAGE_OPENFIRE_GUNS
bool "openfire-guns"
select BR2_PACKAGE_EVSIEVE

help
openfire guns support
15 changes: 15 additions & 0 deletions package/batocera/controllers/guns/openfire-guns/openfire-guns.mk
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion package/batocera/core/batocera-system/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 || \
Expand Down Expand Up @@ -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
Expand Down