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

#include <PS3BT.h>

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

Public Member Functions

 PS3BT (BTD *pBtd, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0)
 
PS3 Controller functions
bool getButtonPress (ButtonEnum b)
 
bool getButtonClick (ButtonEnum b)
 
uint8_t getAnalogButton (ButtonEnum a)
 
uint8_t getAnalogHat (AnalogHatEnum a)
 
int16_t getSensor (SensorEnum a)
 
float getAngle (AngleEnum a)
 
float get9DOFValues (SensorEnum a)
 
bool getStatus (StatusEnum c)
 
void printStatusString ()
 
String getTemperature ()
 
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)
 
uint32_t getLastMessageTime ()
 
- Public Member Functions inherited from BluetoothService
 BluetoothService (BTD *p)
 
void attachOnInit (void(*funcOnInit)(void))
 

Public Attributes

bool PS3Connected
 
bool PS3MoveConnected
 
bool PS3NavigationConnected
 

BluetoothService implementation

void disconnect ()
 
void ACLData (uint8_t *ACLData)
 
void Run ()
 
void Reset ()
 
void onInit ()
 

Additional Inherited Members

- Protected Member Functions inherited from BluetoothService
bool checkHciHandle (uint8_t *buf, uint16_t handle)
 
- Protected Attributes inherited from BluetoothService
void(* pFuncOnInit )(void)
 
BTDpBtd
 
uint16_t hci_handle
 
uint32_t l2cap_event_flag
 
uint8_t identifier
 

Detailed Description

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

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 32 of file PS3BT.h.

Constructor & Destructor Documentation

◆ PS3BT()

PS3BT::PS3BT ( BTD pBtd,
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 PS3BT class.

Parameters
pBtdPointer to BTD class instance.
btadr5,btadr4,btadr3,btadr2,btadr1,btadr0Pass your dongles Bluetooth address into the constructor, This will set BTD::my_bdaddr, so you don't have to plug in the dongle before pairing with your controller.

Definition at line 23 of file PS3BT.cpp.

Member Function Documentation

◆ disconnect()

void PS3BT::disconnect ( )
virtual

Used this to disconnect any of the controllers.

Implements BluetoothService.

Definition at line 220 of file PS3BT.cpp.

◆ getButtonPress()

bool PS3BT::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 49 of file PS3BT.cpp.

◆ getButtonClick()

bool PS3BT::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 54 of file PS3BT.cpp.

◆ getAnalogButton()

uint8_t PS3BT::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 62 of file PS3BT.cpp.

◆ getAnalogHat()

uint8_t PS3BT::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 67 of file PS3BT.cpp.

◆ getSensor()

int16_t PS3BT::getSensor ( SensorEnum  a)

Used to read the sensors inside the Dualshock 3 and Move controller.

Parameters
aThe Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside. The Move controller has a 3-axis accelerometer, a 3-axis gyro, a 3-axis magnetometer and a temperature sensor inside.
Returns
Return the raw sensor value.

Definition at line 71 of file PS3BT.cpp.

◆ getAngle()

float PS3BT::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 88 of file PS3BT.cpp.

◆ get9DOFValues()

float PS3BT::get9DOFValues ( SensorEnum  a)

Read the sensors inside the Move controller.

Parameters
aaXmove, aYmove, aZmove, gXmove, gYmove, gZmove, mXmove, mYmove, and mXmove.
Returns
The value in SI units.

Definition at line 115 of file PS3BT.cpp.

◆ getStatus()

bool PS3BT::getStatus ( StatusEnum  c)

Get the status from the controller.

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

Definition at line 159 of file PS3BT.cpp.

◆ printStatusString()

void PS3BT::printStatusString ( )

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

Definition at line 163 of file PS3BT.cpp.

◆ getTemperature()

String PS3BT::getTemperature ( )

Read the temperature from the Move controller.

Returns
The temperature in degrees Celsius.

Definition at line 144 of file PS3BT.cpp.

◆ setAllOff()

void PS3BT::setAllOff ( )

Used to set all LEDs and rumble off.

Definition at line 522 of file PS3BT.cpp.

◆ setRumbleOff()

void PS3BT::setRumbleOff ( )

Turn off rumble.

Definition at line 533 of file PS3BT.cpp.

◆ setRumbleOn() [1/2]

void PS3BT::setRumbleOn ( RumbleEnum  mode)

Turn on rumble.

Parameters
modeEither RumbleHigh or RumbleLow.

Definition at line 543 of file PS3BT.cpp.

◆ setRumbleOn() [2/2]

void PS3BT::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 552 of file PS3BT.cpp.

◆ setLedRaw()

void PS3BT::setLedRaw ( uint8_t  value)

Set LED value without using LEDEnum.

Parameters
valueSee: LEDEnum.

Definition at line 562 of file PS3BT.cpp.

◆ setLedOff() [1/2]

void PS3BT::setLedOff ( )
inline

Turn all LEDs off.

Definition at line 138 of file PS3BT.h.

◆ setLedOff() [2/2]

void PS3BT::setLedOff ( LEDEnum  a)

Turn the specific LED off.

Parameters
aThe LEDEnum to turn off.

Definition at line 567 of file PS3BT.cpp.

◆ setLedOn()

void PS3BT::setLedOn ( LEDEnum  a)

Turn the specific LED on.

Parameters
aThe LEDEnum to turn on.

Definition at line 572 of file PS3BT.cpp.

◆ setLedToggle()

void PS3BT::setLedToggle ( LEDEnum  a)

Toggle the specific LED.

Parameters
aThe LEDEnum to toggle.

Definition at line 581 of file PS3BT.cpp.

◆ moveSetBulb() [1/2]

void PS3BT::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 607 of file PS3BT.cpp.

◆ moveSetBulb() [2/2]

void PS3BT::moveSetBulb ( ColorsEnum  color)

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

Parameters
colorThe desired color.

Definition at line 616 of file PS3BT.cpp.

◆ moveSetRumble()

void PS3BT::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 620 of file PS3BT.cpp.

◆ getLastMessageTime()

uint32_t PS3BT::getLastMessageTime ( )
inline

Used to get the millis() of the last message

Definition at line 174 of file PS3BT.h.

◆ ACLData()

void PS3BT::ACLData ( uint8_t *  ACLData)
protectedvirtual

Used to pass acldata to the services.

Parameters
ACLDataIncoming acldata.

Implements BluetoothService.

Definition at line 227 of file PS3BT.cpp.

◆ Run()

void PS3BT::Run ( )
protectedvirtual

Used to run part of the state machine.

Implements BluetoothService.

Definition at line 457 of file PS3BT.cpp.

◆ Reset()

void PS3BT::Reset ( )
protectedvirtual

Use this to reset the service.

Implements BluetoothService.

Definition at line 207 of file PS3BT.cpp.

◆ onInit()

void PS3BT::onInit ( )
protectedvirtual

Called when the controller 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.

Implements BluetoothService.

Definition at line 631 of file PS3BT.cpp.

Member Data Documentation

◆ PS3Connected

bool PS3BT::PS3Connected

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

Definition at line 176 of file PS3BT.h.

◆ PS3MoveConnected

bool PS3BT::PS3MoveConnected

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

Definition at line 182 of file PS3BT.h.

◆ PS3NavigationConnected

bool PS3BT::PS3NavigationConnected

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

Definition at line 184 of file PS3BT.h.


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