samples: Bluetooth: periph_hr: add use of HRS nofitication changed cb
Add example usage of the HRS notification callback to peripheral_hr. Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
This commit is contained in:
parent
4d0ef142f3
commit
cb8d623506
1 changed files with 25 additions and 1 deletions
|
@ -22,6 +22,8 @@
|
|||
#include <zephyr/bluetooth/services/bas.h>
|
||||
#include <zephyr/bluetooth/services/hrs.h>
|
||||
|
||||
static bool hrf_ntf_enabled;
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_UUID16_ALL,
|
||||
|
@ -49,6 +51,25 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
|
|||
.disconnected = disconnected,
|
||||
};
|
||||
|
||||
static void hrs_ntf_changed(bool enabled)
|
||||
{
|
||||
hrf_ntf_enabled = enabled;
|
||||
|
||||
printk("HRS notification status changed: %s\n", enabled ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static struct bt_hrs_cb hrs_cb = {
|
||||
.ntf_changed = hrs_ntf_changed,
|
||||
};
|
||||
|
||||
/** @brief Heart rate service callback register
|
||||
*
|
||||
* This function will register callbacks that will be called in
|
||||
* certain events related to Heart rate service.
|
||||
*
|
||||
* @param cb Pointer to callbacks structure
|
||||
*/
|
||||
|
||||
static void bt_ready(void)
|
||||
{
|
||||
int err;
|
||||
|
@ -100,8 +121,10 @@ static void hrs_notify(void)
|
|||
heartrate = 90U;
|
||||
}
|
||||
|
||||
if (hrf_ntf_enabled) {
|
||||
bt_hrs_notify(heartrate);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
@ -117,6 +140,7 @@ int main(void)
|
|||
|
||||
bt_conn_auth_cb_register(&auth_cb_display);
|
||||
|
||||
bt_hrs_cb_register(&hrs_cb);
|
||||
/* Implement notification. At the moment there is no suitable way
|
||||
* of starting delayed work so we do it here
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue