allow notification of sensor values
Some checks failed
Build / Build (push) Failing after 4m26s
Build / build (ubuntu-22.04) (push) Failing after 51s
Documentation / build (push) Failing after -58s

This commit is contained in:
2025-06-02 22:53:18 -06:00
parent 1f024f477a
commit 8d0aa8941e

View File

@ -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;
}