diff --git a/internal/configparser/schema.go b/internal/configparser/schema.go index 1a47172..387022a 100644 --- a/internal/configparser/schema.go +++ b/internal/configparser/schema.go @@ -11,6 +11,8 @@ type Config struct { // TODO: configure custom unmarshaling so we can overload Buttons, Axes, and RelativeAxes... type DeviceConfigVirtual struct { Name string + VendorId string `yaml:"vendor_id,omitempty"` + DeviceId string `yaml:"device_id,omitempty"` Preset string NumButtons int `yaml:"num_buttons,omitempty"` NumAxes int `yaml:"num_axes,omitempty"` diff --git a/internal/virtualdevice/init.go b/internal/virtualdevice/init.go index 14f1c04..3a3242d 100644 --- a/internal/virtualdevice/init.go +++ b/internal/virtualdevice/init.go @@ -7,8 +7,20 @@ import ( "git.annabunches.net/annabunches/joyful/internal/eventcodes" "git.annabunches.net/annabunches/joyful/internal/logger" "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 // evdev.InputDevice, and wraps it in a buffered event emitter. func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, error) { @@ -38,11 +50,11 @@ func NewEventBuffer(config configparser.DeviceConfigVirtual) (*EventBuffer, erro device, err := evdev.CreateDevice( 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{ BusType: 0x03, - Vendor: 0x4711, - Product: 0x0816, + Vendor: ParseUInt16(config.VendorId, VirtualDeviceVendorId), + Product: ParseUInt16(config.DeviceId, VirtualDeviceDeviceId), Version: 1, }, capabilities, diff --git a/internal/virtualdevice/variables.go b/internal/virtualdevice/variables.go index 7102bd5..5810adc 100644 --- a/internal/virtualdevice/variables.go +++ b/internal/virtualdevice/variables.go @@ -7,7 +7,9 @@ const ( DevicePresetGamepad = "gamepad" DevicePresetJoystick = "joystick" DevicePresetMouse = "mouse" - + + VirtualDeviceVendorId = 0x4711 + VirtualDeviceDeviceId = 0x0816 VirtualDeviceMaxButtons = 74 )