Add support for setting vendor/device IDs (#10)
Sets vendor and product IDs, defaults to the prior default values. This is needed for some games to be able to correctly identify the virtual devices since not all games support device indexes. Reviewed-on: https://codeberg.org/annabunches/joyful/pulls/10
This commit is contained in:
parent
77ee020b2a
commit
7e4d4f3c20
3 changed files with 20 additions and 4 deletions
|
|
@ -11,6 +11,8 @@ type Config struct {
|
||||||
// TODO: configure custom unmarshaling so we can overload Buttons, Axes, and RelativeAxes...
|
// TODO: configure custom unmarshaling so we can overload Buttons, Axes, and RelativeAxes...
|
||||||
type DeviceConfigVirtual struct {
|
type DeviceConfigVirtual struct {
|
||||||
Name string
|
Name string
|
||||||
|
VendorId string `yaml:"vendor_id,omitempty"`
|
||||||
|
DeviceId string `yaml:"device_id,omitempty"`
|
||||||
Preset string
|
Preset string
|
||||||
NumButtons int `yaml:"num_buttons,omitempty"`
|
NumButtons int `yaml:"num_buttons,omitempty"`
|
||||||
NumAxes int `yaml:"num_axes,omitempty"`
|
NumAxes int `yaml:"num_axes,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,20 @@ import (
|
||||||
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
|
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
|
||||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||||
"github.com/holoplot/go-evdev"
|
"github.com/holoplot/go-evdev"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ParseUInt16(s string, def uint16) uint16 {
|
||||||
|
if s == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
v, err := strconv.ParseUint(s, 0, 16)
|
||||||
|
if err != nil {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return uint16(v)
|
||||||
|
}
|
||||||
|
|
||||||
// NewEventBuffer takes a virtual device config specification, creates the underlying
|
// NewEventBuffer takes a virtual device config specification, creates the underlying
|
||||||
// evdev.InputDevice, and wraps it in a buffered event emitter.
|
// evdev.InputDevice, and wraps it in a buffered event emitter.
|
||||||
func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, error) {
|
func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, error) {
|
||||||
|
|
@ -38,11 +50,11 @@ func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, erro
|
||||||
|
|
||||||
device, err := evdev.CreateDevice(
|
device, err := evdev.CreateDevice(
|
||||||
name,
|
name,
|
||||||
// TODO: placeholders. Who knows what these should actually be...
|
// TODO: placeholders. BusType = differentiate between input bus (3 = usb), Vendor = uint16 vendor id, Product: uint16 devoce id, Version = device version (differentiate between differing versions of exact same device)
|
||||||
evdev.InputID{
|
evdev.InputID{
|
||||||
BusType: 0x03,
|
BusType: 0x03,
|
||||||
Vendor: 0x4711,
|
Vendor: ParseUInt16(config.VendorId, VirtualDeviceVendorId),
|
||||||
Product: 0x0816,
|
Product: ParseUInt16(config.DeviceId, VirtualDeviceDeviceId),
|
||||||
Version: 1,
|
Version: 1,
|
||||||
},
|
},
|
||||||
capabilities,
|
capabilities,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ const (
|
||||||
DevicePresetGamepad = "gamepad"
|
DevicePresetGamepad = "gamepad"
|
||||||
DevicePresetJoystick = "joystick"
|
DevicePresetJoystick = "joystick"
|
||||||
DevicePresetMouse = "mouse"
|
DevicePresetMouse = "mouse"
|
||||||
|
|
||||||
|
VirtualDeviceVendorId = 0x4711
|
||||||
|
VirtualDeviceDeviceId = 0x0816
|
||||||
VirtualDeviceMaxButtons = 74
|
VirtualDeviceMaxButtons = 74
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue