USB Host Shield 2.0
Public Member Functions | List of all members
SwitchProParser Class Referenceabstract

#include <SwitchProParser.h>

Inheritance diagram for SwitchProParser:
Inheritance graph
[legend]
Collaboration diagram for SwitchProParser:
Collaboration graph
[legend]

Public Member Functions

 SwitchProParser ()
 

Switch Pro Controller functions

SwitchProOutput switchProOutput
 
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 ()
 
void Parse (uint8_t len, uint8_t *buf)
 
void Reset ()
 
virtual void sendOutputReport (uint8_t *data, uint8_t len)=0
 
virtual void sendHandshake ()
 
virtual void disableTimeout ()
 

Detailed Description

This class parses all the data sent by the Switch Pro controller

Definition at line 141 of file SwitchProParser.h.

Constructor & Destructor Documentation

◆ SwitchProParser()

SwitchProParser::SwitchProParser ( )
inline

Constructor for the SwitchProParser class.

Definition at line 144 of file SwitchProParser.h.

Member Function Documentation

◆ getButtonPress()

bool SwitchProParser::getButtonPress ( ButtonEnum  b)

getButtonPress(ButtonEnum b) will return true as long as the button is held down.

While getButtonClick(ButtonEnum b) will only return it once.

So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b), but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b).

Parameters
bButtonEnum to read.
Returns
getButtonPress(ButtonEnum b) will return a true as long as a button is held down, while getButtonClick(ButtonEnum b) will return true once for each button press.

Definition at line 29 of file SwitchProParser.cpp.

◆ getButtonClick()

bool SwitchProParser::getButtonClick ( ButtonEnum  b)

Allow derived classes to access the output variables.

Definition at line 34 of file SwitchProParser.cpp.

◆ getAnalogHat()

int16_t SwitchProParser::getAnalogHat ( AnalogHatEnum  a)

Used to read the analog joystick.

Parameters
aLeftHatX, LeftHatY, RightHatX, and RightHatY.
Returns
Return the analog value as a signed 16-bit value.

Definition at line 42 of file SwitchProParser.cpp.

◆ enableImu()

void SwitchProParser::enableImu ( bool  enable)
inline

Used to enable/disable the IMU. By default it is disabled.

Parameters
enableEnable/disable the IMU.

Definition at line 174 of file SwitchProParser.h.

◆ getAngle()

float SwitchProParser::getAngle ( AngleEnum  a)
inline

Get the angle of the controller calculated using the accelerometer.

Parameters
aEither Pitch or Roll.
Returns
Return the angle in the range of 0-360.

Definition at line 184 of file SwitchProParser.h.

◆ getSensor()

int16_t SwitchProParser::getSensor ( SensorEnum  s)
inline

Used to get the raw values from the 3-axis gyroscope and 3-axis accelerometer inside the PS5 controller.

Parameters
sThe sensor to read.
Returns
Returns the raw sensor reading.

Definition at line 196 of file SwitchProParser.h.

◆ setAllOff()

void SwitchProParser::setAllOff ( )
inline

Turn both rumble and the LEDs off.

Definition at line 216 of file SwitchProParser.h.

◆ setRumbleOff()

void SwitchProParser::setRumbleOff ( )
inline

Set rumble off.

Definition at line 223 of file SwitchProParser.h.

◆ setRumbleToggle()

void SwitchProParser::setRumbleToggle ( )
inline

Toggle rumble.

Definition at line 228 of file SwitchProParser.h.

◆ setRumble()

void SwitchProParser::setRumble ( bool  leftRumbleOn,
bool  rightRumbleOn 
)
inline

Turn on/off rumble.

Parameters
leftRumbleOnTurn on/off left rumble motor.
rightRumbleOnTurn on/off right rumble motor.

Definition at line 237 of file SwitchProParser.h.

◆ setRumbleLeft()

void SwitchProParser::setRumbleLeft ( bool  on)
inline

Turn on/off the left rumble.

Parameters
onTurn on/off left rumble motor.

Definition at line 247 of file SwitchProParser.h.

◆ setRumbleRight()

void SwitchProParser::setRumbleRight ( bool  on)
inline

Turn on/off the right rumble.

Parameters
onTurn on/off right rumble motor.

Definition at line 256 of file SwitchProParser.h.

◆ setLedRaw()

void SwitchProParser::setLedRaw ( uint8_t  mask)
inline

Set LED value without using the LEDEnum. This can also be used to flash the LEDs by setting the high 4-bits of the mask.

Parameters
valueSee: LEDEnum.

Definition at line 266 of file SwitchProParser.h.

◆ setLedOff() [1/2]

void SwitchProParser::setLedOff ( )
inline

Turn all LEDs off.

Definition at line 272 of file SwitchProParser.h.

◆ setLedOff() [2/2]

void SwitchProParser::setLedOff ( LEDEnum  a)
inline

Turn the specific LEDEnum off.

Parameters
aThe LEDEnum to turn off.

Definition at line 280 of file SwitchProParser.h.

◆ setLedOn()

void SwitchProParser::setLedOn ( LEDEnum  a)
inline

Turn the specific LEDEnum on.

Parameters
aThe LEDEnum to turn on.

Definition at line 289 of file SwitchProParser.h.

◆ setLedToggle()

void SwitchProParser::setLedToggle ( LEDEnum  a)
inline

Toggle the specific LEDEnum.

Parameters
aThe LEDEnum to toggle.

Definition at line 298 of file SwitchProParser.h.

◆ setLedHomeOff()

void SwitchProParser::setLedHomeOff ( )
inline

Turn home LED off.

Definition at line 304 of file SwitchProParser.h.

◆ setLedHomeOn()

void SwitchProParser::setLedHomeOn ( )
inline

Turn home LED on.

Definition at line 310 of file SwitchProParser.h.

◆ setLedHomeToggle()

void SwitchProParser::setLedHomeToggle ( )
inline

Toggle home LED.

Definition at line 316 of file SwitchProParser.h.

◆ getMessageCounter()

uint16_t SwitchProParser::getMessageCounter ( )
inline

Get the incoming message count.

Definition at line 322 of file SwitchProParser.h.

◆ getBatteryLevel()

uint8_t SwitchProParser::getBatteryLevel ( )
inline

Return the battery level of the Switch Pro Controller.

Returns
The battery level as a bit mask according to ::SwitchProBatteryLevel: 4=full, 3=medium, 2=low, 1=critical, 0=empty.

Definition at line 331 of file SwitchProParser.h.

◆ isCharging()

bool SwitchProParser::isCharging ( )
inline

Returns whenever the controller is plugged in and charging.

Returns
Returns True if the controller is charging.

Definition at line 339 of file SwitchProParser.h.

◆ Parse()

void SwitchProParser::Parse ( uint8_t  len,
uint8_t *  buf 
)
protected

Used to parse data sent from the Switch Pro controller.

Parameters
lenLength of the data.
bufPointer to the data buffer.

Definition at line 55 of file SwitchProParser.cpp.

◆ Reset()

void SwitchProParser::Reset ( )
protected

Used to reset the different buffers to their default values

Definition at line 231 of file SwitchProParser.cpp.

◆ sendOutputReport()

virtual void SwitchProParser::sendOutputReport ( uint8_t *  data,
uint8_t  len 
)
protectedpure virtual

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

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

Implemented in SwitchProUSB, and SwitchProBT.

◆ sendHandshake()

virtual void SwitchProParser::sendHandshake ( )
inlineprotectedvirtual

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

Reimplemented in SwitchProUSB.

Definition at line 362 of file SwitchProParser.h.

◆ disableTimeout()

virtual void SwitchProParser::disableTimeout ( )
inlineprotectedvirtual

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

Reimplemented in SwitchProUSB.

Definition at line 368 of file SwitchProParser.h.

Member Data Documentation

◆ switchProOutput

SwitchProOutput SwitchProParser::switchProOutput
protected

Allow derived classes to access the output variables.

Definition at line 371 of file SwitchProParser.h.


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