Skip to content

Commit 24c86fe

Browse files
committed
add connection handle to Bluefruit.connParied()
1 parent 264893d commit 24c86fe

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/client_cts/client_cts.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ void startAdv(void)
9494

9595
void loop()
9696
{
97-
// If service is not yet discovered
98-
if ( !bleCTime.discovered() && !Bluefruit.connPaired() ) return;
97+
// Skip if service is not yet discovered
98+
if ( !bleCTime.discovered() ) return;
99+
100+
// Skip if service connection is not paired/secured
101+
if ( !Bluefruit.connPaired( bleCTime.connHandle() ) ) return;
99102

100103
// Get Time from iOS once per second
101104
// Note it is not advised to update this quickly

libraries/Bluefruit52Lib/examples/Peripheral/client_cts_oled/client_cts_oled.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ void startAdv(void)
103103

104104
void loop()
105105
{
106-
// If service is not yet discovered
107-
if ( !bleCTime.discovered() && !Bluefruit.connPaired() ) return;
106+
// Skip if service is not yet discovered
107+
if ( !bleCTime.discovered() ) return;
108+
109+
// Skip if service connection is not paired/secured
110+
if ( !Bluefruit.connPaired( bleCTime.connHandle() ) ) return;
108111

109112
// Get Time from iOS once per second
110113
// Note it is not advised to update this quickly

libraries/Bluefruit52Lib/examples/Peripheral/hid_camerashutter/hid_camerashutter.ino

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
/*
1616
* This sketch uses the HID Consumer Key API to send the Volume Down
1717
* key when PIN_SHUTTER is grounded. This will cause your mobile device
18-
* to capture a photo when you are in the camera app
18+
* to capture a photo when you are in the camera app.
19+
*
20+
* For Feather nRF52840 PIN_SHUTTER is conveniently user switch.
1921
*/
2022
#include <bluefruit.h>
2123

2224
BLEDis bledis;
2325
BLEHidAdafruit blehid;
2426

25-
#define PIN_SHUTTER A0
27+
#define PIN_SHUTTER 7
2628

2729
void setup()
2830
{
@@ -101,30 +103,34 @@ void startAdv(void)
101103

102104
void loop()
103105
{
104-
// Make sure you are connected and bonded/paired
105-
if ( Bluefruit.connected() && Bluefruit.connPaired() )
106+
// Skip if shutter pin is not Ground
107+
if ( digitalRead(PIN_SHUTTER) == 1 ) return;
108+
109+
// Make sure we are connected and bonded/paired
110+
for (uint16_t conn_hdl=0; conn_hdl < BLE_MAX_CONNECTION; conn_hdl++)
106111
{
107-
// Check if pin GND'ed
108-
if ( digitalRead(PIN_SHUTTER) == 0 )
112+
BLEConnection* connection = Bluefruit.Connection(conn_hdl);
113+
114+
if ( connection && connection->connected() && connection->paired() )
109115
{
110116
// Turn on red LED when we start sending data
111117
digitalWrite(LED_RED, 1);
112118

113-
// Send the 'volume down' key press
114-
// Check hid.h for a list of valid consumer usage codes
115-
blehid.consumerKeyPress(HID_USAGE_CONSUMER_VOLUME_DECREMENT);
119+
// Send the 'volume down' key press to the peer
120+
// Check tinyusb/src/class/hid/hid.h for a list of valid consumer usage codes
121+
blehid.consumerKeyPress(conn_hdl, HID_USAGE_CONSUMER_VOLUME_DECREMENT);
116122

117123
// Delay a bit between reports
118124
delay(10);
119125

120126
// Send key release
121-
blehid.consumerKeyRelease();
127+
blehid.consumerKeyRelease(conn_hdl);
122128

123129
// Turn off the red LED
124130
digitalWrite(LED_RED, 0);
125-
126-
// Delay to avoid constant capturing
127-
delay(500);
128131
}
129132
}
133+
134+
// Delay to avoid constant capturing
135+
delay(500);
130136
}

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,9 @@ uint16_t AdafruitBluefruit::connHandle(void)
635635
return _conn_hdl;
636636
}
637637

638-
bool AdafruitBluefruit::connPaired(void)
638+
bool AdafruitBluefruit::connPaired(uint16_t conn_hdl)
639639
{
640-
BLEConnection* conn = Bluefruit.Connection(_conn_hdl);
640+
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
641641
return conn && conn->paired();
642642
}
643643

libraries/Bluefruit52Lib/src/bluefruit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class AdafruitBluefruit
173173
bool connected (uint16_t conn_hdl);
174174

175175
uint16_t connHandle (void);
176-
bool connPaired (void);
176+
bool connPaired (uint16_t conn_hdl);
177177

178178
// Alias to BLEConnection API()
179179
bool disconnect (uint16_t conn_hdl);

0 commit comments

Comments
 (0)