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 SDL motion input and rumble support #10000

Closed
wants to merge 3 commits into from

Conversation

jambonmcyeah
Copy link
Contributor

Add motion input and rumble support for the SDL controller interface, inspired by yuzu-emu/yuzu#6244. This is useful for Windows and MacOS users since it removes the need to have a DSU server to get motion input.

@jambonmcyeah
Copy link
Contributor Author

I'm not familiar with Visual Studio so my approach of adding SDL into Externals is probably wrong. Would appreciate if someone can help me with that. 😃

@AdmiralCurtiss
Copy link
Contributor

Yeah considering the size of the SDL, it's probably a better idea to instead add an actual git submodule of https://github.com/libsdl-org/SDL.git.

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 6, 2021

Yeah considering the size of the SDL, it's probably a better idea to instead add an actual git submodule of https://github.com/libsdl-org/SDL.git.

Ok, I've done that and fixed the visual studio files also.

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 6, 2021

I think this is ready for more review now

@OatmealDome
Copy link
Member

OatmealDome commented Aug 8, 2021

Perhaps if SDL isn't found, the SDL from Externals should be used. (There are checks in Source/Core/InputCommon/CMakeLists.txt, but they might have to moved to the root CMakeLists?)

@jambonmcyeah
Copy link
Contributor Author

Perhaps if SDL isn't found, the SDL from Externals should be used. (There are checks in Source/Core/InputCommon/CMakeLists.txt, but they might have to moved to the root CMakeLists?)

Just finished that as well. Let me know if there's more changes needed.

@jambonmcyeah
Copy link
Contributor Author

This should hopefully fix the FreeBSD build failure.

@jambonmcyeah
Copy link
Contributor Author

This should fix unit tests on Windows

@jambonmcyeah
Copy link
Contributor Author

This should be everything fixed, just need to run it through CI to confirm that.

@Simonx22
Copy link
Member

I have tested this on Windows 10 v20H1 with my DualShock 4 Controller:

  • rumble works fine
  • buttons can be mapped just fine
  • motion control does not work

@OatmealDome also tried this on macOS 11 with a Switch Pro Controller, everything works except motion controls.

Is there anything special we need to do to get motion controls working?

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 11, 2021

Maybe it's some background programs that are interfering with it. If you guys have Steam, DS4Windows or other programs that interact with controllers try closing them.

Also, the system SDL on the macOS build bot might be too old, version 2.0.14 or newer is required for motion controls.

I have personally tested on Windows 10 v21H1 with a DualShock 4 Controller in both bluetooth and wired mode and it works for me.

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 11, 2021

Also macOS might have permission issues, so the solution to that is going to Security & Privacy -> Privacy -> Input Monitoring and allowing Dolphin (or Terminal if you're running dolphin from the terminal)

@OatmealDome
Copy link
Member

Hmm, the universal buildbot uses SDL 2.0.14, so that should be fine. I tried my Pro Controller over Bluetooth and USB with Input Monitoring enabled for Dolphin, and motion isn't being registered in the controller configuration.

If I right click on the binding button to look at the list of inputs, none of the Accel or Gyro inputs appear in the list.

@mbc07
Copy link
Contributor

mbc07 commented Aug 11, 2021

I tested with a DualShock 4 v2 on Windows 10 21H1 and it works (including motion) but:

  • SDL doesn't detect the controller when connected over Bluetooth, only over USB
  • Touchpad isn't accessible (only the touchpad click)
  • It's not possible to access the rumble motors individually, SDL reports only one motor which activates both

Those probably are SDL limitations, but not working over Bluetooth kinda defeats the hability of reading the motion sensors. Regardless it's still a great addition especially for macOS, which has a single DSU Server available that I heard is quite finicky to use...

@mbc07
Copy link
Contributor

mbc07 commented Aug 11, 2021

Ah, nevermind, SDL can see the DualShock 4 over BT on Win10 (I forgot to add Dolphin to the HidHide whitelist earlier), however it can't access the motion sensors over BT (they don't appear in the Advanced Mapping window), rumble also doesn't work over BT (it can be selected in the Advanced Mapping windows but the controller doesn't rumble at all)...

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 11, 2021

Adding touchpad support and individual motor rumble is doable. I'll add support for those after I figure out why it's not working for some people.
Bluetooth should work in theory, it works on both of my computers. (both for rumble and motion input)
I'll try to figure out what the problem is.

@Simonx22
Copy link
Member

Quick update on my issue: a reboot fixed the motion control issues. The pointer works fine now but the actual accelerometer itself shifts heavily to the right. I have tested this with Mario Kart Wii. Calibrating the motion controls doesn't seem to help much. It seems like the accelerometer is shifting further the longer I drive. Not sure if the shifting to the right is an SDL issue or something else with Dolphin.

@mbc07
Copy link
Contributor

mbc07 commented Aug 11, 2021

@jambonmcyeah maybe it's the slightly communication differences between DualShock 4 v1 and v2 bitting again? The v2 (the one I have) is the newer model released with the PS4 Slim, that has the light bar visible through the touchpad, v1 is the model that launched with the PS4 "fat". PR #7614 also exhibited different behavior depending of the DualShock 4 model...

@jambonmcyeah
Copy link
Contributor Author

The one I have seems to be the V2 version which may explain things.

@jambonmcyeah
Copy link
Contributor Author

Also for the shifting problem I have it as well with the gyroscope. Have no idea what's causing the problem

@jambonmcyeah
Copy link
Contributor Author

jambonmcyeah commented Aug 11, 2021

It shouldn't be SDL's problem since from my testing it doesn't seem to happen with other emulator which uses SDL like yuzu and cemu.
I looked through yuzu's SDL motion implementation and it doesn't seem like they are doing anything special.

@CrusadingNinja
Copy link

Is this still being worked on?

@infirit
Copy link

infirit commented Sep 24, 2021

Sdl2 gamepad also works on linux so I would like to suggest to also enable it on linux as well. I am playing mario odyssey right now with my pro controller, rumble and motion work without joycond and hidnintendo kernel modules.

@v1993
Copy link
Contributor

v1993 commented Sep 25, 2021

@infirit If enabled on Linux, this would render evdev nodes of controller unusable due to limits of HIDAPI. While I understand that not needing to install hid_nintendo is handy, breaking working approach is not nice. In addition, on Linux SDL does not build with HIDAPI support by default (it would need to be explicitly enabled during build like it's done in yuzu) exactly to avoid conflict with evdev, so that's something to consider as well.

Becuase dolphin already supports evdev motion, only hid_nintendo is needed. Joycond and joycond-cemuhook are not.

@RinMaru
Copy link

RinMaru commented Nov 7, 2021

While this gets rid of the need for cemuhook and better joy would it also be able to handle TN a wiimotes better since syncing is a problem?

@phire
Copy link
Member

phire commented Nov 7, 2021

Becuase dolphin already supports evdev motion, only hid_nintendo is needed

Looks like native support for switch controllers will land in Linux 5.16, so you won't even need an extra kernel module. It will just work with dolphin's evdev.

@@ -42,6 +42,9 @@
<Manifest>
<AdditionalManifestFiles>DolphinQt.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles>
</Manifest>
<PostBuildEvent>
Copy link
Contributor

Choose a reason for hiding this comment

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

use a Copy task instead (see the end of this file , and add it there)

@@ -22,6 +22,11 @@
<ImportGroup Condition="'$(Platform)'=='ARM64'">
<Import Project="DolphinLib.ARM64.props" />
</ImportGroup>
<ItemDefinitionGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

this belongs in base.props

@@ -24,6 +24,9 @@ Source/Core/Common/scmrev.h
*.VC.db
.vs*/
/Source/enc_temp_folder/
/Source/x64
Copy link
Contributor

@shuffle2 shuffle2 Apr 5, 2022

Choose a reason for hiding this comment

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

should be removed (after changing to own vcxproj file)

@@ -30,6 +30,9 @@
<AdditionalLibraryDirectories Condition="'$(Platform)'=='x64'">$(ExternalsDir)ffmpeg\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Console</SubSystem>
</Link>
<PostBuildEvent>
<Command>copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\SDL2.dll" "$(OutDir)"</Command>
Copy link
Contributor

Choose a reason for hiding this comment

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

should be removed

Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Copy link
Contributor

Choose a reason for hiding this comment

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

revert these x86 additions, remove x86 config from sdl

@shuffle2
Copy link
Contributor

shuffle2 commented Apr 5, 2022

tbh I'm not a fan of adding sdl, but i made some comments for improvements of the pr anyway
sdl just seems like bloat and cruft.

edit: ah, i missed that you're using their vcxproj file from the submodule. unfortunately you need to make a version of the vcxproj file modeled after other things in Externals and use that instead. with that in place, can also just staticly link it.

@shuffle2 shuffle2 mentioned this pull request Apr 5, 2022
@shuffle2
Copy link
Contributor

this PR should be closed now

@SuperSamus
Copy link
Contributor

SuperSamus commented Oct 8, 2022

@infirit If enabled on Linux, this would render evdev nodes of controller unusable due to limits of HIDAPI. While I understand that not needing to install hid_nintendo is handy, breaking working approach is not nice. In addition, on Linux SDL does not build with HIDAPI support by default (it would need to be explicitly enabled during build like it's done in yuzu) exactly to avoid conflict with evdev, so that's something to consider as well.

Becuase dolphin already supports evdev motion, only hid_nintendo is needed. Joycond and joycond-cemuhook are not.

I don't know if it's relevant, but on other emulators, SDL for gamepads is enabled under Linux too.
For example, on DuckStation, Flycast, and PCSX2 (Qt), it's the only input interface available on Linux.
(For the former, only by default.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet