From 6b93de24ce858507cd0576987b66cb33069fd67b Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Fri, 25 May 2012 18:29:58 +0200 Subject: [PATCH] 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. --- PS3BT.cpp | 22 ++++++++++++---------- PS3BT.h | 6 +++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index 827e2867..e9b21f57 100644 --- a/PS3BT.cpp +++ b/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[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_counter = 0; @@ -382,8 +382,8 @@ uint8_t PS3BT::Poll() if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval HCI_event_task(); // poll the HCI event pipe ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected - } - qNextPollTime = millis() + pollInterval; // Poll time + qNextPollTime = millis() + pollInterval; // Set new poll time + } return 0; } void PS3BT::setBdaddr(uint8_t* BDADDR) @@ -608,15 +608,17 @@ void PS3BT::HCI_event_task() switch (hcibuf[0]) //switch on event type { case EV_COMMAND_COMPLETE: - 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 + hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag + if (!hcibuf[5]) { // check if command succeeded + 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_event_flag |= HCI_FLAG_READ_VERSION; + } else if((hcibuf[3] == 0x09) && (hcibuf[4] == 0x10)) { // parameters from read local bluetooth address for (uint8_t i = 0; i < 6; i++) my_bdaddr[i] = hcibuf[6 + i]; - } + hci_event_flag |= HCI_FLAG_READ_BDADDR; + } } break; @@ -750,7 +752,7 @@ void PS3BT::HCI_task() break; case HCI_BDADDR_STATE: - if (hci_cmd_complete) + if (hci_read_bdaddr_complete) { #ifdef DEBUG Notify(PSTR("\r\nLocal Bluetooth Address: ")); @@ -767,7 +769,7 @@ void PS3BT::HCI_task() break; case HCI_LOCAL_VERSION_STATE: - if (hci_cmd_complete) + if (hci_read_version_complete) { #ifdef DEBUG if(hci_version < 3) { diff --git a/PS3BT.h b/PS3BT.h index 3f326454..27a2decd 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -77,6 +77,8 @@ #define HCI_FLAG_DISCONN_COMPLETE 0x04 #define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08 #define HCI_FLAG_INCOMING_REQUEST 0x10 +#define HCI_FLAG_READ_BDADDR 0x20 +#define HCI_FLAG_READ_VERSION 0x40 /*Macros for HCI event flag tests */ #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_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_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 */ #define EV_COMMAND_COMPLETE 0x0E @@ -362,7 +366,7 @@ public: bool PS3NavigationBTConnected;// Variable used to indicate if the navigation controller is successfully connected bool buttonChanged;//Indicate if a button has been changed 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: /* mandatory members */