summaryrefslogtreecommitdiff
path: root/app/src/split/bluetooth/central.c
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2021-01-12 10:49:00 -0500
committerNick Van Doorn <nick@nv.delivery>2021-11-26 09:59:03 -0800
commit8a04dcbdc7479c69df734a049ce55d9656cd9b99 (patch)
tree2a192b8c29b427133da1f5912d570a76b05cbf3a /app/src/split/bluetooth/central.c
parent4e4faca67015df3a3e1bf1b9937265f465c5093d (diff)
refactor(split): Clean up split GATT discovery.
* Use Zephyr auto CCC discovery instead of doing it ourselves. * Split service versus characteristic discovery into dedicated steps in the flow. * Fix for not searching properly when connecting to a peripheral a second time.
Diffstat (limited to 'app/src/split/bluetooth/central.c')
-rw-r--r--app/src/split/bluetooth/central.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c
index 5ac4f83..d123f4e 100644
--- a/app/src/split/bluetooth/central.c
+++ b/app/src/split/bluetooth/central.c
@@ -129,31 +129,18 @@ static uint8_t split_central_chrc_discovery_func(struct bt_conn *conn,
subscribe_params.disc_params = &sub_discover_params;
subscribe_params.end_handle = discover_params.end_handle;
subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);
-
- err = bt_gatt_discover(conn, &discover_params);
- if (err) {
- LOG_ERR("Discover failed (err %d)", err);
- }
- } else if (!bt_uuid_cmp(discover_params.uuid,
- BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID))) {
- run_behavior_handle = bt_gatt_attr_value_handle(attr);
- } else {
subscribe_params.notify = split_central_notify_func;
subscribe_params.value = BT_GATT_CCC_NOTIFY;
split_central_subscribe(conn);
-
- memcpy(&uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID), sizeof(uuid));
- discover_params.uuid = &uuid.uuid;
- discover_params.start_handle = attr->handle + 1;
- discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
-
- err = bt_gatt_discover(conn, &discover_params);
- if (err) {
- LOG_ERR("Discover failed (err %d)", err);
- }
+ } else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid,
+ BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID))) {
+ LOG_DBG("Found run behavior handle");
+ run_behavior_handle = bt_gatt_attr_value_handle(attr);
}
- return subscribe_params.value_handle ? BT_GATT_ITER_STOP : BT_GATT_ITER_CONTINUE;
+ bool subscribed = (run_behavior_handle && subscribe_params.value_handle);
+
+ return subscribed ? BT_GATT_ITER_STOP : BT_GATT_ITER_CONTINUE;
}
static uint8_t split_central_service_discovery_func(struct bt_conn *conn,
@@ -355,6 +342,7 @@ static void split_central_disconnected(struct bt_conn *conn, uint8_t reason) {
// Clean up previously discovered handles;
subscribe_params.value_handle = 0;
+ run_behavior_handle = 0;
start_scan();
}