Fix combo rules and add some example config.
This commit is contained in:
parent
428749a519
commit
a5b59bf39e
6 changed files with 93 additions and 6 deletions
|
@ -21,6 +21,7 @@ func makeSimpleRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice,
|
|||
return &mappingrules.SimpleMappingRule{
|
||||
Input: input,
|
||||
Output: output,
|
||||
Name: ruleConfig.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -42,6 +43,7 @@ func makeComboRule(ruleConfig RuleConfig, pDevs map[string]*evdev.InputDevice, v
|
|||
return &mappingrules.ComboMappingRule{
|
||||
Inputs: inputs,
|
||||
Output: output,
|
||||
Name: ruleConfig.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -61,6 +63,7 @@ func makeRuleTarget(targetConfig RuleTargetConfig, devs map[string]*evdev.InputD
|
|||
}
|
||||
ruleTarget.Type = eventType
|
||||
ruleTarget.Code = eventCode
|
||||
ruleTarget.Inverted = targetConfig.Inverted
|
||||
|
||||
return ruleTarget, nil
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func Log(msg string) {
|
|||
}
|
||||
|
||||
func Logf(msg string, params ...interface{}) {
|
||||
fmt.Printf(msg, params...)
|
||||
fmt.Printf(msg+"\n", params...)
|
||||
}
|
||||
|
||||
func LogError(err error, msg string) {
|
||||
|
|
|
@ -27,16 +27,16 @@ func valueFromTarget(rule RuleTarget, event *evdev.InputEvent) int32 {
|
|||
value = 0
|
||||
}
|
||||
case evdev.EV_ABS:
|
||||
// TODO: how would we invert axes?
|
||||
logger.Logf("STUB: Inverting axes is not yet implemented.")
|
||||
default:
|
||||
logger.Logf("Inverted rule for unknown event type '%d'. Not inverting value\n", event.Type)
|
||||
logger.Logf("Inverted rule for unknown event type '%d'. Not inverting value", event.Type)
|
||||
}
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func (rule SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) *evdev.InputEvent {
|
||||
func (rule *SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) *evdev.InputEvent {
|
||||
if device != rule.Input.Device ||
|
||||
event.Code != rule.Input.Code {
|
||||
return nil
|
||||
|
@ -45,7 +45,7 @@ func (rule SimpleMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev
|
|||
return eventFromTarget(rule.Output, valueFromTarget(rule.Input, event))
|
||||
}
|
||||
|
||||
func (rule ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) *evdev.InputEvent {
|
||||
func (rule *ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) *evdev.InputEvent {
|
||||
// Check each of the inputs, and if we find a match, proceed
|
||||
var match *RuleTarget
|
||||
for _, input := range rule.Inputs {
|
||||
|
@ -63,12 +63,13 @@ func (rule ComboMappingRule) MatchEvent(device *evdev.InputDevice, event *evdev.
|
|||
inputValue := valueFromTarget(*match, event)
|
||||
oldState := rule.State
|
||||
if inputValue == 0 {
|
||||
rule.State--
|
||||
rule.State = max(rule.State-1, 0)
|
||||
}
|
||||
if inputValue == 1 {
|
||||
rule.State++
|
||||
}
|
||||
targetState := len(rule.Inputs)
|
||||
|
||||
if oldState == targetState-1 && rule.State == targetState {
|
||||
return eventFromTarget(rule.Output, 1)
|
||||
}
|
||||
|
|
|
@ -10,12 +10,14 @@ type MappingRule interface {
|
|||
type SimpleMappingRule struct {
|
||||
Input RuleTarget
|
||||
Output RuleTarget
|
||||
Name string
|
||||
}
|
||||
|
||||
// A Combo Mapping Rule can require multiple physical button presses for a single output button
|
||||
type ComboMappingRule struct {
|
||||
Inputs []RuleTarget
|
||||
Output RuleTarget
|
||||
Name string
|
||||
State int
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue