Merge pull request #13 from TKJElectronics/master

Removed all delays
This commit is contained in:
Oleg Mazurov 2012-04-14 16:48:04 -07:00
commit 729cc5817a
2 changed files with 75 additions and 84 deletions

146
PS3BT.cpp
View file

@ -265,17 +265,7 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
// Set Configuration Value // Set Configuration Value
rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum); rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum);
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++)
@ -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];
@ -1165,58 +1155,58 @@ 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;
case L2CAP_EV_HID_ENABLE_SIXAXIS:
if(millis() - timer > 1000) { // loop 1 second before sending the command
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;
enable_sixaxis();
for (uint8_t i = 15; i < 19; i++)
l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position
l2cap_state = L2CAP_EV_HID_PS3_LED;
timer = millis();
} }
break; break;
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
l2capinbuf[i] = 0;
ButtonState = 0;
OldButtonState = 0;
if (remote_name[0] == 'P')//First letter in PLAYSTATION(R)3 Controller ('P') - 0x50 case L2CAP_EV_HID_PS3_LED:
{ if(millis() - timer > 1000) { // loop 1 second before sending the command
delay(1000);//There has to be a delay before sending the commands if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
enable_sixaxis(); setLedOn(LED1);
#ifdef DEBUG
for (uint8_t i = 15; i < 19; i++) Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"));
l2capinbuf[i] = 0x7F;//Set the analog joystick values to center position #endif
PS3BTConnected = true;
delay(1000);//There has to be a delay before data can be read } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
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] == 'M') { // First letter in Motion Controller ('M')
else if (remote_name[0] == 'N')//First letter in Navigation Controller ('N') - 0x4E moveSetBulb(Red);
{ timerBulbRumble = millis();
delay(1000);//There has to be a delay before sending the commands #ifdef DEBUG
enable_sixaxis(); Notify(PSTR("\r\nMotion Controller Enabled\r\n"));
#endif
for (uint8_t i = 15; i < 19; i++) PS3MoveBTConnected = true;
l2capinbuf[i] = 0x7F;//Set the analog joystick values to center }
l2cap_state = L2CAP_EV_L2CAP_DONE;
delay(1000);//There has to be a delay before data can be read }
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') - 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:

13
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
@ -395,12 +394,14 @@ private:
uint8_t hci_state; //current state of bluetooth hci connection uint8_t hci_state; //current state of bluetooth hci connection
uint16_t hci_counter; // counter used for bluetooth hci reset loops uint16_t hci_counter; // counter used for bluetooth hci reset loops
uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
uint16_t hci_event_flag;// hci flags of received bluetooth events uint16_t hci_event_flag;// hci flags of received bluetooth events
/* variables used by high level L2CAP task */ /* variables used by high level L2CAP task */
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