Better deadzones #19
2 changed files with 17 additions and 11 deletions
|
|
@ -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.
|
**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 `start` and `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 `center` and `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 `center` and `size_percent` to use a percentage of the total axis size.
|
||||||
|
|
||||||
See <examples/ruletypes.yml> 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 <examples/> directory for usage examples.
|
||||||
|
|
||||||
## Modes
|
## Modes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,11 +105,19 @@ func NewRuleTargetAxis(device_name string,
|
||||||
// Typically this function is called after RuleTargetAxis.MatchEvent, which checks whether we are
|
// Typically this function is called after RuleTargetAxis.MatchEvent, which checks whether we are
|
||||||
// in the deadzone, among other things.
|
// in the deadzone, among other things.
|
||||||
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
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)
|
axisStrength := target.GetAxisStrength(value)
|
||||||
return LerpInt(target.OutputMin, target.OutputMax, axisStrength)
|
return LerpInt(target.OutputMin, target.OutputMax, axisStrength)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||||
|
fmt.Println("DEBUG: Emitting event")
|
||||||
value = Clamp(value, AxisValueMin, AxisValueMax)
|
value = Clamp(value, AxisValueMin, AxisValueMax)
|
||||||
return &evdev.InputEvent{
|
return &evdev.InputEvent{
|
||||||
Type: evdev.EV_ABS,
|
Type: evdev.EV_ABS,
|
||||||
|
|
@ -149,12 +157,6 @@ func (target *RuleTargetAxis) InDeadZone(value int32) bool {
|
||||||
func (target *RuleTargetAxis) GetAxisStrength(value int32) float64 {
|
func (target *RuleTargetAxis) GetAxisStrength(value int32) float64 {
|
||||||
adjValue := value
|
adjValue := value
|
||||||
for _, dz := range target.Deadzones {
|
for _, dz := range target.Deadzones {
|
||||||
state, dzValue := dz.Match(value)
|
|
||||||
if state == DeadzoneEmit {
|
|
||||||
adjValue = dzValue
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if value > dz.End {
|
if value > dz.End {
|
||||||
adjValue -= dz.Size
|
adjValue -= dz.Size
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue