Skip to content

Commit 63d38ab

Browse files
author
microbuilder
committed
Minor cleanup
1 parent ee94bec commit 63d38ab

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

libraries/Bluefruit52Lib/examples/custom_hrm/custom_hrm.ino

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,35 @@ void loop()
200200
if (blinkyms+BLINKY_MS < millis()) {
201201
blinkyms = millis();
202202
digitalToggle(STATUS_LED);
203+
}
203204

204-
// Set the characteristic to use 8-bit values, with the sensor connected and detected
205-
// Note: We use .notify instead of .write since this characteristic has
206-
// notify as a property!
207-
uint8_t hrmdata[2] = { 0b00000110, bps++ };
208-
hrmc.notify(hrmdata, sizeof(hrmdata));
205+
// Update the HRM value periodically
206+
if (blinkyms+BLINKY_MS < millis()) {
207+
// Make sure we are connected to a Central device!
208+
if (Bluefruit.connected()) {
209+
// Update the value of the notify characteristic
210+
uint8_t hrmdata[2] = { 0b00000110, bps++ }; // Connected, increment BPS value
211+
err_t resp = hrmc.notify(hrmdata, sizeof(hrmdata)); // Note: We use .notify instead of .write!
212+
213+
// Check the results of the attempt to update the notify characteristic
214+
switch (resp) {
215+
case ERROR_NONE:
216+
// Value was written correctly!
217+
Serial.print("Heart Rate Measurement updated to: ");
218+
Serial.println(bps);
219+
break;
220+
case NRF_ERROR_INVALID_PARAM:
221+
// Characteristic property not set to 'Notify'
222+
Serial.println("Error: Characteristic 'Property' not set to Notify!");
223+
break;
224+
case NRF_ERROR_INVALID_STATE:
225+
// Notify bit not set in the CCCD by the Central device
226+
Serial.println("Warning: Notify not enabled in the CCCD!");
227+
break;
228+
default:
229+
Serial.print("Error: Ox"); Serial.println(resp, HEX);
230+
break;
231+
}
232+
}
209233
}
210234
}

0 commit comments

Comments
 (0)