Use testify, write a couple more tests, and start a major refactor.

This commit is contained in:
Anna Rose Wiggins 2025-07-04 23:40:34 -04:00
parent 649fb5e377
commit 3b75fd30e4
10 changed files with 286 additions and 185 deletions

View file

@ -2,15 +2,8 @@ package mappingrules
import (
"time"
"github.com/holoplot/go-evdev"
)
type MappingRule interface {
MatchEvent(*evdev.InputDevice, *evdev.InputEvent, *string) *evdev.InputEvent
OutputName() string
}
type MappingRuleBase struct {
Name string
Output RuleTarget
@ -43,46 +36,3 @@ type ProportionalAxisMappingRule struct {
Output RuleTarget
LastEvent time.Time
}
// RuleTargets represent either a device input to match on, or an output to produce.
// Some RuleTarget types may work via side effects, such as RuleTargetModeSelect.
type RuleTarget interface {
// NormalizeValue takes the raw input value and possibly modifies it based on the Target settings.
// (e.g., inverting the value if Inverted == true)
NormalizeValue(int32) int32
// CreateEvent typically takes the (probably normalized) value and returns an event that can be emitted
// on a virtual device.
//
// For RuleTargetModeSelect, this method modifies the active mode and returns nil.
//
// TODO: should we normalize inside this function to simplify the interface?
CreateEvent(int32, *string) *evdev.InputEvent
GetCode() evdev.EvCode
GetDeviceName() string
GetDevice() *evdev.InputDevice
}
type RuleTargetBase struct {
DeviceName string
Device *evdev.InputDevice
Code evdev.EvCode
Inverted bool
}
type RuleTargetButton struct {
RuleTargetBase
}
type RuleTargetAxis struct {
RuleTargetBase
AxisStart int32
AxisEnd int32
Sensitivity float64
}
type RuleTargetModeSelect struct {
RuleTargetBase
ModeSelect []string
}