mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Call registerBluetoothService in BluetoothService constructor
I needed to move the BluetoothService class down after the BTD class in order for it to work
This commit is contained in:
parent
25c8d87ba2
commit
106aff6411
6 changed files with 64 additions and 73 deletions
6
BTD.cpp
6
BTD.cpp
|
@ -380,6 +380,12 @@ uint8_t BTD::Poll() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void BTD::disconnect() {
|
||||
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
|
||||
if(btService[i])
|
||||
btService[i]->disconnect();
|
||||
};
|
||||
|
||||
void BTD::HCI_event_task() {
|
||||
uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this
|
||||
uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf); // Input on endpoint 1
|
||||
|
|
115
BTD.h
115
BTD.h
|
@ -204,58 +204,7 @@
|
|||
*/
|
||||
#define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20)))
|
||||
#endif
|
||||
|
||||
class BTD;
|
||||
|
||||
/** All Bluetooth services should inherit this class. */
|
||||
class BluetoothService {
|
||||
public:
|
||||
BluetoothService(BTD *p) : pBtd(p) {};
|
||||
/**
|
||||
* Used to pass acldata to the Bluetooth service.
|
||||
* @param ACLData Pointer to the incoming acldata.
|
||||
*/
|
||||
virtual void ACLData(uint8_t* ACLData) = 0;
|
||||
/** Used to run the different state machines in the Bluetooth service. */
|
||||
virtual void Run() = 0;
|
||||
/** Used to reset the Bluetooth service. */
|
||||
virtual void Reset() = 0;
|
||||
/** Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service. */
|
||||
virtual void disconnect() = 0;
|
||||
|
||||
/**
|
||||
* Used to call your own function when the device is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit; // TODO: This really belong in a class of it's own as it is repeated several times
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called when a device is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
virtual void onInit() = 0;
|
||||
|
||||
// TODO: Implement "UHS_ACL_HANDLE_OK" function
|
||||
|
||||
/** Pointer to function called in onInit(). */
|
||||
void (*pFuncOnInit)(void);
|
||||
|
||||
/** Pointer to BTD instance. */
|
||||
BTD *pBtd;
|
||||
|
||||
/** The HCI Handle for the connection. */
|
||||
uint16_t hci_handle;
|
||||
|
||||
/** L2CAP flags of received Bluetooth events. */
|
||||
uint32_t l2cap_event_flag;
|
||||
|
||||
/** Identifier for L2CAP commands. */
|
||||
uint8_t identifier;
|
||||
};
|
||||
class BluetoothService;
|
||||
|
||||
/**
|
||||
* The Bluetooth Dongle class will take care of all the USB communication
|
||||
|
@ -353,25 +302,21 @@ public:
|
|||
/**@}*/
|
||||
|
||||
/** Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services. */
|
||||
void disconnect() {
|
||||
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++)
|
||||
if(btService[i])
|
||||
btService[i]->disconnect();
|
||||
};
|
||||
void disconnect();
|
||||
|
||||
/**
|
||||
* Register Bluetooth dongle members/services.
|
||||
* @param pService Pointer to BluetoothService class instance.
|
||||
* @return The service ID on success or -1 on fail.
|
||||
*/
|
||||
int8_t registerServiceClass(BluetoothService *pService) {
|
||||
int8_t registerBluetoothService(BluetoothService *pService) {
|
||||
for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) {
|
||||
if(!btService[i]) {
|
||||
btService[i] = pService;
|
||||
return i; // Return ID
|
||||
}
|
||||
}
|
||||
return -1; // ErrorregisterServiceClass
|
||||
return -1; // Error registering BluetoothService
|
||||
};
|
||||
|
||||
/** @name HCI Commands */
|
||||
|
@ -628,4 +573,56 @@ private:
|
|||
void setBdaddr(uint8_t* BDADDR);
|
||||
void setMoveBdaddr(uint8_t* BDADDR);
|
||||
};
|
||||
|
||||
/** All Bluetooth services should inherit this class. */
|
||||
class BluetoothService {
|
||||
public:
|
||||
BluetoothService(BTD *p) : pBtd(p) {
|
||||
if(pBtd)
|
||||
pBtd->registerBluetoothService(this); // Register it as a Bluetooth service
|
||||
};
|
||||
/**
|
||||
* Used to pass acldata to the Bluetooth service.
|
||||
* @param ACLData Pointer to the incoming acldata.
|
||||
*/
|
||||
virtual void ACLData(uint8_t* ACLData) = 0;
|
||||
/** Used to run the different state machines in the Bluetooth service. */
|
||||
virtual void Run() = 0;
|
||||
/** Used to reset the Bluetooth service. */
|
||||
virtual void Reset() = 0;
|
||||
/** Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service. */
|
||||
virtual void disconnect() = 0;
|
||||
|
||||
/**
|
||||
* Used to call your own function when the device is successfully initialized.
|
||||
* @param funcOnInit Function to call.
|
||||
*/
|
||||
void attachOnInit(void (*funcOnInit)(void)) {
|
||||
pFuncOnInit = funcOnInit; // TODO: This really belong in a class of it's own as it is repeated several times
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called when a device is successfully initialized.
|
||||
* Use attachOnInit(void (*funcOnInit)(void)) to call your own function.
|
||||
* This is useful for instance if you want to set the LEDs in a specific way.
|
||||
*/
|
||||
virtual void onInit() = 0;
|
||||
|
||||
/** Pointer to function called in onInit(). */
|
||||
void (*pFuncOnInit)(void);
|
||||
|
||||
/** Pointer to BTD instance. */
|
||||
BTD *pBtd;
|
||||
|
||||
/** The HCI Handle for the connection. */
|
||||
uint16_t hci_handle;
|
||||
|
||||
/** L2CAP flags of received Bluetooth events. */
|
||||
uint32_t l2cap_event_flag;
|
||||
|
||||
/** Identifier for L2CAP commands. */
|
||||
uint8_t identifier;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,9 +26,6 @@ protocolMode(HID_BOOT_PROTOCOL) {
|
|||
for(uint8_t i = 0; i < NUM_PARSERS; i++)
|
||||
pRptParser[i] = NULL;
|
||||
|
||||
if(pBtd)
|
||||
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
||||
|
||||
pBtd->pairWithHIDDevice = pair;
|
||||
pBtd->btdPin = pin;
|
||||
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
PS3BT::PS3BT(BTD *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) :
|
||||
BluetoothService(p) // Pointer to USB class instance - mandatory
|
||||
{
|
||||
if(pBtd)
|
||||
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
||||
|
||||
pBtd->my_bdaddr[5] = btadr5; // Change to your dongle's Bluetooth address instead
|
||||
pBtd->my_bdaddr[4] = btadr4;
|
||||
pBtd->my_bdaddr[3] = btadr3;
|
||||
|
|
3
SPP.cpp
3
SPP.cpp
|
@ -45,9 +45,6 @@ const uint8_t rfcomm_crc_table[256] PROGMEM = {/* reversed, 8-bit, poly=0x07 */
|
|||
SPP::SPP(BTD *p, const char* name, const char* pin) :
|
||||
BluetoothService(p) // Pointer to BTD class instance - mandatory
|
||||
{
|
||||
if(pBtd)
|
||||
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
||||
|
||||
pBtd->btdName = name;
|
||||
pBtd->btdPin = pin;
|
||||
|
||||
|
|
3
Wii.cpp
3
Wii.cpp
|
@ -85,9 +85,6 @@ const uint32_t WII_PROCONTROLLER_BUTTONS[] PROGMEM = {
|
|||
WII::WII(BTD *p, bool pair) :
|
||||
BluetoothService(p) // Pointer to USB class instance - mandatory
|
||||
{
|
||||
if(pBtd)
|
||||
pBtd->registerServiceClass(this); // Register it as a Bluetooth service
|
||||
|
||||
pBtd->pairWithWii = pair;
|
||||
|
||||
HIDBuffer[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02)
|
||||
|
|
Loading…
Reference in a new issue