Add support for Joystick hats.
This commit is contained in:
parent
62befa045a
commit
fce8888c77
8 changed files with 134 additions and 13 deletions
|
|
@ -70,6 +70,17 @@ rules:
|
||||||
device: main
|
device: main
|
||||||
axis: RZ
|
axis: RZ
|
||||||
|
|
||||||
|
# Hat mapping. Hats are technically an axis, but only output -1, 0, or 1, so we don't normalize
|
||||||
|
# them to an output range, we just pass them through mostly unmodified
|
||||||
|
- type: hat
|
||||||
|
input:
|
||||||
|
device: flightstick
|
||||||
|
inverted: true # hats do support inversion. As with other rule types, this only has an effect on *inputs*.
|
||||||
|
hat: hat0x # a typical joystick hat actually has 2 hat axes: x and y
|
||||||
|
output:
|
||||||
|
device: main
|
||||||
|
hat: hat0x
|
||||||
|
|
||||||
# Straightforward button mapping
|
# Straightforward button mapping
|
||||||
- type: button
|
- type: button
|
||||||
input:
|
input:
|
||||||
|
|
@ -111,8 +122,9 @@ rules:
|
||||||
input:
|
input:
|
||||||
device: flightstick
|
device: flightstick
|
||||||
axis: ABS_RY # This axis commonly represents thumbsticks
|
axis: ABS_RY # This axis commonly represents thumbsticks
|
||||||
deadzone_start: 0
|
deadzones:
|
||||||
deadzone_end: 30000
|
- start: 0
|
||||||
|
end: 30000
|
||||||
output:
|
output:
|
||||||
device: main
|
device: main
|
||||||
button: BTN_BASE4
|
button: BTN_BASE4
|
||||||
|
|
@ -129,8 +141,9 @@ rules:
|
||||||
input:
|
input:
|
||||||
device: flightstick
|
device: flightstick
|
||||||
axis: ABS_Z
|
axis: ABS_Z
|
||||||
deadzone_start: 0
|
deadzones:
|
||||||
deadzone_end: 500
|
- start: 0
|
||||||
|
end: 500
|
||||||
output:
|
output:
|
||||||
device: mouse
|
device: mouse
|
||||||
button: REL_WHEEL
|
button: REL_WHEEL
|
||||||
|
|
@ -48,6 +48,7 @@ All `rules` must have a `type` parameter. Valid values for this parameter are:
|
||||||
* `axis-combined` - a mapping that combines 2 input axes into a single output axis.
|
* `axis-combined` - a mapping that combines 2 input axes into a single output axis.
|
||||||
* `axis-to-button` - causes an axis input to produce a button output. This can be repeated with variable speed proportional to the axis' input value
|
* `axis-to-button` - causes an axis input to produce a button output. This can be repeated with variable speed proportional to the axis' input value
|
||||||
* `axis-to-relaxis` - like axis-to-button, but produces a "relative axis" output value. This is useful for simulating mouse scrollwheel and movement events.
|
* `axis-to-relaxis` - like axis-to-button, but produces a "relative axis" output value. This is useful for simulating mouse scrollwheel and movement events.
|
||||||
|
* `hat` - a special type of axis with ternary output. Each joystick hat will typically be 2 hat axes named `ABS_HAT0X` / `ABS_HAT0Y`, where the `0` is an index between 0 - 3. So for a typical hat you would define 2 `hat` rules.
|
||||||
|
|
||||||
Configuration options for each rule type vary. See [examples/ruletypes.yml](examples/ruletypes.yml) for an example of each type with all options specified.
|
Configuration options for each rule type vary. See [examples/ruletypes.yml](examples/ruletypes.yml) for an example of each type with all options specified.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,9 @@ type RuleTargetConfigRelaxis struct {
|
||||||
type RuleTargetConfigModeSelect struct {
|
type RuleTargetConfigModeSelect struct {
|
||||||
Modes []string
|
Modes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RuleTargetConfigHat struct {
|
||||||
|
Device string
|
||||||
|
Hat string
|
||||||
|
Inverted bool
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,11 @@ type RuleConfigAxis struct {
|
||||||
Output RuleTargetConfigAxis
|
Output RuleTargetConfigAxis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RuleConfigHat struct {
|
||||||
|
Input RuleTargetConfigHat
|
||||||
|
Output RuleTargetConfigHat
|
||||||
|
}
|
||||||
|
|
||||||
type RuleConfigAxisCombined struct {
|
type RuleConfigAxisCombined struct {
|
||||||
InputLower RuleTargetConfigAxis `yaml:"input_lower,omitempty"`
|
InputLower RuleTargetConfigAxis `yaml:"input_lower,omitempty"`
|
||||||
InputUpper RuleTargetConfigAxis `yaml:"input_upper,omitempty"`
|
InputUpper RuleTargetConfigAxis `yaml:"input_upper,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,6 @@ type RuleTarget interface {
|
||||||
// (e.g., inverting the value if Inverted == true)
|
// (e.g., inverting the value if Inverted == true)
|
||||||
NormalizeValue(int32) int32
|
NormalizeValue(int32) int32
|
||||||
|
|
||||||
// MatchEvent returns true if the provided device and input event are a match for this rule target
|
|
||||||
ValidateEvent(*evdev.InputDevice, *evdev.InputEvent) bool
|
|
||||||
|
|
||||||
// CreateEvent creates an event that can be emitted on a virtual device.
|
// CreateEvent creates an event that can be emitted on a virtual device.
|
||||||
// For RuleTargetModeSelect, this method modifies the active mode and returns nil.
|
// For RuleTargetModeSelect, this method modifies the active mode and returns nil.
|
||||||
//
|
//
|
||||||
|
|
@ -35,6 +32,7 @@ type RuleTarget interface {
|
||||||
// for most implementations.
|
// for most implementations.
|
||||||
CreateEvent(int32, *string) *evdev.InputEvent
|
CreateEvent(int32, *string) *evdev.InputEvent
|
||||||
|
|
||||||
|
// MatchEvent returns true if the provided device and input event are a match for this rule target
|
||||||
MatchEvent(device Device, event *evdev.InputEvent) bool
|
MatchEvent(device Device, event *evdev.InputEvent) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
45
internal/mappingrules/mapping_rule_hat.go
Normal file
45
internal/mappingrules/mapping_rule_hat.go
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
package mappingrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.annabunches.net/annabunches/joyful/internal/configparser"
|
||||||
|
"github.com/holoplot/go-evdev"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A Simple Mapping Rule can map a button to a button or an axis to an axis.
|
||||||
|
type MappingRuleHat struct {
|
||||||
|
MappingRuleBase
|
||||||
|
Input *RuleTargetHat
|
||||||
|
Output *RuleTargetHat
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMappingRuleHat(ruleConfig configparser.RuleConfigHat,
|
||||||
|
pDevs map[string]Device,
|
||||||
|
vDevs map[string]Device,
|
||||||
|
base MappingRuleBase) (*MappingRuleHat, error) {
|
||||||
|
|
||||||
|
input, err := NewRuleTargetHatFromConfig(ruleConfig.Input, pDevs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := NewRuleTargetHatFromConfig(ruleConfig.Output, vDevs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MappingRuleHat{
|
||||||
|
MappingRuleBase: base,
|
||||||
|
Input: input,
|
||||||
|
Output: output,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rule *MappingRuleHat) 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// The cast here is safe because the interface is only ever different for unit tests
|
||||||
|
return rule.Output.Device.(*evdev.InputDevice), rule.Output.CreateEvent(rule.Input.NormalizeValue(event.Value), mode)
|
||||||
|
}
|
||||||
53
internal/mappingrules/rule_target_hat.go
Normal file
53
internal/mappingrules/rule_target_hat.go
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
package mappingrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.annabunches.net/annabunches/joyful/internal/configparser"
|
||||||
|
"git.annabunches.net/annabunches/joyful/internal/eventcodes"
|
||||||
|
"github.com/holoplot/go-evdev"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RuleTargetHat struct {
|
||||||
|
Device Device
|
||||||
|
Hat evdev.EvCode
|
||||||
|
Inverted bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRuleTargetHatFromConfig(config configparser.RuleTargetConfigHat, devs map[string]Device) (*RuleTargetHat, error) {
|
||||||
|
dev, ok := devs[config.Device]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("device '%s' not found", config.Device)
|
||||||
|
}
|
||||||
|
|
||||||
|
code, err := eventcodes.ParseCode(config.Hat, eventcodes.CodePrefixAxis)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &RuleTargetHat{
|
||||||
|
Device: dev,
|
||||||
|
Hat: code,
|
||||||
|
Inverted: config.Inverted,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (target *RuleTargetHat) NormalizeValue(value int32) int32 {
|
||||||
|
if !target.Inverted {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
return value * -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (target *RuleTargetHat) CreateEvent(value int32, _ *string) *evdev.InputEvent {
|
||||||
|
return &evdev.InputEvent{
|
||||||
|
Type: evdev.EV_ABS,
|
||||||
|
Code: target.Hat,
|
||||||
|
Value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (target *RuleTargetHat) MatchEvent(device Device, event *evdev.InputEvent) bool {
|
||||||
|
return device == target.Device && event.Code == target.Hat
|
||||||
|
}
|
||||||
12
readme.md
12
readme.md
|
|
@ -10,13 +10,13 @@ Joyful is ideal for Linux gamers who enjoy space and flight sims and miss the fe
|
||||||
|
|
||||||
### Current Features
|
### Current Features
|
||||||
|
|
||||||
* Create virtual devices with up to 8 axes and 74 buttons.
|
* Create virtual devices with up to 8 axes, 4 hats, and 74 buttons.
|
||||||
* Flexible rule system that allows several different types of rules, including:
|
* Flexible rule system that allows several different types of rules, including:
|
||||||
* Simple 1:1 mappings of buttons and axes: Button1 -> VirtualButtonA
|
* Simple 1:1 mappings of buttons, axes, and hats: Button1 -> VirtualButtonA
|
||||||
* Combination mappings: Button1 + Button2 -> VirtualButtonA
|
* Combination mappings: Button1 + Button2 -> VirtualButtonA
|
||||||
* "Split" axis mapping: map sections of an axis to different outputs using deadzones.
|
* "Split" axis mapping: map sections of an axis to different outputs using deadzones.
|
||||||
* "Combined" axis mapping: map two physical axes to one virtual axis.
|
* "Combined" axis mapping: map two physical axes to one virtual axis.
|
||||||
* Axis -> button mapping with optional "proportional" repeat speed (i.e. repeat faster as the axis is engaged further)
|
* Axis -> Button mapping with optional "proportional" repeat speed (i.e. repeat faster as the axis is engaged further)
|
||||||
* Axis -> Relative Axis mapping, for converting a joystick axis to mouse movement and scrollwheel events.
|
* Axis -> Relative Axis mapping, for converting a joystick axis to mouse movement and scrollwheel events.
|
||||||
* Define keyboard, mouse, and gamepad outputs in addition to joysticks.
|
* Define keyboard, mouse, and gamepad outputs in addition to joysticks.
|
||||||
* Configure per-rule configurable deadzones for axes, with multiple ways to specify deadzones.
|
* Configure per-rule configurable deadzones for axes, with multiple ways to specify deadzones.
|
||||||
|
|
@ -27,10 +27,10 @@ Joyful is ideal for Linux gamers who enjoy space and flight sims and miss the fe
|
||||||
|
|
||||||
* Macros - have a single input produce a sequence of button presses with configurable pauses.
|
* Macros - have a single input produce a sequence of button presses with configurable pauses.
|
||||||
* Sequence combos - Button1, Button2, Button3 -> VirtualButtonA
|
* Sequence combos - Button1, Button2, Button3 -> VirtualButtonA
|
||||||
* Hat support
|
* Hat -> Button and Button -> Hat support.
|
||||||
* HIDRAW support for more button options.
|
* HIDRAW support for more button options
|
||||||
* Sensitivity Curves?
|
* Sensitivity Curves?
|
||||||
* Packaged builds non-Arch distributions.
|
* Packaged builds for non-Arch distributions.
|
||||||
|
|
||||||
## Configure
|
## Configure
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue