USB Host Shield 2.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
PS3USB Class Reference

#include <PS3USB.h>

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

Public Member Functions

 PS3USB (USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
 
void setBdaddr (uint8_t *bdaddr)
 
void getBdaddr (uint8_t *bdaddr)
 
void setMoveBdaddr (uint8_t *bdaddr)
 
void getMoveBdaddr (uint8_t *bdaddr)
 
void getMoveCalibration (uint8_t *data)
 
USBDeviceConfig implementation
uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 
uint8_t Release ()
 
uint8_t Poll ()
 
virtual uint8_t GetAddress ()
 
virtual bool isReady ()
 
virtual bool VIDPIDOK (uint16_t vid, uint16_t pid)
 
PS3 Controller functions
bool getButtonPress (ButtonEnum b)
 
bool getButtonClick (ButtonEnum b)
 
uint8_t getAnalogButton (ButtonEnum a)
 
uint8_t getAnalogHat (AnalogHatEnum a)
 
uint16_t getSensor (SensorEnum a)
 
float getAngle (AngleEnum a)
 
bool getStatus (StatusEnum c)
 
void printStatusString ()
 
void setAllOff ()
 
void setRumbleOff ()
 
void setRumbleOn (RumbleEnum mode)
 
void setRumbleOn (uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower)
 
void setLedRaw (uint8_t value)
 
void setLedOff ()
 
void setLedOff (LEDEnum a)
 
void setLedOn (LEDEnum a)
 
void setLedToggle (LEDEnum a)
 
void moveSetBulb (uint8_t r, uint8_t g, uint8_t b)
 
void moveSetBulb (ColorsEnum color)
 
void moveSetRumble (uint8_t rumble)
 
void attachOnInit (void(*funcOnInit)(void))
 
- 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 Attributes

bool PS3Connected
 
bool PS3MoveConnected
 
bool PS3NavigationConnected
 

Protected Attributes

USBpUsb
 
uint8_t bAddress
 
EpInfo epInfo [PS3_MAX_ENDPOINTS]
 

Detailed Description

This class implements support for all the official PS3 Controllers: Dualshock 3, Navigation or a Motion controller via USB.

One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB on the Move controller.

Information about the protocol can be found at the wiki: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information.

Definition at line 49 of file PS3USB.h.

Constructor & Destructor Documentation

◆ PS3USB()

PS3USB::PS3USB ( USB pUsb,
uint8_t  btadr5 = 0,
uint8_t  btadr4 = 0,
uint8_t  btadr3 = 0,
uint8_t  btadr2 = 0,
uint8_t  btadr1 = 0,
uint8_t  btadr0 = 0 
)

Constructor for the PS3USB class.

Parameters
pUsbPointer to USB class instance.
btadr5,btadr4,btadr3,btadr2,btadr1,btadr0Pass your dongles Bluetooth address into the constructor, so you are able to pair the controller with a Bluetooth dongle.

Definition at line 23 of file PS3USB.cpp.

Member Function Documentation

◆ Init()

uint8_t PS3USB::Init ( uint8_t  parent,
uint8_t  port,
bool  lowspeed 
)
virtual

Initialize the PS3 Controller.

Parameters
parentHub number.
portPort number on the hub.
lowspeedSpeed of the device.
Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 47 of file PS3USB.cpp.

◆ Release()

uint8_t PS3USB::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 262 of file PS3USB.cpp.

◆ Poll()

uint8_t PS3USB::Poll ( )
virtual

Poll the USB Input endpoins and run the state machines.

Returns
0 on success.

Reimplemented from USBDeviceConfig.

Definition at line 272 of file PS3USB.cpp.

◆ GetAddress()

virtual uint8_t PS3USB::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Reimplemented from USBDeviceConfig.

Definition at line 84 of file PS3USB.h.

◆ isReady()

virtual bool PS3USB::isReady ( )
inlinevirtual

Used to check if the controller has been initialized.

Returns
True if it's ready.

Definition at line 92 of file PS3USB.h.

◆ VIDPIDOK()

virtual bool PS3USB::VIDPIDOK ( uint16_t  vid,
uint16_t  pid 
)
inlinevirtual

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.

Reimplemented from USBDeviceConfig.

Definition at line 102 of file PS3USB.h.

◆ setBdaddr()

void PS3USB::setBdaddr ( uint8_t *  bdaddr)

Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller. Set using LSB first.

Parameters
bdaddrYour dongles Bluetooth address.

Definition at line 468 of file PS3USB.cpp.

◆ getBdaddr()

void PS3USB::getBdaddr ( uint8_t *  bdaddr)

Used to get the Bluetooth address inside the Dualshock 3 and Navigation controller. Will return LSB first.

Parameters
bdaddrYour dongles Bluetooth address.

Definition at line 481 of file PS3USB.cpp.

◆ setMoveBdaddr()

void PS3USB::setMoveBdaddr ( uint8_t *  bdaddr)

Used to set the Bluetooth address inside the Move controller. Set using LSB first.

Parameters
bdaddrYour dongles Bluetooth address.

Definition at line 530 of file PS3USB.cpp.

◆ getMoveBdaddr()

void PS3USB::getMoveBdaddr ( uint8_t *  bdaddr)

Used to get the Bluetooth address inside the Move controller. Will return LSB first.

Parameters
bdaddrYour dongles Bluetooth address.

Definition at line 546 of file PS3USB.cpp.

◆ getMoveCalibration()

void PS3USB::getMoveCalibration ( uint8_t *  data)

Used to get the calibration data inside the Move controller.

Parameters
dataBuffer to store data in. Must be at least 147 bytes

Definition at line 556 of file PS3USB.cpp.

◆ getButtonPress()

bool PS3USB::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 316 of file PS3USB.cpp.

◆ getButtonClick()

bool PS3USB::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 321 of file PS3USB.cpp.

◆ getAnalogButton()

uint8_t PS3USB::getAnalogButton ( ButtonEnum  a)

Used to get the analog value from button presses.

Parameters
aThe 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 329 of file PS3USB.cpp.

◆ getAnalogHat()

uint8_t PS3USB::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 334 of file PS3USB.cpp.

◆ getSensor()

uint16_t PS3USB::getSensor ( SensorEnum  a)

Used to read the sensors inside the Dualshock 3 controller.

Parameters
aThe Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside.
Returns
Return the raw sensor value.

Definition at line 338 of file PS3USB.cpp.

◆ getAngle()

float PS3USB::getAngle ( AngleEnum  a)

Use this to get Pitch and Roll calculated using the accelerometer.

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

Definition at line 342 of file PS3USB.cpp.

◆ getStatus()

bool PS3USB::getStatus ( StatusEnum  c)

Get the StatusEnum from the controller.

Parameters
cThe StatusEnum you want to read.
Returns
True if correct and false if not.

Definition at line 363 of file PS3USB.cpp.

◆ printStatusString()

void PS3USB::printStatusString ( )

Read all the available statuses from the controller and prints it as a nice formated string.

Definition at line 367 of file PS3USB.cpp.

◆ setAllOff()

void PS3USB::setAllOff ( )

Used to set all LEDs and rumble off.

Definition at line 406 of file PS3USB.cpp.

◆ setRumbleOff()

void PS3USB::setRumbleOff ( )

Turn off rumble.

Definition at line 413 of file PS3USB.cpp.

◆ setRumbleOn() [1/2]

void PS3USB::setRumbleOn ( RumbleEnum  mode)

Turn on rumble.

Parameters
modeEither RumbleHigh or RumbleLow.

Definition at line 423 of file PS3USB.cpp.

◆ setRumbleOn() [2/2]

void PS3USB::setRumbleOn ( uint8_t  rightDuration,
uint8_t  rightPower,
uint8_t  leftDuration,
uint8_t  leftPower 
)

Turn on rumble using custom duration and power.

Parameters
rightDurationThe duration of the right/low rumble effect.
rightPowerThe intensity of the right/low rumble effect.
leftDurationThe duration of the left/high rumble effect.
leftPowerThe intensity of the left/high rumble effect.

Definition at line 434 of file PS3USB.cpp.

◆ setLedRaw()

void PS3USB::setLedRaw ( uint8_t  value)

Set LED value without using the LEDEnum.

Parameters
valueSee: LEDEnum.

Definition at line 444 of file PS3USB.cpp.

◆ setLedOff() [1/2]

void PS3USB::setLedOff ( )
inline

Turn all LEDs off.

Definition at line 215 of file PS3USB.h.

◆ setLedOff() [2/2]

void PS3USB::setLedOff ( LEDEnum  a)

Turn the specific LEDEnum off.

Parameters
aThe LEDEnum to turn off.

Definition at line 449 of file PS3USB.cpp.

◆ setLedOn()

void PS3USB::setLedOn ( LEDEnum  a)

Turn the specific LEDEnum on.

Parameters
aThe LEDEnum to turn on.

Definition at line 454 of file PS3USB.cpp.

◆ setLedToggle()

void PS3USB::setLedToggle ( LEDEnum  a)

Toggle the specific LEDEnum.

Parameters
aThe LEDEnum to toggle.

Definition at line 463 of file PS3USB.cpp.

◆ moveSetBulb() [1/2]

void PS3USB::moveSetBulb ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)

Use this to set the Color using RGB values.

Parameters
r,g,bRGB value.

Definition at line 507 of file PS3USB.cpp.

◆ moveSetBulb() [2/2]

void PS3USB::moveSetBulb ( ColorsEnum  color)

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

Parameters
colorThe desired color.

Definition at line 516 of file PS3USB.cpp.

◆ moveSetRumble()

void PS3USB::moveSetRumble ( uint8_t  rumble)

Set the rumble value inside the Move controller.

Parameters
rumbleThe desired value in the range from 64-255.

Definition at line 520 of file PS3USB.cpp.

◆ attachOnInit()

void PS3USB::attachOnInit ( void(*)(void)  funcOnInit)
inline

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

Parameters
funcOnInitFunction to call.

Definition at line 254 of file PS3USB.h.

Member Data Documentation

◆ PS3Connected

bool PS3USB::PS3Connected

Variable used to indicate if the normal playstation controller is successfully connected.

Definition at line 260 of file PS3USB.h.

◆ PS3MoveConnected

bool PS3USB::PS3MoveConnected

Variable used to indicate if the move controller is successfully connected.

Definition at line 262 of file PS3USB.h.

◆ PS3NavigationConnected

bool PS3USB::PS3NavigationConnected

Variable used to indicate if the navigation controller is successfully connected.

Definition at line 264 of file PS3USB.h.

◆ pUsb

USB* PS3USB::pUsb
protected

Pointer to USB class instance.

Definition at line 268 of file PS3USB.h.

◆ bAddress

uint8_t PS3USB::bAddress
protected

Device address.

Definition at line 270 of file PS3USB.h.

◆ epInfo

EpInfo PS3USB::epInfo[PS3_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 272 of file PS3USB.h.


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