USB Host Shield 2.0
Public Member Functions | List of all members
SwitchProUSB Class Reference

#include <SwitchProUSB.h>

Inheritance diagram for SwitchProUSB:
Inheritance graph
Collaboration diagram for SwitchProUSB:
Collaboration graph

Public Member Functions

 SwitchProUSB (USB *p)
bool connected ()
void attachOnInit (void(*funcOnInit)(void))
- Public Member Functions inherited from HIDUniversal
 HIDUniversal (USB *p)
uint8_t Poll () override
void EndpointXtract (uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep) override
- Public Member Functions inherited from HIDComposite
 HIDComposite (USB *p)
bool SetReportParser (uint8_t id, HIDReportParser *prs)
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
uint8_t Release ()
virtual uint8_t GetAddress ()
virtual bool isReady ()
uint8_t SndRpt (uint16_t nbytes, uint8_t *dataptr)
- Public Member Functions inherited from USBHID
 USBHID (USB *pusb)
const USBGetUsb ()
uint8_t SetProtocol (uint8_t iface, uint8_t protocol)
uint8_t GetProtocol (uint8_t iface, uint8_t *dataptr)
uint8_t GetIdle (uint8_t iface, uint8_t reportID, uint8_t *dataptr)
uint8_t SetIdle (uint8_t iface, uint8_t reportID, uint8_t duration)
uint8_t GetReportDescr (uint16_t wIndex, USBReadParser *parser=NULL)
uint8_t GetHidDescr (uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
uint8_t GetReport (uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)
uint8_t SetReport (uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)
- Public Member Functions inherited from USBDeviceConfig
virtual uint8_t ConfigureDevice (uint8_t parent, uint8_t port, bool lowspeed)
virtual void ResetHubPort (uint8_t port)
virtual bool DEVCLASSOK (uint8_t klass)
virtual bool DEVSUBCLASSOK (uint8_t subklass)
- Public Member Functions inherited from SwitchProParser
 SwitchProParser ()
bool getButtonPress (ButtonEnum b)
bool getButtonClick (ButtonEnum b)
int16_t getAnalogHat (AnalogHatEnum a)
void enableImu (bool enable)
float getAngle (AngleEnum a)
int16_t getSensor (SensorEnum s)
void setAllOff ()
void setRumbleOff ()
void setRumbleToggle ()
void setRumble (bool leftRumbleOn, bool rightRumbleOn)
void setRumbleLeft (bool on)
void setRumbleRight (bool on)
void setLedRaw (uint8_t mask)
void setLedOff ()
void setLedOff (LEDEnum a)
void setLedOn (LEDEnum a)
void setLedToggle (LEDEnum a)
void setLedHomeOff ()
void setLedHomeOn ()
void setLedHomeToggle ()
uint16_t getMessageCounter ()
uint8_t getBatteryLevel ()
bool isCharging ()

Protected Member Functions

HIDUniversal implementation
virtual void ParseHIDData (USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual uint8_t OnInitSuccessful ()
SwitchProParser implementation
virtual void sendOutputReport (uint8_t *data, uint8_t len)
virtual void sendHandshake ()
virtual void disableTimeout ()
USBDeviceConfig implementation
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
- Protected Member Functions inherited from HIDComposite
uint16_t GetHidClassDescrLen (uint8_t type, uint8_t num)
void Initialize ()
HIDInterfaceFindInterface (uint8_t iface, uint8_t alt, uint8_t proto)
void ZeroMemory (uint8_t len, uint8_t *buf)
HIDReportParserGetReportParser (uint8_t id)
- Protected Member Functions inherited from USBHID
void PrintEndpointDescriptor (const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
void PrintHidDescriptor (const USB_HID_DESCRIPTOR *pDesc)
- Protected Member Functions inherited from SwitchProParser
void Parse (uint8_t len, uint8_t *buf)
void Reset ()

Additional Inherited Members

- Protected Attributes inherited from HIDComposite
struct HIDComposite::ReportParser rptParsers [MAX_REPORT_PARSERS]
uint8_t bConfNum
uint8_t bNumIface
uint8_t bNumEP
uint32_t qNextPollTime
uint8_t pollInterval
bool bPollEnable
EpInfo epInfo [totalEndpoints]
HIDInterface hidInterfaces [maxHidInterfaces]
bool bHasReportId
uint16_t PID
uint16_t VID
- Protected Attributes inherited from USBHID
uint8_t bAddress
- Protected Attributes inherited from SwitchProParser
SwitchProOutput switchProOutput
- Static Protected Attributes inherited from HIDComposite
static const uint16_t constBuffLen = 64
- Static Protected Attributes inherited from USBHID
static const uint8_t epInterruptInIndex = 1
static const uint8_t epInterruptOutIndex = 2
static const uint8_t maxHidInterfaces = 5
static const uint8_t maxEpPerInterface = 2
static const uint8_t totalEndpoints = (maxHidInterfaces * maxEpPerInterface + 1)

Detailed Description

This class implements support for the Switch Pro controller via USB. It uses the HIDUniversal class for all the USB communication.

Definition at line 31 of file SwitchProUSB.h.

Constructor & Destructor Documentation

◆ SwitchProUSB()

SwitchProUSB::SwitchProUSB ( USB p)

Constructor for the SwitchProUSB class.

pPointer to the USB class instance.

Definition at line 37 of file SwitchProUSB.h.

Member Function Documentation

◆ connected()

bool SwitchProUSB::connected ( )

Used to check if a Switch Pro controller is connected.

Returns true if it is connected.

Definition at line 46 of file SwitchProUSB.h.

◆ attachOnInit()

void SwitchProUSB::attachOnInit ( void(*)(void)  funcOnInit)

Used to call your own function when the device is successfully initialized.

funcOnInitFunction to call.

Definition at line 54 of file SwitchProUSB.h.

◆ ParseHIDData()

virtual void SwitchProUSB::ParseHIDData ( USBHID hid,
bool  is_rpt_id,
uint8_t  len,
uint8_t *  buf 

Used to parse USB HID data.

hidPointer to the HID class.
is_rpt_idOnly used for Hubs.
lenThe length of the incoming data.
bufPointer to the data buffer.

Reimplemented from HIDUniversal.

Definition at line 67 of file SwitchProUSB.h.

◆ OnInitSuccessful()

virtual uint8_t SwitchProUSB::OnInitSuccessful ( )

Called when a device is successfully initialized. Use attachOnInit(void (*funcOnInit)(void)) to call your own function. This is useful for instance if you want to set the LEDs in a specific way.

Reimplemented from HIDComposite.

Definition at line 77 of file SwitchProUSB.h.

◆ sendOutputReport()

virtual void SwitchProUSB::sendOutputReport ( uint8_t *  data,
uint8_t  len 

Send the output to the Switch Pro controller. This is implemented in SwitchProBT.h and SwitchProUSB.h.

dataPointer to buffer to send by the derived class.
lenLength of buffer.

Implements SwitchProParser.

Definition at line 98 of file SwitchProUSB.h.

◆ sendHandshake()

virtual void SwitchProUSB::sendHandshake ( )

Used to send a handshake command via USB before disabling the timeout.

Reimplemented from SwitchProParser.

Definition at line 118 of file SwitchProUSB.h.

◆ disableTimeout()

virtual void SwitchProUSB::disableTimeout ( )

Needed to disable USB timeout for the controller, so it sends out data without the host having to send data continuously.

Reimplemented from SwitchProParser.

Definition at line 129 of file SwitchProUSB.h.


virtual bool SwitchProUSB::VIDPIDOK ( uint16_t  vid,
uint16_t  pid 

Used by the USB core to check what this driver support.

vidThe device's VID.
pidThe device's PID.
Returns true if the device's VID and PID matches this driver.

Reimplemented from USBDeviceConfig.

Definition at line 148 of file SwitchProUSB.h.

The documentation for this class was generated from the following file: