adding ancs example

This commit is contained in:
hathach committed 2017-03-30 15:01:54 +07:00
1 parent e8873a43e7
commit d92438be4d
1 file changed
+80
@@ -0,0 +1,80 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <bluefruit.h>
// BLE Service
BLEAncs bleancs;
void setup()
{
Serial.begin(115200);
Serial.println("Bluefruit52 BLE ANCS Example");
Serial.println("----------------------------");
Bluefruit.begin();
Bluefruit.setName("Bluefruit52");
Bluefruit.setConnectCallback(connect_callback);
Bluefruit.setDisconnectCallback(disconnect_callback);
// Configure and Start Service
bleancs.begin();
// Set up Advertising Packet
setupAdv();
// Start Advertising
Bluefruit.Advertising.start();
}
void setupAdv(void)
{
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
// Include ancs 128-bit uuid
Bluefruit.Advertising.addService(bleancs);
// There is no room for Name in Advertising packet
// Use Scan response for Name
Bluefruit.ScanResponse.addName();
}
void loop()
{
// not connected, nothing to do
if ( !Bluefruit.connected() ) return ;
// Discover service if not yet
if ( !bleancs.discovered() )
{
if ( bleancs.discover( Bluefruit.connHandle() ) )
{
}
}
}
void connect_callback(void)
{
Serial.println("Connected");
}
void disconnect_callback(uint8_t reason)
{
(void) reason;
Serial.println();
Serial.println("Disconnected");
Serial.println("Bluefruit will auto start advertising (default)");
}