JoyCon.NET
|
Joy-Con controller to control Joy-Con or Pro Controller. More...
Inherits IDisposable.
Public Types | |
enum class | Subcommand : byte { Nothing = 0x00 , BluetoothManualPairing = 0x01 , RequestDeviceInfo = 0x02 , SetInputReportMode = 0x03 , TriggerButtonsElapseTime = 0x04 , GetPageListState = 0x05 , SetHciState = 0x06 , ResetPairingInfo = 0x07 , SetShipmentLowPowerState = 0x08 , SpiFlashRead = 0x10 , SpiFlashWrite = 0x11 , SpiFlashSectorErase = 0x12 , ResetMcu = 0x20 , SetMcuConfig = 0x21 , SetMcuState = 0x22 , SetUnknownX24 = 0x24 , ResetUnknownX24 = 0x25 , SetUnknownMcuData = 0x28 , GetMcuData = 0x29 , SetGpioOutputPort2 = 0x2A , GetMcuData2 = 0x2B , SetPlayerLights = 0x30 , GetPlayerLights = 0x31 , SetHomeLed = 0x38 , EnableImu = 0x40 , SetImuSensitivity = 0x41 , WriteImuRegister = 0x42 , ReadImuRegister = 0x43 , EnableRumble = 0x48 , GetRegulatedVoltage = 0x50 , SetGpioOutputPort1 = 0x51 , GetGpioInput = 0x52 } |
Subcommands. More... | |
enum class | InputReportType : byte { NfcIr0 = 0x00 , NfcIr1 = 0x01 , NfcIr2 = 0x02 , NfcIr3 = 0x03 , SubcommandReply = 0x21 , McuUpdateStateReport = 0x23 , Full = 0x30 , McuMode = 0x31 , UnknownX32 = 0x32 , UnknownX33 = 0x33 , UnknownX35 = 0x35 , Simple = 0x3F } |
Input report type, e.g. type of the data sent by the controller. More... | |
enum class | OutputReportType { Subcommand = 0x01 , McuUpdatePacket = 0x03 , RumbleOnly = 0x10 , RequestMcuData = 0x11 , UnknownX12 = 0x12 } |
Output report type. More... | |
enum class | GyroSensitivity : byte { DPS250 = 0x00 , DPS500 = 0x01 , DPS1000 = 0x02 , DPS2000 = 0x03 } |
Gyroscope sensitivity. More... | |
enum class | GyroPerformance : byte { Hz833 = 0x00 , Hz208 = 0x01 } |
Gyroscope performance rate. More... | |
enum class | AccSensitivity : byte { G8 = 0x00 , G4 = 0x01 , G2 = 0x02 , G16 = 0x03 } |
Accelerometer sensitivity. More... | |
enum class | AccFilter : byte { Hz200 = 0 , Hz100 = 1 } |
Accelerometer Anti-aliasing filter bandwidth. More... | |
enum class | LedState : byte { Off = 0 , On = 0b0000_0001 , Blinking = 0b0001_0000 } |
LED state. More... | |
Public Member Functions | |
delegate Task | ReportReceivedHandler (JoyCon source, IJoyConReport report) |
Event handler for report received. More... | |
delegate Task | StoppedOnErrorHandler (JoyCon source, Exception exception) |
Event handler for stopped on error. More... | |
JoyCon (HidDevice hidDevice) | |
Create a /new Joy-Con controller to control Joy-Con or Pro Controller. More... | |
void | Start () |
Start controller polling. More... | |
void | Stop () |
Stop controller polling. More... | |
async Task< SubCmdReply?> | WriteSubcommandAsync (OutputReportType outputReportID, RumbleSet? rumble, Subcommand subcommandID, byte[]? subcommandData=null, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Write a subcommand to the controller using the specified output report ID. More... | |
async Task< SubCmdReply?> | WriteSubcommandAsync (byte outputReportID, RumbleSet? rumble, Subcommand subcommandID, byte[]? subcommandData=null, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Write a subcommand to the controller using the specified output report ID. More... | |
async Task< SubCmdReply?> | WriteSubcommandAsync (RumbleSet? rumble, Subcommand subcommandID, byte[]? subcommandData=null, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Write a subcommand to the controller. More... | |
async Task | SetInputReportModeAsync (InputReportType inputReportMode, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Set input report mode, e.g. format of the data sent by the controller. InputReportType.Full is recommended for most cases. More... | |
async Task | EnableImuAsync (bool enable, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Enable or disable IMU sensor. More... | |
async Task | EnableRumbleAsync (bool enable, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Enable or disable vibration. More... | |
async Task | WriteRumble (RumbleSet rumbleSet, CancellationToken cancellationToken=default) |
Write a rumble data to the controller. More... | |
async Task | WriteRumble (RumbleData leftRumble, RumbleData rightRumble, CancellationToken cancellationToken=default) |
Write a rumble data to the controller. More... | |
async Task | WriteRumble (double freqLeft, double ampLeft, double freqRight, double ampRight, CancellationToken cancellationToken=default) |
Write a rumble data to the controller. More... | |
async Task | WriteRumble (double freqBoth, double ampBoth, CancellationToken cancellationToken=default) |
Write a rumble data to the controller. More... | |
async Task | SetImuSensitivityAsync (AccSensitivity accSensitivity, AccFilter accFilter, GyroSensitivity gyroSensitivity, GyroPerformance gyroPerformance, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Set IMU sensor sensitivity. More... | |
async Task | SetPlayerLedsAsync (LedState led1, LedState led2, LedState led3, LedState led4, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Set LEDs state on the controller. More... | |
async Task< LedState[]> | GetPlayerLedsAsync (CancellationToken cancellationToken=default) |
Get LEDs state on the controller. More... | |
async Task | SetHomeLedDimmingPatternAsync (HomeLedDimmingPattern homeLedDimmingPattern, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Set Home LED dimming pattern. More... | |
async Task< DeviceInfo > | GetDeviceInfoAsync (CancellationToken cancellationToken=default) |
Get device info. More... | |
async Task< ushort > | GetVoltageAsync (CancellationToken cancellationToken=default) |
Get battery voltage in mV. More... | |
async Task< TriggerButtonsElapsedTime > | GetTriggerButtonElapsedTimeAsync (CancellationToken cancellationToken=default) |
Get trigger button elapsed time. More... | |
async Task | ImuRegisterWriteAsync (byte address, byte value, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Write to IMU register directly. Consult LSM6DS3 datasheet for all registers and their meaning. More... | |
async Task< byte[]> | ImuRegisterReadAsync (byte address, byte length, CancellationToken cancellationToken=default) |
Read IMU registers directly. Consult LSM6DS3 datasheet for all registers and their meaning. More... | |
async Task< byte[]> | ReadSpiFlashAsync (int address, int length, CancellationToken cancellationToken=default) |
Read the internal SPI flash data. More... | |
async Task | WriteSpiFlashAsync (int address, byte[] data, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Write data to the internal SPI flash. More... | |
async Task | EraseSpiFlashSectorAsync (int address, bool noWaitAck=false, CancellationToken cancellationToken=default) |
Erase the SPI flash sector. WARNING! This will erase data in the whole 4KB sector! More... | |
async Task< CalibrationData > | GetFactoryCalibrationAsync (CancellationToken cancellationToken=default) |
Read the factory stick calibration data from the SPI flash memory. More... | |
async Task< CalibrationData > | GetUserCalibrationAsync (CancellationToken cancellationToken=default) |
Get the user calibration data from the SPI flash memory. More... | |
async Task< StickParametersSet > | GetStickParametersAsync (CancellationToken cancellationToken=default) |
Get a minor stick parameters: dead-zone and range ratio. More... | |
async Task< string?> | GetSerialNumberAsync (CancellationToken cancellationToken=default) |
Get the controller's serial number. Can be null if not present. More... | |
async Task< bool > | GetIsJoyConNewAsync (CancellationToken cancellationToken=default) |
Check if the controller is new. It's programmed to true on the factory. Switch makes sure to set it to false after the first connection. Can be inaccurate. More... | |
async Task< ControllerColors?> | GetColorsAsync (CancellationToken cancellationToken=default) |
Get the controller's colors stored in the SPI flash memory. Can be null if not present. More... | |
override string | ToString () |
void | Dispose () |
Events | |
ReportReceivedHandler | ReportReceived = delegate { return Task.CompletedTask; } |
Event raised when a report is received. More... | |
StoppedOnErrorHandler | StoppedOnError = delegate { return Task.CompletedTask; } |
Event raised when controller polling is stopped because of an error. More... | |
Joy-Con controller to control Joy-Con or Pro Controller.
|
strong |
Subcommands.
|
strong |
Input report type, e.g. type of the data sent by the controller.
Enumerator | |
---|---|
NfcIr0 | Used with cmd OutputReportType.RequestMcuData. Active polling for MCU (NFC/IR camera) data. InputReportType.McuMode data format must be set first. |
NfcIr1 | Same as NfcIr0. Active polling mode for NFC/IR MCU configuration data. |
NfcIr2 | Same as NfcIr0. Active polling mode for NFC/IR data and configuration. For specific NFC/IR modes. |
NfcIr3 | Same as NfcIr0. Active polling mode for IR camera data. For specific IR modes. |
SubcommandReply | Full input report + subcommand reply. |
McuUpdateStateReport | MCU FW update input report. |
Full | Standard full report. Pushes current buttons/sticks state @ 60Hz. |
McuMode | MCU mode. Pushes large packets: standard input report + MCU data (usually NFC/IR) input report. |
UnknownX32 | Unknown. Sends standard input reports. |
UnknownX33 | Unknown. Sends standard input reports. |
UnknownX35 | Unknown. |
Simple | Simple report. Pushes current buttons/sticks state with every data change. |
|
strong |
Output report type.
Enumerator | |
---|---|
Subcommand | Subcommand (also includes rumble data). |
McuUpdatePacket | MCU FW Update packet. |
RumbleOnly | Only rumble data. |
RequestMcuData | Request specific data from the MCU (also includes rumble data). |
UnknownX12 | Unknown. Does the same thing with Subcommand.SetUnknownMcuData subcommand. |
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
JoyCon.JoyCon | ( | HidDevice | hidDevice | ) |
Create a /new Joy-Con controller to control Joy-Con or Pro Controller.
hidDevice | HID device which represents the controller. |
delegate Task JoyCon.ReportReceivedHandler | ( | JoyCon | source, |
IJoyConReport | report | ||
) |
Event handler for report received.
source | The JoyCon instance. |
report | The report received as IJoyConReport. |
delegate Task JoyCon.StoppedOnErrorHandler | ( | JoyCon | source, |
Exception | exception | ||
) |
Event handler for stopped on error.
source | The JoyCon instance. |
exception | The exception that caused the stop. |
|
inline |
Start controller polling.
|
inline |
Stop controller polling.
async Task<SubCmdReply?> JoyCon.WriteSubcommandAsync | ( | OutputReportType | outputReportID, |
RumbleSet? | rumble, | ||
Subcommand | subcommandID, | ||
byte?[] | subcommandData = null , |
||
bool | noWaitAck = false , |
||
CancellationToken | cancellationToken = default |
||
) |
Write a subcommand to the controller using the specified output report ID.
outputReportID | Output report ID. |
rumble | Optional rumble data if you want to keep the vibration on. |
subcommandID | Subcommand ID. |
subcommandData | Subcommand data. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
|
inline |
Write a subcommand to the controller using the specified output report ID.
outputReportID | Output report ID. |
rumble | Optional rumble data if you want to keep the vibration on. |
subcommandID | Subcommand ID. |
subcommandData | Subcommand data. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
async Task<SubCmdReply?> JoyCon.WriteSubcommandAsync | ( | RumbleSet? | rumble, |
Subcommand | subcommandID, | ||
byte?[] | subcommandData = null , |
||
bool | noWaitAck = false , |
||
CancellationToken | cancellationToken = default |
||
) |
Write a subcommand to the controller.
rumble | Optional rumble data if you want to keep the vibration on. |
subcommandID | Subcommand ID. |
subcommandData | Subcommand data. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
|
inline |
Set input report mode, e.g. format of the data sent by the controller. InputReportType.Full is recommended for most cases.
inputReportMode | Input report mode as InputReportType. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Enable or disable IMU sensor.
enable | True to enable, false to disable. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Enable or disable vibration.
enable | True to enable, false to disable. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
async Task JoyCon.WriteRumble | ( | RumbleSet | rumbleSet, |
CancellationToken | cancellationToken = default |
||
) |
Write a rumble data to the controller.
rumbleSet | Set of rumble data as RumbleSet. |
cancellationToken | Cancellation token. |
async Task JoyCon.WriteRumble | ( | RumbleData | leftRumble, |
RumbleData | rightRumble, | ||
CancellationToken | cancellationToken = default |
||
) |
Write a rumble data to the controller.
leftRumble | Left rumble data as Rumble. |
rightRumble | Right rumble data as Rumble. |
cancellationToken | Cancellation token. |
async Task JoyCon.WriteRumble | ( | double | freqLeft, |
double | ampLeft, | ||
double | freqRight, | ||
double | ampRight, | ||
CancellationToken | cancellationToken = default |
||
) |
Write a rumble data to the controller.
freqLeft | Left rumble frequency. |
ampLeft | Left rumble amplitude. |
freqRight | Right rumble frequency. |
ampRight | Right rumble amplitude. |
cancellationToken | Cancellation token. |
async Task JoyCon.WriteRumble | ( | double | freqBoth, |
double | ampBoth, | ||
CancellationToken | cancellationToken = default |
||
) |
Write a rumble data to the controller.
freqBoth | Frequency for both left and right rumble. |
ampBoth | Amplitude for both left and right rumble. |
cancellationToken | Cancellation token. |
|
inline |
Set IMU sensor sensitivity.
gyroSensitivity | Gyroscope sensitivity. |
accSensitivity | Accelerometer sensitivity. |
gyroPerformance | Gyroscope performance rate. |
accFilter | Accelerometer anti-aliasing filter bandwidth. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Set LEDs state on the controller.
led1 | LED 1 state. |
led2 | LED 2 state. |
led3 | LED 3 state. |
led4 | LED 4 state. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Get LEDs state on the controller.
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Set Home LED dimming pattern.
homeLedDimmingPattern | Home LED dimming pattern as HomeLedDimmingPattern. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Get device info.
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Get battery voltage in mV.
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Get trigger button elapsed time.
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Write to IMU register directly. Consult LSM6DS3 datasheet for all registers and their meaning.
address | Address of the register. |
value | Value to write. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Read IMU registers directly. Consult LSM6DS3 datasheet for all registers and their meaning.
address | Address of the first register. |
length | Number of registers to read (up to 32). |
cancellationToken | Cancellation token. |
ArgumentOutOfRangeException | Thrown when length is out of range. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Read the internal SPI flash data.
address | Address to read. |
length | Number of bytes to read (up to 29). |
cancellationToken | Cancellation token. |
ArgumentOutOfRangeException | Thrown when length is out of range. |
InvalidOperationException | Thrown when acknowledgement is failed. |
|
inline |
Write data to the internal SPI flash.
address | Address to write. |
data | Data to write (up to 29 bytes). |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
ArgumentOutOfRangeException | Thrown when data length is out of range. |
InvalidOperationException | Thrown when acknowledgement is failed or SPI flash is write-protected. |
|
inline |
Erase the SPI flash sector. WARNING! This will erase data in the whole 4KB sector!
address | Address of the sector. |
noWaitAck | True to not wait for acknowledgement. |
cancellationToken | Cancellation token. |
InvalidOperationException | Thrown when acknowledgement is failed or SPI flash is write-protected. |
|
inline |
Read the factory stick calibration data from the SPI flash memory.
cancellationToken | Cancellation token. |
|
inline |
Get the user calibration data from the SPI flash memory.
cancellationToken | Cancellation token. |
|
inline |
Get a minor stick parameters: dead-zone and range ratio.
cancellationToken | Cancellation token. |
|
inline |
Get the controller's serial number. Can be null if not present.
cancellationToken | Cancellation token. |
|
inline |
Check if the controller is new. It's programmed to true on the factory. Switch makes sure to set it to false after the first connection. Can be inaccurate.
cancellationToken | Cancellation token. |
|
inline |
Get the controller's colors stored in the SPI flash memory. Can be null if not present.
cancellationToken | Cancellation token. |
ReportReceivedHandler JoyCon.ReportReceived = delegate { return Task.CompletedTask; } |
Event raised when a report is received.
StoppedOnErrorHandler JoyCon.StoppedOnError = delegate { return Task.CompletedTask; } |
Event raised when controller polling is stopped because of an error.