Big Refactor (#2)
Refactor Everything. Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
a0949e719f
commit
ff38db6596
21 changed files with 413 additions and 309 deletions
|
@ -1,49 +0,0 @@
|
|||
package mappingrules
|
||||
|
||||
import "github.com/holoplot/go-evdev"
|
||||
|
||||
// A Combo Mapping Rule can require multiple physical button presses for a single output button
|
||||
type MappingRuleCombo struct {
|
||||
MappingRuleBase
|
||||
Inputs []*RuleTargetButton
|
||||
Output *RuleTargetButton
|
||||
State int
|
||||
}
|
||||
|
||||
func (rule *MappingRuleCombo) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Check each of the inputs, and if we find a match, proceed
|
||||
var match RuleTarget
|
||||
for _, input := range rule.Inputs {
|
||||
if device == input.GetDevice() &&
|
||||
event.Code == input.GetCode() {
|
||||
match = input
|
||||
}
|
||||
}
|
||||
|
||||
if match == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Get the value and add/subtract it from State
|
||||
inputValue := match.NormalizeValue(event.Value)
|
||||
oldState := rule.State
|
||||
if inputValue == 0 {
|
||||
rule.State = max(rule.State-1, 0)
|
||||
}
|
||||
if inputValue == 1 {
|
||||
rule.State++
|
||||
}
|
||||
targetState := len(rule.Inputs)
|
||||
|
||||
if oldState == targetState-1 && rule.State == targetState {
|
||||
return rule.Output.GetDevice(), rule.Output.CreateEvent(1, mode)
|
||||
}
|
||||
if oldState == targetState && rule.State == targetState-1 {
|
||||
return rule.Output.GetDevice(), rule.Output.CreateEvent(0, mode)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue