Add more deadzone specification options. (#9)
Reviewed-on: #9 Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
5b9dfe0967
commit
97a1acd228
20 changed files with 344 additions and 108 deletions
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
type MappingRule interface {
|
||||
MatchEvent(RuleTargetDevice, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
|
||||
MatchEvent(Device, *evdev.InputEvent, *string) (*evdev.InputDevice, *evdev.InputEvent)
|
||||
}
|
||||
|
||||
type TimedEventEmitter interface {
|
||||
|
@ -35,13 +35,13 @@ type RuleTarget interface {
|
|||
// for most implementations.
|
||||
CreateEvent(int32, *string) *evdev.InputEvent
|
||||
|
||||
MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool
|
||||
MatchEvent(device Device, event *evdev.InputEvent) bool
|
||||
}
|
||||
|
||||
// RuleTargetDevice is an interface abstraction on top of evdev.InputDevice, implementing
|
||||
// Device is an interface abstraction on top of evdev.InputDevice, implementing
|
||||
// only the methods we need in this package. This is used for testing, and the
|
||||
// RuleTargetDevice can be safely cast to an *evdev.InputDevice when necessary.
|
||||
type RuleTargetDevice interface {
|
||||
// Device can be safely cast to an *evdev.InputDevice when necessary.
|
||||
type Device interface {
|
||||
AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ func NewMappingRuleAxis(base MappingRuleBase, input *RuleTargetAxis, output *Rul
|
|||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
func (rule *MappingRuleAxis) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||
!rule.Input.MatchEvent(device, event) {
|
||||
return nil, nil
|
||||
|
|
|
@ -39,7 +39,7 @@ func NewMappingRuleAxisToButton(base MappingRuleBase, input *RuleTargetAxis, out
|
|||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleAxisToButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
func (rule *MappingRuleAxisToButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
|
||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||
!rule.Input.MatchEventDeviceAndCode(device, event) {
|
||||
|
@ -105,5 +105,5 @@ func (rule *MappingRuleAxisToButton) TimerEvent() *evdev.InputEvent {
|
|||
}
|
||||
|
||||
func (rule *MappingRuleAxisToButton) GetOutputDevice() *evdev.InputDevice {
|
||||
return rule.Output.Device
|
||||
return rule.Output.Device.(*evdev.InputDevice)
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func NewMappingRuleAxisToRelaxis(
|
|||
}
|
||||
|
||||
func (rule *MappingRuleAxisToRelaxis) MatchEvent(
|
||||
device RuleTargetDevice,
|
||||
device Device,
|
||||
event *evdev.InputEvent,
|
||||
mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ func NewMappingRuleButton(
|
|||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
func (rule *MappingRuleButton) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -31,5 +31,5 @@ func (rule *MappingRuleButton) MatchEvent(device RuleTargetDevice, event *evdev.
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
return rule.Output.Device, rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
|
||||
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func NewMappingRuleButtonCombo(
|
|||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
func (rule *MappingRuleButtonCombo) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ func (rule *MappingRuleButtonCombo) MatchEvent(device RuleTargetDevice, event *e
|
|||
targetState := len(rule.Inputs)
|
||||
|
||||
if oldState == targetState-1 && rule.State == targetState {
|
||||
return rule.Output.Device, rule.Output.CreateEvent(1, mode)
|
||||
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(1, mode)
|
||||
}
|
||||
if oldState == targetState && rule.State == targetState-1 {
|
||||
return rule.Output.Device, rule.Output.CreateEvent(0, mode)
|
||||
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(0, mode)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewMappingRuleButtonLatched(
|
|||
}
|
||||
}
|
||||
|
||||
func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
func (rule *MappingRuleButtonLatched) MatchEvent(device Device, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
if !rule.MappingRuleBase.modeCheck(mode) {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -42,5 +42,5 @@ func (rule *MappingRuleButtonLatched) MatchEvent(device RuleTargetDevice, event
|
|||
value = 0
|
||||
}
|
||||
|
||||
return rule.Output.Device, rule.Output.CreateEvent(value, mode)
|
||||
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(value, mode)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewMappingRuleModeSelect(
|
|||
}
|
||||
|
||||
func (rule *MappingRuleModeSelect) MatchEvent(
|
||||
device RuleTargetDevice,
|
||||
device Device,
|
||||
event *evdev.InputEvent,
|
||||
mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
type RuleTargetAxis struct {
|
||||
DeviceName string
|
||||
Device RuleTargetDevice
|
||||
Device Device
|
||||
Axis evdev.EvCode
|
||||
Inverted bool
|
||||
DeadzoneStart int32
|
||||
|
@ -19,7 +19,7 @@ type RuleTargetAxis struct {
|
|||
}
|
||||
|
||||
func NewRuleTargetAxis(device_name string,
|
||||
device RuleTargetDevice,
|
||||
device Device,
|
||||
axis evdev.EvCode,
|
||||
inverted bool,
|
||||
deadzoneStart int32,
|
||||
|
@ -89,13 +89,13 @@ func (target *RuleTargetAxis) CreateEvent(value int32, mode *string) *evdev.Inpu
|
|||
}
|
||||
}
|
||||
|
||||
func (target *RuleTargetAxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||
func (target *RuleTargetAxis) MatchEvent(device Device, 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 {
|
||||
func (target *RuleTargetAxis) MatchEventDeviceAndCode(device Device, event *evdev.InputEvent) bool {
|
||||
return device == target.Device &&
|
||||
event.Type == evdev.EV_ABS &&
|
||||
event.Code == target.Axis
|
||||
|
|
|
@ -4,12 +4,12 @@ import "github.com/holoplot/go-evdev"
|
|||
|
||||
type RuleTargetButton struct {
|
||||
DeviceName string
|
||||
Device *evdev.InputDevice
|
||||
Device Device
|
||||
Button evdev.EvCode
|
||||
Inverted bool
|
||||
}
|
||||
|
||||
func NewRuleTargetButton(device_name string, device *evdev.InputDevice, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) {
|
||||
func NewRuleTargetButton(device_name string, device Device, code evdev.EvCode, inverted bool) (*RuleTargetButton, error) {
|
||||
return &RuleTargetButton{
|
||||
DeviceName: device_name,
|
||||
Device: device,
|
||||
|
@ -36,7 +36,7 @@ func (target *RuleTargetButton) CreateEvent(value int32, _ *string) *evdev.Input
|
|||
}
|
||||
}
|
||||
|
||||
func (target *RuleTargetButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||
func (target *RuleTargetButton) MatchEvent(device Device, event *evdev.InputEvent) bool {
|
||||
return device == target.Device &&
|
||||
event.Type == evdev.EV_KEY &&
|
||||
event.Code == target.Button
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
|
||||
type RuleTargetRelaxis struct {
|
||||
DeviceName string
|
||||
Device RuleTargetDevice
|
||||
Device Device
|
||||
Axis evdev.EvCode
|
||||
Inverted bool
|
||||
}
|
||||
|
||||
func NewRuleTargetRelaxis(device_name string,
|
||||
device RuleTargetDevice,
|
||||
device Device,
|
||||
axis evdev.EvCode,
|
||||
inverted bool) (*RuleTargetRelaxis, error) {
|
||||
|
||||
|
@ -41,6 +41,6 @@ func (target *RuleTargetRelaxis) CreateEvent(value int32, mode *string) *evdev.I
|
|||
}
|
||||
|
||||
// Relative axis is only supported for output.
|
||||
func (target *RuleTargetRelaxis) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent) bool {
|
||||
func (target *RuleTargetRelaxis) MatchEvent(device Device, event *evdev.InputEvent) bool {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue