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 hidapi wiimote #934

Merged
merged 12 commits into from
Aug 15, 2023
Merged

Add hidapi wiimote #934

merged 12 commits into from
Aug 15, 2023

Conversation

capitalistspz
Copy link
Contributor

Allows Wii remotes to be used on Linux and (probably) macOS devices.

@Exzap
Copy link
Member

Exzap commented Aug 8, 2023

Looks good on a quick glance. I did not test it, however.

Small nitpick, we should probably not include hidapi on Windows where it's not used.
In vcpkg.json you can do this by changing:
"hidapi",
to

  {
    "name": "hidapi",
    "platform": "!windows"
  }

if (ENABLE_HIDAPI)
find_package(hidapi REQUIRED)
set(ENABLE_WIIMOTE ON)
add_compile_definitions(HAS_HIDAPI)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please move this to src/input/CMakeLists.txt and use target_compile_definitions(PRIVATE) instead? It'd be a bit cleaner, in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about moving this, considering that every other find_package() usage in the project is in the base CMakeLists.txt. Also add_compile_definitions() is used everywhere else in the project, rather than target_compile_definitions()

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case consistency is better than supposed code clarity, it's fine to leave this as is :)

@capitalistspz capitalistspz marked this pull request as ready for review August 10, 2023 00:21
@SpaceXCheeseWheel
Copy link

Been looking forward to this change for a long time. Tested this with an original Wii remote and a Dolphin Bar / Mayflash on Linux Mint; works flawlessly. This should solve #505 for Linux users and MAYBE #539 for MacOS users, would like to see a mac user confirm.
Thank you!

@SpaceXCheeseWheel
Copy link

Followup: After the excitement of finally being able to get cemu to recognize wiimotes connected, I did some more thorough testing and ran into some issues.

I ran into some oddball issues with certain inputs not registering when using the dolphinbar, but they are sporadic and could totally be my fault. The core functionality of a wiimote w/o accessories works fine.
The more concerning issue is that, if I pair my wiimote directly through my computer instead of through the dolphinbar, cemu will instantly segfault with no descriptive error message. If the wiimote is connected while cemu is running, it will segfault on the spot. I am using the debug build type. Will attempt to repro on clean system, would appreciate it if someone else could do the same. Below are relevant logs. Let me know if there's any info I can provide, I'd love to help any way I can.

GDB

Thread 13 "MainThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe8ff9640 (LWP 19914)]
0x0000000001ff8f17 in hid_write (dev=0x0, data=0x7fffb400ceb0 "\025", length=2) at /home/crazy/Applications/cemu-wiimote/dependencies/vcpkg/buildtrees/hidapi/src/api-0.13.1-ad14f0e8b8.clean/linux/hid.c:1013
1013		bytes_written = write(dev->device_handle, data, length); 

log.txt

[02:35:13.446] XMLConfig::Load > failed "/home/crazy/Applications/cemu-wiimote/bin/settings.xml" with error 2
[02:35:13.446] XMLConfig::Load > failed "/home/crazy/Applications/cemu-wiimote/bin/settings.xml" with error 2
[02:35:13.448] XMLConfig::Load > failed "/home/crazy/Applications/cemu-wiimote/bin/settings.xml" with error 2
[02:35:15.647] ------- Init Cemu 2.0 (experimental) -------
[02:35:15.647] Init Wii U memory space (base: 0x00007f1ac4000000)
[02:35:15.648] mlc01 path: /home/crazy/Applications/cemu-wiimote/bin/mlc01
[02:35:15.648] CPU: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
[02:35:15.648] RAM: 31780MB
[02:35:15.648] Used CPU extensions: SSSE3, SSE4.1, AVX, AVX2, LZCNT, MOVBE, BMI2, AES-NI, INVARIANT-TSC
Error: signal 11:
./Cemu_debug() [0x1ff8f17]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f1c12c50520]
./Cemu_debug() [0x1ff8f17]
./Cemu_debug() [0x11cb192]
./Cemu_debug() [0x11bd073]
./Cemu_debug() [0x11bb110]
./Cemu_debug() [0x11c664e]
./Cemu_debug() [0x11c6562]
./Cemu_debug() [0x11c6522]
./Cemu_debug() [0x11c64d5]
./Cemu_debug() [0x11c6339]
[02:35:15.659] IOSU_CRYPTO: No otp.bin found. Online mode cannot be used
[02:35:15.659] IOSU_CRYPTO: No Seeprom.bin found. Online mode cannot be used
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xdc253) [0x7f1c11a1b253]
/lib/x86_64-linux-gnu/libc.so.6(+0x94b43) [0x7f1c12ca2b43]
/lib/x86_64-linux-gnu/libc.so.6(+0x126a00) [0x7f1c12d34a00]```

@SpaceXCheeseWheel
Copy link

These two commits fixed the immediate crash, however, hidapi continues to not detect the remote if it is connected via a standard bluetooth dongle to the computer; the list appears empty. SDLController recognizes the remote fine. Connecting via a dolphinbar, cemu continues to list the remotes with no issue.

@capitalistspz
Copy link
Contributor Author

hidapi continues to not detect the remote if it is connected via a standard bluetooth dongle to the computer; the list appears empty.

So far, I've been unable to reproduce this. Could you compile and run Cemu with this PR, in debug mode, and check if there are any messages in the Logging Window?

@SpaceXCheeseWheel
Copy link

My bad, it was a dumb typo in my udev permissions. Cemu can now see the remote.
Testing several remotes and accessories, I have run into several problems. I go into detail below, but in short, the two big issues is that the presence of MotionPlus causes unusual behavior, and that the C and Z button on the Nunchuck do not work.
All the behaviors below have been replicated through both a standard Bluetooth dongle and the DolphinBar. The game I used to test these features was Mario Kart 8.

Original Wii Remote (RVL-CNT-01)

No accessories

No noticeable user issues.

  • Tilt controls work
  • All Buttons work
    In the log, about every 5 seconds, I would get the following message repeated over and over:
WiimoteControllerProvider::read_thread: kRead
Recieved error on data read 0x7

This seems to have no impact.

Nunchuck

The joystick works, but C and Z do not. According to the Nunchuck status listed in the log, cemu believes that C and Z are held down at all times: C and Z are allways set to "True"
[22:10:01.084] Nunchuck: Z=true, C=true | 0.029699441, -0.009729683 | 10771.61, -2692.90, 29048.96

Wii Motion Plus

Attaching a wii motion plus causes cemu to spam unhandled input packet id 0 for wiimote several times every 2-3 seconds. While the buttons on the wiimote continue to function, features such as tilt control and the IR Screen Pointer do not work. Accessories such as the nunchuck work for a few seconds, but noticeably halts for about two seconds following the "unhandled input" error message. This is noted by the continuous numchuck info message also stopping at the same time.

Below is a sample from the log.

[13:51:29.149] WiimoteControllerProvider::read_thread: kStatus
[13:51:29.149] Setting report type to 51
[13:51:29.153] Failed to read valid PlayDiary header
[13:51:29.215] unhandled input packet id 0 for wiimote
[13:51:29.240] unhandled input packet id 0 for wiimote
[13:51:29.265] unhandled input packet id 0 for wiimote
[13:51:29.291] unhandled input packet id 0 for wiimote
[13:51:29.316] unhandled input packet id 0 for wiimote
[13:51:29.354] WiimoteControllerProvider::read_thread: kRead
[13:51:29.354] Calibration received
[13:51:29.354] Setting report type to 51
[13:51:29.374] WiimoteControllerProvider::read_thread: kRead
[13:51:29.374] Setting report type to 51
[13:51:29.425] WiimoteControllerProvider::read_thread: kRead
[13:51:29.425] Calibration received
[13:51:29.425] Setting report type to 51

Wii Remote w/ Motion Plus Built In (RVL-CNT-01-TR)

I originally chalked up the issues I was having with this remote up to documented weirdness. However, I now think this is because the aforementioned wii motion plus issues. Using this remote, I experienced the same issues with tilt and nunchuck control as I experienced with the Motion Plus accessory on the original wiimote. This is a problem because motion plus is permanently enabled on the controller. This means that on MotionPlus enabled controllers, tilt and nunchuck controls don't work right now.

Below is an excerpt from the log. Refer to the time between the nunchuck info messages at the top and bottom (3.5 seconds before nunchuck works again):

[14:13:36.549] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -5042.03, -1776.17, 29048.96
[14:13:36.549] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -4812.85, -1546.99, 29048.96
[14:13:36.552] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -4583.66, -1546.99, 28819.78
[14:13:36.554] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -4354.48, -1546.99, 29048.96
[14:13:36.560] WiimoteControllerProvider::read_thread: kStatus
[14:13:36.560] Extension flag is set
[14:13:36.560] Setting report type to 55
[14:13:36.567] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -4125.30, -1546.99, 29048.96
[14:13:36.570] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -4125.30, -1546.99, 29048.96
[14:13:36.577] WiimoteControllerProvider::read_thread: kRead
[14:13:36.577] Setting report type to 51
[14:13:36.577] Setting report type to 51
[14:13:36.706] unhandled input packet id 0 for wiimote
[14:13:36.730] unhandled input packet id 0 for wiimote
[14:13:36.755] unhandled input packet id 0 for wiimote
[14:13:36.781] unhandled input packet id 0 for wiimote
[14:13:36.811] unhandled input packet id 0 for wiimote
[14:13:39.750] WiimoteControllerProvider::read_thread: kStatus
[14:13:39.751] Extension flag is set
[14:13:39.751] Setting report type to 51
[14:13:39.764] WiimoteControllerProvider::read_thread: kRead
[14:13:39.765] Setting report type to 51
[14:13:39.790] unhandled input packet id 0 for wiimote
[14:13:39.818] unhandled input packet id 0 for wiimote
[14:13:39.851] WiimoteControllerProvider::read_thread: kRead
[14:13:39.851] Extension Type Received: Nunchuck
[14:13:39.851] Setting report type to 55
[14:13:39.851] Setting report type to 55
[14:13:39.922] WiimoteControllerProvider::read_thread: kRead
[14:13:39.922] Extension calibration received
[14:13:39.922] Setting report type to 55
[14:13:39.953] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -2521.01, -2005.35, 28819.78
[14:13:39.955] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -2521.01, -2005.35, 28819.78
[14:13:39.961] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -2521.01, -2005.35, 28819.78
[14:13:39.967] Nunchuck: Z=true, C=true | 0.019799627, -0.019343913 | -2521.01, -2005.35, 29048.96

@capitalistspz capitalistspz marked this pull request as draft August 12, 2023 03:46
@@ -2,7 +2,8 @@

static constexpr uint16 WIIMOTE_VENDOR_ID = 0x057e;
static constexpr uint16 WIIMOTE_PRODUCT_ID = 0x0306;
static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 21;
static constexpr uint16 WIIMOTE_MP_PRODUCT_ID = 0x0330;
static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 22;
Copy link
Contributor Author

@capitalistspz capitalistspz Aug 12, 2023

Choose a reason for hiding this comment

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

The nunchuk c and z weren't being read because I chose an incorrect read size
this also means that the nunchuck accelerometer values were inaccurate

@SpaceXCheeseWheel
Copy link

C and Z now work on all controllers. Tilt control works on the original, non MotionPlus wiimote. As far as I can tell, most significant features of an original, non MP remote work without issue. I tested: nunchuk, all buttons, tilt control, IR pointer.

Motion plus continues to cause problems.
Unchanged: The nunchuk joystick and C+Z continue to work for a bit, stop, then continue. Tilt controls don't work at all.
The error messages I receive changed.
On a MotionPlus controller, I get the following message continuously

WiimoteControllerProvider::read_thread: kRead
Unknown extension: 0x100a4200005
Setting report type to 51

And on a NonMP controller, with the MP accessory, I get

WiimoteControllerProvider::read_thread: kRead
Unknwon extension: 0xa6200405
Setting report type to 51

@capitalistspz
Copy link
Contributor Author

capitalistspz commented Aug 12, 2023

Thanks for the info. When you have a non-motionplus controller without any extensions, does it still send "unknown extension" messages? @SpaceXCheeseWheel

@SpaceXCheeseWheel
Copy link

No. There is an error message, same one I mentioned up here: #934 (comment), but as far as I can tell this has no significant impact from what I tested. The full series of events is

WiimoteControllerProvider::read_thread: kStatus
Setting report type to 51
WiimoteControllerProvider::read_thread: kRead
Recieved error on data read 0x7

These messages are repeated in the log every 2 seconds or so, as long as the controller is connected.

@capitalistspz
Copy link
Contributor Author

Recieved error on data read 0x7

Apparently that error happens when the application tries to access the Motion Plus when it's not connected, it's harmless

@capitalistspz
Copy link
Contributor Author

I'm gonna make this as ready for review, my original intent was to bring Wiimote support to parity with Windows.

I'm planning to submit another PR in a few days to change a decent chunk of the Wiimote code, including making Motion Plus work.

@capitalistspz capitalistspz marked this pull request as ready for review August 15, 2023 00:56
@Exzap Exzap merged commit 85aa4f0 into cemu-project:main Aug 15, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

4 participants