diff --git a/docs/readme.md b/docs/readme.md index f6e7f37..5544f1b 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -73,13 +73,17 @@ evtest | grep BTN_ **NOTE: For most axis mappings, you probably don't want to specify a deadzone!** Use deadzone configurations in your target game instead. Joyful-configured deadzones are intended to be used in conjunction with the `axis-to-button` and `axis-to-relaxis` input types, or when splitting an axis into multiple outputs. Using them with standard `axis` mappings may result in a loss of fidelity and "stuck" inputs. -There are three ways to specify deadzones: +Axis inputs can define a list of deadzones. Each deadzone can be specified a few ways: -* Define `deadzone_start` and `deadzone_end` to explicitly set the deadzone bounds. -* Define `deadzone_center` and `deadzone_size`; this will create a deadzone of the indicated size centered at the given axis position. -* Define `deadzone_center` and `deadzone_size_percent` to use a percentage of the total axis size. +* Define `start` and `end` to explicitly set the deadzone bounds. +* Define `center` and `size`; this will create a deadzone of the indicated size centered at the given axis position. +* Define `center` and `size_percent` to use a percentage of the total axis size. -See for usage examples. +In addition, deadzones can set `emit` to `true` and `emit_value` to a value that should be emitted when inside the deadzone. + +**Note**: The `emit_value` is the final output value and should be between -32,768 and 32,767. + +See the directory for usage examples. ## Modes diff --git a/internal/mappingrules/rule_target_axis.go b/internal/mappingrules/rule_target_axis.go index a9b9804..6fa62f6 100644 --- a/internal/mappingrules/rule_target_axis.go +++ b/internal/mappingrules/rule_target_axis.go @@ -105,11 +105,19 @@ func NewRuleTargetAxis(device_name string, // Typically this function is called after RuleTargetAxis.MatchEvent, which checks whether we are // in the deadzone, among other things. func (target *RuleTargetAxis) NormalizeValue(value int32) int32 { + for _, dz := range target.Deadzones { + state, dzValue := dz.Match(value) + if state == DeadzoneEmit { + return Clamp(dzValue, target.OutputMin, target.OutputMax) + } + } + axisStrength := target.GetAxisStrength(value) return LerpInt(target.OutputMin, target.OutputMax, axisStrength) } func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent { + fmt.Println("DEBUG: Emitting event") value = Clamp(value, AxisValueMin, AxisValueMax) return &evdev.InputEvent{ Type: evdev.EV_ABS, @@ -149,12 +157,6 @@ func (target *RuleTargetAxis) InDeadZone(value int32) bool { func (target *RuleTargetAxis) GetAxisStrength(value int32) float64 { adjValue := value for _, dz := range target.Deadzones { - state, dzValue := dz.Match(value) - if state == DeadzoneEmit { - adjValue = dzValue - break - } - if value > dz.End { adjValue -= dz.Size }