USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 setMoveBdaddr (uint8_t *BDADDR)
 
USBDeviceConfig implementation
virtual uint8_t Init (uint8_t parent, uint8_t port, bool lowspeed)
 
virtual uint8_t Release ()
 
virtual uint8_t Poll ()
 
virtual uint8_t GetAddress ()
 
virtual bool isReady ()
 
PS3 Controller functions
bool getButtonPress (Button b)
 
bool getButtonClick (Button b)
 
uint8_t getAnalogButton (Button a)
 
uint8_t getAnalogHat (AnalogHat a)
 
uint16_t getSensor (Sensor a)
 
double getAngle (Angle a)
 
bool getStatus (Status c)
 
String getStatusString ()
 
void setAllOff ()
 
void setRumbleOff ()
 
void setRumbleOn (Rumble mode)
 
void setRumbleOn (uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower)
 
void setLedRaw (uint8_t value)
 
void setLedOff (LED a)
 
void setLedOn (LED a)
 
void setLedToggle (LED a)
 
void moveSetBulb (uint8_t r, uint8_t g, uint8_t b)
 
void moveSetBulb (Colors color)
 
void moveSetRumble (uint8_t rumble)
 

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 61 of file PS3USB.h.

Constructor & Destructor Documentation

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

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.

Implements USBDeviceConfig.

Definition at line 46 of file PS3USB.cpp.

uint8_t PS3USB::Release ( )
virtual

Release the USB device.

Returns
0 on success.

Implements USBDeviceConfig.

Definition at line 248 of file PS3USB.cpp.

uint8_t PS3USB::Poll ( )
virtual

Poll the USB Input endpoins and run the state machines.

Returns
0 on success.

Implements USBDeviceConfig.

Definition at line 258 of file PS3USB.cpp.

virtual uint8_t PS3USB::GetAddress ( )
inlinevirtual

Get the device address.

Returns
The device address.

Implements USBDeviceConfig.

Definition at line 96 of file PS3USB.h.

virtual bool PS3USB::isReady ( )
inlinevirtual

Used to check if the controller has been initialized.

Returns
True if it's ready.

Definition at line 104 of file PS3USB.h.

void PS3USB::setBdaddr ( uint8_t *  BDADDR)

Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller.

Parameters
BDADDRYour dongles Bluetooth address.

Definition at line 464 of file PS3USB.cpp.

void PS3USB::setMoveBdaddr ( uint8_t *  BDADDR)

Used to set the Bluetooth address inside the Move controller.

Parameters
BDADDRYour dongles Bluetooth address.

Definition at line 516 of file PS3USB.cpp.

bool PS3USB::getButtonPress ( Button  b)

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

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

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

Definition at line 308 of file PS3USB.cpp.

bool PS3USB::getButtonClick ( Button  b)

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

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

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

Definition at line 312 of file PS3USB.cpp.

uint8_t PS3USB::getAnalogButton ( Button  a)

Used to get the analog value from button presses.

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

uint8_t PS3USB::getAnalogHat ( AnalogHat  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 325 of file PS3USB.cpp.

uint16_t PS3USB::getSensor ( Sensor  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 331 of file PS3USB.cpp.

double PS3USB::getAngle ( Angle  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 337 of file PS3USB.cpp.

bool PS3USB::getStatus ( Status  c)

Get the Status from the controller.

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

Definition at line 363 of file PS3USB.cpp.

String PS3USB::getStatusString ( )

Read all the available Status from the controller.

Returns
One large string with all the information.

Definition at line 371 of file PS3USB.cpp.

void PS3USB::setAllOff ( )

Used to set all LEDs and Rumble off.

Definition at line 412 of file PS3USB.cpp.

void PS3USB::setRumbleOff ( )

Turn off Rumble.

Definition at line 419 of file PS3USB.cpp.

void PS3USB::setRumbleOn ( Rumble  mode)

Turn on Rumble.

Parameters
modeEither RumbleHigh or RumbleLow.

Definition at line 428 of file PS3USB.cpp.

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 439 of file PS3USB.cpp.

void PS3USB::setLedRaw ( uint8_t  value)

Set LED value without using the LED enum.

Parameters
valueSee: LED enum.

Definition at line 447 of file PS3USB.cpp.

void PS3USB::setLedOff ( LED  a)

Turn the specific LED off.

Parameters
aThe LED to turn off.

Definition at line 451 of file PS3USB.cpp.

void PS3USB::setLedOn ( LED  a)

Turn the specific LED on.

Parameters
aThe LED to turn on.

Definition at line 455 of file PS3USB.cpp.

void PS3USB::setLedToggle ( LED  a)

Toggle the specific LED.

Parameters
aThe LED to toggle.

Definition at line 459 of file PS3USB.cpp.

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 492 of file PS3USB.cpp.

void PS3USB::moveSetBulb ( Colors  color)

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

Parameters
colorThe desired color.

Definition at line 501 of file PS3USB.cpp.

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 505 of file PS3USB.cpp.

Member Data Documentation

bool PS3USB::PS3Connected

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

Definition at line 230 of file PS3USB.h.

bool PS3USB::PS3MoveConnected

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

Definition at line 232 of file PS3USB.h.

bool PS3USB::PS3NavigationConnected

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

Definition at line 234 of file PS3USB.h.

USB* PS3USB::pUsb
protected

Pointer to USB class instance.

Definition at line 238 of file PS3USB.h.

uint8_t PS3USB::bAddress
protected

Device address.

Definition at line 240 of file PS3USB.h.

EpInfo PS3USB::epInfo[PS3_MAX_ENDPOINTS]
protected

Endpoint info structure.

Definition at line 242 of file PS3USB.h.


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