Completed implementation.
This commit is contained in:
parent
0915ea059a
commit
58abd4cc34
10 changed files with 260 additions and 66 deletions
|
@ -77,12 +77,7 @@ func NewRuleTargetAxis(device_name string,
|
|||
// in the deadzone, among other things.
|
||||
func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
||||
axisStrength := target.GetAxisStrength(value)
|
||||
|
||||
if target.Inverted {
|
||||
axisStrength = 1.0 - axisStrength
|
||||
}
|
||||
normalizedValue := LerpInt(AxisValueMin, AxisValueMax, axisStrength)
|
||||
return normalizedValue
|
||||
return LerpInt(AxisValueMin, AxisValueMax, axisStrength)
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
|
@ -111,6 +106,16 @@ func (target *RuleTargetAxis) InDeadZone(value int32) bool {
|
|||
return value >= target.DeadzoneStart && value <= target.DeadzoneEnd
|
||||
}
|
||||
|
||||
// GetAxisStrength returns a float between 0.0 and 1.0, representing the proportional
|
||||
// position along the axis' full range. (after factoring in deadzones)
|
||||
// Calling this function with `value` inside the deadzone range will produce undefined behavior
|
||||
func (target *RuleTargetAxis) GetAxisStrength(value int32) float64 {
|
||||
return float64(value-target.deadzoneSize) / float64(target.axisSize)
|
||||
if value > target.DeadzoneEnd {
|
||||
value -= target.deadzoneSize
|
||||
}
|
||||
strength := float64(value) / float64(target.axisSize)
|
||||
if target.Inverted {
|
||||
strength = 1.0 - strength
|
||||
}
|
||||
return strength
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue