mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Created separate flags for read bdaddr and read local version
Sometimes it didn't read the bluetooth address correctly, but still just went on with the state machine. The start number og reset loops also had to be increased.
This commit is contained in:
parent
73427c0384
commit
6b93de24ce
2 changed files with 17 additions and 11 deletions
16
PS3BT.cpp
16
PS3BT.cpp
|
@ -264,7 +264,7 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
interrupt_dcid[0] = 0x41;//0x0041
|
interrupt_dcid[0] = 0x41;//0x0041
|
||||||
interrupt_dcid[1] = 0x00;
|
interrupt_dcid[1] = 0x00;
|
||||||
|
|
||||||
hci_num_reset_loops = 10; // only loop 10 times before trying to send the hci reset command
|
hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command
|
||||||
|
|
||||||
hci_state = HCI_INIT_STATE;
|
hci_state = HCI_INIT_STATE;
|
||||||
hci_counter = 0;
|
hci_counter = 0;
|
||||||
|
@ -382,8 +382,8 @@ uint8_t PS3BT::Poll()
|
||||||
if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
|
if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
|
||||||
HCI_event_task(); // poll the HCI event pipe
|
HCI_event_task(); // poll the HCI event pipe
|
||||||
ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected
|
ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected
|
||||||
|
qNextPollTime = millis() + pollInterval; // Set new poll time
|
||||||
}
|
}
|
||||||
qNextPollTime = millis() + pollInterval; // Poll time
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void PS3BT::setBdaddr(uint8_t* BDADDR)
|
void PS3BT::setBdaddr(uint8_t* BDADDR)
|
||||||
|
@ -608,14 +608,16 @@ void PS3BT::HCI_event_task()
|
||||||
switch (hcibuf[0]) //switch on event type
|
switch (hcibuf[0]) //switch on event type
|
||||||
{
|
{
|
||||||
case EV_COMMAND_COMPLETE:
|
case EV_COMMAND_COMPLETE:
|
||||||
|
hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
|
||||||
if (!hcibuf[5]) { // check if command succeeded
|
if (!hcibuf[5]) { // check if command succeeded
|
||||||
hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
|
if((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) { // parameters from read local version information
|
||||||
if((hcibuf[3] == 0x01) && (hcibuf[4] == 0x10)) // parameters from read local version information
|
|
||||||
hci_version = hcibuf[6]; // Check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
|
hci_version = hcibuf[6]; // Check if it supports 2.0+EDR - see http://www.bluetooth.org/Technical/AssignedNumbers/hci.htm
|
||||||
|
hci_event_flag |= HCI_FLAG_READ_VERSION;
|
||||||
|
}
|
||||||
else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address
|
else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address
|
||||||
for (uint8_t i = 0; i < 6; i++)
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
my_bdaddr[i] = hcibuf[6 + i];
|
my_bdaddr[i] = hcibuf[6 + i];
|
||||||
|
hci_event_flag |= HCI_FLAG_READ_BDADDR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -750,7 +752,7 @@ void PS3BT::HCI_task()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_BDADDR_STATE:
|
case HCI_BDADDR_STATE:
|
||||||
if (hci_cmd_complete)
|
if (hci_read_bdaddr_complete)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Notify(PSTR("\r\nLocal Bluetooth Address: "));
|
Notify(PSTR("\r\nLocal Bluetooth Address: "));
|
||||||
|
@ -767,7 +769,7 @@ void PS3BT::HCI_task()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_LOCAL_VERSION_STATE:
|
case HCI_LOCAL_VERSION_STATE:
|
||||||
if (hci_cmd_complete)
|
if (hci_read_version_complete)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(hci_version < 3) {
|
if(hci_version < 3) {
|
||||||
|
|
6
PS3BT.h
6
PS3BT.h
|
@ -77,6 +77,8 @@
|
||||||
#define HCI_FLAG_DISCONN_COMPLETE 0x04
|
#define HCI_FLAG_DISCONN_COMPLETE 0x04
|
||||||
#define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08
|
#define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08
|
||||||
#define HCI_FLAG_INCOMING_REQUEST 0x10
|
#define HCI_FLAG_INCOMING_REQUEST 0x10
|
||||||
|
#define HCI_FLAG_READ_BDADDR 0x20
|
||||||
|
#define HCI_FLAG_READ_VERSION 0x40
|
||||||
|
|
||||||
/*Macros for HCI event flag tests */
|
/*Macros for HCI event flag tests */
|
||||||
#define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE)
|
#define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE)
|
||||||
|
@ -84,6 +86,8 @@
|
||||||
#define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)
|
#define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)
|
||||||
#define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
|
#define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
|
||||||
#define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
|
#define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
|
||||||
|
#define hci_read_bdaddr_complete (hci_event_flag & HCI_FLAG_READ_BDADDR)
|
||||||
|
#define hci_read_version_complete (hci_event_flag & HCI_FLAG_READ_VERSION)
|
||||||
|
|
||||||
/* HCI Events managed */
|
/* HCI Events managed */
|
||||||
#define EV_COMMAND_COMPLETE 0x0E
|
#define EV_COMMAND_COMPLETE 0x0E
|
||||||
|
@ -362,7 +366,7 @@ public:
|
||||||
bool PS3NavigationBTConnected;// Variable used to indicate if the navigation controller is successfully connected
|
bool PS3NavigationBTConnected;// Variable used to indicate if the navigation controller is successfully connected
|
||||||
bool buttonChanged;//Indicate if a button has been changed
|
bool buttonChanged;//Indicate if a button has been changed
|
||||||
bool buttonPressed;//Indicate if a button has been pressed
|
bool buttonPressed;//Indicate if a button has been pressed
|
||||||
bool buttonReleased;//Indicate if a button has been pressed
|
bool buttonReleased;//Indicate if a button has been released
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* mandatory members */
|
/* mandatory members */
|
||||||
|
|
Loading…
Reference in a new issue