Implement combined axis logic and tests.
This commit is contained in:
parent
a7e78c33f3
commit
49292ff13f
5 changed files with 192 additions and 65 deletions
|
@ -1,15 +1,51 @@
|
|||
package mappingrules
|
||||
|
||||
import "github.com/holoplot/go-evdev"
|
||||
import (
|
||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
type MappingRuleAxisCombined struct {
|
||||
MappingRuleBase
|
||||
InputLower *RuleTargetAxis
|
||||
InputUpper *RuleTargetAxis
|
||||
Output *RuleTargetAxis
|
||||
}
|
||||
|
||||
func NewMappingRuleAxisCombined(base MappingRuleBase, inputLower *RuleTargetAxis, inputUpper *RuleTargetAxis, output *RuleTargetAxis) *MappingRuleAxisCombined {
|
||||
return nil
|
||||
inputLower.OutputMax = 0
|
||||
inputUpper.OutputMin = 0
|
||||
return &MappingRuleAxisCombined{
|
||||
MappingRuleBase: base,
|
||||
InputLower: inputLower,
|
||||
InputUpper: inputUpper,
|
||||
Output: output,
|
||||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleAxisCombined) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
return nil, nil
|
||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||
!(rule.InputLower.MatchEvent(device, event) ||
|
||||
rule.InputUpper.MatchEvent(device, event)) {
|
||||
logger.Log("DEBUG: Did not match event")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Since lower and upper are guaranteed to have opposite signs,
|
||||
// we can just sum them.
|
||||
var value int32
|
||||
value += getValueFromAbs(rule.InputLower)
|
||||
value += getValueFromAbs(rule.InputUpper)
|
||||
|
||||
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(value, mode)
|
||||
}
|
||||
|
||||
func getValueFromAbs(ruleTarget *RuleTargetAxis) int32 {
|
||||
absInfo, err := ruleTarget.Device.AbsInfos()
|
||||
if err != nil {
|
||||
logger.LogErrorf(err, "WARNING: Couldn't get axis data for device '%s'", ruleTarget.DeviceName)
|
||||
return 0
|
||||
}
|
||||
|
||||
return ruleTarget.NormalizeValue(absInfo[ruleTarget.Axis].Value)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue