remove AdafruitBluefruit::requestPairing
default CFG_DEFAULT_NAME to USB_PRODUCT
This commit is contained in:
1 parent
cc7de3d270
commit
e0cda21a1a
3 files changed
+38
-29
No files matched your search
@@ -30,7 +30,7 @@ hid_mouse_report_t last_mse_report = { 0 };
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
// while ( !Serial ) delay(10); // for nrf52840 with native usb
|
||||
|
||||
Serial.println("Bluefruit52 Central HID (Keyboard + Mouse) Example");
|
||||
Serial.println("--------------------------------------------------\n");
|
||||
@@ -55,6 +55,9 @@ void setup()
|
||||
Bluefruit.Central.setConnectCallback(connect_callback);
|
||||
Bluefruit.Central.setDisconnectCallback(disconnect_callback);
|
||||
|
||||
// Set connection secured callback, invoked when connection is encrypted
|
||||
Bluefruit.Pairing.setSecuredCallback(connection_secured_callback);
|
||||
|
||||
/* Start Central Scanning
|
||||
* - Enable auto scan if disconnected
|
||||
* - Interval = 100 ms, window = 80 ms
|
||||
@@ -88,6 +91,8 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
|
||||
*/
|
||||
void connect_callback(uint16_t conn_handle)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_handle);
|
||||
|
||||
Serial.println("Connected");
|
||||
|
||||
Serial.print("Discovering HID Service ... ");
|
||||
@@ -97,11 +102,31 @@ void connect_callback(uint16_t conn_handle)
|
||||
Serial.println("Found it");
|
||||
|
||||
// HID device mostly require pairing/bonding
|
||||
if ( !Bluefruit.requestPairing(conn_handle) )
|
||||
{
|
||||
Serial.print("Failed to paired");
|
||||
return;
|
||||
}
|
||||
conn->requestPairing();
|
||||
}else
|
||||
{
|
||||
Serial.println("Found NONE");
|
||||
|
||||
// disconnect since we couldn't find blehid service
|
||||
conn->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void connection_secured_callback(uint16_t conn_handle)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_handle);
|
||||
|
||||
if ( !conn->secured() )
|
||||
{
|
||||
// It is possible that connection is still not secured by this time.
|
||||
// This happens (central only) when we try to encrypt connection using stored bond keys
|
||||
// but peer reject it (probably it remove its stored key).
|
||||
// Therefore we will request an pairing again --> callback again when encrypted
|
||||
conn->requestPairing();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Secured");
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.hid_information.xml
|
||||
uint8_t hidInfo[4];
|
||||
@@ -120,15 +145,9 @@ void connect_callback(uint16_t conn_handle)
|
||||
|
||||
// Enable Mouse report notification if present on prph
|
||||
if ( hid.mousePresent() ) hid.enableMouse();
|
||||
|
||||
|
||||
Serial.println("Ready to receive from peripheral");
|
||||
}else
|
||||
{
|
||||
Serial.println("Found NONE");
|
||||
|
||||
// disconnect since we couldn't find blehid service
|
||||
Bluefruit.disconnect(conn_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,8 +41,10 @@
|
||||
#define CFG_BLE_TX_POWER_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_DEFAULT_NAME
|
||||
#define CFG_DEFAULT_NAME "Bluefruit52"
|
||||
#ifdef USB_PRODUCT
|
||||
#define CFG_DEFAULT_NAME USB_PRODUCT
|
||||
#else
|
||||
#define CFG_DEFAULT_NAME "Feather nRF52832"
|
||||
#endif
|
||||
|
||||
#ifndef CFG_BLE_TASK_STACKSIZE
|
||||
@@ -916,17 +918,6 @@ void AdafruitBluefruit::_setConnLed (bool on_off)
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Bonds
|
||||
*------------------------------------------------------------------*/
|
||||
bool AdafruitBluefruit::requestPairing(uint16_t conn_hdl)
|
||||
{
|
||||
BLEConnection* conn = this->Connection(conn_hdl);
|
||||
VERIFY(conn);
|
||||
|
||||
return conn->requestPairing();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -164,11 +164,10 @@ class AdafruitBluefruit
|
||||
bool connected (uint16_t conn_hdl);
|
||||
|
||||
uint16_t connHandle (void);
|
||||
bool connPaired (uint16_t conn_hdl);
|
||||
|
||||
// Alias to BLEConnection API()
|
||||
bool connPaired (uint16_t conn_hdl);
|
||||
bool disconnect (uint16_t conn_hdl);
|
||||
bool requestPairing (uint16_t conn_hdl);
|
||||
|
||||
uint16_t getMaxMtu(uint8_t role);
|
||||
|
||||
|
||||
Reference in new issue
Block a user