Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
PS3USB Class Reference
This class implements support for all the official PS3 Controllers: Dualshock 3, Navigation or a Motion controller via USB. More...
#include <PS3USB.h>
Inherits USBDeviceConfig.
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) | |
| Constructor for the PS3USB class. | |
| void | setBdaddr (uint8_t *bdaddr) |
| Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller. | |
| void | getBdaddr (uint8_t *bdaddr) |
| Used to get the Bluetooth address inside the Dualshock 3 and Navigation controller. | |
| void | setMoveBdaddr (uint8_t *bdaddr) |
| Used to set the Bluetooth address inside the Move controller. | |
| void | getMoveBdaddr (uint8_t *bdaddr) |
| Used to get the Bluetooth address inside the Move controller. | |
| void | getMoveCalibration (uint8_t *data) |
| Used to get the calibration data inside the Move controller. | |
USBDeviceConfig implementation | |
| uint8_t | Init (uint8_t parent, uint8_t port, bool lowspeed) |
| Initialize the PS3 Controller. | |
| uint8_t | Release () |
| Release the USB device. | |
| uint8_t | Poll () |
| Poll the USB Input endpoins and run the state machines. | |
| virtual uint8_t | GetAddress () |
| Get the device address. | |
| virtual bool | isReady () |
| Used to check if the controller has been initialized. | |
| virtual bool | VIDPIDOK (uint16_t vid, uint16_t pid) |
| Used by the USB core to check what this driver support. | |
PS3 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 a) |
| Used to get the analog value from button presses. | |
| uint8_t | getAnalogHat (AnalogHatEnum a) |
| Used to read the analog joystick. | |
| uint16_t | getSensor (SensorEnum a) |
| Used to read the sensors inside the Dualshock 3 controller. | |
| float | getAngle (AngleEnum a) |
| Use this to get Pitch and Roll calculated using the accelerometer. | |
| bool | getStatus (StatusEnum c) |
| Get the StatusEnum from the controller. | |
| void | printStatusString () |
| Read all the available statuses from the controller and prints it as a nice formated string. | |
| void | setAllOff () |
| Used to set all LEDs and rumble off. | |
| void | setRumbleOff () |
| Turn off rumble. | |
| void | setRumbleOn (RumbleEnum mode) |
| Turn on rumble. | |
| void | setRumbleOn (uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) |
| Turn on rumble using custom duration and power. | |
| void | setLedRaw (uint8_t value) |
| Set LED value without using the LEDEnum. | |
| void | setLedOff () |
| Turn all LEDs off. | |
| void | setLedOff (LEDEnum a) |
| Turn the specific LEDEnum off. | |
| void | setLedOn (LEDEnum a) |
| Turn the specific LEDEnum on. | |
| void | setLedToggle (LEDEnum a) |
| Toggle the specific LEDEnum. | |
| void | moveSetBulb (uint8_t r, uint8_t g, uint8_t b) |
| Use this to set the Color using RGB values. | |
| void | moveSetBulb (ColorsEnum color) |
| Use this to set the color using the predefined colors in ColorsEnum. | |
| void | moveSetRumble (uint8_t rumble) |
| Set the rumble value inside the Move controller. | |
| void | attachOnInit (void(*funcOnInit)(void)) |
| Used to call your own function when the controller is successfully initialized. | |
Data Fields | |
| bool | PS3Connected |
| Variable used to indicate if the normal playstation controller is successfully connected. | |
| bool | PS3MoveConnected |
| Variable used to indicate if the move controller is successfully connected. | |
| bool | PS3NavigationConnected |
| Variable used to indicate if the navigation controller is successfully connected. | |
Protected Attributes | |
| Usb * | pUsb |
| Pointer to USB class instance. | |
| uint8_t | bAddress |
| Device address. | |
| EpInfo | epInfo [PS3_MAX_ENDPOINTS] |
| Endpoint info structure. | |
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 | ( | 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:
-
pUsb Pointer to USB class instance. btadr5,btadr4,btadr3,btadr2,btadr1,btadr0 Pass 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
| void attachOnInit | ( | void(*)(void) | funcOnInit ) |
| virtual uint8_t GetAddress | ( | ) | [virtual] |
| uint8_t getAnalogButton | ( | ButtonEnum | a ) |
Used to get the analog value from button presses.
- Parameters:
-
a The 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 327 of file PS3USB.cpp.
| uint8_t getAnalogHat | ( | AnalogHatEnum | a ) |
Used to read the analog joystick.
- Parameters:
-
a LeftHatX, LeftHatY, RightHatX, and RightHatY.
- Returns:
- Return the analog value in the range of 0-255.
Definition at line 331 of file PS3USB.cpp.
| float getAngle | ( | AngleEnum | a ) |
Use this to get Pitch and Roll calculated using the accelerometer.
- Parameters:
-
a Either Pitch or Roll.
- Returns:
- Return the angle in the range of 0-360.
Definition at line 339 of file PS3USB.cpp.
| void getBdaddr | ( | uint8_t * | bdaddr ) |
Used to get the Bluetooth address inside the Dualshock 3 and Navigation controller.
Will return LSB first.
- Parameters:
-
bdaddr Your dongles Bluetooth address.
Definition at line 479 of file PS3USB.cpp.
| bool 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:
-
b ButtonEnum 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.
| void getMoveBdaddr | ( | uint8_t * | bdaddr ) |
Used to get the Bluetooth address inside the Move controller.
Will return LSB first.
- Parameters:
-
bdaddr Your dongles Bluetooth address.
Definition at line 544 of file PS3USB.cpp.
| void getMoveCalibration | ( | uint8_t * | data ) |
Used to get the calibration data inside the Move controller.
- Parameters:
-
data Buffer to store data in. Must be at least 147 bytes
Definition at line 554 of file PS3USB.cpp.
| uint16_t getSensor | ( | SensorEnum | a ) |
Used to read the sensors inside the Dualshock 3 controller.
- Parameters:
-
a The Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside.
- Returns:
- Return the raw sensor value.
Definition at line 335 of file PS3USB.cpp.
| bool getStatus | ( | StatusEnum | c ) |
Get the StatusEnum from the controller.
- Parameters:
-
c The StatusEnum you want to read.
- Returns:
- True if correct and false if not.
Definition at line 360 of file PS3USB.cpp.
| uint8_t Init | ( | uint8_t | parent, |
| uint8_t | port, | ||
| bool | lowspeed | ||
| ) |
Initialize the PS3 Controller.
- Parameters:
-
parent Hub number. port Port number on the hub. lowspeed Speed of the device.
- Returns:
- 0 on success.
Definition at line 47 of file PS3USB.cpp.
| virtual bool isReady | ( | ) | [virtual] |
| void moveSetBulb | ( | uint8_t | r, |
| uint8_t | g, | ||
| uint8_t | b | ||
| ) |
Use this to set the Color using RGB values.
- Parameters:
-
r,g,b RGB value.
Definition at line 505 of file PS3USB.cpp.
| void moveSetBulb | ( | ColorsEnum | color ) |
Use this to set the color using the predefined colors in ColorsEnum.
- Parameters:
-
color The desired color.
Definition at line 514 of file PS3USB.cpp.
| void moveSetRumble | ( | uint8_t | rumble ) |
Set the rumble value inside the Move controller.
- Parameters:
-
rumble The desired value in the range from 64-255.
Definition at line 518 of file PS3USB.cpp.
| uint8_t Poll | ( | ) |
Poll the USB Input endpoins and run the state machines.
- Returns:
- 0 on success.
Definition at line 272 of file PS3USB.cpp.
| void printStatusString | ( | ) |
Read all the available statuses from the controller and prints it as a nice formated string.
Definition at line 364 of file PS3USB.cpp.
| uint8_t Release | ( | ) |
| void setAllOff | ( | ) |
Used to set all LEDs and rumble off.
Definition at line 404 of file PS3USB.cpp.
| void setBdaddr | ( | uint8_t * | bdaddr ) |
Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller.
Set using LSB first.
- Parameters:
-
bdaddr Your dongles Bluetooth address.
Definition at line 466 of file PS3USB.cpp.
| void setLedOff | ( | LEDEnum | a ) |
Turn the specific LEDEnum off.
- Parameters:
-
a The LEDEnum to turn off.
Definition at line 447 of file PS3USB.cpp.
| void setLedOn | ( | LEDEnum | a ) |
Turn the specific LEDEnum on.
- Parameters:
-
a The LEDEnum to turn on.
Definition at line 452 of file PS3USB.cpp.
| void setLedRaw | ( | uint8_t | value ) |
Set LED value without using the LEDEnum.
- Parameters:
-
value See: LEDEnum.
Definition at line 442 of file PS3USB.cpp.
| void setLedToggle | ( | LEDEnum | a ) |
Toggle the specific LEDEnum.
- Parameters:
-
a The LEDEnum to toggle.
Definition at line 461 of file PS3USB.cpp.
| void setMoveBdaddr | ( | uint8_t * | bdaddr ) |
Used to set the Bluetooth address inside the Move controller.
Set using LSB first.
- Parameters:
-
bdaddr Your dongles Bluetooth address.
Definition at line 528 of file PS3USB.cpp.
| void setRumbleOff | ( | ) |
Turn off rumble.
Definition at line 411 of file PS3USB.cpp.
| void setRumbleOn | ( | RumbleEnum | mode ) |
Turn on rumble.
- Parameters:
-
mode Either RumbleHigh or RumbleLow.
Definition at line 421 of file PS3USB.cpp.
| void setRumbleOn | ( | uint8_t | rightDuration, |
| uint8_t | rightPower, | ||
| uint8_t | leftDuration, | ||
| uint8_t | leftPower | ||
| ) |
Turn on rumble using custom duration and power.
- Parameters:
-
rightDuration The duration of the right/low rumble effect. rightPower The intensity of the right/low rumble effect. leftDuration The duration of the left/high rumble effect. leftPower The intensity of the left/high rumble effect.
Definition at line 432 of file PS3USB.cpp.
| virtual bool VIDPIDOK | ( | uint16_t | vid, |
| uint16_t | pid | ||
| ) | [virtual] |
Field Documentation
EpInfo epInfo[PS3_MAX_ENDPOINTS] [protected] |
| bool PS3Connected |
| bool PS3MoveConnected |
Generated on Tue Jul 12 2022 18:12:05 by
1.7.2