Implement config generator for AxisToButton. Use RuleTargetDevice interface more broadly.

This commit is contained in:
Anna Rose Wiggins 2025-07-12 17:14:57 -04:00
parent e93187b8a5
commit ed2627e113
9 changed files with 28 additions and 16 deletions

View file

@ -1,7 +1,6 @@
package config
import (
"errors"
"fmt"
"strings"
@ -134,13 +133,22 @@ func makeMappingRuleAxis(ruleConfig RuleConfig,
return mappingrules.NewMappingRuleAxis(base, input, output), nil
}
// STUB
func makeMappingRuleAxisToButton(ruleConfig RuleConfig,
pDevs map[string]*evdev.InputDevice,
vDevs map[string]*evdev.InputDevice,
base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleAxisToButton, error) {
return nil, errors.New("stub: makeMappingRuleAxisToButton")
input, err := makeRuleTargetAxis(ruleConfig.Input, pDevs)
if err != nil {
return nil, err
}
output, err := makeRuleTargetButton(ruleConfig.Output, vDevs)
if err != nil {
return nil, err
}
return mappingrules.NewMappingRuleAxisToButton(base, input, output, ruleConfig.RepeatRateMin, ruleConfig.RepeatRateMax), nil
}
func makeMappingRuleModeSelect(ruleConfig RuleConfig,

View file

@ -25,6 +25,8 @@ type RuleConfig struct {
Inputs []RuleTargetConfig `yaml:"inputs,omitempty"`
Output RuleTargetConfig `yaml:"output"`
Modes []string `yaml:"modes,omitempty"`
RepeatRateMin int `yaml:"repeat_rate_min,omitempty"`
RepeatRateMax int `yaml:"repeat_rate_max,omitempty"`
}
type RuleTargetConfig struct {

View file

@ -3,7 +3,7 @@ package mappingrules
import "github.com/holoplot/go-evdev"
type MappingRule interface {
MatchEvent(*evdev.InputDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
MatchEvent(RuleTargetDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
}
// RuleTargets represent either a device input to match on, or an output to produce.
@ -25,6 +25,8 @@ type RuleTarget interface {
// Typically int32 is the input event's normalized value. *string is the current mode, but is optional
// for most implementations.
CreateEvent(int32, *string) *evdev.InputEvent
MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool
}
// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing

View file

@ -17,7 +17,7 @@ func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *Rul
}
}
func (rule *MappingRuleAxis) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
func (rule *MappingRuleAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) ||
!rule.Input.MatchEvent(device, event) {
return nil, nil

View file

@ -21,7 +21,7 @@ func NewMappingRuleButton(
}
}
func (rule *MappingRuleButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil
}

View file

@ -23,7 +23,7 @@ func NewMappingRuleButtonCombo(
}
}
func (rule *MappingRuleButtonCombo) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil
}

View file

@ -22,7 +22,7 @@ func NewMappingRuleButtonLatched(
}
}
func (rule *MappingRuleButtonLatched) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
if !rule.MappingRuleBase.modeCheck(mode) {
return nil, nil
}

View file

@ -22,7 +22,7 @@ func NewMappingRuleModeSelect(
}
func (rule *MappingRuleModeSelect) MatchEvent(
device *evdev.InputDevice,
device RuleTargetDevice,
event *evdev.InputEvent,
mode *string) (*evdev.InputDevice, *evdev.InputEvent) {

View file

@ -36,7 +36,7 @@ func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.Input
}
}
func (target *RuleTargetButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) bool {
func (target *RuleTargetButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
return device == target.Device &&
event.Type == evdev.EV_KEY &&
event.Code == target.Button