Clamp values falling outside of the axis bounds.

This commit is contained in:
Anna Rose Wiggins 2025-07-10 19:58:31 -04:00
parent 681e1fef70
commit a6ad1b609a
3 changed files with 17 additions and 6 deletions

View file

@ -51,7 +51,7 @@ func NewRuleTargetAxis(device_name string,
return nil, errors.New("deadzone_end must be a higher value than deadzone_start")
}
deadzoneSize := AbsInt(deadzoneEnd - deadzoneStart)
deadzoneSize := Abs(deadzoneEnd - deadzoneStart)
// Our output range is limited to 16 bits, but we represent values internally with 32 bits.
// As a result, we shouldn't need to worry about integer overruns
@ -82,6 +82,7 @@ func NewRuleTargetAxis(device_name string,
// in the deadzone, among other things.
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
axisStrength := float64(value-target.deadzoneSize) / float64(target.axisSize)
if target.Inverted {
axisStrength = 1.0 - axisStrength
}
@ -90,7 +91,7 @@ func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
}
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
value = ClampInt(value, AxisValueMin, AxisValueMax)
value = Clamp(value, AxisValueMin, AxisValueMax)
return &evdev.InputEvent{
Type: evdev.EV_ABS,
Code: target.Axis,