Improve config yaml schema (#16)

Leverages custom unmarshaling to be more declarative for our config specification.

Reviewed-on: #16
Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com>
Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
Anna Rose Wiggins 2025-08-09 16:33:46 +00:00 committed by Anna Rose Wiggins
parent 1a7b288083
commit d9babf5dc0
8 changed files with 364 additions and 238 deletions

View file

@ -8,13 +8,13 @@ import (
"github.com/holoplot/go-evdev"
)
// CreateVirtualDevices will register any configured devices with type = virtual
// InitVirtualDevices will register any configured devices with type = virtual
// using /dev/uinput, and return a map of those devices.
//
// This function assumes you have already called Parse() on the config directory.
// This function assumes Parse() has been called.
//
// This function should only be called once, unless you want to create duplicate devices for some reason.
func (parser *ConfigParser) CreateVirtualDevices() map[string]*evdev.InputDevice {
// This function should only be called once, unless we want to create duplicate devices for some reason.
func (parser *ConfigParser) InitVirtualDevices() map[string]*evdev.InputDevice {
deviceMap := make(map[string]*evdev.InputDevice)
for _, deviceConfig := range parser.config.Devices {
@ -22,6 +22,8 @@ func (parser *ConfigParser) CreateVirtualDevices() map[string]*evdev.InputDevice
continue
}
deviceConfig := deviceConfig.Config.(DeviceConfigVirtual)
name := fmt.Sprintf("joyful-%s", deviceConfig.Name)
var capabilities map[evdev.EvType][]evdev.EvCode
@ -74,13 +76,13 @@ func (parser *ConfigParser) CreateVirtualDevices() map[string]*evdev.InputDevice
return deviceMap
}
// ConnectPhysicalDevices will create InputDevices corresponding to any registered
// InitPhysicalDevices will create InputDevices corresponding to any registered
// devices with type = physical.
//
// This function assumes you have already called Parse() on the config directory.
// This function assumes Parse() has been called.
//
// This function should only be called once.
func (parser *ConfigParser) ConnectPhysicalDevices() map[string]*evdev.InputDevice {
func (parser *ConfigParser) InitPhysicalDevices() map[string]*evdev.InputDevice {
deviceMap := make(map[string]*evdev.InputDevice)
for _, deviceConfig := range parser.config.Devices {
@ -88,6 +90,8 @@ func (parser *ConfigParser) ConnectPhysicalDevices() map[string]*evdev.InputDevi
continue
}
deviceConfig := deviceConfig.Config.(DeviceConfigPhysical)
var infoName string
var device *evdev.InputDevice
var err error