joyful/internal/mappingrules/mapping_rule_axis.go
Anna Rose Wiggins 97a1acd228 Add more deadzone specification options. (#9)
Reviewed-on: #9
Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com>
Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
2025-07-18 23:10:12 +00:00

28 lines
910 B
Go

package mappingrules
import "github.com/holoplot/go-evdev"
// A Simple Mapping Rule can map a button to a button or an axis to an axis.
type MappingRuleAxis struct {
MappingRuleBase
Input *RuleTargetAxis
Output *RuleTargetAxis
}
func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *RuleTargetAxis) *MappingRuleAxis {
return &MappingRuleAxis{
MappingRuleBase: base,
Input: input,
Output: output,
}
}
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
}
// The cast here is safe because the interface is only ever different for unit tests
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
}