mirror of https://github.com/zmkfirmware/zmk.git
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:
parent
bc6bb90414
commit
e6343f44ce
|
|
@ -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 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
s/^d_03: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/peripheral 0 /p
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
CONFIG_ZMK_SPLIT=y
|
||||
CONFIG_ZMK_HID_INDICATORS=y
|
||||
CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS=y
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include <behaviors.dtsi>
|
||||
#include <dt-bindings/zmk/bt.h>
|
||||
#include <dt-bindings/zmk/keys.h>
|
||||
|
||||
&kscan {
|
||||
/delete-property/ exit-after;
|
||||
events = <>;
|
||||
};
|
||||
/ {
|
||||
keymap {
|
||||
compatible = "zmk,keymap";
|
||||
|
||||
default_layer {
|
||||
bindings = <
|
||||
&kp A &kp B
|
||||
&kp C &kp D>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
#include <dt-bindings/zmk/kscan_mock.h>
|
||||
|
||||
|
||||
&kscan {
|
||||
/delete-property/ exit-after;
|
||||
events = <>;
|
||||
};
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
./ble_test_central.exe -d=2 -wait_on_start=1300 -write_hid_indicators_on_discovery
|
||||
./tests_ble_split_set-hid-indicators_peripheral.exe -d=3
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
peripheral 0 OS build 702e50c58f67 ***
|
||||
peripheral 0 <inf> bt_hci_core: HW Platform: Nordic Semiconductor (0x0002)
|
||||
peripheral 0 <inf> bt_hci_core: HW Variant: nRF52x (0x0002)
|
||||
peripheral 0 <inf> bt_hci_core: Firmware: Standard Bluetooth controller (0x00) Version 3.5 Build 0
|
||||
peripheral 0 <wrn> bt_id: No static addresses stored in controller
|
||||
peripheral 0 <inf> bt_hci_core: Identity: D1:0B:03:A3:ED:6F (random)
|
||||
peripheral 0 <inf> bt_hci_core: HCI: version 5.4 (0x0d) revision 0x0000, manufacturer 0x05f1
|
||||
peripheral 0 <inf> bt_hci_core: LMP: version 5.4 (0x0d) subver 0xffff
|
||||
peripheral 0 <inf> zmk: Welcome to ZMK!
|
||||
peripheral 0 <dbg> zmk: security_changed: Security changed: FD:9E:B2:48:47:39 (random) level 2
|
||||
peripheral 0 <dbg> zmk: split_svc_pos_state_ccc: value 1
|
||||
peripheral 0 <dbg> zmk: split_svc_select_phys_layout_callback: Selecting physical layout after GATT write of 0
|
||||
peripheral 0 <dbg> zmk: split_svc_update_indicators_callback: Raising HID indicators changed event: 7
|
||||
Loading…
Reference in New Issue