From 627c0ebc777c43ea452eb5508a9c5372e2382cda Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 13 Jan 2016 17:50:10 +0100 Subject: [PATCH 1/2] Store rumble value in local buffer, so the rumble is not affected when setting the LEDs Fixes #186 --- PS3BT.cpp | 25 ++++++++++++++----------- PS3USB.cpp | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index ab5a8ed5..cf1670bb 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -528,12 +528,13 @@ void PS3BT::setAllOff() { } void PS3BT::setRumbleOff() { - HIDBuffer[3] = 0x00; - HIDBuffer[4] = 0x00; - HIDBuffer[5] = 0x00; - HIDBuffer[6] = 0x00; - - HID_Command(HIDBuffer, HID_BUFFERSIZE); + uint8_t rumbleBuf[HID_BUFFERSIZE]; + memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE); + rumbleBuf[3] = 0x00; + rumbleBuf[4] = 0x00; + rumbleBuf[5] = 0x00; + rumbleBuf[6] = 0x00; + HID_Command(rumbleBuf, HID_BUFFERSIZE); } void PS3BT::setRumbleOn(RumbleEnum mode) { @@ -546,11 +547,13 @@ void PS3BT::setRumbleOn(RumbleEnum mode) { } void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { - HIDBuffer[3] = rightDuration; - HIDBuffer[4] = rightPower; - HIDBuffer[5] = leftDuration; - HIDBuffer[6] = leftPower; - HID_Command(HIDBuffer, HID_BUFFERSIZE); + uint8_t rumbleBuf[HID_BUFFERSIZE]; + memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE); + rumbleBuf[3] = rightDuration; + rumbleBuf[4] = rightPower; + rumbleBuf[5] = leftDuration; + rumbleBuf[6] = leftPower; + HID_Command(rumbleBuf, HID_BUFFERSIZE); } void PS3BT::setLedRaw(uint8_t value) { diff --git a/PS3USB.cpp b/PS3USB.cpp index f247cc91..c263613a 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -408,12 +408,13 @@ void PS3USB::setAllOff() { } void PS3USB::setRumbleOff() { - writeBuf[1] = 0x00; - writeBuf[2] = 0x00; // Low mode off - writeBuf[3] = 0x00; - writeBuf[4] = 0x00; // High mode off - - PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); + uint8_t rumbleBuf[EP_MAXPKTSIZE]; + memcpy(rumbleBuf, writeBuf, EP_MAXPKTSIZE); + rumbleBuf[1] = 0x00; + rumbleBuf[2] = 0x00; // Low mode off + rumbleBuf[3] = 0x00; + rumbleBuf[4] = 0x00; // High mode off + PS3_Command(rumbleBuf, PS3_REPORT_BUFFER_SIZE); } void PS3USB::setRumbleOn(RumbleEnum mode) { @@ -428,11 +429,13 @@ void PS3USB::setRumbleOn(RumbleEnum mode) { } void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { - writeBuf[1] = rightDuration; - writeBuf[2] = rightPower; - writeBuf[3] = leftDuration; - writeBuf[4] = leftPower; - PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); + uint8_t rumbleBuf[EP_MAXPKTSIZE]; + memcpy(rumbleBuf, writeBuf, EP_MAXPKTSIZE); + rumbleBuf[1] = rightDuration; + rumbleBuf[2] = rightPower; + rumbleBuf[3] = leftDuration; + rumbleBuf[4] = leftPower; + PS3_Command(rumbleBuf, PS3_REPORT_BUFFER_SIZE); } void PS3USB::setLedRaw(uint8_t value) { From b9220a90e6d5df5211079d9f40174af2c8b3cf52 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 20 Jan 2016 01:07:26 +0100 Subject: [PATCH 2/2] Updated PS3BT example, so it demonstrates rumble functionality --- examples/Bluetooth/PS3BT/PS3BT.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index b8967344..610269bb 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -21,8 +21,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so PS3BT PS3(&Btd); // This will just create the instance //PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch -bool printTemperature; -bool printAngle; +bool printTemperature, printAngle; void setup() { Serial.begin(115200); @@ -61,15 +60,20 @@ void loop() { Serial.print(PS3.getAnalogButton(R2)); } } + if (PS3.getButtonClick(PS)) { Serial.print(F("\r\nPS")); PS3.disconnect(); } else { - if (PS3.getButtonClick(TRIANGLE)) + if (PS3.getButtonClick(TRIANGLE)) { Serial.print(F("\r\nTraingle")); - if (PS3.getButtonClick(CIRCLE)) + PS3.setRumbleOn(RumbleLow); + } + if (PS3.getButtonClick(CIRCLE)) { Serial.print(F("\r\nCircle")); + PS3.setRumbleOn(RumbleHigh); + } if (PS3.getButtonClick(CROSS)) Serial.print(F("\r\nCross")); if (PS3.getButtonClick(SQUARE))