forked from kofal.net/zmk
test(split): Test split HID indicator setting. (#2747)
Add integration test for HID indicator state being propagated to split peripherals.
This commit is contained in:
@@ -44,6 +44,7 @@ static bool read_hid_report_on_connect = false;
|
||||
static bool skip_set_security_on_connect = false;
|
||||
static bool skip_discovery_on_connect = false;
|
||||
static bool read_directly_on_discovery = false;
|
||||
static bool write_hid_indicators_on_discovery = false;
|
||||
static int32_t wait_on_start = 0;
|
||||
|
||||
static void ble_central_native_posix_options(void) {
|
||||
@@ -83,6 +84,11 @@ static void ble_central_native_posix_options(void) {
|
||||
.type = 'b',
|
||||
.dest = (void *)&read_directly_on_discovery,
|
||||
.descript = "Read HIDS report after GATT characteristic discovery"},
|
||||
{.is_switch = true,
|
||||
.option = "write_hid_indicators_on_discovery",
|
||||
.type = 'b',
|
||||
.dest = (void *)&write_hid_indicators_on_discovery,
|
||||
.descript = "Write HIDS indecator report after GATT characteristic discovery"},
|
||||
{.option = "wait_on_start",
|
||||
.name = "milliseconds",
|
||||
.type = 'u',
|
||||
@@ -97,7 +103,7 @@ NATIVE_TASK(ble_central_native_posix_options, PRE_BOOT_1, 1);
|
||||
|
||||
#endif
|
||||
|
||||
static void start_scan(void);
|
||||
static int start_scan(void);
|
||||
|
||||
static struct bt_conn *default_conn;
|
||||
|
||||
@@ -140,25 +146,21 @@ static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *at
|
||||
|
||||
LOG_DBG("[ATTRIBUTE] handle %u", attr->handle);
|
||||
|
||||
if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HIDS)) {
|
||||
memcpy(&uuid, BT_UUID_HIDS_REPORT, sizeof(uuid));
|
||||
discover_params.uuid = &uuid.uuid;
|
||||
discover_params.start_handle = attr->handle + 1;
|
||||
discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;
|
||||
bool find_next_hids_report = false;
|
||||
|
||||
err = bt_gatt_discover(conn, &discover_params);
|
||||
if (err) {
|
||||
LOG_DBG("[Discover failed] (err %d)", err);
|
||||
}
|
||||
if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HIDS)) {
|
||||
find_next_hids_report = true;
|
||||
} else if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HIDS_REPORT)) {
|
||||
if (read_directly_on_discovery) {
|
||||
if (read_directly_on_discovery && !read_params.single.handle) {
|
||||
read_params.single.handle = bt_gatt_attr_value_handle(attr);
|
||||
read_params.single.offset = 0;
|
||||
read_params.handle_count = 1;
|
||||
read_params.func = read_cb;
|
||||
|
||||
bt_gatt_read(conn, &read_params);
|
||||
} else {
|
||||
|
||||
find_next_hids_report = write_hid_indicators_on_discovery;
|
||||
} else if (!subscribe_params.value_handle) {
|
||||
memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid));
|
||||
discover_params.uuid = &uuid.uuid;
|
||||
discover_params.start_handle = attr->handle + 2;
|
||||
@@ -169,8 +171,17 @@ static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *at
|
||||
if (err) {
|
||||
LOG_DBG("[Discover failed] (err %d)", err);
|
||||
}
|
||||
} else {
|
||||
uint8_t indicators = 0b00000111;
|
||||
int resp = bt_gatt_write_without_response(conn, bt_gatt_attr_value_handle(attr),
|
||||
&indicators, 1, true);
|
||||
if (resp < 0) {
|
||||
LOG_ERR("Failed to write %d", resp);
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_CONTINUE;
|
||||
}
|
||||
} else {
|
||||
} else if (discover_params.type == BT_GATT_DISCOVER_DESCRIPTOR) {
|
||||
subscribe_params.notify = notify_func;
|
||||
subscribe_params.value = BT_GATT_CCC_NOTIFY;
|
||||
subscribe_params.ccc_handle = attr->handle;
|
||||
@@ -182,7 +193,19 @@ static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *at
|
||||
LOG_DBG("[SUBSCRIBED]");
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
find_next_hids_report = write_hid_indicators_on_discovery;
|
||||
}
|
||||
|
||||
if (find_next_hids_report) {
|
||||
memcpy(&uuid, BT_UUID_HIDS_REPORT, 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_DBG("[Discover failed] (err %d)", err);
|
||||
}
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
@@ -264,7 +287,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
|
||||
}
|
||||
}
|
||||
|
||||
static void start_scan(void) {
|
||||
static int start_scan(void) {
|
||||
int err;
|
||||
|
||||
/* Use active scanning and disable duplicate filtering to handle any
|
||||
@@ -279,10 +302,11 @@ static void start_scan(void) {
|
||||
err = bt_le_scan_start(&scan_param, device_found);
|
||||
if (err) {
|
||||
LOG_DBG("[Scanning failed to start] (err %d)", err);
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
|
||||
LOG_DBG("[Scanning successfully started]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void discover_conn(struct bt_conn *conn) {
|
||||
@@ -401,7 +425,7 @@ struct bt_conn_auth_info_cb auth_info_cb = {
|
||||
.pairing_complete = pairing_complete,
|
||||
};
|
||||
|
||||
void main(void) {
|
||||
int main(void) {
|
||||
int err;
|
||||
|
||||
if (wait_on_start > 0) {
|
||||
@@ -414,10 +438,10 @@ void main(void) {
|
||||
|
||||
if (err) {
|
||||
LOG_DBG("[Bluetooth init failed] (err %d)", err);
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
|
||||
LOG_DBG("[Bluetooth initialized]");
|
||||
|
||||
start_scan();
|
||||
return start_scan();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user