Skip to content

Commit bd5e974

Browse files
author
microbuilder
committed
Added CCCD update text
1 parent 04796e2 commit bd5e974

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

libraries/Bluefruit52Lib/examples/custom_hrm/custom_hrm.ino

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ void setup()
8080
setupAdv();
8181

8282
// Start Advertising
83-
Serial.println("Ready Player One! (Advertising)");
83+
Serial.println("Ready Player One!!!");
84+
Serial.println("\nAdvertising");
8485
Bluefruit.startAdvertising();
8586
}
8687

@@ -131,11 +132,10 @@ void setupHRM(void)
131132
hrmc.setProperties(CHR_PROPS_NOTIFY);
132133
hrmc.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
133134
hrmc.setMaxLen(2);
135+
hrmc.setCccdWriteCallback(cccd_callback);
134136
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!
139139

140140
// Configure the Body Sensor Location characteristic
141141
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml
@@ -155,9 +155,35 @@ void setupHRM(void)
155155
bslc.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
156156
bslc.setFixedLen(1);
157157
bslc.start();
158+
bslc.write(2); // Set the characteristic to 'Wrist' (2)
159+
}
158160

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+
}
161187
}
162188

163189
uint8_t bps = 0;
@@ -169,26 +195,9 @@ void loop()
169195
digitalToggle(STATUS_LED);
170196

171197
// Set the characteristic to use 8-bit values, with the sensor connected and detected
172-
uint8_t hrmdata[2] = { 0b00000110, bps++ };
173198
// Note: We use .notify instead of .write since this characteristic has
174199
// 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));
180202
}
181203
}
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

Comments
 (0)