joaorb64 / joycond-cemuhook

Support for cemuhook's UDP protocol for joycond devices
MIT License
139 stars 19 forks source link

Support for hid-nx #71

Closed git-developer closed 1 year ago

git-developer commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

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

git-developer commented 1 year ago
* Provide an installable python module

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

git-developer commented 1 year ago

Now using hid-nintendo and python-dbus as normal dependency, PR https://github.com/joaorb64/joycond-cemuhook/pull/73

git-developer commented 1 year ago

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

joaorb64 commented 1 year ago

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 :)