Skip to content

Commit

Permalink
add initial support for OpenFIRE
Browse files Browse the repository at this point in the history
(WIP - UNTESTED)

Only the basics, it's missing all the extra features.

Simplicity for calibration is missing. Must go to `pause mode` first by pressing `C` and `SELECT` at the same time, then select profile, then calibrate, then confirm with trigger. Not user-friendly, need workaround for simplicity.
  • Loading branch information
Tovarichtch committed Nov 8, 2024
1 parent bd7329c commit 999a110
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Three events at all time:
# Keyboard, Mouse and Gamepad
SUBSYSTEM=="input", KERNEL=="event*", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Keyboard", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", RUN+="/usr/bin/openfire-guns-add"
SUBSYSTEM=="input", KERNEL=="event*", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon Mouse", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", RUN+="/usr/bin/openfire-guns-add"
SUBSYSTEM=="input", KERNEL=="event*", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_MOUSE}="0", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", RUN+="/usr/bin/openfire-guns-add"

# Virtual Light Gun
SUBSYSTEM=="input", ACTION=="add", ATTRS{name}=="OpenFIRE FIRECon light gun", MODE="0666", ENV{ID_INPUT_JOYSTICK}="0", ENV{ID_INPUT_GUN}="1", ENV{ID_INPUT_KEYBOARD}="0", ENV{ID_INPUT_KEY}="0", ENV{ID_INPUT_MOUSE}="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/openfire-guns-add $(TARGET_DIR)/usr/bin/openfire-guns-add
endef

$(eval $(generic-package))
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/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)

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)

# 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

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
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

0 comments on commit 999a110

Please sign in to comment.