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
51
internal/mappingrules/mapping_rule_axis_to_button.go
Normal file
51
internal/mappingrules/mapping_rule_axis_to_button.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package mappingrules
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
// TODO: This whole file is still WIP
|
||||
type MappingRuleAxisToButton struct {
|
||||
MappingRuleBase
|
||||
Input *RuleTargetAxis
|
||||
Output *RuleTargetButton
|
||||
RepeatSpeedMin int32
|
||||
RepeatSpeedMax int32
|
||||
lastValue int32
|
||||
lastEvent time.Time
|
||||
}
|
||||
|
||||
func (rule *MappingRuleAxisToButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||
!rule.Input.MatchEvent(device, event) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// set the last value to the normalized input value
|
||||
rule.lastValue = rule.Input.NormalizeValue(event.Value)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TimerEvent returns an event when enough time has passed (compared to the last recorded axis value)
|
||||
// to emit an event.
|
||||
func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent {
|
||||
// This is tighter coupling than we'd like, but it will do for now.
|
||||
// TODO: maybe it would be better to just be more declarative about event types and their inputs and outputs.
|
||||
if rule.lastValue < rule.Input.DeadzoneStart {
|
||||
rule.lastEvent = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
// calculate target time until next event press
|
||||
// nextEvent := rule.LastEvent + (rule.LastValue)
|
||||
|
||||
// TODO: figure out what the condition should be
|
||||
if false {
|
||||
// TODO: emit event
|
||||
rule.lastEvent = time.Now()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue