Removed all delays

This commit is contained in:
Kristian Lauszus 2012-04-15 01:42:16 +02:00
parent da6eb99a2f
commit fd58db2680
2 changed files with 75 additions and 84 deletions

130
PS3BT.cpp
View file

@ -267,16 +267,6 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
if(rcode) if(rcode)
goto FailSetConf; goto FailSetConf;
if(VID == CSR_VID && PID == CSR_PID) {
if((uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->bcdDevice < 0x1915) { // I don't know the exact number, plese let me know if you do
#ifdef DEBUG
Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour Revision ID is: 0x"));
PrintHex<uint16_t>((uint16_t)((USB_DEVICE_DESCRIPTOR*)buf)->bcdDevice);
Notify(PSTR("\r\nBut should be at least 0x1915\r\nThis usually means that it doesn't support Bluetooth Version 2.0+EDR"));
#endif
}
}
//Needed for PS3 Dualshock Controller commands to work via bluetooth //Needed for PS3 Dualshock Controller commands to work via bluetooth
for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++) 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 HIDBuffer[i + 2] = pgm_read_byte(&OUTPUT_REPORT_BUFFER[i]);//First two bytes reserved for report type and ID
@ -948,12 +938,12 @@ void PS3BT::ACL_event_task()
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001)//l2cap_control - Channel ID for ACL-U if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001)//l2cap_control - Channel ID for ACL-U
{ {
/* /*
if (l2capinbuf[8] != 0x00) if (l2capinbuf[8] != 0x00)
{ {
Serial.print("\r\nL2CAP Signaling Command - 0x"); Serial.print("\r\nL2CAP Signaling Command - 0x");
PrintHex<uint8_t>(l2capoutbuf[8]); PrintHex<uint8_t>(l2capoutbuf[8]);
} }
*/ */
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -974,20 +964,20 @@ void PS3BT::ACL_event_task()
else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST)
{ {
/* /*
Notify(PSTR("\r\nL2CAP Connection Request - PSM: ")); Notify(PSTR("\r\nL2CAP Connection Request - PSM: "));
PrintHex<uint8_t>(l2capinbuf[13]); PrintHex<uint8_t>(l2capinbuf[13]);
Serial.print(" "); Serial.print(" ");
PrintHex<uint8_t>(l2capinbuf[12]); PrintHex<uint8_t>(l2capinbuf[12]);
Serial.print(" "); Serial.print(" ");
Notify(PSTR(" SCID: ")); Notify(PSTR(" SCID: "));
PrintHex<uint8_t>(l2capinbuf[15]); PrintHex<uint8_t>(l2capinbuf[15]);
Serial.print(" "); Serial.print(" ");
PrintHex<uint8_t>(l2capinbuf[14]); PrintHex<uint8_t>(l2capinbuf[14]);
Notify(PSTR(" Identifier: ")); Notify(PSTR(" Identifier: "));
PrintHex<uint8_t>(l2capinbuf[9]); PrintHex<uint8_t>(l2capinbuf[9]);
*/ */
if ((l2capinbuf[13] | l2capinbuf[12]) == L2CAP_PSM_HID_CTRL) if ((l2capinbuf[13] | l2capinbuf[12]) == L2CAP_PSM_HID_CTRL)
{ {
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
@ -1166,57 +1156,57 @@ void PS3BT::L2CAP_task()
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nHID Interrupt Successfully Configured")); Notify(PSTR("\r\nHID Interrupt Successfully Configured"));
#endif #endif
l2cap_state = L2CAP_EV_HID_ENABLE_SIXAXIS; if(remote_name[0] == 'M') { // First letter in Motion Controller ('M')
for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++) // Reset l2cap in buffer as it sometimes read it as a button has been pressed
l2capinbuf[i] = 0;
ButtonState = 0;
OldButtonState = 0;
l2cap_state = L2CAP_EV_HID_PS3_LED;
} else
l2cap_state = L2CAP_EV_HID_ENABLE_SIXAXIS;
timer = millis();
} }
break; break;
case L2CAP_EV_HID_ENABLE_SIXAXIS: case L2CAP_EV_HID_ENABLE_SIXAXIS:
for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++)//Reset l2cap in buffer as it sometimes read it as a button has been pressed if(millis() - timer > 1000) { // loop 1 second before sending the command
l2capinbuf[i] = 0; for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++) // Reset l2cap in buffer as it sometimes read it as a button has been pressed
ButtonState = 0; l2capinbuf[i] = 0;
OldButtonState = 0; ButtonState = 0;
OldButtonState = 0;
if (remote_name[0] == 'P')//First letter in PLAYSTATION(R)3 Controller ('P') - 0x50
{
delay(1000);//There has to be a delay before sending the commands
enable_sixaxis(); enable_sixaxis();
for (uint8_t i = 15; i < 19; i++) for (uint8_t i = 15; i < 19; i++)
l2capinbuf[i] = 0x7F;//Set the analog joystick values to center position l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
l2cap_state = L2CAP_EV_HID_PS3_LED;
delay(1000);//There has to be a delay before data can be read timer = millis();
setLedOn(LED1);
#ifdef DEBUG
Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"));
#endif
PS3BTConnected = true;
} }
else if (remote_name[0] == 'N')//First letter in Navigation Controller ('N') - 0x4E break;
{
delay(1000);//There has to be a delay before sending the commands
enable_sixaxis();
for (uint8_t i = 15; i < 19; i++) case L2CAP_EV_HID_PS3_LED:
l2capinbuf[i] = 0x7F;//Set the analog joystick values to center if(millis() - timer > 1000) { // loop 1 second before sending the command
if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
delay(1000);//There has to be a delay before data can be read setLedOn(LED1);
setLedOn(LED1);//This just turns LED constantly on, on the Navigation controller #ifdef DEBUG
#ifdef DEBUG Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"));
Notify(PSTR("\r\nNavigation Controller Enabled\r\n")); #endif
#endif PS3BTConnected = true;
PS3NavigationBTConnected = true; } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller
#ifdef DEBUG
Notify(PSTR("\r\nNavigation Controller Enabled\r\n"));
#endif
PS3NavigationBTConnected = true;
} else if(remote_name[0] == 'M') { // First letter in Motion Controller ('M')
moveSetBulb(Red);
timerBulbRumble = millis();
#ifdef DEBUG
Notify(PSTR("\r\nMotion Controller Enabled\r\n"));
#endif
PS3MoveBTConnected = true;
}
l2cap_state = L2CAP_EV_L2CAP_DONE;
} }
else if (remote_name[0] == 'M')//First letter in Motion Controller ('M') - 0x4D
{
delay(1000);//There has to be a delay before data can be read
moveSetBulb(Red);
#ifdef DEBUG
Notify(PSTR("\r\nMotion Controller Enabled\r\n"));
#endif
PS3MoveBTConnected = true;
timerBulbRumble = millis();
}
l2cap_state = L2CAP_EV_L2CAP_DONE;
break; break;
case L2CAP_EV_L2CAP_DONE: case L2CAP_EV_L2CAP_DONE:

11
PS3BT.h
View file

@ -43,8 +43,6 @@
#define PS3_INPUT_PIPE 2 #define PS3_INPUT_PIPE 2
//PID and VID of the different devices //PID and VID of the different devices
#define CSR_VID 0x0A12 // Cambridge Silicon Radio Ltd.
#define CSR_PID 0x0001 // Bluetooth HCI Device
#define PS3_VID 0x054C // Sony Corporation #define PS3_VID 0x054C // Sony Corporation
#define PS3_PID 0x0268 // PS3 Controller DualShock 3 #define PS3_PID 0x0268 // PS3 Controller DualShock 3
#define PS3NAVIGATION_PID 0x042F // Navigation controller #define PS3NAVIGATION_PID 0x042F // Navigation controller
@ -112,9 +110,10 @@
#define L2CAP_EV_INTERRUPT_REQUEST 5 #define L2CAP_EV_INTERRUPT_REQUEST 5
#define L2CAP_EV_INTERRUPT_SUCCESS 6 #define L2CAP_EV_INTERRUPT_SUCCESS 6
#define L2CAP_EV_HID_ENABLE_SIXAXIS 7 #define L2CAP_EV_HID_ENABLE_SIXAXIS 7
#define L2CAP_EV_L2CAP_DONE 8 #define L2CAP_EV_HID_PS3_LED 8
#define L2CAP_EV_INTERRUPT_DISCONNECT 9 #define L2CAP_EV_L2CAP_DONE 9
#define L2CAP_EV_CONTROL_DISCONNECT 10 #define L2CAP_EV_INTERRUPT_DISCONNECT 10
#define L2CAP_EV_CONTROL_DISCONNECT 11
/* L2CAP event flags */ /* L2CAP event flags */
#define L2CAP_EV_CONTROL_CONNECTION_REQUEST 0x01 #define L2CAP_EV_CONTROL_CONNECTION_REQUEST 0x01
@ -401,6 +400,8 @@ private:
uint8_t l2cap_state; uint8_t l2cap_state;
uint16_t l2cap_event_flag;// l2cap flags of received bluetooth events uint16_t l2cap_event_flag;// l2cap flags of received bluetooth events
unsigned long timer;
uint32_t ButtonState; uint32_t ButtonState;
uint32_t OldButtonState; uint32_t OldButtonState;
uint32_t timerHID;// timer used see if there has to be a delay before a new HID command uint32_t timerHID;// timer used see if there has to be a delay before a new HID command