Introduction
This is a small follow up on my testings. Long time it was believed that the PlusInside Wiimotes (“-TR”) are not working with the default Bluetooth Windows Stack. Every program and library recommends the common Toshiba Bluetooth “hack” to get “-TR” Wiimotes and Wii U Pro controllers working on Windows. I did some research with the HIDAPI on Windows and came to the result, that on Windows 8 and above using the proper API Calls, “-TR” Wiimotes, as well as the Wii U Pro Controller is working perfectly fine.
I implemented and fixed the Wiimote Code in the Dolphin Project, which also lead to improved Wiimote Audio for “-TR” Wiimotes.
TLDR;
Using the proper API Calls the Toshiba Bluetooth Stack is not needed anymore on Windows 8 and above. Both Wiimotes types (TR & non-TR) and the Wii U Pro are working fine. Here is the code repository of my test program.
The following post is basically just a copy & paste of the Readme, as it got quite extensive.
Windows 7
The API Calls would also work fine on Windows 7, but there is a bug in the Microsoft HID Class Driver. This renders the “WriteFile”-Method unusable on Windows 7, therefore it is not possible to use the HIDAPI to send data to “-TR” Wiimotes.
HIDAPI
Sending & Receiving
WriteFile
(Preferred)HidD_SetOutputReport
ReadFile
(Preferred)HidD_GetInputReport
The MSDN Design Guides Sending HID Reports and Obtaining HID Reports are stating, that WriteFile
and ReadFile
are the preferred methods to send and recieve data from the device. Additionally sending data to a “-TR” Wiimote via WriteFile
is working fine, whereas using HidD_SetOutputReport
will result in the Wiimote turning off.
Issues with WriteFile
As the MSDN Desgin Guide Sending HID Reports by Kernel-Mode Drivers (WriteFile
will send out an IRP_MJ_WRITE
request to the driver interface) suggests, the output report buffers shall have the size of the largest output report supported by the device. In case of the Wiimote this is 22 Byte.
This seems to be currently enforced by the Microsoft HID Class Driver on Windows 7 and the Toshiba Bluetooth Stack, as they will fail WriteFile
attempts with the error ERROR_INVALID_USER_BUFFER
, when the buffer size is less.
On Windows 7 however more bytes than the acutal report are sent to the device, which produces an error on the Wiimote. It is unknown whether this is a bug or intented behaviour. The Toshiba Bluetooth Stack in contrast only sends the appropiate amount of bytes according to the used report to the device.
On Windows 8 and higher, the output report buffer can be arbitrary in size, as the given amount of byte are submitted to the device.
This results in the following table of compability.
Table of compability
x | Toshiba Stack | Win 7 | Win 8.1 | Win 10 |
---|---|---|---|---|
WriteFile Largest Report Size | + | – | – | – |
WriteFile Acutal Report Size | – | – | + | + |
SetOutputReport | – | +* | +* | +* |
* does not support “-TR” when connected via Bluetooth
Method Priority Order
This leads us to the following order of prioritized methods:
- Detect whether the Microsoft Stack or the Toshiba Stack is used for the Wii Remote.
- In case of Toshiba Stack, use
WriteFile
with the largest report size for the buffer - In case of Microsoft Stack, try
WriteFile
with the actual report size - If WriteFile fails, fall back to
HidD_SetOutputReport
Detecting Stack
To detect the used stack for the Wiimote, the provider property of the used HID Class Driver is evaluated. As the enumerated Wiimote Devices are just raw PDO’s, that are acting as interfaces for the HID Class Driver and don’t have a driver directly associated with, it is neccessary to move one node up in the device tree to get to the device node that is associated with the HID Class Driver. To do so the PnP Configuration Manager API is used.
Why WriteFile
supports “-TR”
It is believed, that the usage of HidD_SetOutputReport
will result in sending the output report via the Control Channel. This is not supported by “-TR” Wiimotes, as they will immediately shut down. In contrast WriteFile
seems to send the data to device via the Interrput/Data Channel.
DolphinBar
The Mayflash DolphinBar enumerates Wiimotes as USB Devices, resulting in using the Microsoft HID Class Driver. Therefore WriteFile won’t work on Windows 7 for Wiimotes connected through the DolphinBar either. However as the DolphinBar takes care of the Bluetooth communication and the outgoing data is send via USB to the DolphinBar, HidD_SetOutputReport
does support “-TR” Wiimotes as long as they are connected through a DolphinBar.