Skip to content

Commit b66cfc8

Browse files
committed
fix build for ancs oled
1 parent b5f2e74 commit b66cfc8

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/ancs_arcada/ancs_arcada.ino

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
*********************************************************************/
1414

1515
/*
16-
* This sketch is similar to 'ancs', but it also uses a Feather OLED
17-
* Wing to display incoming ANCS alerts:
18-
* https://www.adafruit.com/product/2900
16+
* This sketch is similar to 'ancs', but it uses TFT to display
17+
* incoming ANCS alerts. Supported boards are:
18+
* - CLUE https://www.adafruit.com/product/4500
19+
* - Circuit Playground Bluefruit + TFT Gizmo
20+
* - https://www.adafruit.com/product/4333
21+
* - https://www.adafruit.com/product/4367
1922
*
20-
* BUTTON A: Up or accept call
21-
* BUTTON B: Not used since it is hard to press
22-
* BUTTON C: Down or decline call
23+
* Button Left: Next or Answer call
24+
* Button Right: Previous or Reject call
25+
*
26+
* Note on CPB button A is RIGHT and button B is LEFT, this is due to
27+
* the TFT is on the back of the board.
2328
*/
2429
#include <Adafruit_Arcada.h>
2530
#include <bluefruit.h>

libraries/Bluefruit52Lib/examples/Peripheral/ancs_oled/ancs_oled.ino

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
#define BUTTON_B 30
3434
#define BUTTON_C 27
3535

36-
#elif defined ARDUINO_NRF52840_CIRCUITPLAY
37-
// Circuit Playground nRF52840 - FYI doesnt work probably because of button polarity!
38-
#define BUTTON_A 4 // left button
39-
#define BUTTON_B 7 // center switch
40-
#define BUTTON_C 5 // right button
41-
4236
#else
4337
// Default for others
4438
#define BUTTON_A 9
@@ -67,7 +61,7 @@ MyNotif_t myNotifs[MAX_COUNT] = { 0 };
6761
int notifCount = 0;
6862

6963
/*------------- Display Management -------------*/
70-
#define ONSCREEN_TIME 5000 // On-screen time for each notification
64+
#define ONSCREEN_TIME 10000 // On-screen time for each notification
7165

7266
int activeIndex = 0; // Index of currently displayed notification
7367
int displayIndex = -1; // Index of notification about to display
@@ -94,14 +88,17 @@ void setup()
9488
// Config the peripheral connection with maximum bandwidth
9589
// more SRAM required by SoftDevice
9690
// Note: All config***() function must be called before begin()
97-
//Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
91+
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
9892

9993
Bluefruit.begin();
10094
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
10195
Bluefruit.setName("Bluefruit52");
10296
Bluefruit.Periph.setConnectCallback(connect_callback);
10397
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
10498

99+
// Set connection secured callback, invoked when connection is encrypted
100+
Bluefruit.Pairing.setSecuredCallback(connection_secured_callback);
101+
105102
// Configure and Start Service
106103
bleancs.begin();
107104
bleancs.setNotificationCallback(ancs_notification_callback);
@@ -148,6 +145,13 @@ void startAdv(void)
148145

149146
void loop()
150147
{
148+
// This example only support 1 connection
149+
uint16_t const conn_handle = 0;
150+
BLEConnection* conn = Bluefruit.Connection(conn_handle);
151+
152+
// connection exist, connected, and secured
153+
if ( !(conn && conn->connected() && conn->secured()) ) return;
154+
151155
// If service is not yet discovered
152156
if ( !bleancs.discovered() ) return;
153157

@@ -261,6 +265,8 @@ void displayNotification(int index)
261265
*/
262266
void connect_callback(uint16_t conn_handle)
263267
{
268+
BLEConnection* conn = Bluefruit.Connection(conn_handle);
269+
264270
oled.clearDisplay();
265271
oled.setCursor(0, 0);
266272
oled.println("Connected.");
@@ -272,20 +278,9 @@ void connect_callback(uint16_t conn_handle)
272278
oled.println("OK");
273279

274280
// ANCS requires pairing to work
275-
oled.print("Paring ... ");
276-
277-
oled.display();
278-
279-
if ( Bluefruit.requestPairing(conn_handle) )
280-
{
281-
oled.println("OK");
282-
283-
bleancs.enableNotification();
284-
oled.println("Receiving ...");
285-
}else
286-
{
287-
oled.println("Failed");
288-
}
281+
// request Pairing if not bonded
282+
oled.println("Paring ... ");
283+
conn->requestPairing();
289284
}else
290285
{
291286
oled.println("Failed");
@@ -294,6 +289,31 @@ void connect_callback(uint16_t conn_handle)
294289
oled.display();
295290
}
296291

292+
void connection_secured_callback(uint16_t conn_handle)
293+
{
294+
BLEConnection* conn = Bluefruit.Connection(conn_handle);
295+
296+
if ( !conn->secured() )
297+
{
298+
// It is possible that connection is still not secured by this time.
299+
// This happens (central only) when we try to encrypt connection using stored bond keys
300+
// but peer reject it (probably it remove its stored key).
301+
// Therefore we will request an pairing again --> callback again when encrypted
302+
conn->requestPairing();
303+
}
304+
else
305+
{
306+
Serial.println("Secured");
307+
308+
if ( bleancs.discovered() )
309+
{
310+
bleancs.enableNotification();
311+
oled.println("Ready to receive");
312+
oled.display();
313+
}
314+
}
315+
}
316+
297317
/**
298318
* Notification callback
299319
* @param notif Notification from iDevice

0 commit comments

Comments
 (0)