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

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
@ -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')
}
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 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; l2capinbuf[i] = 0;
ButtonState = 0; ButtonState = 0;
OldButtonState = 0; OldButtonState = 0;
if (remote_name[0] == 'P')//First letter in PLAYSTATION(R)3 Controller ('P') - 0x50 l2cap_state = L2CAP_EV_HID_PS3_LED;
{ } else
delay(1000);//There has to be a delay before sending the commands l2cap_state = L2CAP_EV_HID_ENABLE_SIXAXIS;
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++) 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;
timer = millis();
}
break;
delay(1000);//There has to be a delay before data can be read case L2CAP_EV_HID_PS3_LED:
if(millis() - timer > 1000) { // loop 1 second before sending the command
if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
setLedOn(LED1); setLedOn(LED1);
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n")); Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"));
#endif #endif
PS3BTConnected = true; PS3BTConnected = true;
} } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
else if (remote_name[0] == 'N')//First letter in Navigation Controller ('N') - 0x4E
{
delay(1000);//There has to be a delay before sending the commands
enable_sixaxis();
for (uint8_t i = 15; i < 19; i++)
l2capinbuf[i] = 0x7F;//Set the analog joystick values to center
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 setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nNavigation Controller Enabled\r\n")); Notify(PSTR("\r\nNavigation Controller Enabled\r\n"));
#endif #endif
PS3NavigationBTConnected = true; PS3NavigationBTConnected = true;
} } else if(remote_name[0] == 'M') { // First letter in Motion Controller ('M')
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); moveSetBulb(Red);
timerBulbRumble = millis();
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nMotion Controller Enabled\r\n")); Notify(PSTR("\r\nMotion Controller Enabled\r\n"));
#endif #endif
PS3MoveBTConnected = true; PS3MoveBTConnected = true;
timerBulbRumble = millis();
} }
l2cap_state = L2CAP_EV_L2CAP_DONE; 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