Fix up refactored rule targets.
This commit is contained in:
parent
c14ec074d1
commit
db848db810
5 changed files with 71 additions and 38 deletions
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func (rule *MappingRuleBase) OutputName() string {
|
||||
return rule.Output.DeviceName
|
||||
return rule.Output.GetDeviceName()
|
||||
}
|
||||
|
||||
func (rule *MappingRuleBase) modeCheck(mode *string) bool {
|
||||
|
@ -22,12 +22,12 @@ func (rule *SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evde
|
|||
return nil
|
||||
}
|
||||
|
||||
if device != rule.Input.Device ||
|
||||
event.Code != rule.Input.Code {
|
||||
if device != rule.Input.GetDevice() ||
|
||||
event.Code != rule.Input.GetCode() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return eventFromTarget(rule.Output, valueFromTarget(rule.Input, event), 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 {
|
||||
|
@ -36,11 +36,11 @@ func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev
|
|||
}
|
||||
|
||||
// Check each of the inputs, and if we find a match, proceed
|
||||
var match *RuleTarget
|
||||
var match RuleTarget
|
||||
for _, input := range rule.Inputs {
|
||||
if device == input.Device &&
|
||||
event.Code == input.Code {
|
||||
match = &input
|
||||
if device == input.GetDevice() &&
|
||||
event.Code == input.GetCode() {
|
||||
match = input
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev
|
|||
}
|
||||
|
||||
// Get the value and add/subtract it from State
|
||||
inputValue := valueFromTarget(*match, event)
|
||||
inputValue := match.NormalizeValue(event.Value)
|
||||
oldState := rule.State
|
||||
if inputValue == 0 {
|
||||
rule.State = max(rule.State-1, 0)
|
||||
|
@ -60,10 +60,10 @@ func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev
|
|||
targetState := len(rule.Inputs)
|
||||
|
||||
if oldState == targetState-1 && rule.State == targetState {
|
||||
return eventFromTarget(rule.Output, 1, mode)
|
||||
return rule.Output.CreateEvent(1, mode)
|
||||
}
|
||||
if oldState == targetState && rule.State == targetState-1 {
|
||||
return eventFromTarget(rule.Output, 0, mode)
|
||||
return rule.Output.CreateEvent(0, mode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ func (rule *LatchedMappingRule) MatchEvent(device *evdev.InputDevice, event *evd
|
|||
return nil
|
||||
}
|
||||
|
||||
if device != rule.Input.Device ||
|
||||
event.Code != rule.Input.Code ||
|
||||
if device != rule.Input.GetDevice() ||
|
||||
event.Code != rule.Input.GetCode() ||
|
||||
rule.Input.NormalizeValue(event.Value) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,6 +7,18 @@ import (
|
|||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
func (target *RuleTargetBase) GetCode() evdev.EvCode {
|
||||
return target.Code
|
||||
}
|
||||
|
||||
func (target *RuleTargetBase) GetDeviceName() string {
|
||||
return target.DeviceName
|
||||
}
|
||||
|
||||
func (target *RuleTargetBase) GetDevice() *evdev.InputDevice {
|
||||
return target.Device
|
||||
}
|
||||
|
||||
func (target *RuleTargetButton) NormalizeValue(value int32) int32 {
|
||||
if value == 0 {
|
||||
return 1
|
||||
|
@ -14,6 +26,14 @@ func (target *RuleTargetButton) NormalizeValue(value int32) int32 {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (target *RuleTargetButton) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
return &evdev.InputEvent{
|
||||
Type: evdev.EV_KEY,
|
||||
Code: target.Code,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
||||
if !target.Inverted {
|
||||
return value
|
||||
|
@ -37,19 +57,6 @@ func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
|||
return value
|
||||
}
|
||||
|
||||
// RuleTargetModeSelect doesn't make sense as an input type
|
||||
func (target *RuleTargetModeSelect) NormalizeValue(value int32) int32 {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (target *RuleTargetButton) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
return &evdev.InputEvent{
|
||||
Type: evdev.EV_KEY,
|
||||
Code: target.Code,
|
||||
Value: value,
|
||||
}
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
return &evdev.InputEvent{
|
||||
Type: evdev.EV_ABS,
|
||||
|
@ -58,6 +65,11 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu
|
|||
}
|
||||
}
|
||||
|
||||
// RuleTargetModeSelect doesn't make sense as an input type
|
||||
func (target *RuleTargetModeSelect) NormalizeValue(value int32) int32 {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (target *RuleTargetModeSelect) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
if value == 0 {
|
||||
return nil
|
||||
|
|
|
@ -47,6 +47,9 @@ type ProportionalAxisMappingRule struct {
|
|||
type RuleTarget interface {
|
||||
NormalizeValue(int32) int32
|
||||
CreateEvent(int32, *string) *evdev.InputEvent
|
||||
GetCode() evdev.EvCode
|
||||
GetDeviceName() string
|
||||
GetDevice() *evdev.InputDevice
|
||||
}
|
||||
|
||||
type RuleTargetBase struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue