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

Support for hid-nx #71

Closed
git-developer opened this issue Feb 7, 2023 · 7 comments
Closed

Support for hid-nx #71

git-developer opened this issue Feb 7, 2023 · 7 comments

Comments

@git-developer
Copy link
Contributor

git-developer commented Feb 7, 2023

The retro-gaming distribution batocera contains hid-nx, an alternative Linux kernel HID driver for Nintendo Switch controllers.

I managed to run joycond-cemuhook in this environment successfully, but I had to jump though a few hoops to achieve this.

Here is a list of the required changes:

  1. The name of the kernel module is hid_nx instead of hid_nintendo.
    The checks in the main function have to be extended accordingly.
  2. The module does not use hard-coded names per device; instead, each device reports its name on connection.
    Thus, the device names differ slightly. The currently supported name is Nintendo Switch Pro Controller. In my case, the name was Pro Controller when connected via Bluetooth and Nintendo Co., Ltd. Pro Controller when connected via USB.
    These names requires an entry in the list of controller names and a configuration file profiles/Pro Controller.json / profiles/Nintendo Co., Ltd. Pro Controller.json.
  3. The battery dbus interface seems not to be available (in batocera?), the application crashes when the UPower object is read.
    My workaround was to simply suppress the respective call (effectively disabling battery monitoring).

Technically speaking, this is my patch to make it run:

  sed -i -E \
    -e 's/(hid[_-])nintendo/\1nx/g' \
    -e 's/^(\s*)"Nintendo Switch Pro Controller",$/\0\n\1"Pro Controller",\n\1"Nintendo Co., Ltd. Pro Controller",/g' \
    -e 's/self\.dbus_interface, self\.dbus_properties_interface = .+/self.dbus_interface, self.dbus_properties_interface = None, None/g' \
   joycond-cemuhook.py"
   for name in "Pro Controller" "Nintendo Co., Ltd. Pro Controller"; do
     if [ ! -e "profiles/${name}.json" ]; then
       ln -s "Nintendo Switch Pro Controller.json" "profiles/${name}.json"
     fi
   done

With these changes, joycond-cemuhook comes up properly and serves motion data via UDP. Within batocera, Cemu and Citra can be configured to use cemuhook (although I had to customize a few things there, too).

I opened this issue to ask if we can add support for hid-nx so that it may work out-of-the-box in a future release. My experience in Python programming and the D-Bus interface is very basic, so I don't feel ready to provide a pull request here yet. Nevertheless I'd like to give active support, be it with further investigations or testing, just need a little assistance.

@git-developer
Copy link
Contributor Author

I created the repo git-developer/batocera-extra as proof-of-concept for the integration of batocera and joycond-cemuhook. Feel free to have a look and report feedback.

@joaorb64
Copy link
Owner

Really nice, and since it all can be added without breaking what we already have I think it's a good addition. For now I've been overwhelmed with bugfixes in other project and busy overall, but as soon as I get more time I can work on this too. I think we could create a simple list with all possible names for Pro Controllers, for example, and check on that instead of checking on a single string.

@git-developer
Copy link
Contributor Author

Great, thanks for your quick feedback! Just for the record, I see the following subtasks for a proper integration of joycond-cemuhook in batocera:

  • Consider hid-nx as kernel module name
  • Create a mapping of controller names to a profile file
  • Avoid error on missing object org.freedesktop.UPower
  • Provide an installable python module

If I find the time and skills for any of these, I will open a PR.

@git-developer
Copy link
Contributor Author

* Provide an installable python module

Update: I have a working branch here, but it's not ready to merge yet because

  • it currently support only hid-nx and not hid-nintendo and
  • it declares python-dbus as optional dependency because batocera does not provide it as pip package

@git-developer
Copy link
Contributor Author

Now using hid-nintendo and python-dbus as normal dependency, PR #73

@git-developer
Copy link
Contributor Author

Thanks for merging all relevant PRs, and thanks a lot for maintaining this project!

@joaorb64
Copy link
Owner

Sorry I didn't help at all with the commits, but also congrats for figuring it all out! Once again thanks for the contributions, I imagine it will help a lot of people in the future :)

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

No branches or pull requests

2 participants