Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable feature for axes / Add anti ghost flickering for axes #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Features
- Custom mappings, map buttons and sticks to whatever mouse, key or joystick
action you want
- Settings profiles that can be cycled through with a button binding

- Disable Buttons and Axes

Installing
----------
Expand Down
1 change: 1 addition & 0 deletions ds4drv/actions/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..action import ReportAction
from ..config import buttoncombo
from ..config import axescombo

ReportAction.add_option("--bindings", metavar="bindings",
help="Use custom action bindings specified in the "
Expand Down
9 changes: 9 additions & 0 deletions ds4drv/actions/input.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..action import ReportAction
from ..config import buttoncombo
from ..config import axescombo
from ..exceptions import DeviceError
from ..uinput import create_uinput_device

Expand All @@ -18,6 +19,10 @@
"as joystick events. For example specify 'PS' to "
"disable Steam's big picture mode shortcut when "
"using the --emulate-* options")
ReportAction.add_option("--ignored-axes", metavar="button(s)",
type=axescombo(","), default=[],
help="A comma-separated list of Axes to never send "
"as joystick events.")
ReportAction.add_option("--mapping", metavar="mapping",
help="Use a custom button mapping specified in the "
"config file")
Expand Down Expand Up @@ -89,6 +94,10 @@ def load_options(self, options):
for button in options.ignored_buttons:
self.joystick.ignored_buttons.add(button)

self.joystick.ignored_axes = set()
for axes in options.ignored_axes:
self.joystick.ignored_axes.add(axes)

if joystick:
self.joystick_layout = joystick_layout

Expand Down
7 changes: 7 additions & 0 deletions ds4drv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import __version__
from .uinput import parse_uinput_mapping
from .utils import parse_button_combo
from .utils import parse_axes_combo


CONFIG_FILES = ("~/.config/ds4drv.conf", "/etc/ds4drv.conf")
Expand Down Expand Up @@ -179,6 +180,12 @@ def buttoncombo(sep):
return func


def axescombo(sep):
func = partial(parse_axes_combo, sep=sep)
func.__name__ = "button combo"
return func


def merge_options(src, dst, defaults):
for key, value in src.__dict__.items():
if key == "controllers":
Expand Down
10 changes: 9 additions & 1 deletion ds4drv/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def __init__(self, layout):
self.joystick_dev = None
self.evdev_dev = None
self.ignored_buttons = set()
self.ignored_axes = set()
self.create_device(layout)

self._write_cache = {}
Expand Down Expand Up @@ -312,7 +313,14 @@ def emit(self, report):
"""Writes axes, buttons and hats with values from the report to
the device."""
for name, attr in self.layout.axes.items():
value = getattr(report, attr)

if attr in self.ignored_axes:
value = False
else:
value = getattr(report, attr)
if value > 120 and value < 140:
value = 130

self.write_event(ecodes.EV_ABS, name, value)

for name, attr in self.layout.buttons.items():
Expand Down
11 changes: 11 additions & 0 deletions ds4drv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def button_prefix(button):

return tuple(map(button_prefix, combo.lower().split(sep)))

def parse_axes_combo(combo, sep="+"):
def button_prefix(button):
button = button.strip()

if button not in VALID_BUTTONS:
raise ValueError("Invalid Input: {0}".format(button))

return button

return tuple(map(button_prefix, combo.lower().split(sep)))


def with_metaclass(meta, base=object):
"""Create a base class with a metaclass."""
Expand Down