Code cleanup

This commit is contained in:
Kevin Mark 2013-03-30 04:15:25 -04:00
parent 67a8989cef
commit f3342aa589
4 changed files with 366 additions and 356 deletions

View file

@ -589,22 +589,24 @@ void PS3BT::setRumbleOff() {
} }
void PS3BT::setRumbleOn(Rumble mode) { void PS3BT::setRumbleOn(Rumble mode) {
if ((mode & 0x30) > 0) { if ((mode & 0x30) > 0) {
uint8_t power[2] = { 0xff, 0 }; // Defaults to RumbleLow uint8_t power[2] = { 0xff, 0 }; // Defaults to RumbleLow
if (mode == RumbleHigh) { if (mode == RumbleHigh) {
power[0] = 0; power[0] = 0;
power[1] = 0xff; power[1] = 0xff;
}
setRumbleOn(0xfe, power[0], 0xfe, power[1]);
} }
setRumbleOn(0xfe, power[0], 0xfe, power[1]);
}
} }
void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
HIDBuffer[3] = rightDuration; HIDBuffer[3] = rightDuration;
HIDBuffer[4] = rightPower; HIDBuffer[4] = rightPower;
HIDBuffer[5] = leftDuration; HIDBuffer[5] = leftDuration;
HIDBuffer[6] = leftPower; HIDBuffer[6] = leftPower;
HID_Command(HIDBuffer, HID_BUFFERSIZE); HID_Command(HIDBuffer, HID_BUFFERSIZE);
} }
void PS3BT::setLedOff(LED a) { void PS3BT::setLedOff(LED a) {
HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1)); HIDBuffer[11] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
HID_Command(HIDBuffer, HID_BUFFERSIZE); HID_Command(HIDBuffer, HID_BUFFERSIZE);
@ -663,4 +665,4 @@ void PS3BT::moveSetRumble(uint8_t rumble) {
HIDMoveBuffer[7] = rumble; HIDMoveBuffer[7] = rumble;
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);
} }

294
PS3BT.h
View file

@ -65,152 +65,152 @@
*/ */
class PS3BT : public BluetoothService { class PS3BT : public BluetoothService {
public: public:
/** /**
* Constructor for the PS3BT class. * Constructor for the PS3BT class.
* @param pBtd Pointer to BTD class instance. * @param pBtd Pointer to BTD class instance.
* @param btadr5,btadr4,btadr3,btadr2,btadr1,btadr0 * @param btadr5,btadr4,btadr3,btadr2,btadr1,btadr0
* Pass your dongles Bluetooth address into the constructor, * Pass 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. * This will set BTD#my_bdaddr, so you don't have to plug in the dongle before pairing with your controller.
*/ */
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); 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);
/** @name BluetoothService implementation */ /** @name BluetoothService implementation */
/** /**
* Used to pass acldata to the services. * Used to pass acldata to the services.
* @param ACLData Incoming acldata. * @param ACLData Incoming acldata.
*/ */
virtual void ACLData(uint8_t* ACLData); virtual void ACLData(uint8_t* ACLData);
/** Used to run part of the state maschine. */ /** Used to run part of the state maschine. */
virtual void Run(); virtual void Run();
/** Use this to reset the service. */ /** Use this to reset the service. */
virtual void Reset(); virtual void Reset();
/** Used this to disconnect any of the controllers. */ /** Used this to disconnect any of the controllers. */
virtual void disconnect(); virtual void disconnect();
/**@}*/ /**@}*/
/** @name PS3 Controller functions */ /** @name PS3 Controller functions */
/** /**
* getButtonPress(Button b) will return true as long as the button is held down. * getButtonPress(Button b) will return true as long as the button is held down.
* *
* While getButtonClick(Button b) will only return it once. * 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), * 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). * but if you need to drive a robot forward you would use getButtonPress(Button b).
*/ */
bool getButtonPress(Button b); bool getButtonPress(Button b);
bool getButtonClick(Button b); bool getButtonClick(Button b);
/**@}*/ /**@}*/
/** @name PS3 Controller functions */ /** @name PS3 Controller functions */
/** /**
* Used to get the analog value from button presses. * Used to get the analog value from button presses.
* @param a The ::Button to read. * @param a The ::Button to read.
* The supported buttons are: * The supported buttons are:
* ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2, * ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2,
* ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T. * ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T.
* @return Analog value in the range of 0-255. * @return Analog value in the range of 0-255.
*/ */
uint8_t getAnalogButton(Button a); uint8_t getAnalogButton(Button a);
/** /**
* Used to read the analog joystick. * Used to read the analog joystick.
* @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY. * @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY.
* @return Return the analog value in the range of 0-255. * @return Return the analog value in the range of 0-255.
*/ */
uint8_t getAnalogHat(AnalogHat a); uint8_t getAnalogHat(AnalogHat a);
/** /**
* Used to read the sensors inside the Dualshock 3 and Move controller. * Used to read the sensors inside the Dualshock 3 and Move controller.
* @param a * @param a
* The Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside. * The 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 * The Move controller has a 3-axis accelerometer, a 3-axis gyro, a 3-axis magnetometer
* and a temperature sensor inside. * and a temperature sensor inside.
* @return Return the raw sensor value. * @return Return the raw sensor value.
*/ */
int16_t getSensor(Sensor a); int16_t getSensor(Sensor a);
/** /**
* Use this to get ::Pitch and ::Roll calculated using the accelerometer. * Use this to get ::Pitch and ::Roll calculated using the accelerometer.
* @param a Either ::Pitch or ::Roll. * @param a Either ::Pitch or ::Roll.
* @return Return the angle in the range of 0-360. * @return Return the angle in the range of 0-360.
*/ */
double getAngle(Angle a); double getAngle(Angle a);
/** /**
* Read the sensors inside the Move controller. * Read the sensors inside the Move controller.
* @param a ::aXmove, ::aYmove, ::aZmove, ::gXmove, ::gYmove, ::gZmove, ::mXmove, ::mYmove, and ::mXmove. * @param a ::aXmove, ::aYmove, ::aZmove, ::gXmove, ::gYmove, ::gZmove, ::mXmove, ::mYmove, and ::mXmove.
* @return The value in SI units. * @return The value in SI units.
*/ */
double get9DOFValues(Sensor a); double get9DOFValues(Sensor a);
/** /**
* Get the ::Status from the controller. * Get the ::Status from the controller.
* @param c The ::Status you want to read. * @param c The ::Status you want to read.
* @return True if correct and false if not. * @return True if correct and false if not.
*/ */
bool getStatus(Status c); bool getStatus(Status c);
/** /**
* Read all the available ::Status from the controller. * Read all the available ::Status from the controller.
* @return One large string with all the information. * @return One large string with all the information.
*/ */
String getStatusString(); String getStatusString();
/** /**
* Read the temperature from the Move controller. * Read the temperature from the Move controller.
* @return The temperature in degrees celsius. * @return The temperature in degrees celsius.
*/ */
String getTemperature(); String getTemperature();
/** Used to set all LEDs and ::Rumble off. */ /** Used to set all LEDs and ::Rumble off. */
void setAllOff(); void setAllOff();
/** Turn off ::Rumble. */ /** Turn off ::Rumble. */
void setRumbleOff(); void setRumbleOff();
/** /**
* Turn on ::Rumble. * Turn on ::Rumble.
* @param mode Either ::RumbleHigh or ::RumbleLow. * @param mode Either ::RumbleHigh or ::RumbleLow.
*/ */
void setRumbleOn(Rumble mode); void setRumbleOn(Rumble mode);
/** /**
* Turn on ::Rumble using custom duration and power. * Turn on ::Rumble using custom duration and power.
* @param rightDuration The duration of the right/low rumble effect. * @param rightDuration The duration of the right/low rumble effect.
* @param rightPower The intensity of the right/low rumble effect. * @param rightPower The intensity of the right/low rumble effect.
* @param leftDuration The duration of the left/high rumble effect. * @param leftDuration The duration of the left/high rumble effect.
* @param leftPower The intensity of the left/high rumble effect. * @param leftPower The intensity of the left/high rumble effect.
*/ */
void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower); void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
/** /**
* Turn the specific ::LED off. * Turn the specific ::LED off.
* @param a The ::LED to turn off. * @param a The ::LED to turn off.
*/ */
void setLedOff(LED a); void setLedOff(LED a);
/** /**
* Turn the specific ::LED on. * Turn the specific ::LED on.
* @param a The ::LED to turn on. * @param a The ::LED to turn on.
*/ */
void setLedOn(LED a); void setLedOn(LED a);
/** /**
* Toggle the specific ::LED. * Toggle the specific ::LED.
* @param a The ::LED to toggle. * @param a The ::LED to toggle.
*/ */
void setLedToggle(LED a); void setLedToggle(LED a);
/** /**
* Use this to set the Color using RGB values. * Use this to set the Color using RGB values.
* @param r,g,b RGB value. * @param r,g,b RGB value.
*/ */
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b); void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
/** /**
* Use this to set the color using the predefined colors in ::Colors. * Use this to set the color using the predefined colors in ::Colors.
* @param color The desired color. * @param color The desired color.
*/ */
void moveSetBulb(Colors color); void moveSetBulb(Colors color);
/** /**
* Set the rumble value inside the Move controller. * Set the rumble value inside the Move controller.
* @param rumble The desired value in the range from 64-255. * @param rumble The desired value in the range from 64-255.
*/ */
void moveSetRumble(uint8_t rumble); void moveSetRumble(uint8_t rumble);
/**@}*/ /**@}*/
/** Variable used to indicate if the normal playstation controller is successfully connected. */ /** Variable used to indicate if the normal playstation controller is successfully connected. */
bool PS3Connected; bool PS3Connected;
/** Variable used to indicate if the move controller is successfully connected. */ /** Variable used to indicate if the move controller is successfully connected. */
bool PS3MoveConnected; bool PS3MoveConnected;
/** Variable used to indicate if the navigation controller is successfully connected. */ /** Variable used to indicate if the navigation controller is successfully connected. */
bool PS3NavigationConnected; bool PS3NavigationConnected;
private: private:
/* mandatory members */ /* mandatory members */
BTD *pBtd; BTD *pBtd;
@ -251,4 +251,4 @@ private:
void HIDMove_Command(uint8_t* data, uint8_t nbytes); void HIDMove_Command(uint8_t* data, uint8_t nbytes);
void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via Bluetooth
}; };
#endif #endif

View file

@ -445,22 +445,24 @@ void PS3USB::setRumbleOff() {
} }
void PS3USB::setRumbleOn(Rumble mode) { void PS3USB::setRumbleOn(Rumble mode) {
if ((mode & 0x30) > 0) { if ((mode & 0x30) > 0x00) {
uint8_t power[2] = { 0xff, 0 }; // Defaults to RumbleLow uint8_t power[2] = { 0xff, 0x00 }; // Defaults to RumbleLow
if (mode == RumbleHigh) { if (mode == RumbleHigh) {
power[0] = 0; power[0] = 0x00;
power[1] = 0xff; power[1] = 0xff;
}
setRumbleOn(0xfe, power[0], 0xfe, power[1]);
} }
setRumbleOn(0xfe, power[0], 0xfe, power[1]);
}
} }
void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) {
writeBuf[1] = rightDuration; writeBuf[1] = rightDuration;
writeBuf[2] = rightPower; writeBuf[2] = rightPower;
writeBuf[3] = leftDuration; writeBuf[3] = leftDuration;
writeBuf[4] = leftPower; writeBuf[4] = leftPower;
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
} }
void PS3USB::setLedOff(LED a) { void PS3USB::setLedOff(LED a) {
writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1)); writeBuf[9] &= ~((uint8_t)((pgm_read_byte(&LEDS[(uint8_t)a]) & 0x0f) << 1));
PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE);
@ -560,4 +562,4 @@ void PS3USB::setMoveBdaddr(uint8_t* BDADDR) {
PrintHex<uint8_t > (my_bdaddr[0], 0x80); PrintHex<uint8_t > (my_bdaddr[0], 0x80);
#endif #endif
return; return;
} }

372
PS3USB.h
View file

@ -63,194 +63,200 @@
*/ */
class PS3USB : public USBDeviceConfig { class PS3USB : public USBDeviceConfig {
public: public:
/** /**
* Constructor for the PS3USB class. * Constructor for the PS3USB class.
* @param pUsb Pointer to USB class instance. * @param pUsb Pointer to USB class instance.
* @param btadr5,btadr4,btadr3,btadr2,btadr1,btadr0 * @param btadr5,btadr4,btadr3,btadr2,btadr1,btadr0
* Pass your dongles Bluetooth address into the constructor, * Pass your dongles Bluetooth address into the constructor,
* so you are able to pair the controller with a Bluetooth dongle. * so you are able to pair the controller with a Bluetooth dongle.
*/ */
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); 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);
/** @name USBDeviceConfig implementation */
/**
* Initialize the PS3 Controller.
* @param parent Hub number.
* @param port Port number on the hub.
* @param lowspeed Speed of the device.
* @return 0 on success.
*/
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
/**
* Release the USB device.
* @return 0 on success.
*/
virtual uint8_t Release();
/**
* Poll the USB Input endpoins and run the state machines.
* @return 0 on success.
*/
virtual uint8_t Poll();
/**
* Get the device address.
* @return The device address.
*/
virtual uint8_t GetAddress() { return bAddress; };
/**
* Used to check if the controller has been initialized.
* @return True if it's ready.
*/
virtual bool isReady() { return bPollEnable; };
/**@}*/
/** /** @name USBDeviceConfig implementation */
* Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller. /**
* @param BDADDR Your dongles Bluetooth address. * Initialize the PS3 Controller.
*/ * @param parent Hub number.
void setBdaddr(uint8_t* BDADDR); * @param port Port number on the hub.
/** * @param lowspeed Speed of the device.
* Used to set the Bluetooth address inside the Move controller. * @return 0 on success.
* @param BDADDR Your dongles Bluetooth address. */
*/ virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
void setMoveBdaddr(uint8_t* BDADDR); /**
* Release the USB device.
* @return 0 on success.
*/
virtual uint8_t Release();
/**
* Poll the USB Input endpoins and run the state machines.
* @return 0 on success.
*/
virtual uint8_t Poll();
/** @name PS3 Controller functions */ /**
/** * Get the device address.
* getButtonPress(Button b) will return true as long as the button is held down. * @return The device address.
* */
* While getButtonClick(Button b) will only return it once. virtual uint8_t GetAddress() {
* return bAddress;
* 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).
*/
bool getButtonPress(Button b);
bool getButtonClick(Button b);
/**@}*/
/** @name PS3 Controller functions */
/**
* Used to get the analog value from button presses.
* @param a The ::Button to read.
* The supported buttons are:
* ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2,
* ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T.
* @return Analog value in the range of 0-255.
*/
uint8_t getAnalogButton(Button a);
/**
* Used to read the analog joystick.
* @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY.
* @return Return the analog value in the range of 0-255.
*/
uint8_t getAnalogHat(AnalogHat a);
/**
* Used to read the sensors inside the Dualshock 3 controller.
* @param a
* The Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside.
* @return Return the raw sensor value.
*/
uint16_t getSensor(Sensor a);
/**
* Use this to get ::Pitch and ::Roll calculated using the accelerometer.
* @param a Either ::Pitch or ::Roll.
* @return Return the angle in the range of 0-360.
*/
double getAngle(Angle a);
/**
* Get the ::Status from the controller.
* @param c The ::Status you want to read.
* @return True if correct and false if not.
*/
bool getStatus(Status c);
/**
* Read all the available ::Status from the controller.
* @return One large string with all the information.
*/
String getStatusString();
/** Used to set all LEDs and ::Rumble off. */ /**
void setAllOff(); * Used to check if the controller has been initialized.
/** Turn off ::Rumble. */ * @return True if it's ready.
void setRumbleOff(); */
/** virtual bool isReady() {
* Turn on ::Rumble. return bPollEnable;
* @param mode Either ::RumbleHigh or ::RumbleLow. };
*/ /**@}*/
void setRumbleOn(Rumble mode);
/**
* Turn on ::Rumble using custom duration and power.
* @param rightDuration The duration of the right/low rumble effect.
* @param rightPower The intensity of the right/low rumble effect.
* @param leftDuration The duration of the left/high rumble effect.
* @param leftPower The intensity of the left/high rumble effect.
*/
void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
/**
* Turn the specific ::LED off.
* @param a The ::LED to turn off.
*/
void setLedOff(LED a);
/**
* Turn the specific ::LED on.
* @param a The ::LED to turn on.
*/
void setLedOn(LED a);
/**
* Toggle the specific ::LED.
* @param a The ::LED to toggle.
*/
void setLedToggle(LED a);
/**
* Use this to set the Color using RGB values.
* @param r,g,b RGB value.
*/
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
/**
* Use this to set the color using the predefined colors in ::Colors.
* @param color The desired color.
*/
void moveSetBulb(Colors color);
/**
* Set the rumble value inside the Move controller.
* @param rumble The desired value in the range from 64-255.
*/
void moveSetRumble(uint8_t rumble);
/**@}*/
/** Variable used to indicate if the normal playstation controller is successfully connected. */ /**
bool PS3Connected; * Used to set the Bluetooth address inside the Dualshock 3 and Navigation controller.
/** Variable used to indicate if the move controller is successfully connected. */ * @param BDADDR Your dongles Bluetooth address.
bool PS3MoveConnected; */
/** Variable used to indicate if the navigation controller is successfully connected. */ void setBdaddr(uint8_t* BDADDR);
bool PS3NavigationConnected; /**
* Used to set the Bluetooth address inside the Move controller.
protected: * @param BDADDR Your dongles Bluetooth address.
/** Pointer to USB class instance. */ */
USB *pUsb; void setMoveBdaddr(uint8_t* BDADDR);
/** Device address. */
uint8_t bAddress;
/** Endpoint info structure. */
EpInfo epInfo[PS3_MAX_ENDPOINTS];
private:
bool bPollEnable;
uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values
uint32_t ButtonState; /** @name PS3 Controller functions */
uint32_t OldButtonState; /**
uint32_t ButtonClickState; * getButtonPress(Button b) will return true as long as the button is held down.
*
uint8_t my_bdaddr[6]; // Change to your dongles Bluetooth address in the constructor * While getButtonClick(Button b) will only return it once.
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data *
uint8_t writeBuf[EP_MAXPKTSIZE]; // General purpose buffer for output data * 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).
void readReport(); // read incoming data */
void printReport(); // print incoming date - Uncomment for debugging bool getButtonPress(Button b);
bool getButtonClick(Button b);
/**@}*/
/** @name PS3 Controller functions */
/**
* Used to get the analog value from button presses.
* @param a The ::Button to read.
* The supported buttons are:
* ::UP, ::RIGHT, ::DOWN, ::LEFT, ::L1, ::L2, ::R1, ::R2,
* ::TRIANGLE, ::CIRCLE, ::CROSS, ::SQUARE, and ::T.
* @return Analog value in the range of 0-255.
*/
uint8_t getAnalogButton(Button a);
/**
* Used to read the analog joystick.
* @param a ::LeftHatX, ::LeftHatY, ::RightHatX, and ::RightHatY.
* @return Return the analog value in the range of 0-255.
*/
uint8_t getAnalogHat(AnalogHat a);
/**
* Used to read the sensors inside the Dualshock 3 controller.
* @param a
* The Dualshock 3 has a 3-axis accelerometer and a 1-axis gyro inside.
* @return Return the raw sensor value.
*/
uint16_t getSensor(Sensor a);
/**
* Use this to get ::Pitch and ::Roll calculated using the accelerometer.
* @param a Either ::Pitch or ::Roll.
* @return Return the angle in the range of 0-360.
*/
double getAngle(Angle a);
/**
* Get the ::Status from the controller.
* @param c The ::Status you want to read.
* @return True if correct and false if not.
*/
bool getStatus(Status c);
/**
* Read all the available ::Status from the controller.
* @return One large string with all the information.
*/
String getStatusString();
/* Private commands */ /** Used to set all LEDs and ::Rumble off. */
void PS3_Command(uint8_t* data, uint16_t nbytes); void setAllOff();
void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via USB /** Turn off ::Rumble. */
void Move_Command(uint8_t* data, uint16_t nbytes); void setRumbleOff();
/**
* Turn on ::Rumble.
* @param mode Either ::RumbleHigh or ::RumbleLow.
*/
void setRumbleOn(Rumble mode);
/**
* Turn on ::Rumble using custom duration and power.
* @param rightDuration The duration of the right/low rumble effect.
* @param rightPower The intensity of the right/low rumble effect.
* @param leftDuration The duration of the left/high rumble effect.
* @param leftPower The intensity of the left/high rumble effect.
*/
void setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower);
/**
* Turn the specific ::LED off.
* @param a The ::LED to turn off.
*/
void setLedOff(LED a);
/**
* Turn the specific ::LED on.
* @param a The ::LED to turn on.
*/
void setLedOn(LED a);
/**
* Toggle the specific ::LED.
* @param a The ::LED to toggle.
*/
void setLedToggle(LED a);
/**
* Use this to set the Color using RGB values.
* @param r,g,b RGB value.
*/
void moveSetBulb(uint8_t r, uint8_t g, uint8_t b);
/**
* Use this to set the color using the predefined colors in ::Colors.
* @param color The desired color.
*/
void moveSetBulb(Colors color);
/**
* Set the rumble value inside the Move controller.
* @param rumble The desired value in the range from 64-255.
*/
void moveSetRumble(uint8_t rumble);
/**@}*/
/** Variable used to indicate if the normal playstation controller is successfully connected. */
bool PS3Connected;
/** Variable used to indicate if the move controller is successfully connected. */
bool PS3MoveConnected;
/** Variable used to indicate if the navigation controller is successfully connected. */
bool PS3NavigationConnected;
protected:
/** Pointer to USB class instance. */
USB *pUsb;
/** Device address. */
uint8_t bAddress;
/** Endpoint info structure. */
EpInfo epInfo[PS3_MAX_ENDPOINTS];
private:
bool bPollEnable;
uint32_t timer; // used to continuously set PS3 Move controller Bulb and rumble values
uint32_t ButtonState;
uint32_t OldButtonState;
uint32_t ButtonClickState;
uint8_t my_bdaddr[6]; // Change to your dongles Bluetooth address in the constructor
uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
uint8_t writeBuf[EP_MAXPKTSIZE]; // General purpose buffer for output data
void readReport(); // read incoming data
void printReport(); // print incoming date - Uncomment for debugging
/* Private commands */
void PS3_Command(uint8_t* data, uint16_t nbytes);
void enable_sixaxis(); // Command used to enable the Dualshock 3 and Navigation controller to send data via USB
void Move_Command(uint8_t* data, uint16_t nbytes);
}; };
#endif #endif