summaryrefslogtreecommitdiff
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-22 08:42:14 -0800
commit139db2b53d42e24e75232f8c76e83af4c93b1929 (patch)
tree2a192b8c29b427133da1f5912d570a76b05cbf3a
parentfd609695ae510344c5dbb88f1d253565bd588ea3 (diff)
refactor(split): Clean up split GATT discovery.core/peripheral-behavior-invocation
* 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.
-rw-r--r--app/src/split/bluetooth/central.c28
-rw-r--r--app/src/split_listener.c2
2 files changed, 8 insertions, 22 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();
}
diff --git a/app/src/split_listener.c b/app/src/split_listener.c
index 8ac56c9..01cd89d 100644
--- a/app/src/split_listener.c
+++ b/app/src/split_listener.c
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: MIT
*/
-#define DT_DRV_COMPAT zmk_split_listener
-
#include <device.h>
#include <power/reboot.h>
#include <logging/log.h>