Start adding stubs and tests for combined axis, and updating RuleTargetAxis to support it.
This commit is contained in:
parent
4c04a9215d
commit
a7e78c33f3
3 changed files with 109 additions and 1 deletions
15
internal/mappingrules/mapping_rule_axis_combined.go
Normal file
15
internal/mappingrules/mapping_rule_axis_combined.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package mappingrules
|
||||
|
||||
import "github.com/holoplot/go-evdev"
|
||||
|
||||
type MappingRuleAxisCombined struct {
|
||||
MappingRuleBase
|
||||
}
|
||||
|
||||
func NewMappingRuleAxisCombined(base MappingRuleBase, inputLower *RuleTargetAxis, inputUpper *RuleTargetAxis, output *RuleTargetAxis) *MappingRuleAxisCombined {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rule *MappingRuleAxisCombined) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
return nil, nil
|
||||
}
|
71
internal/mappingrules/mapping_rule_axis_combined_test.go
Normal file
71
internal/mappingrules/mapping_rule_axis_combined_test.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
package mappingrules
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/holoplot/go-evdev"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// TODO: revisit all of this after adding new functionality to
|
||||
// RuleTargetAxis
|
||||
type MappingRuleAxisCombinedTests struct {
|
||||
suite.Suite
|
||||
|
||||
inputDevice *InputDeviceMock
|
||||
outputDevice *evdev.InputDevice
|
||||
inputTargetLower *RuleTargetAxis
|
||||
inputTargetUpper *RuleTargetAxis
|
||||
outputTarget *RuleTargetAxis
|
||||
|
||||
base MappingRuleBase
|
||||
mode *string
|
||||
}
|
||||
|
||||
func TestRunnerMappingRuleAxisCombined(t *testing.T) {
|
||||
suite.Run(t, new(MappingRuleAxisCombinedTests))
|
||||
}
|
||||
|
||||
func (t *MappingRuleAxisCombinedTests) SetupTest() {
|
||||
mode := "*"
|
||||
t.mode = &mode
|
||||
t.inputDevice = new(InputDeviceMock)
|
||||
t.inputDevice.On("AbsInfos").Return(map[evdev.EvCode]evdev.AbsInfo{
|
||||
evdev.ABS_X: {
|
||||
Minimum: 0,
|
||||
Maximum: 10000,
|
||||
},
|
||||
evdev.ABS_Y: {
|
||||
Minimum: 0,
|
||||
Maximum: 10000,
|
||||
},
|
||||
}, nil)
|
||||
|
||||
t.outputDevice = &evdev.InputDevice{}
|
||||
t.outputTarget, _ = NewRuleTargetAxis("test-output", t.outputDevice, evdev.ABS_X, false, 0, 0)
|
||||
t.base = NewMappingRuleBase("", []string{"*"})
|
||||
}
|
||||
|
||||
func (t *MappingRuleAxisCombinedTests) TestMatchEventSplitAxis() {
|
||||
t.inputTargetLower, _ = NewRuleTargetAxisPartial("test-input", t.inputDevice, evdev.ABS_X, true, 0, 0, AxisValueMin, 0)
|
||||
t.inputTargetUpper, _ = NewRuleTargetAxisPartial("test-input", t.inputDevice, evdev.ABS_Y, false, 0, 0, 0, AxisValueMax)
|
||||
|
||||
rule := NewMappingRuleAxisCombined(t.base, t.inputTargetLower, t.inputTargetUpper, t.outputTarget)
|
||||
|
||||
t.Run("Lower Input", func() {
|
||||
device, event := rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 10000}, t.mode)
|
||||
t.Equal(t.outputDevice, device)
|
||||
t.EqualValues(0, event.Value)
|
||||
|
||||
_, event = rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 0}, t.mode)
|
||||
t.EqualValues(AxisValueMin, event.Value)
|
||||
|
||||
_, event = rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 5000}, t.mode)
|
||||
t.EqualValues(0, event.Value)
|
||||
})
|
||||
|
||||
t.Run("Upper Input Only", func() {
|
||||
|
||||
})
|
||||
|
||||
}
|
|
@ -14,6 +14,8 @@ type RuleTargetAxis struct {
|
|||
Inverted bool
|
||||
DeadzoneStart int32
|
||||
DeadzoneEnd int32
|
||||
OutputMin int32
|
||||
OutputMax int32
|
||||
axisSize int32
|
||||
deadzoneSize int32
|
||||
}
|
||||
|
@ -24,6 +26,26 @@ func NewRuleTargetAxis(device_name string,
|
|||
inverted bool,
|
||||
deadzoneStart int32,
|
||||
deadzoneEnd int32) (*RuleTargetAxis, error) {
|
||||
return NewRuleTargetAxisPartial(
|
||||
device_name,
|
||||
device,
|
||||
axis,
|
||||
inverted,
|
||||
deadzoneStart,
|
||||
deadzoneEnd,
|
||||
AxisValueMin,
|
||||
AxisValueMax,
|
||||
)
|
||||
}
|
||||
|
||||
func NewRuleTargetAxisPartial(device_name string,
|
||||
device Device,
|
||||
axis evdev.EvCode,
|
||||
inverted bool,
|
||||
deadzoneStart int32,
|
||||
deadzoneEnd int32,
|
||||
minOutput int32,
|
||||
maxOutput int32) (*RuleTargetAxis, error) {
|
||||
|
||||
info, err := device.AbsInfos()
|
||||
|
||||
|
@ -77,7 +99,7 @@ func NewRuleTargetAxis(device_name string,
|
|||
// in the deadzone, among other things.
|
||||
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
||||
axisStrength := target.GetAxisStrength(value)
|
||||
return LerpInt(AxisValueMin, AxisValueMax, axisStrength)
|
||||
return LerpInt(target.OutputMin, target.OutputMax, axisStrength)
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue