From f26bd495ea0dad0a9b610752555ce428197e9cc8 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Aug 2020 14:51:42 -0500 Subject: Fix interval update, add PHY update --- app/src/split/bluetooth/central.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'app/src/split') diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index b6d7222..905cbd7 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -67,6 +67,13 @@ static u8_t split_central_notify_func(struct bt_conn *conn, } } + bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400)); + + struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + LOG_DBG("Interval: %d, Latency: %d, PHY: %d", info.le.interval, info.le.latency, info.le.phy->rx_phy); return BT_GATT_ITER_CONTINUE; } @@ -149,6 +156,12 @@ static void split_central_process_connection(struct bt_conn *conn) { return; } } + + struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + LOG_DBG("New connection params: Interval: %d, Latency: %d, PHY: %d", info.le.interval, info.le.latency, info.le.phy->rx_phy); } static bool split_central_eir_found(struct bt_data *data, void *user_data) @@ -199,13 +212,19 @@ static bool split_central_eir_found(struct bt_data *data, void *user_data) LOG_DBG("Found existing connection"); split_central_process_connection(default_conn); } else { - param = BT_LE_CONN_PARAM(0x0006, 0x000c, 5, 400); + param = BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400); err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &default_conn); if (err) { LOG_ERR("Create conn failed (err %d)", err); start_scan(); } + + err = bt_conn_le_phy_update(default_conn, BT_CONN_LE_PHY_PARAM_2M); + if (err) { + LOG_ERR("Update phy conn failed (err %d)", err); + start_scan(); + } } return false; -- cgit v1.3.1 From f23ca9d7ee7481ebdbbed3234e902e5b7753ae41 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 2 Aug 2020 15:51:38 -0500 Subject: Add two solutions to param updates --- app/src/ble.c | 29 +++++++++++++++++++++++++++++ app/src/split/bluetooth/central.c | 7 ------- 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'app/src/split') diff --git a/app/src/ble.c b/app/src/ble.c index 3a7755f..db80a36 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -76,10 +76,39 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, } } +static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param) { + static struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + if (info.role == BT_CONN_ROLE_MASTER && (param->interval_min != 6 || param->latency != 30)) { + return false; + } + + return true; +} + +static void le_param_updated(struct bt_conn *conn, u16_t interval, + u16_t latency, u16_t timeout) { + static struct bt_conn_info info; + + bt_conn_get_info(conn, &info); + + if (info.role == BT_CONN_ROLE_MASTER && (interval != 6 || latency != 30)) { + bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400)); + } + + LOG_DBG("Params updated: Interval: %d, Latency: %d", interval, latency); +}; + static struct bt_conn_cb conn_callbacks = { .connected = connected, .disconnected = disconnected, .security_changed = security_changed, +#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) + .le_param_req = le_param_req, + .le_param_updated = le_param_updated, +#endif }; static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 905cbd7..237096f 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -67,13 +67,6 @@ static u8_t split_central_notify_func(struct bt_conn *conn, } } - bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400)); - - struct bt_conn_info info; - - bt_conn_get_info(conn, &info); - - LOG_DBG("Interval: %d, Latency: %d, PHY: %d", info.le.interval, info.le.latency, info.le.phy->rx_phy); return BT_GATT_ITER_CONTINUE; } -- cgit v1.3.1