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

#include <PS4Parser.h>

Inheritance diagram for PS4Parser:
Inheritance graph
[legend]

Public Member Functions

 PS4Parser ()
 
PS4 Controller functions
bool getButtonPress (ButtonEnum b)
 
bool getButtonClick (ButtonEnum b)
 
uint8_t getAnalogButton (ButtonEnum b)
 
uint8_t getAnalogHat (AnalogHatEnum a)
 
uint16_t getX (uint8_t finger=0, uint8_t xyId=0)
 
uint16_t getY (uint8_t finger=0, uint8_t xyId=0)
 
bool isTouching (uint8_t finger=0, uint8_t xyId=0)
 
uint8_t getTouchCounter (uint8_t finger=0, uint8_t xyId=0)
 
float getAngle (AngleEnum a)
 
int16_t getSensor (SensorEnum s)
 
uint8_t getBatteryLevel ()
 
bool getUsbStatus ()
 
bool getAudioStatus ()
 
bool getMicStatus ()
 
void setAllOff ()
 
void setRumbleOff ()
 
void setRumbleOn (RumbleEnum mode)
 
void setRumbleOn (uint8_t bigRumble, uint8_t smallRumble)
 
void setLedOff ()
 
void setLed (uint8_t r, uint8_t g, uint8_t b)
 
void setLed (ColorsEnum color)
 
void setLedFlash (uint8_t flashOn, uint8_t flashOff)
 

Protected Member Functions

void Parse (uint8_t len, uint8_t *buf)
 
void Reset ()
 
virtual void sendOutputReport (PS4Output *output)=0
 

Detailed Description

This class parses all the data sent by the PS4 controller

Definition at line 124 of file PS4Parser.h.

Constructor & Destructor Documentation

PS4Parser::PS4Parser ( )
inline

Constructor for the PS4Parser class.

Definition at line 127 of file PS4Parser.h.

Member Function Documentation

bool PS4Parser::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 50 of file PS4Parser.cpp.

bool PS4Parser::getButtonClick ( 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 57 of file PS4Parser.cpp.

uint8_t PS4Parser::getAnalogButton ( ButtonEnum  b)

Used to get the analog value from button presses.

Parameters
bThe ButtonEnum to read. The supported buttons are: UP, RIGHT, DOWN, LEFT, L1, L2, R1, R2, TRIANGLE, CIRCLE, CROSS, SQUARE, and T.
Returns
Analog value in the range of 0-255.

Definition at line 64 of file PS4Parser.cpp.

uint8_t PS4Parser::getAnalogHat ( AnalogHatEnum  a)

Used to read the analog joystick.

Parameters
aLeftHatX, LeftHatY, RightHatX, and RightHatY.
Returns
Return the analog value in the range of 0-255.

Definition at line 72 of file PS4Parser.cpp.

uint16_t PS4Parser::getX ( uint8_t  finger = 0,
uint8_t  xyId = 0 
)
inline

Get the x-coordinate of the touchpad. Position 0 is in the top left.

Parameters
finger0 = first finger, 1 = second finger. If omitted, then 0 will be used.
xyIdThe controller sends out three packets with the same structure. The third one will contain the last measure, but if you read from the controller then there is only be data in the first one. For that reason it will be set to 0 if the argument is omitted.
Returns
Returns the x-coordinate of the finger.

Definition at line 171 of file PS4Parser.h.

uint16_t PS4Parser::getY ( uint8_t  finger = 0,
uint8_t  xyId = 0 
)
inline

Get the y-coordinate of the touchpad. Position 0 is in the top left.

Parameters
finger0 = first finger, 1 = second finger. If omitted, then 0 will be used.
xyIdThe controller sends out three packets with the same structure. The third one will contain the last measure, but if you read from the controller then there is only be data in the first one. For that reason it will be set to 0 if the argument is omitted.
Returns
Returns the y-coordinate of the finger.

Definition at line 183 of file PS4Parser.h.

bool PS4Parser::isTouching ( uint8_t  finger = 0,
uint8_t  xyId = 0 
)
inline

Returns whenever the user is toucing the touchpad.

Parameters
finger0 = first finger, 1 = second finger. If omitted, then 0 will be used.
xyIdThe controller sends out three packets with the same structure. The third one will contain the last measure, but if you read from the controller then there is only be data in the first one. For that reason it will be set to 0 if the argument is omitted.
Returns
Returns true if the specific finger is touching the touchpad.

Definition at line 195 of file PS4Parser.h.

uint8_t PS4Parser::getTouchCounter ( uint8_t  finger = 0,
uint8_t  xyId = 0 
)
inline

This counter increments every time a finger touches the touchpad.

Parameters
finger0 = first finger, 1 = second finger. If omitted, then 0 will be used.
xyIdThe controller sends out three packets with the same structure. The third one will contain the last measure, but if you read from the controller then there is only be data in the first one. For that reason it will be set to 0 if the argument is omitted.
Returns
Return the value of the counter, note that it is only a 7-bit value.

Definition at line 207 of file PS4Parser.h.

float PS4Parser::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 216 of file PS4Parser.h.

int16_t PS4Parser::getSensor ( SensorEnum  s)
inline

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

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

Definition at line 228 of file PS4Parser.h.

uint8_t PS4Parser::getBatteryLevel ( )
inline

Return the battery level of the PS4 controller.

Returns
The battery level in the range 0-15.

Definition at line 251 of file PS4Parser.h.

bool PS4Parser::getUsbStatus ( )
inline

Use this to check if an USB cable is connected to the PS4 controller.

Returns
Returns true if an USB cable is connected.

Definition at line 259 of file PS4Parser.h.

bool PS4Parser::getAudioStatus ( )
inline

Use this to check if an audio jack cable is connected to the PS4 controller.

Returns
Returns true if an audio jack cable is connected.

Definition at line 267 of file PS4Parser.h.

bool PS4Parser::getMicStatus ( )
inline

Use this to check if a microphone is connected to the PS4 controller.

Returns
Returns true if a microphone is connected.

Definition at line 275 of file PS4Parser.h.

void PS4Parser::setAllOff ( )
inline

Turn both rumble and the LEDs off.

Definition at line 280 of file PS4Parser.h.

void PS4Parser::setRumbleOff ( )
inline

Set rumble off.

Definition at line 286 of file PS4Parser.h.

void PS4Parser::setRumbleOn ( RumbleEnum  mode)
inline

Turn on rumble.

Parameters
modeEither RumbleHigh or RumbleLow.

Definition at line 294 of file PS4Parser.h.

void PS4Parser::setRumbleOn ( uint8_t  bigRumble,
uint8_t  smallRumble 
)
inline

Turn on rumble.

Parameters
bigRumbleValue for big motor.
smallRumbleValue for small motor.

Definition at line 306 of file PS4Parser.h.

void PS4Parser::setLedOff ( )
inline

Turn all LEDs off.

Definition at line 313 of file PS4Parser.h.

void PS4Parser::setLed ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inline

Use this to set the color using RGB values.

Parameters
r,g,bRGB value.

Definition at line 321 of file PS4Parser.h.

void PS4Parser::setLed ( ColorsEnum  color)
inline

Use this to set the color using the predefined colors in ColorsEnum.

Parameters
colorThe desired color.

Definition at line 332 of file PS4Parser.h.

void PS4Parser::setLedFlash ( uint8_t  flashOn,
uint8_t  flashOff 
)
inline

Set the LEDs flash time.

Parameters
flashOnTime to flash bright (255 = 2.5 seconds).
flashOffTime to flash dark (255 = 2.5 seconds).

Definition at line 341 of file PS4Parser.h.

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

Used to parse data sent from the PS4 controller.

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

Definition at line 76 of file PS4Parser.cpp.

void PS4Parser::Reset ( )
protected

Used to reset the different buffers to their default values

Definition at line 130 of file PS4Parser.cpp.

virtual void PS4Parser::sendOutputReport ( PS4Output output)
protectedpure virtual

Send the output to the PS4 controller. This is implemented in PS4BT.h and PS4USB.h.

Parameters
outputPointer to PS4Output buffer;

Implemented in PS4USB, and PS4BT.


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