allow notification of sensor values
This commit is contained in:
@ -20,11 +20,7 @@
|
|||||||
LOG_MODULE_DECLARE(main, CONFIG_APP_LOG_LEVEL);
|
LOG_MODULE_DECLARE(main, CONFIG_APP_LOG_LEVEL);
|
||||||
|
|
||||||
static sensors_raw_t sensors;
|
static sensors_raw_t sensors;
|
||||||
|
static struct bt_gatt_indicate_params ind_params;
|
||||||
void set_sensors(const sensors_raw_t *values)
|
|
||||||
{
|
|
||||||
sensors = *values;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback definitions
|
// Callback definitions
|
||||||
static ssize_t read_sensors(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
|
static ssize_t read_sensors(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf,
|
||||||
@ -47,14 +43,24 @@ static ssize_t read_string(struct bt_conn *conn, const struct bt_gatt_attr *attr
|
|||||||
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, strlen((char *)attr->user_data));
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, attr->user_data, strlen((char *)attr->user_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
BT_GATT_SERVICE_DEFINE(my_lbs_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_IMU),
|
static void myimu_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(attr);
|
||||||
|
|
||||||
|
bool notif_enabled = (value == BT_GATT_CCC_NOTIFY);
|
||||||
|
|
||||||
|
LOG_INF("IMU Notifications %s", notif_enabled ? "enabled" : "disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
BT_GATT_SERVICE_DEFINE(my_imu_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_IMU),
|
||||||
// Read raw sensor values
|
// Read raw sensor values
|
||||||
BT_GATT_CHARACTERISTIC(BT_UUID_IMU_SENSORS,
|
BT_GATT_CHARACTERISTIC(BT_UUID_IMU_SENSORS,
|
||||||
BT_GATT_CHRC_READ,
|
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
|
||||||
BT_GATT_PERM_READ,
|
BT_GATT_PERM_READ,
|
||||||
read_sensors,
|
read_sensors,
|
||||||
NULL,
|
NULL,
|
||||||
&sensors),
|
&sensors),
|
||||||
|
BT_GATT_CCC(myimu_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
|
||||||
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD,
|
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD,
|
||||||
BT_GATT_PERM_READ,
|
BT_GATT_PERM_READ,
|
||||||
read_string,
|
read_string,
|
||||||
@ -62,3 +68,12 @@ BT_GATT_SERVICE_DEFINE(my_lbs_svc, BT_GATT_PRIMARY_SERVICE(BT_UUID_IMU),
|
|||||||
"Read raw sensor values"),
|
"Read raw sensor values"),
|
||||||
// TODO: add characteristic to read state estimate
|
// TODO: add characteristic to read state estimate
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void set_sensors(const sensors_raw_t *values)
|
||||||
|
{
|
||||||
|
sensors = *values;
|
||||||
|
|
||||||
|
int rc = bt_gatt_notify(NULL, &my_imu_svc.attrs[1], &sensors, sizeof(sensors));
|
||||||
|
|
||||||
|
// return rc == -ENOTCONN ? 0 : rc;
|
||||||
|
}
|
Reference in New Issue
Block a user