Implement config file parsing for physical devices.

This commit is contained in:
Anna Rose Wiggins 2025-07-01 13:23:21 -04:00
parent faa51bdda2
commit 5b3b70da14
3 changed files with 38 additions and 22 deletions

View file

@ -2,8 +2,10 @@ package main
import (
"fmt"
"maps"
"os"
"path/filepath"
"slices"
"time"
"git.annabunches.net/annabunches/joyful/internal/config"
@ -23,6 +25,10 @@ func readConfig() *config.ConfigParser {
func initVirtualDevices(config *config.ConfigParser) map[string]*virtualdevice.EventBuffer {
vDevices := config.CreateVirtualDevices()
if len(vDevices) == 0 {
logger.Log("Warning: no virtual devices found in configuration. No rules will work.")
}
vBuffers := make(map[string]*virtualdevice.EventBuffer)
for name, device := range vDevices {
vBuffers[name] = virtualdevice.NewEventBuffer(device)
@ -30,6 +36,14 @@ func initVirtualDevices(config *config.ConfigParser) map[string]*virtualdevice.E
return vBuffers
}
func initPhysicalDevices(config *config.ConfigParser) map[string]*evdev.InputDevice {
pDeviceMap := config.ConnectPhysicalDevices()
if len(pDeviceMap) == 0 {
logger.Log("Warning: no physical devices found in configuration. No rules will work.")
}
return pDeviceMap
}
func main() {
// parse configs
config := readConfig()
@ -38,17 +52,20 @@ func main() {
vBuffers := initVirtualDevices(config)
// Initialize physical devices
// pDevices := config.ConnectPhysicalDevices()
pDevices := initPhysicalDevices(config)
// TEST CODE
pDevice, err := evdev.Open("/dev/input/event11")
logger.FatalIfError(err, "Couldn't open physical device")
testDriver(vBuffers, pDevices)
}
func testDriver(vBuffers map[string]*virtualdevice.EventBuffer, pDevices map[string]*evdev.InputDevice) {
pDevice := slices.Collect(maps.Values(pDevices))[0]
name, err := pDevice.Name()
if err != nil {
name = "Unknown"
}
fmt.Printf("Connected to physical device %s\n", name)
fmt.Printf("Test Driver using physical device %s\n", name)
var combo int32 = 0
buffer := vBuffers["main"]
@ -63,31 +80,25 @@ func main() {
switch event.Code {
case evdev.BTN_TRIGGER:
if event.Value == 0 {
fmt.Println("Trigger 0")
combo++
}
if event.Value == 1 {
fmt.Println("Trigger 1")
combo--
}
case evdev.BTN_THUMB:
if event.Value == 0 {
fmt.Println("Thumb 0")
combo--
}
if event.Value == 1 {
fmt.Println("Thumb 1")
combo++
}
case evdev.BTN_THUMB2:
if event.Value == 0 {
fmt.Println("Thumb2 0")
combo--
}
if event.Value == 1 {
fmt.Println("Thumb2 1")
combo++
}