Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

PS4USB Class Reference

This class implements support for the PS4 controller via USB. More...

#include <PS4USB.h>

Inherits HIDUniversal, and PS4Parser.

Public Member Functions

 PS4USB (Usb *p)
 Constructor for the PS4USB class.
bool connected ()
 Used to check if a PS4 controller is connected.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the device is successfully initialized.
PS4 Controller functions
bool getButtonPress (ButtonEnum b)
 getButtonPress(ButtonEnum b) will return true as long as the button is held down.
bool getButtonClick (ButtonEnum b)
uint8_t getAnalogButton (ButtonEnum b)
 Used to get the analog value from button presses.
uint8_t getAnalogHat (AnalogHatEnum a)
 Used to read the analog joystick.
uint16_t getX (uint8_t finger=0, uint8_t xyId=0)
 Get the x-coordinate of the touchpad.
uint16_t getY (uint8_t finger=0, uint8_t xyId=0)
 Get the y-coordinate of the touchpad.
bool isTouching (uint8_t finger=0, uint8_t xyId=0)
 Returns whenever the user is toucing the touchpad.
uint8_t getTouchCounter (uint8_t finger=0, uint8_t xyId=0)
 This counter increments every time a finger touches the touchpad.
float getAngle (AngleEnum a)
 Get the angle of the controller calculated using the accelerometer.
int16_t getSensor (SensorEnum s)
 Used to get the raw values from the 3-axis gyroscope and 3-axis accelerometer inside the PS4 controller.
uint8_t getBatteryLevel ()
 Return the battery level of the PS4 controller.
bool getUsbStatus ()
 Use this to check if an USB cable is connected to the PS4 controller.
bool getAudioStatus ()
 Use this to check if an audio jack cable is connected to the PS4 controller.
bool getMicStatus ()
 Use this to check if a microphone is connected to the PS4 controller.
void setAllOff ()
 Turn both rumble and the LEDs off.
void setRumbleOff ()
 Set rumble off.
void setRumbleOn (RumbleEnum mode)
 Turn on rumble.
void setRumbleOn (uint8_t bigRumble, uint8_t smallRumble)
 Turn on rumble.
void setLedOff ()
 Turn all LEDs off.
void setLed (uint8_t r, uint8_t g, uint8_t b)
 Use this to set the color using RGB values.
void setLed (ColorsEnum color)
 Use this to set the color using the predefined colors in ColorsEnum.
void setLedFlash (uint8_t flashOn, uint8_t flashOff)
 Set the LEDs flash time.

Protected Member Functions

void Parse (uint8_t len, uint8_t *buf)
 Used to parse data sent from the PS4 controller.
void Reset ()
 Used to reset the different buffers to their default values.
HIDUniversal implementation
virtual void ParseHIDData (USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
 Used to parse USB HID data.
virtual uint8_t OnInitSuccessful ()
 Called when a device is successfully initialized.
PS4Parser implementation
virtual void sendOutputReport (PS4Output *output)
 Send the output to the PS4 controller.
USBDeviceConfig implementation
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 Used by the USB core to check what this driver support.

Detailed Description

This class implements support for the PS4 controller via USB.

It uses the HIDUniversal class for all the USB communication.

Definition at line 32 of file PS4USB.h.


Constructor & Destructor Documentation

PS4USB ( Usb *  p )

Constructor for the PS4USB class.

Parameters:
pPointer to the USB class instance.

Definition at line 38 of file PS4USB.h.


Member Function Documentation

void attachOnInit ( void(*)(void)  funcOnInit )

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

Parameters:
funcOnInitFunction to call.

Definition at line 55 of file PS4USB.h.

bool connected (  )

Used to check if a PS4 controller is connected.

Returns:
Returns true if it is connected.

Definition at line 47 of file PS4USB.h.

uint8_t getAnalogButton ( ButtonEnum  b ) [inherited]

Used to get the analog value from button presses.

Parameters:
bThe ButtonEnum to read. The supported buttons are: L2 and R2.
Returns:
Analog value in the range of 0-255.

Definition at line 64 of file PS4Parser.cpp.

uint8_t getAnalogHat ( AnalogHatEnum  a ) [inherited]

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.

float getAngle ( AngleEnum  a ) [inherited]

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 215 of file PS4Parser.h.

bool getAudioStatus (  ) [inherited]

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 266 of file PS4Parser.h.

uint8_t getBatteryLevel (  ) [inherited]

Return the battery level of the PS4 controller.

Returns:
The battery level in the range 0-15.

Definition at line 250 of file PS4Parser.h.

bool getButtonPress ( ButtonEnum  b ) [inherited]

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 getMicStatus (  ) [inherited]

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

Returns:
Returns true if a microphone is connected.

Definition at line 274 of file PS4Parser.h.

int16_t getSensor ( SensorEnum  s ) [inherited]

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 227 of file PS4Parser.h.

uint8_t getTouchCounter ( uint8_t  finger = 0,
uint8_t  xyId = 0 
) [inherited]

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 206 of file PS4Parser.h.

bool getUsbStatus (  ) [inherited]

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 258 of file PS4Parser.h.

uint16_t getX ( uint8_t  finger = 0,
uint8_t  xyId = 0 
) [inherited]

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 170 of file PS4Parser.h.

uint16_t getY ( uint8_t  finger = 0,
uint8_t  xyId = 0 
) [inherited]

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 182 of file PS4Parser.h.

bool isTouching ( uint8_t  finger = 0,
uint8_t  xyId = 0 
) [inherited]

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 194 of file PS4Parser.h.

virtual uint8_t OnInitSuccessful (  ) [protected, virtual]

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.

Definition at line 78 of file PS4USB.h.

void Parse ( uint8_t  len,
uint8_t *  buf 
) [protected, inherited]

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.

virtual void ParseHIDData ( USBHID *  hid,
bool  is_rpt_id,
uint8_t  len,
uint8_t *  buf 
) [protected, virtual]

Used to parse USB HID data.

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

Definition at line 68 of file PS4USB.h.

void Reset (  ) [protected, inherited]

Used to reset the different buffers to their default values.

Definition at line 130 of file PS4Parser.cpp.

virtual void sendOutputReport ( PS4Output *  output ) [protected, virtual]

Send the output to the PS4 controller.

This is implemented in PS4BT.h and PS4USB.h.

Parameters:
outputPointer to PS4Output buffer;

Implements PS4Parser.

Definition at line 91 of file PS4USB.h.

void setAllOff (  ) [inherited]

Turn both rumble and the LEDs off.

Definition at line 279 of file PS4Parser.h.

void setLed ( uint8_t  r,
uint8_t  g,
uint8_t  b 
) [inherited]

Use this to set the color using RGB values.

Parameters:
r,g,bRGB value.

Definition at line 320 of file PS4Parser.h.

void setLed ( ColorsEnum  color ) [inherited]

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

Parameters:
colorThe desired color.

Definition at line 331 of file PS4Parser.h.

void setLedFlash ( uint8_t  flashOn,
uint8_t  flashOff 
) [inherited]

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 340 of file PS4Parser.h.

void setLedOff (  ) [inherited]

Turn all LEDs off.

Definition at line 312 of file PS4Parser.h.

void setRumbleOff (  ) [inherited]

Set rumble off.

Definition at line 285 of file PS4Parser.h.

void setRumbleOn ( uint8_t  bigRumble,
uint8_t  smallRumble 
) [inherited]

Turn on rumble.

Parameters:
bigRumbleValue for big motor.
smallRumbleValue for small motor.

Definition at line 305 of file PS4Parser.h.

void setRumbleOn ( RumbleEnum  mode ) [inherited]

Turn on rumble.

Parameters:
modeEither RumbleHigh or RumbleLow.

Definition at line 293 of file PS4Parser.h.

virtual bool VIDPIDOK ( uint16_t  vid,
uint16_t  pid 
) [protected, virtual]

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

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

Definition at line 123 of file PS4USB.h.