diff --git a/internal/mappingrules/interfaces.go b/internal/mappingrules/interfaces.go index bc10e9b..33b290a 100644 --- a/internal/mappingrules/interfaces.go +++ b/internal/mappingrules/interfaces.go @@ -7,7 +7,7 @@ import ( ) type MappingRule interface { - MatchEvent(RuleTargetDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent) + MatchEvent(Device, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent) } type TimedEventEmitter interface { @@ -35,13 +35,13 @@ type RuleTarget interface { // for most implementations. CreateEvent(int32, *string) *evdev.InputEvent - MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool + MatchEvent(device Device, event *evdev.InputEvent) bool } -// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing +// Device is an interface abstraction on top of evdev.InputDevice, implementing // only the methods we need in this package. This is used for testing, and the -// RuleTargetDevice can be safely cast to an *evdev.InputDevice when necessary. -type RuleTargetDevice interface { +// Device can be safely cast to an *evdev.InputDevice when necessary. +type Device interface { AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error) } diff --git a/internal/mappingrules/mapping_rule_axis.go b/internal/mappingrules/mapping_rule_axis.go index 7b3e778..a2ab41d 100644 --- a/internal/mappingrules/mapping_rule_axis.go +++ b/internal/mappingrules/mapping_rule_axis.go @@ -17,7 +17,7 @@ func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *Rul } } -func (rule *MappingRuleAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { +func (rule *MappingRuleAxis) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { if !rule.MappingRuleBase.modeCheck(mode) || !rule.Input.MatchEvent(device, event) { return nil, nil diff --git a/internal/mappingrules/mapping_rule_axis_to_button.go b/internal/mappingrules/mapping_rule_axis_to_button.go index 3e15312..3356dbe 100644 --- a/internal/mappingrules/mapping_rule_axis_to_button.go +++ b/internal/mappingrules/mapping_rule_axis_to_button.go @@ -39,7 +39,7 @@ func NewMappingRuleAxisToButton(base MappingRuleBase, input *RuleTargetAxis, out } } -func (rule *MappingRuleAxisToButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { +func (rule *MappingRuleAxisToButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { if !rule.MappingRuleBase.modeCheck(mode) || !rule.Input.MatchEventDeviceAndCode(device, event) { @@ -105,5 +105,5 @@ func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent { } func (rule *MappingRuleAxisToButton) GetOutputDevice() *evdev.InputDevice { - return rule.Output.Device + return rule.Output.Device.(*evdev.InputDevice) } diff --git a/internal/mappingrules/mapping_rule_axis_to_relaxis.go b/internal/mappingrules/mapping_rule_axis_to_relaxis.go index 16c3912..153b992 100644 --- a/internal/mappingrules/mapping_rule_axis_to_relaxis.go +++ b/internal/mappingrules/mapping_rule_axis_to_relaxis.go @@ -43,7 +43,7 @@ func NewMappingRuleAxisToRelaxis( } func (rule *MappingRuleAxisToRelaxis) MatchEvent( - device RuleTargetDevice, + device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { diff --git a/internal/mappingrules/mapping_rule_button.go b/internal/mappingrules/mapping_rule_button.go index a13d5a6..69a7cfe 100644 --- a/internal/mappingrules/mapping_rule_button.go +++ b/internal/mappingrules/mapping_rule_button.go @@ -21,7 +21,7 @@ func NewMappingRuleButton( } } -func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { +func (rule *MappingRuleButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { if !rule.MappingRuleBase.modeCheck(mode) { return nil, nil } @@ -31,5 +31,5 @@ func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev. return nil, nil } - return rule.Output.Device, rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode) + return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode) } diff --git a/internal/mappingrules/mapping_rule_button_combo.go b/internal/mappingrules/mapping_rule_button_combo.go index 4f488ef..a7b7c23 100644 --- a/internal/mappingrules/mapping_rule_button_combo.go +++ b/internal/mappingrules/mapping_rule_button_combo.go @@ -23,7 +23,7 @@ func NewMappingRuleButtonCombo( } } -func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { +func (rule *MappingRuleButtonCombo) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { if !rule.MappingRuleBase.modeCheck(mode) { return nil, nil } @@ -53,10 +53,10 @@ func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *e targetState := len(rule.Inputs) if oldState == targetState-1 && rule.State == targetState { - return rule.Output.Device, rule.Output.CreateEvent(1, mode) + return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(1, mode) } if oldState == targetState && rule.State == targetState-1 { - return rule.Output.Device, rule.Output.CreateEvent(0, mode) + return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(0, mode) } return nil, nil } diff --git a/internal/mappingrules/mapping_rule_button_latched.go b/internal/mappingrules/mapping_rule_button_latched.go index 1204968..d8e5bec 100644 --- a/internal/mappingrules/mapping_rule_button_latched.go +++ b/internal/mappingrules/mapping_rule_button_latched.go @@ -22,7 +22,7 @@ func NewMappingRuleButtonLatched( } } -func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { +func (rule *MappingRuleButtonLatched) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { if !rule.MappingRuleBase.modeCheck(mode) { return nil, nil } @@ -42,5 +42,5 @@ func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event value = 0 } - return rule.Output.Device, rule.Output.CreateEvent(value, mode) + return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(value, mode) } diff --git a/internal/mappingrules/mapping_rule_mode_select.go b/internal/mappingrules/mapping_rule_mode_select.go index 1bb13fa..69afd0b 100644 --- a/internal/mappingrules/mapping_rule_mode_select.go +++ b/internal/mappingrules/mapping_rule_mode_select.go @@ -22,7 +22,7 @@ func NewMappingRuleModeSelect( } func (rule *MappingRuleModeSelect) MatchEvent( - device RuleTargetDevice, + device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) { diff --git a/internal/mappingrules/rule_target_axis.go b/internal/mappingrules/rule_target_axis.go index c0d4b95..79b4492 100644 --- a/internal/mappingrules/rule_target_axis.go +++ b/internal/mappingrules/rule_target_axis.go @@ -9,7 +9,7 @@ import ( type RuleTargetAxis struct { DeviceName string - Device RuleTargetDevice + Device Device Axis evdev.EvCode Inverted bool DeadzoneStart int32 @@ -19,7 +19,7 @@ type RuleTargetAxis struct { } func NewRuleTargetAxis(device_name string, - device RuleTargetDevice, + device Device, axis evdev.EvCode, inverted bool, deadzoneStart int32, @@ -89,13 +89,13 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu } } -func (target *RuleTargetAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { +func (target *RuleTargetAxis) MatchEvent(device Device, event *evdev.InputEvent) bool { return target.MatchEventDeviceAndCode(device, event) && !target.InDeadZone(event.Value) } // TODO: Add tests -func (target *RuleTargetAxis) MatchEventDeviceAndCode(device RuleTargetDevice, event *evdev.InputEvent) bool { +func (target *RuleTargetAxis) MatchEventDeviceAndCode(device Device, event *evdev.InputEvent) bool { return device == target.Device && event.Type == evdev.EV_ABS && event.Code == target.Axis diff --git a/internal/mappingrules/rule_target_button.go b/internal/mappingrules/rule_target_button.go index 93534c7..68fd252 100644 --- a/internal/mappingrules/rule_target_button.go +++ b/internal/mappingrules/rule_target_button.go @@ -4,12 +4,12 @@ import "github.com/holoplot/go-evdev" type RuleTargetButton struct { DeviceName string - Device *evdev.InputDevice + Device Device Button evdev.EvCode Inverted bool } -func NewRuleTargetButton(device_name string, device *evdev.InputDevice, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) { +func NewRuleTargetButton(device_name string, device Device, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) { return &RuleTargetButton{ DeviceName: device_name, Device: device, @@ -36,7 +36,7 @@ func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.Input } } -func (target *RuleTargetButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { +func (target *RuleTargetButton) MatchEvent(device Device, event *evdev.InputEvent) bool { return device == target.Device && event.Type == evdev.EV_KEY && event.Code == target.Button diff --git a/internal/mappingrules/rule_target_relaxis.go b/internal/mappingrules/rule_target_relaxis.go index 648d7fc..8de8c0b 100644 --- a/internal/mappingrules/rule_target_relaxis.go +++ b/internal/mappingrules/rule_target_relaxis.go @@ -6,13 +6,13 @@ import ( type RuleTargetRelaxis struct { DeviceName string - Device RuleTargetDevice + Device Device Axis evdev.EvCode Inverted bool } func NewRuleTargetRelaxis(device_name string, - device RuleTargetDevice, + device Device, axis evdev.EvCode, inverted bool) (*RuleTargetRelaxis, error) { @@ -41,6 +41,6 @@ func (target *RuleTargetRelaxis) CreateEvent(value int32, mode *string) *evdev.I } // Relative axis is only supported for output. -func (target *RuleTargetRelaxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool { +func (target *RuleTargetRelaxis) MatchEvent(device Device, event *evdev.InputEvent) bool { return false }