JoyCon.NET
Public Types | Public Member Functions | Events
JoyCon Class Reference

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< DeviceInfoGetDeviceInfoAsync (CancellationToken cancellationToken=default)
 Get device info. More...
 
async Task< ushort > GetVoltageAsync (CancellationToken cancellationToken=default)
 Get battery voltage in mV. More...
 
async Task< TriggerButtonsElapsedTimeGetTriggerButtonElapsedTimeAsync (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< CalibrationDataGetFactoryCalibrationAsync (CancellationToken cancellationToken=default)
 Read the factory stick calibration data from the SPI flash memory. More...
 
async Task< CalibrationDataGetUserCalibrationAsync (CancellationToken cancellationToken=default)
 Get the user calibration data from the SPI flash memory. More...
 
async Task< StickParametersSetGetStickParametersAsync (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...
 

Detailed Description

Joy-Con controller to control Joy-Con or Pro Controller.

Member Enumeration Documentation

◆ Subcommand

enum JoyCon.Subcommand : byte
strong

Subcommands.

Enumerator
Nothing 

Get Only Controller State. Does nothing actually, but can be used to get Controller state only (w/o 6-Axis sensor data), like any subcommand that does nothing.

BluetoothManualPairing 

Bluetooth manual pairing.

RequestDeviceInfo 

Request device info.

SetInputReportMode 

Set input report mode.

TriggerButtonsElapseTime 

Trigger buttons elapsed time. Replies with 7 little-endian uint16. The values are in 10ms. They reset by turning off the controller.

GetPageListState 

Get page list state. Replies a uint8 with a value of x01 if there's a Host list with BD addresses/link keys in memory.

SetHciState 

Set HCI state (disconnect/page/pair/turn off). Causes the controller to change power state.

ResetPairingInfo 

Reset pairing info. Initializes the 0x2000 SPI section.

SetShipmentLowPowerState 

Set shipment low power state. If set, the feature Triggered Broadcom Fast Connect scans when in suspened or disconnected state is disabled. Additionally, it sets the low power mode, when disconnected, to HID OFF.

SpiFlashRead 

SPI flash read.

SpiFlashWrite 

SPI flash Write.

SpiFlashSectorErase 

SPI sector erase.

ResetMcu 

Reset MCU.

SetMcuConfig 

Set MCU configuration. Write configuration data to MCU. This data can be IR configuration, NFC configuration or data for the 512KB MCU firmware update.

SetMcuState 

Set MCU state.

SetUnknownX24 

Set unknown data (fw 3.86 and up). Sets a byte to x01 (enable something?) and sets also an unknown data (configuration? for MCU?) to the bt device struct that copies it from given argument.

ResetUnknownX24 

Reset SetUnknownX24 unknown data (fw 3.86 and up).

SetUnknownMcuData 

Set unknown MCU data.

GetMcuData 

Get SetUnknownMcuData MCU data.

SetGpioOutputPort2 

Set GPIO Pin Output value (2 pin @ port 2).

GetMcuData2 

Get GetMcuData MCU data.

SetPlayerLights 

Set player lights.

GetPlayerLights 

Get player lights.

SetHomeLed 

Set Home LED.

EnableImu 

Enable IMU (6-Axis sensor).

SetImuSensitivity 

Set IMU sensitivity.

WriteImuRegister 

Write to IMU registers. Consult LSM6DS3 datasheet for all registers and their meaning. The registers addresses are mapped 1:1 in the subcmd. With this subcmd you can completely control the IMU.

ReadImuRegister 

Read IMU registers.

EnableRumble 

Enable rumble.

GetRegulatedVoltage 

Get regulated voltage. Internally, the values come from 1000mV - 1800mV regulated voltage samples, that are translated to 1320-1680 values. These follow a curve between 3.3V and 4.2V. So a 2.5x multiplier can get us the real battery voltage in mV.

SetGpioOutputPort1 

Set GPIO Pin Output value (7, 15 pins @ port 1).

GetGpioInput 

Get GPIO Pin Input/Output value.

◆ InputReportType

enum JoyCon.InputReportType : byte
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.

◆ OutputReportType

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.

◆ GyroSensitivity

enum JoyCon.GyroSensitivity : byte
strong

Gyroscope sensitivity.

Enumerator
DPS250 

±250dps

DPS500 

±500dps

DPS1000 

±1000dps

DPS2000 

±2000dps (default)

◆ GyroPerformance

enum JoyCon.GyroPerformance : byte
strong

Gyroscope performance rate.

Enumerator
Hz833 

833Hz (high performance)

Hz208 

208Hz (default)

◆ AccSensitivity

enum JoyCon.AccSensitivity : byte
strong

Accelerometer sensitivity.

Enumerator
G8 

±8G (default)

G4 

±4G

G2 

±2G

G16 

±16G

◆ AccFilter

enum JoyCon.AccFilter : byte
strong

Accelerometer Anti-aliasing filter bandwidth.

Enumerator
Hz200 

200Hz.

Hz100 

100Hz (default).

◆ LedState

enum JoyCon.LedState : byte
strong

LED state.

Enumerator
Off 

LED is off.

On 

LED is on.

Blinking 

LED is blinking.

Constructor & Destructor Documentation

◆ JoyCon()

JoyCon.JoyCon ( HidDevice  hidDevice)

Create a /new Joy-Con controller to control Joy-Con or Pro Controller.

Parameters
hidDeviceHID device which represents the controller.

Member Function Documentation

◆ ReportReceivedHandler()

delegate Task JoyCon.ReportReceivedHandler ( JoyCon  source,
IJoyConReport  report 
)

Event handler for report received.

Parameters
sourceThe JoyCon instance.
reportThe report received as IJoyConReport.
Returns
The task.

◆ StoppedOnErrorHandler()

delegate Task JoyCon.StoppedOnErrorHandler ( JoyCon  source,
Exception  exception 
)

Event handler for stopped on error.

Parameters
sourceThe JoyCon instance.
exceptionThe exception that caused the stop.
Returns
The task.

◆ Start()

void JoyCon.Start ( )
inline

Start controller polling.

◆ Stop()

void JoyCon.Stop ( )
inline

Stop controller polling.

◆ WriteSubcommandAsync() [1/3]

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.

Parameters
outputReportIDOutput report ID.
rumbleOptional rumble data if you want to keep the vibration on.
subcommandIDSubcommand ID.
subcommandDataSubcommand data.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The subcommand reply as SubCmdReply object or null if noWaitAck is true.

◆ WriteSubcommandAsync() [2/3]

async Task<SubCmdReply?> JoyCon.WriteSubcommandAsync ( byte  outputReportID,
RumbleSet rumble,
Subcommand  subcommandID,
byte?[]  subcommandData = null,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Write a subcommand to the controller using the specified output report ID.

Parameters
outputReportIDOutput report ID.
rumbleOptional rumble data if you want to keep the vibration on.
subcommandIDSubcommand ID.
subcommandDataSubcommand data.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The subcommand reply as SubCmdReply object or null if noWaitAck is true.

◆ WriteSubcommandAsync() [3/3]

async Task<SubCmdReply?> JoyCon.WriteSubcommandAsync ( RumbleSet rumble,
Subcommand  subcommandID,
byte?[]  subcommandData = null,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)

Write a subcommand to the controller.

Parameters
rumbleOptional rumble data if you want to keep the vibration on.
subcommandIDSubcommand ID.
subcommandDataSubcommand data.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The subcommand reply as SubCmdReply object or null if noWaitAck is true.

◆ SetInputReportModeAsync()

async Task JoyCon.SetInputReportModeAsync ( InputReportType  inputReportMode,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Set input report mode, e.g. format of the data sent by the controller. InputReportType.Full is recommended for most cases.

Parameters
inputReportModeInput report mode as InputReportType.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ EnableImuAsync()

async Task JoyCon.EnableImuAsync ( bool  enable,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Enable or disable IMU sensor.

Parameters
enableTrue to enable, false to disable.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ EnableRumbleAsync()

async Task JoyCon.EnableRumbleAsync ( bool  enable,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Enable or disable vibration.

Parameters
enableTrue to enable, false to disable.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ WriteRumble() [1/4]

async Task JoyCon.WriteRumble ( RumbleSet  rumbleSet,
CancellationToken  cancellationToken = default 
)

Write a rumble data to the controller.

Parameters
rumbleSetSet of rumble data as RumbleSet.
cancellationTokenCancellation token.
Returns
The task.

◆ WriteRumble() [2/4]

async Task JoyCon.WriteRumble ( RumbleData  leftRumble,
RumbleData  rightRumble,
CancellationToken  cancellationToken = default 
)

Write a rumble data to the controller.

Parameters
leftRumbleLeft rumble data as Rumble.
rightRumbleRight rumble data as Rumble.
cancellationTokenCancellation token.
Returns
The task.

◆ WriteRumble() [3/4]

async Task JoyCon.WriteRumble ( double  freqLeft,
double  ampLeft,
double  freqRight,
double  ampRight,
CancellationToken  cancellationToken = default 
)

Write a rumble data to the controller.

Parameters
freqLeftLeft rumble frequency.
ampLeftLeft rumble amplitude.
freqRightRight rumble frequency.
ampRightRight rumble amplitude.
cancellationTokenCancellation token.
Returns
The task.

◆ WriteRumble() [4/4]

async Task JoyCon.WriteRumble ( double  freqBoth,
double  ampBoth,
CancellationToken  cancellationToken = default 
)

Write a rumble data to the controller.

Parameters
freqBothFrequency for both left and right rumble.
ampBothAmplitude for both left and right rumble.
cancellationTokenCancellation token.
Returns
The task.

◆ SetImuSensitivityAsync()

async Task JoyCon.SetImuSensitivityAsync ( AccSensitivity  accSensitivity,
AccFilter  accFilter,
GyroSensitivity  gyroSensitivity,
GyroPerformance  gyroPerformance,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Set IMU sensor sensitivity.

Parameters
gyroSensitivityGyroscope sensitivity.
accSensitivityAccelerometer sensitivity.
gyroPerformanceGyroscope performance rate.
accFilterAccelerometer anti-aliasing filter bandwidth.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ SetPlayerLedsAsync()

async Task JoyCon.SetPlayerLedsAsync ( LedState  led1,
LedState  led2,
LedState  led3,
LedState  led4,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Set LEDs state on the controller.

Parameters
led1LED 1 state.
led2LED 2 state.
led3LED 3 state.
led4LED 4 state.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ GetPlayerLedsAsync()

async Task<LedState[]> JoyCon.GetPlayerLedsAsync ( CancellationToken  cancellationToken = default)
inline

Get LEDs state on the controller.

Parameters
cancellationTokenCancellation token.
Returns
LEDs state as an array of LedState.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ SetHomeLedDimmingPatternAsync()

async Task JoyCon.SetHomeLedDimmingPatternAsync ( HomeLedDimmingPattern  homeLedDimmingPattern,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Set Home LED dimming pattern.

Parameters
homeLedDimmingPatternHome LED dimming pattern as HomeLedDimmingPattern.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ GetDeviceInfoAsync()

async Task<DeviceInfo> JoyCon.GetDeviceInfoAsync ( CancellationToken  cancellationToken = default)
inline

Get device info.

Parameters
cancellationTokenCancellation token.
Returns
The device info as DeviceInfo.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ GetVoltageAsync()

async Task<ushort> JoyCon.GetVoltageAsync ( CancellationToken  cancellationToken = default)
inline

Get battery voltage in mV.

Parameters
cancellationTokenCancellation token.
Returns
The battery voltage in mV.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ GetTriggerButtonElapsedTimeAsync()

async Task<TriggerButtonsElapsedTime> JoyCon.GetTriggerButtonElapsedTimeAsync ( CancellationToken  cancellationToken = default)
inline

Get trigger button elapsed time.

Parameters
cancellationTokenCancellation token.
Returns
The trigger button elapsed time as TriggerButtonsElapsedTime.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ ImuRegisterWriteAsync()

async Task JoyCon.ImuRegisterWriteAsync ( byte  address,
byte  value,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Write to IMU register directly. Consult LSM6DS3 datasheet for all registers and their meaning.

Parameters
addressAddress of the register.
valueValue to write.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ ImuRegisterReadAsync()

async Task<byte[]> JoyCon.ImuRegisterReadAsync ( byte  address,
byte  length,
CancellationToken  cancellationToken = default 
)
inline

Read IMU registers directly. Consult LSM6DS3 datasheet for all registers and their meaning.

Parameters
addressAddress of the first register.
lengthNumber of registers to read (up to 32).
cancellationTokenCancellation token.
Returns
Register data.
Exceptions
ArgumentOutOfRangeExceptionThrown when length is out of range.
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ ReadSpiFlashAsync()

async Task<byte[]> JoyCon.ReadSpiFlashAsync ( int  address,
int  length,
CancellationToken  cancellationToken = default 
)
inline

Read the internal SPI flash data.

Parameters
addressAddress to read.
lengthNumber of bytes to read (up to 29).
cancellationTokenCancellation token.
Returns
Read data.
Exceptions
ArgumentOutOfRangeExceptionThrown when length is out of range.
InvalidOperationExceptionThrown when acknowledgement is failed.

◆ WriteSpiFlashAsync()

async Task JoyCon.WriteSpiFlashAsync ( int  address,
byte[]  data,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Write data to the internal SPI flash.

Parameters
addressAddress to write.
dataData to write (up to 29 bytes).
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
ArgumentOutOfRangeExceptionThrown when data length is out of range.
InvalidOperationExceptionThrown when acknowledgement is failed or SPI flash is write-protected.

◆ EraseSpiFlashSectorAsync()

async Task JoyCon.EraseSpiFlashSectorAsync ( int  address,
bool  noWaitAck = false,
CancellationToken  cancellationToken = default 
)
inline

Erase the SPI flash sector. WARNING! This will erase data in the whole 4KB sector!

Parameters
addressAddress of the sector.
noWaitAckTrue to not wait for acknowledgement.
cancellationTokenCancellation token.
Returns
The task.
Exceptions
InvalidOperationExceptionThrown when acknowledgement is failed or SPI flash is write-protected.

◆ GetFactoryCalibrationAsync()

async Task<CalibrationData> JoyCon.GetFactoryCalibrationAsync ( CancellationToken  cancellationToken = default)
inline

Read the factory stick calibration data from the SPI flash memory.

Parameters
cancellationTokenCancellation token.
Returns
The factory calibration data as a Calibration object.

◆ GetUserCalibrationAsync()

async Task<CalibrationData> JoyCon.GetUserCalibrationAsync ( CancellationToken  cancellationToken = default)
inline

Get the user calibration data from the SPI flash memory.

Parameters
cancellationTokenCancellation token.
Returns
The user calibration data as Calibration object.

◆ GetStickParametersAsync()

async Task<StickParametersSet> JoyCon.GetStickParametersAsync ( CancellationToken  cancellationToken = default)
inline

Get a minor stick parameters: dead-zone and range ratio.

Parameters
cancellationTokenCancellation token.
Returns
The stick parameters as StickParameters object.

◆ GetSerialNumberAsync()

async Task<string?> JoyCon.GetSerialNumberAsync ( CancellationToken  cancellationToken = default)
inline

Get the controller's serial number. Can be null if not present.

Parameters
cancellationTokenCancellation token.
Returns
The serial number or null if not present.

◆ GetIsJoyConNewAsync()

async Task<bool> JoyCon.GetIsJoyConNewAsync ( CancellationToken  cancellationToken = default)
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.

Parameters
cancellationTokenCancellation token.
Returns
True if the controller is new, false otherwise.

◆ GetColorsAsync()

async Task<ControllerColors?> JoyCon.GetColorsAsync ( CancellationToken  cancellationToken = default)
inline

Get the controller's colors stored in the SPI flash memory. Can be null if not present.

Parameters
cancellationTokenCancellation token.
Returns
The controller's colors as ControllerColors object or null if not present.

Event Documentation

◆ ReportReceived

ReportReceivedHandler JoyCon.ReportReceived = delegate { return Task.CompletedTask; }

Event raised when a report is received.

◆ StoppedOnError

StoppedOnErrorHandler JoyCon.StoppedOnError = delegate { return Task.CompletedTask; }

Event raised when controller polling is stopped because of an error.