@@ -80,7 +80,8 @@ void setup()
80
80
setupAdv ();
81
81
82
82
// Start Advertising
83
- Serial.println (" Ready Player One! (Advertising)" );
83
+ Serial.println (" Ready Player One!!!" );
84
+ Serial.println (" \n Advertising" );
84
85
Bluefruit.startAdvertising ();
85
86
}
86
87
@@ -131,11 +132,10 @@ void setupHRM(void)
131
132
hrmc.setProperties (CHR_PROPS_NOTIFY);
132
133
hrmc.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
133
134
hrmc.setMaxLen (2 );
135
+ hrmc.setCccdWriteCallback (cccd_callback);
134
136
hrmc.start ();
135
-
136
- // Set the characteristic to use 8-bit values, with the sensor connected and detected
137
- uint8_t hrmdata[2 ] = { 0b00000110 , 0x40 };
138
- hrmc.write (hrmdata, 2 );
137
+ uint8_t hrmdata[2 ] = { 0b00000110 , 0x40 }; // Set the characteristic to use 8-bit values, with the sensor connected and detected
138
+ hrmc.notify (hrmdata, 2 ); // Use .notify instead of .write!
139
139
140
140
// Configure the Body Sensor Location characteristic
141
141
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml
@@ -155,9 +155,35 @@ void setupHRM(void)
155
155
bslc.setPermission (SECMODE_OPEN, SECMODE_NO_ACCESS);
156
156
bslc.setFixedLen (1 );
157
157
bslc.start ();
158
+ bslc.write (2 ); // Set the characteristic to 'Wrist' (2)
159
+ }
158
160
159
- // Set the characteristic to 'Wrist' (2)
160
- bslc.write (2 );
161
+ void connect_callback (void )
162
+ {
163
+ Serial.println (" Connected" );
164
+ }
165
+
166
+ void disconnect_callback (uint8_t reason)
167
+ {
168
+ (void ) reason;
169
+
170
+ Serial.println (" Disconnected" );
171
+ Serial.println (" Advertising!" );
172
+ }
173
+
174
+ void cccd_callback (BLECharacteristic& chr, ble_gatts_evt_write_t * request)
175
+ {
176
+ (void ) request;
177
+
178
+ // Check the characteristic this CCCD record is associated with in case
179
+ // this callback is used for multiple CCCD callbacks.
180
+ if (chr.uuid == hrmc.uuid ) {
181
+ if (chr.notifyEnabled ()) {
182
+ Serial.println (" Heart Rate Measurement CCCD: Notify enabled" );
183
+ } else {
184
+ Serial.println (" Heart Rate Measurement CCCD: Notify disabled" );
185
+ }
186
+ }
161
187
}
162
188
163
189
uint8_t bps = 0 ;
@@ -169,26 +195,9 @@ void loop()
169
195
digitalToggle (STATUS_LED);
170
196
171
197
// Set the characteristic to use 8-bit values, with the sensor connected and detected
172
- uint8_t hrmdata[2 ] = { 0b00000110 , bps++ };
173
198
// Note: We use .notify instead of .write since this characteristic has
174
199
// notify as a property!
175
- if (hrmc.notifyEnabled ()) {
176
- hrmc.notify (hrmdata, sizeof (hrmdata));
177
- } else {
178
- hrmc.write (hrmdata, sizeof (hrmdata));
179
- }
200
+ uint8_t hrmdata[2 ] = { 0b00000110 , bps++ };
201
+ hrmc.notify (hrmdata, sizeof (hrmdata));
180
202
}
181
203
}
182
-
183
- void connect_callback (void )
184
- {
185
- Serial.println (" Connected" );
186
- }
187
-
188
- void disconnect_callback (uint8_t reason)
189
- {
190
- (void ) reason;
191
-
192
- Serial.println (" Disconnected" );
193
- Serial.println (" Advertising!" );
194
- }
0 commit comments