Completed implementation.

This commit is contained in:
Anna Rose Wiggins 2025-07-15 15:27:49 -04:00
parent 0915ea059a
commit 58abd4cc34
10 changed files with 260 additions and 66 deletions

View file

@ -5,14 +5,13 @@ import (
"git.annabunches.net/annabunches/joyful/internal/logger"
"github.com/holoplot/go-evdev"
"github.com/jonboulle/clockwork"
)
// TODO: add tests
// TODO: deadzones seem to calculate correctly in one direction but not the other when computing axis strength...
// MappingRuleAxisToRelaxis represents a rule that converts an axis input into a (potentially repeating)
// button output.
// relative axis output. This is most commonly used to generate mouse output events
type MappingRuleAxisToRelaxis struct {
MappingRuleBase
Input *RuleTargetAxis
@ -22,6 +21,7 @@ type MappingRuleAxisToRelaxis struct {
Increment int32
nextEvent time.Duration
lastEvent time.Time
clock clockwork.Clock
}
func NewMappingRuleAxisToRelaxis(
@ -39,6 +39,7 @@ func NewMappingRuleAxisToRelaxis(
Increment: int32(increment),
lastEvent: time.Now(),
nextEvent: NoNextEvent,
clock: clockwork.NewRealClock(),
}
}
@ -81,12 +82,12 @@ func (rule *MappingRuleAxisToRelaxis) MatchEvent(
func (rule *MappingRuleAxisToRelaxis) TimerEvent() *evdev.InputEvent {
// This indicates that we should not emit another event
if rule.nextEvent == NoNextEvent {
rule.lastEvent = time.Now()
rule.lastEvent = rule.clock.Now()
return nil
}
if time.Now().Compare(rule.lastEvent.Add(rule.nextEvent)) > -1 {
rule.lastEvent = time.Now()
if rule.clock.Now().Compare(rule.lastEvent.Add(rule.nextEvent)) > -1 {
rule.lastEvent = rule.clock.Now()
return rule.Output.CreateEvent(rule.Increment, nil)
}