Skip to content
 
 

Repository files navigation

GunCon 2 USB Lightgun Driver

Linux driver for the GunCon 2 light gun.

  • A joystick device:
    • Reports absolute ABS_X and ABS_Y positions from the GunCon 2 sensor.
    • Reports trigger and other buttons as standard gamepad buttons (e.g. trigger as BTN_LEFT by default).
  • A mouse device:
    • Provides relative motion and a standard mouse left-click, mapped from the same GunCon 2 trigger.

Emulators and frontends can use either:

  • The joystick device (absolute aiming + buttons), or
  • The mouse device (relative pointer + left click), depending on what works best.

Calibration

The GunCon 2 must be calibrated for your display.

The joystick device’s ABS_X and ABS_Y ranges can be adjusted using evdev-joystick. This allows you to map the raw GunCon 2 coordinates to the visible area of your screen.

Example (adjust the values to your setup):

# X axis (joystick device)
evdev-joystick --e /dev/input/by-id/usb-0b9a_016a-event-joystick -m 175 -M 720 -a 0

# Y axis (joystick device)
evdev-joystick --e /dev/input/by-id/usb-0b9a_016a-event-joystick -m 20 -M 240 -a 1

It is also included a simple script for calibrating the GunCon 2, however the calibration must be performed each time the GunCon 2 is connected. This can be done with a set of udev rules.

For example;

SUBSYSTEM=="input", ATTRS{idVendor}=="0b9a", ATTRS{idProduct}=="016a", ACTION=="add", RUN+="/bin/bash -c 'evdev-joystick --e %E{DEVNAME} -m 175 -M 720 -a 0; evdev-joystick --e %E{DEVNAME} -m 20 -M 240 -a 1'"

Build and installation

The build requires a C compiler, GNU Make, and headers matching the target kernel.

Build and install the module for the running kernel:

make -j"$(nproc)"
sudo make install
sudo modprobe guncon2

The module is installed under /lib/modules/$(uname -r)/extra/ by default. The modules_install target remains available as an alias for install.

Manual loading

Build the module without installing it, then load it temporarily:

make modules
sudo insmod ./guncon2.ko

Build options

Run make help for the complete target and override list. For example:

make KERNEL_RELEASE=6.12.0-rpi-2712 modules
make KDIR=/path/to/kernel/build modules
make DESTDIR=/tmp/guncon2-package install

KERNEL_RELEASE defaults to the running kernel, and KDIR defaults to its build directory under /lib/modules/.

Uninstallation

Unload the driver before uninstalling it if it is currently in use:

sudo modprobe -r guncon2
sudo make uninstall

To reload the driver after rebuilding it, unload it with sudo modprobe -r guncon2 before loading it again.

About

Linux driver for the Guncon 2 light gun

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages