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:
Anna Rose Wiggins 2025-07-08 03:26:24 +00:00 committed by Anna Rose
parent a0949e719f
commit ff38db6596
21 changed files with 413 additions and 309 deletions

View file

@ -5,35 +5,43 @@ import (
)
type RuleTargetAxis struct {
RuleTargetBase
AxisStart int32
AxisEnd int32
Sensitivity float64
DeviceName string
Device *evdev.InputDevice
Axis evdev.EvCode
Inverted bool
DeadzoneStart int32
DeadzoneEnd int32
Sensitivity float64
}
func NewRuleTargetAxis(device_name string,
device *evdev.InputDevice,
code evdev.EvCode,
axis evdev.EvCode,
inverted bool,
axis_start int32,
axis_end int32,
deadzone_start int32,
deadzone_end int32,
sensitivity float64) *RuleTargetAxis {
return &RuleTargetAxis{
RuleTargetBase: NewRuleTargetBase(device_name, device, code, inverted),
AxisStart: axis_start,
AxisEnd: axis_end,
Sensitivity: sensitivity,
DeviceName: device_name,
Device: device,
Axis: axis,
Inverted: inverted,
DeadzoneStart: deadzone_start,
DeadzoneEnd: deadzone_end,
Sensitivity: sensitivity,
}
}
// TODO: lots of fixes and decisions to make here. Should we normalize all axes to the same range?
// How do we handle deadzones in light of that?
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
if !target.Inverted {
return value
}
axisRange := target.AxisEnd - target.AxisStart
axisMid := target.AxisEnd - axisRange/2
axisRange := target.DeadzoneEnd - target.DeadzoneStart
axisMid := target.DeadzoneEnd - axisRange/2
delta := value - axisMid
if delta < 0 {
delta = -delta
@ -55,7 +63,13 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu
// TODO: oh no we need center deadzones actually...
return &evdev.InputEvent{
Type: evdev.EV_ABS,
Code: target.Code,
Code: target.Axis,
Value: value,
}
}
func (target *RuleTargetAxis) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent) bool {
return device == target.Device &&
event.Type == evdev.EV_ABS &&
event.Code == target.Axis
}