Skip to content

Commit 36cfbe0

Browse files
author
microbuilder
committed
Minor cleanup
1 parent a461435 commit 36cfbe0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

libraries/Bluefruit52Lib/examples/custom_hrm/custom_hrm.ino

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#define BLINKY_MS (2000)
1818

1919
/* HRM Service Definitions
20-
* Heart Rate Monitor Service: 0x180D
21-
* Heart Rate Measurement Char: 0x2A37
22-
* Body Sensor Location Char: 0x2A38
20+
* Heart Rate Monitor Service: 0x180D
21+
* Heart Rate Measurement Char: 0x2A37
22+
* Body Sensor Location Char: 0x2A38
2323
*/
2424
BLEService hrms = BLEService(UUID16_SVC_HEART_RATE);
2525
BLECharacteristic hrmc = BLECharacteristic(UUID16_CHR_HEART_RATE_MEASUREMENT);
@@ -74,7 +74,7 @@ void setup()
7474
// BLEService and BLECharacteristic classes
7575
Serial.println("Configuring the Heart Rate Monitor Service");
7676
setupHRM();
77-
77+
7878
// Setup the advertising packet(s)
7979
Serial.println("Setting up the advertising payload(s)");
8080
setupAdv();
@@ -107,12 +107,12 @@ void setupHRM(void)
107107
// Heart Rate Measurement 0x2137 Mandatory Notify
108108
// Body Sensor Location 0x2138 Optional Read
109109
// Heart Rate Control Point 0x2A39 Conditional Write <-- Not used here
110-
hrms.start();
111-
110+
hrms.start();
111+
112112
// Note: You must start the service before calling any characteristics
113113
// Calling .start() on a BLECharacteristic will cause it to be added to
114114
// the last BLEService that was 'start()'ed!
115-
115+
116116
// Configure the Heart Rate Measurement characteristic
117117
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.heart_rate_measurement.xml
118118
// Permission = Notify
@@ -170,7 +170,13 @@ void loop()
170170

171171
// Set the characteristic to use 8-bit values, with the sensor connected and detected
172172
uint8_t hrmdata[2] = { 0b00000110, bps++ };
173-
hrmc.write(hrmdata, sizeof(hrmdata));
173+
// Note: We use .notify instead of .write since this characteristic has
174+
// notify as a property!
175+
if (hrmc.notifyEnabled()) {
176+
hrmc.notify(hrmdata, sizeof(hrmdata));
177+
} else {
178+
hrmc.write(hrmdata, sizeof(hrmdata));
179+
}
174180
}
175181
}
176182

@@ -182,7 +188,7 @@ void connect_callback(void)
182188
void disconnect_callback(uint8_t reason)
183189
{
184190
(void) reason;
185-
191+
186192
Serial.println("Disconnected");
187-
Serial.println("Bluefruit will auto start advertising (default)");
193+
Serial.println("Advertising!");
188194
}

0 commit comments

Comments
 (0)