JoyCon.NET
|
You can use this .NET library to communicate with Nintendo Switch Joy-Con or Pro controllers. It's based on the HidSharp library, which is a cross-platform .NET library for USB HID devices, and it's compatible with Windows, Linux and macOS. So, this library should work on all these platforms too.
And what you can't do (yet?):
It's pretty simple. First, you need to connect your controller via Bluetooth to the computer. Then you need get the controller's HidDevice object using the HidSharp library, create a JoyCon
object, subscribe to the events and call the Start()
method. Here's an example:
You should call the SetInputReportModeAsync()
method to set the input report format. Most of the time you'll need to use:
InputReportType.Full
mode, in this mode you'll receive InputFull
objects, which contains all the data: buttons, sticks, gyroscope, accelerometer, battery level, etc. You'll receive reports at a rate of 60 Hz. This is the most common mode.InputReportType.Simple
mode, in this mode you'll receive InputSimple
objects, which contains the base data only. You'll receive reports with every data change.ReportReceived
event is fired when a new input report is received from the controller. It will be the object that implements the IJoyConReport
interface. Possible objects are:
InputSimple
, used in the InputReportType.Simple
mode, contains the base data only.InputFull
, used in the InputReportType.Full
mode, contains all the data: buttons and sticks.InputFullWithImu
- derived from InputFull
, contains the base data and IMU data.InputFullWithSubCmdReply
- derived from InputFull
, contains the base data and subcommand reply data. You should handle subcommand replies only if you send subcommands with noWaitAck = true
parameter. Otherwise, the library will handle it for you.InputFullWithImuMcuFw
- derived from InputFull
, contains the base data, IMU data and some additional MCU data. This feature in not implemented in this library.InputFullWithMcuFw
- derived from InputFull
, contains the base data and MCU firmware update data. This feature in not implemented in this library.Most of the time you'll need just InputReportType.Full
mode and handle only InputFullWithImu
or InputFull
objects. You should handle the ReportReceived
event as fast as possible, because the next report will not be received until the current one is processed. If you need to do some heavy calculations, you should use a separate thread or a timer.
StoppedOnError
event is fired when an critical error occurs during the controller polling than causes the polling to stop, i.e. the controller is disconnected. You should handle this event to stop the application properly or to try to reconnect the controller.
You can find full documentation here: https://clusterm.github.io/joycon/
GetFactoryCalibrationAsync()
, GetUserCalibrationAsync()
and GetStickParametersAsync()
methods, then use IStickPosition.GetCalibrated()
and ImuFrame.GetCalibrated()
methods to get calibrated data. User calibration can be set in the Switch's system settings.EnableImuAsync()
method if you need to use the accelerometer and gyroscope data, it's disabled by default.EnableRumbleAsync()
method but rumble is enabled by default.dotnet add package JoyCon.NET
https://www.nuget.org/packages/JoyCon.NET