From a890d4aca807540563d47ac59155e0ae60f20e64 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 2 Apr 2013 00:12:38 +0200 Subject: [PATCH] Moved PS3 report buffer into PS3Enums --- PS3BT.cpp | 20 ++++---------------- PS3BT.h | 3 +-- PS3Enums.h | 19 +++++++++++++++++++ PS3USB.cpp | 22 +--------------------- PS3USB.h | 3 --- 5 files changed, 25 insertions(+), 42 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index ad263f61..46ada469 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -20,18 +20,6 @@ //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers -const uint8_t OUTPUT_REPORT_BUFFER[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - PS3BT::PS3BT(BTD *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) : pBtd(p) // pointer to USB class instance - mandatory { @@ -243,8 +231,8 @@ void PS3BT::Reset() { l2cap_state = L2CAP_WAIT; // Needed for PS3 Dualshock Controller commands to work via bluetooth - for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++) - HIDBuffer[i + 2] = pgm_read_byte(&OUTPUT_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID + for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) + HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID } void PS3BT::disconnect() { // Use this void to disconnect any of the controllers @@ -573,8 +561,8 @@ void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) { } void PS3BT::setAllOff() { - for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++) - HIDBuffer[i + 2] = pgm_read_byte(&OUTPUT_REPORT_BUFFER[i]); //First two bytes reserved for report type and ID + for (uint8_t i = 0; i < PS3_REPORT_BUFFER_SIZE; i++) + HIDBuffer[i + 2] = pgm_read_byte(&PS3_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID HID_Command(HIDBuffer, HID_BUFFERSIZE); } diff --git a/PS3BT.h b/PS3BT.h index a4200a65..1336828e 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -21,8 +21,7 @@ #include "BTD.h" #include "PS3Enums.h" -#define HID_BUFFERSIZE 50 // size of the buffer for the Playstation Motion Controller -#define OUTPUT_REPORT_BUFFER_SIZE 48 //Size of the output report buffer for the controllers +#define HID_BUFFERSIZE 50 // Size of the buffer for the Playstation Motion Controller /* Bluetooth L2CAP states for L2CAP_task() */ #define L2CAP_WAIT 0 diff --git a/PS3Enums.h b/PS3Enums.h index d42f7903..b6a7b22d 100644 --- a/PS3Enums.h +++ b/PS3Enums.h @@ -20,6 +20,25 @@ #include "controllerEnums.h" +/** Report buffer for all PS3 commands */ +const uint8_t PS3_REPORT_BUFFER[] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0xff, 0x27, 0x10, 0x00, 0x32, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/** Size of the output report buffer for the Dualshock and Navigation controllers */ +#define PS3_REPORT_BUFFER_SIZE 48 + +/** Size of the output report buffer for the Move Controller */ +#define MOVE_REPORT_BUFFER_SIZE 7 + /** Used to set the LEDs on the controllers */ const uint8_t LEDS[] PROGMEM = { 0x01, // LED1 diff --git a/PS3USB.cpp b/PS3USB.cpp index bba4d7e3..fd14a04e 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -20,24 +20,6 @@ //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers -const uint8_t PS3_REPORT_BUFFER[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0xff, 0x27, 0x10, 0x00, 0x32, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; -const uint8_t MOVE_REPORT_BUFFER[] PROGMEM = { - 0x02, 0x00, // Always 0x02, 0x00, - 0x00, 0x00, 0x00, // r, g, b, - 0x00, // Always 0x00, - 0x00 // Rumble -}; - PS3USB::PS3USB(USB *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) : pUsb(p), // pointer to USB class instance - mandatory bAddress(0), // device address - mandatory @@ -220,9 +202,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { setMoveBdaddr(my_bdaddr); // Set internal bluetooth address moveSetBulb(Red); - // Needed for Move commands to work - for (uint8_t i = 0; i < MOVE_REPORT_BUFFER_SIZE; i++) - writeBuf[i] = pgm_read_byte(&MOVE_REPORT_BUFFER[i]); + writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work } bPollEnable = true; diff --git a/PS3USB.h b/PS3USB.h index 697dd00b..d0b45e47 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -44,9 +44,6 @@ #define PS3NAVIGATION_PID 0x042F // Navigation controller #define PS3MOVE_PID 0x03D5 // Motion controller -#define PS3_REPORT_BUFFER_SIZE 48 // Size of the output report buffer for the Dualshock and Navigation controllers -#define MOVE_REPORT_BUFFER_SIZE 7 // Size of the output report buffer for the Move Controller - // used in control endpoint header for HID Commands #define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE #define HID_REQUEST_SET_REPORT 0x09