Skip to content

Commit efb67c8

Browse files
author
microbuilder
committed
Error handling cleanup
1 parent 63d38ab commit efb67c8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

libraries/Bluefruit52Lib/examples/custom_hrm/custom_hrm.ino

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,28 @@ void loop()
204204

205205
// Update the HRM value periodically
206206
if (blinkyms+BLINKY_MS < millis()) {
207-
// Make sure we are connected to a Central device!
208207
if (Bluefruit.connected()) {
209-
// Update the value of the notify characteristic
210-
uint8_t hrmdata[2] = { 0b00000110, bps++ }; // Connected, increment BPS value
208+
uint8_t hrmdata[2] = { 0b00000110, bps++ }; // Sensor connected, increment BPS value
211209
err_t resp = hrmc.notify(hrmdata, sizeof(hrmdata)); // Note: We use .notify instead of .write!
212210

213-
// Check the results of the attempt to update the notify characteristic
211+
// This isn't strictly necessary, but you can check the result
212+
// of the .notify() attempt to see if it was successful or not
214213
switch (resp) {
215214
case ERROR_NONE:
216215
// Value was written correctly!
217-
Serial.print("Heart Rate Measurement updated to: ");
218-
Serial.println(bps);
216+
Serial.print("Heart Rate Measurement updated to: "); Serial.println(bps);
219217
break;
220218
case NRF_ERROR_INVALID_PARAM:
221219
// Characteristic property not set to 'Notify'
222-
Serial.println("Error: Characteristic 'Property' not set to Notify!");
220+
Serial.println("ERROR: Characteristic 'Property' not set to Notify!");
223221
break;
224222
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!");
223+
// Notify bit not set in the CCCD or not connected
224+
Serial.println("ERROR: Notify not set in the CCCD or not connected!");
227225
break;
228226
default:
229-
Serial.print("Error: Ox"); Serial.println(resp, HEX);
227+
// Unhandled error code
228+
Serial.print("ERROR: Ox"); Serial.println(resp, HEX);
230229
break;
231230
}
232231
}

0 commit comments

Comments
 (0)