Implement axis targets, axis -> button and axis -> relative axis mappings. #1
9 changed files with 28 additions and 16 deletions
|
@ -1,7 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -134,13 +133,22 @@ func makeMappingRuleAxis(ruleConfig RuleConfig,
|
||||||
return mappingrules.NewMappingRuleAxis(base, input, output), nil
|
return mappingrules.NewMappingRuleAxis(base, input, output), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// STUB
|
|
||||||
func makeMappingRuleAxisToButton(ruleConfig RuleConfig,
|
func makeMappingRuleAxisToButton(ruleConfig RuleConfig,
|
||||||
pDevs map[string]*evdev.InputDevice,
|
pDevs map[string]*evdev.InputDevice,
|
||||||
vDevs map[string]*evdev.InputDevice,
|
vDevs map[string]*evdev.InputDevice,
|
||||||
base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleAxisToButton, error) {
|
base mappingrules.MappingRuleBase) (*mappingrules.MappingRuleAxisToButton, error) {
|
||||||
|
|
||||||
return nil, errors.New("stub: makeMappingRuleAxisToButton")
|
input, err := makeRuleTargetAxis(ruleConfig.Input, pDevs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := makeRuleTargetButton(ruleConfig.Output, vDevs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappingrules.NewMappingRuleAxisToButton(base, input, output, ruleConfig.RepeatRateMin, ruleConfig.RepeatRateMax), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeMappingRuleModeSelect(ruleConfig RuleConfig,
|
func makeMappingRuleModeSelect(ruleConfig RuleConfig,
|
||||||
|
|
|
@ -25,6 +25,8 @@ type RuleConfig struct {
|
||||||
Inputs []RuleTargetConfig `yaml:"inputs,omitempty"`
|
Inputs []RuleTargetConfig `yaml:"inputs,omitempty"`
|
||||||
Output RuleTargetConfig `yaml:"output"`
|
Output RuleTargetConfig `yaml:"output"`
|
||||||
Modes []string `yaml:"modes,omitempty"`
|
Modes []string `yaml:"modes,omitempty"`
|
||||||
|
RepeatRateMin int `yaml:"repeat_rate_min,omitempty"`
|
||||||
|
RepeatRateMax int `yaml:"repeat_rate_max,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleTargetConfig struct {
|
type RuleTargetConfig struct {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package mappingrules
|
||||||
import "github.com/holoplot/go-evdev"
|
import "github.com/holoplot/go-evdev"
|
||||||
|
|
||||||
type MappingRule interface {
|
type MappingRule interface {
|
||||||
MatchEvent(*evdev.InputDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
|
MatchEvent(RuleTargetDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RuleTargets represent either a device input to match on, or an output to produce.
|
// RuleTargets represent either a device input to match on, or an output to produce.
|
||||||
|
@ -25,6 +25,8 @@ type RuleTarget interface {
|
||||||
// Typically int32 is the input event's normalized value. *string is the current mode, but is optional
|
// Typically int32 is the input event's normalized value. *string is the current mode, but is optional
|
||||||
// for most implementations.
|
// for most implementations.
|
||||||
CreateEvent(int32, *string) *evdev.InputEvent
|
CreateEvent(int32, *string) *evdev.InputEvent
|
||||||
|
|
||||||
|
MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing
|
// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing
|
||||||
|
|
|
@ -17,7 +17,7 @@ func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *Rul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleAxis) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
func (rule *MappingRuleAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||||
!rule.Input.MatchEvent(device, event) {
|
!rule.Input.MatchEvent(device, event) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -21,7 +21,7 @@ func NewMappingRuleButton(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func NewMappingRuleButtonCombo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleButtonCombo) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func NewMappingRuleButtonLatched(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleButtonLatched) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func NewMappingRuleModeSelect(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleModeSelect) MatchEvent(
|
func (rule *MappingRuleModeSelect) MatchEvent(
|
||||||
device *evdev.InputDevice,
|
device RuleTargetDevice,
|
||||||
event *evdev.InputEvent,
|
event *evdev.InputEvent,
|
||||||
mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (target *RuleTargetButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) bool {
|
func (target *RuleTargetButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||||
return device == target.Device &&
|
return device == target.Device &&
|
||||||
event.Type == evdev.EV_KEY &&
|
event.Type == evdev.EV_KEY &&
|
||||||
event.Code == target.Button
|
event.Code == target.Button
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue