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.
This commit is contained in:
parent
47f873b038
commit
0febaa142a
2 changed files with 8 additions and 22 deletions
|
@ -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.disc_params = &sub_discover_params;
|
||||||
subscribe_params.end_handle = discover_params.end_handle;
|
subscribe_params.end_handle = discover_params.end_handle;
|
||||||
subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);
|
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.notify = split_central_notify_func;
|
||||||
subscribe_params.value = BT_GATT_CCC_NOTIFY;
|
subscribe_params.value = BT_GATT_CCC_NOTIFY;
|
||||||
split_central_subscribe(conn);
|
split_central_subscribe(conn);
|
||||||
|
} else if (!bt_uuid_cmp(((struct bt_gatt_chrc *)attr->user_data)->uuid,
|
||||||
memcpy(&uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID), sizeof(uuid));
|
BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID))) {
|
||||||
discover_params.uuid = &uuid.uuid;
|
LOG_DBG("Found run behavior handle");
|
||||||
discover_params.start_handle = attr->handle + 1;
|
run_behavior_handle = bt_gatt_attr_value_handle(attr);
|
||||||
discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
|
|
||||||
|
|
||||||
err = bt_gatt_discover(conn, &discover_params);
|
|
||||||
if (err) {
|
|
||||||
LOG_ERR("Discover failed (err %d)", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
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;
|
// Clean up previously discovered handles;
|
||||||
subscribe_params.value_handle = 0;
|
subscribe_params.value_handle = 0;
|
||||||
|
run_behavior_handle = 0;
|
||||||
|
|
||||||
start_scan();
|
start_scan();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DT_DRV_COMPAT zmk_split_listener
|
|
||||||
|
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <power/reboot.h>
|
#include <power/reboot.h>
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
|
|
Loading…
Reference in a new issue