mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge pull request #16 from TKJElectronics/master
Combined constructors and created separate flags for read bdaddr and read local version
This commit is contained in:
commit
c28a671695
3 changed files with 21 additions and 34 deletions
35
PS3BT.cpp
35
PS3BT.cpp
|
@ -62,25 +62,6 @@ bPollEnable(false) // don't start polling before dongle is connected
|
||||||
my_bdaddr[0] = btadr0;
|
my_bdaddr[0] = btadr0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PS3BT::PS3BT(USB *p):
|
|
||||||
pUsb(p), // pointer to USB class instance - mandatory
|
|
||||||
bAddress(0), // device address - mandatory
|
|
||||||
bNumEP(1), // if config descriptor needs to be parsed
|
|
||||||
qNextPollTime(0),
|
|
||||||
bPollEnable(false) // don't start polling before dongle is connected
|
|
||||||
{
|
|
||||||
for(uint8_t i=0; i<PS3_MAX_ENDPOINTS; i++)
|
|
||||||
{
|
|
||||||
epInfo[i].epAddr = 0;
|
|
||||||
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
|
||||||
epInfo[i].epAttribs = 0;
|
|
||||||
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pUsb) // register in USB subsystem
|
|
||||||
pUsb->RegisterDeviceClass(this); //set devConfig[] entry
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
{
|
{
|
||||||
uint8_t buf[sizeof(USB_DEVICE_DESCRIPTOR)];
|
uint8_t buf[sizeof(USB_DEVICE_DESCRIPTOR)];
|
||||||
|
@ -283,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;
|
||||||
|
@ -399,10 +380,10 @@ uint8_t PS3BT::Poll()
|
||||||
if (!bPollEnable)
|
if (!bPollEnable)
|
||||||
return 0;
|
return 0;
|
||||||
if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
|
if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
|
||||||
|
qNextPollTime = millis() + pollInterval; // Set new poll time
|
||||||
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; // Poll time
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void PS3BT::setBdaddr(uint8_t* BDADDR)
|
void PS3BT::setBdaddr(uint8_t* BDADDR)
|
||||||
|
@ -627,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:
|
||||||
if (!hcibuf[5]) { // check if command succeeded
|
|
||||||
hci_event_flag |= HCI_FLAG_CMD_COMPLETE; // set command complete flag
|
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[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_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;
|
||||||
|
@ -769,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: "));
|
||||||
|
@ -786,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) {
|
||||||
|
|
9
PS3BT.h
9
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
|
||||||
|
@ -317,8 +321,7 @@ enum Rumble
|
||||||
class PS3BT : public USBDeviceConfig, public UsbConfigXtracter
|
class PS3BT : public USBDeviceConfig, public UsbConfigXtracter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PS3BT(USB *pUsb, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0);
|
PS3BT(USB *pUsb, uint8_t btadr5=0, uint8_t btadr4=0, uint8_t btadr3=0, uint8_t btadr2=0, uint8_t btadr1=0, uint8_t btadr0=0);
|
||||||
PS3BT(USB *pUsb);
|
|
||||||
|
|
||||||
// USBDeviceConfig implementation
|
// USBDeviceConfig implementation
|
||||||
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
|
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
|
||||||
|
@ -363,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 */
|
||||||
|
|
|
@ -198,4 +198,5 @@ void loop()
|
||||||
Serial.println(templow);
|
Serial.println(templow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue