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

Added better default mapping and added basic multi-touch support #51

Open
wants to merge 4 commits 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 ds4drv.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
##
# Controller settings
#
# This is the default profile for each controller.
# This is the default profile for each controller. It is created before the other profiles as "default".
# Multiple controllers slots are defined by increasing the number.
#
# Controller sections contain:
Expand Down
6 changes: 5 additions & 1 deletion ds4drv/actions/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
ReportAction.add_option("--emulate-xpad-wireless", action="store_true",
help="Emulates the same joystick layout as a wireless "
"Xbox 360 controller used via the xpad module")
ReportAction.add_option("--emulate-kernel", action="store_true",
help="Emulates the same joystick layout as the default kernel driver.")
ReportAction.add_option("--ignored-buttons", metavar="button(s)",
type=buttoncombo(","), default=[],
help="A comma-separated list of buttons to never send "
Expand Down Expand Up @@ -62,8 +64,10 @@ def load_options(self, options):
joystick_layout = "xpad"
elif options.emulate_xpad_wireless:
joystick_layout = "xpad_wireless"
else:
elif options.emulate_kernel:
joystick_layout = "ds4"
else:
joystick_layout = "ds4drv"

if not self.mouse and options.trackpad_mouse:
self.mouse = create_uinput_device("mouse")
Expand Down
75 changes: 70 additions & 5 deletions ds4drv/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
ecodes.REL_WHEELUP = 13 # Unique value for this lib
ecodes.REL_WHEELDOWN = 14 # Ditto


def parse_button(attr):
if attr[0] in BUTTON_MODIFIERS:
modifier = attr[0]
Expand All @@ -52,8 +51,62 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0,
mouse_options)
_mappings[name] = mapping


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White space error.

# Pre-configued mappings
# Emulate it the (mostly) correct way
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it here?

create_mapping(
"ds4drv", "Sony Computer Entertainment Wireless Controller (Userspace)",
# Bus type, vendor, product, version
ecodes.BUS_USB, 1356, 1476, 273,
# Axes
{
"ABS_X": "left_analog_x",
"ABS_Y": "left_analog_y",
"ABS_RX": "right_analog_x",
"ABS_RY": "right_analog_y",
"ABS_Z": "l2_analog",
"ABS_RZ": "r2_analog",
"ABS_THROTTLE": "orientation_roll",
"ABS_RUDDER": "orientation_pitch",
"ABS_WHEEL": "orientation_yaw",
"ABS_DISTANCE": "motion_z",
"ABS_TILT_X": "motion_x",
"ABS_TILT_Y": "motion_y",
},
# Axes options
{
"ABS_THROTTLE": (-16385, 16384, 0, 0),
"ABS_RUDDER": (-16385, 16384, 0, 0),
"ABS_WHEEL": (-16385, 16384, 0, 0),
"ABS_DISTANCE": (-32768, 32767, 0, 10),
"ABS_TILT_X": (-32768, 32767, 0, 10),
"ABS_TILT_Y": (-32768, 32767, 0, 10),
},
# Buttons
{
"BTN_START": "button_options",
"BTN_MODE": "button_ps",
"BTN_SELECT": "button_share",
"BTN_A": "button_cross",
"BTN_B": "button_circle",
"BTN_X": "button_square",
"BTN_Y": "button_triangle",
"BTN_TL": "button_l1",
"BTN_TR": "button_r1",
"BTN_THUMBL": "button_l3",
"BTN_THUMBR": "button_r3",

},

# Hats
{
"ABS_HAT0X": ("dpad_left", "dpad_right"),
"ABS_HAT0Y": ("dpad_up", "dpad_down")
},

)

#Emulate the way the kernel does it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a space to these comments. E.g.

# Emulate the way the kernel does it

create_mapping(
"ds4", "Sony Computer Entertainment Wireless Controller",
# Bus type, vendor, product, version
Expand Down Expand Up @@ -104,8 +157,10 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0,
"ABS_HAT0X": ("dpad_left", "dpad_right"),
"ABS_HAT0Y": ("dpad_up", "dpad_down")
}

)

#Emulate xboxdrv's button assignments.
create_mapping(
"xboxdrv", "Xbox Gamepad (userspace driver)",
# Bus type, vendor, product, version
Expand Down Expand Up @@ -142,6 +197,7 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0,
}
)

# Emulate the way the kernel does Xbox 360/Xbone controllers with xpad
create_mapping(
"xpad", "Microsoft X-Box 360 pad",
# Bus type, vendor, product, version
Expand Down Expand Up @@ -178,6 +234,7 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0,
}
)

#Emulate the way the kernel does Xbox 360 Wireless controllers with xpad
create_mapping(
"xpad_wireless", "Xbox 360 Wireless Receiver",
# Bus type, vendor, product, version
Expand Down Expand Up @@ -214,14 +271,20 @@ def create_mapping(name, description, bustype=0, vendor=0, product=0,
},
)

#Emulate a multi-touch trackpad
create_mapping(
"mouse", "DualShock4 Mouse Emulation",
buttons={
"BTN_LEFT": "button_trackpad",
"BTN_TOOL_FINGER" : "trackpad_touch0_active",
"BTN_TOOL_DOUBLETAP" : "trackpad_touch1_active"
},
mouse={
"REL_X": "trackpad_touch0_x",
"REL_Y": "trackpad_touch0_y"

"REL_X" : "trackpad_touch0_x",
"REL_Y" : "trackpad_touch0_y",
"REL_RX" : "trackpad_touch1_x",
"REL_RY" : "trackpad_touch1_y"
},
)

Expand Down Expand Up @@ -372,8 +435,9 @@ def emit_mouse(self, report):
continue

sensitivity = self.mouse_analog_sensitivity
self.mouse_rel[name] += accel * sensitivity
self.mouse_rel[name] += accel * sensitivity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a minor white space error here.



# Emulate mouse wheel (needs special handling)
if name in (ecodes.REL_WHEELUP, ecodes.REL_WHEELDOWN):
ecode = ecodes.REL_WHEEL # The real event we need to emit
Expand Down Expand Up @@ -407,6 +471,7 @@ def emit_mouse(self, report):
if self._scroll_details.get('direction') == name:
self._scroll_details['last_write'] = 0
self._scroll_details['count'] = 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this new line added?


rel = int(self.mouse_rel[name])
self.mouse_rel[name] = self.mouse_rel[name] - rel
Expand Down