Rename mapping rules for consistent prefix.

This commit is contained in:
Anna Rose Wiggins 2025-07-04 23:47:25 -04:00
parent 80bfdfde90
commit 7ef62cbdc7
6 changed files with 21 additions and 21 deletions

View file

@ -75,7 +75,7 @@ func main() {
timerCount := 0 timerCount := 0
for _, rule := range rules { for _, rule := range rules {
if timedRule, ok := rule.(*mappingrules.ProportionalAxisMappingRule); ok { if timedRule, ok := rule.(*mappingrules.MappingRuleProportionalAxis); ok {
go timerWatcher(timedRule, eventChannel) go timerWatcher(timedRule, eventChannel)
timerCount++ timerCount++
} }

View file

@ -28,7 +28,7 @@ func eventWatcher(device *evdev.InputDevice, channel chan<- ChannelEvent) {
} }
} }
func timerWatcher(rule *mappingrules.ProportionalAxisMappingRule, channel chan<- ChannelEvent) { func timerWatcher(rule *mappingrules.MappingRuleProportionalAxis, channel chan<- ChannelEvent) {
for { for {
event := rule.TimerEvent() event := rule.TimerEvent()
if event != nil { if event != nil {

View file

@ -63,19 +63,19 @@ func setBaseRuleParameters(ruleConfig RuleConfig, vDevs map[string]*evdev.InputD
}, nil }, nil
} }
func makeSimpleRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.SimpleMappingRule, error) { func makeSimpleRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleSimple, error) {
input, err := makeRuleTarget(ruleConfig.Input, pDevs) input, err := makeRuleTarget(ruleConfig.Input, pDevs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &mappingrules.SimpleMappingRule{ return &mappingrules.MappingRuleSimple{
MappingRuleBase: base, MappingRuleBase: base,
Input: input, Input: input,
}, nil }, nil
} }
func makeComboRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.ComboMappingRule, error) { func makeComboRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleCombo, error) {
inputs := make([]mappingrules.RuleTarget, 0) inputs := make([]mappingrules.RuleTarget, 0)
for _, inputConfig := range ruleConfig.Inputs { for _, inputConfig := range ruleConfig.Inputs {
input, err := makeRuleTarget(inputConfig, pDevs) input, err := makeRuleTarget(inputConfig, pDevs)
@ -85,20 +85,20 @@ func makeComboRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, b
inputs = append(inputs, input) inputs = append(inputs, input)
} }
return &mappingrules.ComboMappingRule{ return &mappingrules.MappingRuleCombo{
MappingRuleBase: base, MappingRuleBase: base,
Inputs: inputs, Inputs: inputs,
State: 0, State: 0,
}, nil }, nil
} }
func makeLatchedRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.LatchedMappingRule, error) { func makeLatchedRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleLatched, error) {
input, err := makeRuleTarget(ruleConfig.Input, pDevs) input, err := makeRuleTarget(ruleConfig.Input, pDevs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &mappingrules.LatchedMappingRule{ return &mappingrules.MappingRuleLatched{
MappingRuleBase: base, MappingRuleBase: base,
Input: input, Input: input,
State: false, State: false,

View file

@ -13,8 +13,8 @@ type SimpleMappingRuleTests struct {
wrongInputDevice *evdev.InputDevice wrongInputDevice *evdev.InputDevice
outputDevice *evdev.InputDevice outputDevice *evdev.InputDevice
mode *string mode *string
sampleRule *SimpleMappingRule sampleRule *MappingRuleSimple
invertedRule *SimpleMappingRule invertedRule *MappingRuleSimple
} }
func (t *SimpleMappingRuleTests) SetupTest() { func (t *SimpleMappingRuleTests) SetupTest() {
@ -25,7 +25,7 @@ func (t *SimpleMappingRuleTests) SetupTest() {
t.mode = &mode t.mode = &mode
// TODO: implement a constructor function... // TODO: implement a constructor function...
t.sampleRule = &SimpleMappingRule{ t.sampleRule = &MappingRuleSimple{
MappingRuleBase: MappingRuleBase{ MappingRuleBase: MappingRuleBase{
Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false), Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false),
Modes: []string{"*"}, Modes: []string{"*"},
@ -33,7 +33,7 @@ func (t *SimpleMappingRuleTests) SetupTest() {
Input: NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, false), Input: NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, false),
} }
t.invertedRule = &SimpleMappingRule{ t.invertedRule = &MappingRuleSimple{
MappingRuleBase: MappingRuleBase{ MappingRuleBase: MappingRuleBase{
Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false), Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false),
Modes: []string{"*"}, Modes: []string{"*"},

View file

@ -17,7 +17,7 @@ func (rule *MappingRuleBase) modeCheck(mode *string) bool {
return slices.Contains(rule.Modes, *mode) return slices.Contains(rule.Modes, *mode)
} }
func (rule *SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent { func (rule *MappingRuleSimple) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil return nil
} }
@ -30,7 +30,7 @@ func (rule *SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evde
return rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode) return rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
} }
func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent { func (rule *MappingRuleCombo) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil return nil
} }
@ -68,7 +68,7 @@ func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev
return nil return nil
} }
func (rule *LatchedMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent { func (rule *MappingRuleLatched) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
if !rule.MappingRuleBase.modeCheck(mode) { if !rule.MappingRuleBase.modeCheck(mode) {
return nil return nil
} }
@ -91,14 +91,14 @@ func (rule *LatchedMappingRule) MatchEvent(device *evdev.InputDevice, event *evd
return rule.Output.CreateEvent(value, mode) return rule.Output.CreateEvent(value, mode)
} }
func (rule *ProportionalAxisMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent { func (rule *MappingRuleProportionalAxis) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) *evdev.InputEvent {
// STUB // STUB
return nil return nil
} }
// TimerEvent returns an event when enough time has passed (compared to the last recorded axis value) // TimerEvent returns an event when enough time has passed (compared to the last recorded axis value)
// to emit an event. // to emit an event.
func (rule *ProportionalAxisMappingRule) TimerEvent() *evdev.InputEvent { func (rule *MappingRuleProportionalAxis) TimerEvent() *evdev.InputEvent {
// STUB // STUB
return nil return nil
} }

View file

@ -11,26 +11,26 @@ type MappingRuleBase struct {
} }
// A Simple Mapping Rule can map a button to a button or an axis to an axis. // A Simple Mapping Rule can map a button to a button or an axis to an axis.
type SimpleMappingRule struct { type MappingRuleSimple struct {
MappingRuleBase MappingRuleBase
Input RuleTarget Input RuleTarget
} }
// A Combo Mapping Rule can require multiple physical button presses for a single output button // A Combo Mapping Rule can require multiple physical button presses for a single output button
type ComboMappingRule struct { type MappingRuleCombo struct {
MappingRuleBase MappingRuleBase
Inputs []RuleTarget Inputs []RuleTarget
State int State int
} }
type LatchedMappingRule struct { type MappingRuleLatched struct {
MappingRuleBase MappingRuleBase
Input RuleTarget Input RuleTarget
State bool State bool
} }
// TODO: How are we going to implement this? It needs to operate on a timer... // TODO: How are we going to implement this? It needs to operate on a timer...
type ProportionalAxisMappingRule struct { type MappingRuleProportionalAxis struct {
MappingRuleBase MappingRuleBase
Input RuleTarget Input RuleTarget
Output RuleTarget Output RuleTarget