Implement MappingRuleAxisToButton.
This commit is contained in:
parent
a6ad1b609a
commit
47fac539da
3 changed files with 81 additions and 27 deletions
|
@ -18,11 +18,6 @@ type RuleTargetAxis struct {
|
|||
deadzoneSize int32
|
||||
}
|
||||
|
||||
const (
|
||||
AxisValueMin = int32(-32768)
|
||||
AxisValueMax = int32(32767)
|
||||
)
|
||||
|
||||
func NewRuleTargetAxis(device_name string,
|
||||
device RuleTargetDevice,
|
||||
axis evdev.EvCode,
|
||||
|
@ -81,7 +76,7 @@ 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 {
|
||||
axisStrength := float64(value-target.deadzoneSize) / float64(target.axisSize)
|
||||
axisStrength := target.GetAxisStrength(value)
|
||||
|
||||
if target.Inverted {
|
||||
axisStrength = 1.0 - axisStrength
|
||||
|
@ -100,8 +95,22 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu
|
|||
}
|
||||
|
||||
func (target *RuleTargetAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||
return target.MatchEventDeviceAndCode(device, event) &&
|
||||
!target.InDeadZone(event.Value)
|
||||
}
|
||||
|
||||
// TODO: Add tests
|
||||
func (target *RuleTargetAxis) MatchEventDeviceAndCode(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||
return device == target.Device &&
|
||||
event.Type == evdev.EV_ABS &&
|
||||
event.Code == target.Axis &&
|
||||
(event.Value < target.DeadzoneStart || event.Value > target.DeadzoneEnd)
|
||||
event.Code == target.Axis
|
||||
}
|
||||
|
||||
// TODO: Add tests
|
||||
func (target *RuleTargetAxis) InDeadZone(value int32) bool {
|
||||
return value >= target.DeadzoneStart && value <= target.DeadzoneEnd
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) GetAxisStrength(value int32) float64 {
|
||||
return float64(value-target.deadzoneSize) / float64(target.axisSize)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue