Don't fail target creation when AbsInfo errors.
This commit is contained in:
parent
6646044d28
commit
681e1fef70
2 changed files with 30 additions and 14 deletions
|
@ -19,8 +19,8 @@ type RuleTargetAxis struct {
|
|||
}
|
||||
|
||||
const (
|
||||
MinAxisValue = int32(-32768)
|
||||
MaxAxisValue = int32(32767)
|
||||
AxisValueMin = int32(-32768)
|
||||
AxisValueMax = int32(32767)
|
||||
)
|
||||
|
||||
func NewRuleTargetAxis(device_name string,
|
||||
|
@ -31,8 +31,16 @@ func NewRuleTargetAxis(device_name string,
|
|||
deadzoneEnd int32) (*RuleTargetAxis, error) {
|
||||
|
||||
info, err := device.AbsInfos()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// If we can't get AbsInfo (for example, we're a virtual device)
|
||||
// we set the bounds to the maximum allowable
|
||||
info = map[evdev.EvCode]evdev.AbsInfo{
|
||||
axis: {
|
||||
Minimum: AxisValueMin,
|
||||
Maximum: AxisValueMax,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := info[axis]; !ok {
|
||||
|
@ -77,12 +85,12 @@ func (target *RuleTargetAxis) NormalizeValue(value int32) int32 {
|
|||
if target.Inverted {
|
||||
axisStrength = 1.0 - axisStrength
|
||||
}
|
||||
normalizedValue := LerpInt(MinAxisValue, MaxAxisValue, axisStrength)
|
||||
normalizedValue := LerpInt(AxisValueMin, AxisValueMax, axisStrength)
|
||||
return normalizedValue
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.InputEvent {
|
||||
value = ClampInt(value, MinAxisValue, MaxAxisValue)
|
||||
value = ClampInt(value, AxisValueMin, AxisValueMax)
|
||||
return &evdev.InputEvent{
|
||||
Type: evdev.EV_ABS,
|
||||
Code: target.Axis,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue