diff --git a/device/prj.conf b/device/prj.conf index 079dbf37..cfc45635 100644 --- a/device/prj.conf +++ b/device/prj.conf @@ -17,8 +17,8 @@ CONFIG_NCS_SAMPLES_DEFAULTS=y CONFIG_BT=y # CONFIG_BT_DEBUG_LOG=y -CONFIG_BT_MAX_CONN=2 -CONFIG_BT_MAX_PAIRED=2 +CONFIG_BT_MAX_CONN=4 +CONFIG_BT_MAX_PAIRED=20 CONFIG_BT_SMP=y CONFIG_BT_L2CAP_TX_BUF_COUNT=5 CONFIG_BT_PERIPHERAL=y diff --git a/device/src/bt_conn.c b/device/src/bt_conn.c index 47f72d04..ff468361 100644 --- a/device/src/bt_conn.c +++ b/device/src/bt_conn.c @@ -131,7 +131,6 @@ static void assignPeer(const bt_addr_le_t *addr, int8_t peerId) { char addrString[32]; bt_addr_le_to_str(addr, addrString, sizeof(addrString)); printk("Peer slot %s already occupied. Overwriting with address %s\n", Peers[peerId].name, addrString); - return; } Peers[peerId].addr = *addr; Peers[peerId].isConnected = true; @@ -155,27 +154,31 @@ static void connected(struct bt_conn *conn, uint8_t err) { printk("Bt connected to %s\n", GetPeerStringByConn(conn)); + if (peerId == PeerIdUnknown || peerId == PeerIdHid) { + static const struct bt_le_conn_param conn_params = BT_LE_CONN_PARAM_INIT( + 6, 9, // keep it low, lowest allowed is 6 (7.5ms), lowest supported widely is 9 (11.25ms) + 10, // keeping it higher allows power saving on peripheral when there's nothing to send (keep it under 30 though) + 100 // connection timeout (*10ms) + ); + bt_conn_le_param_update(conn, &conn_params); + } + if (peerId == PeerIdUnknown) { - peerId = PeerIdHid; + return; } assignPeer(bt_conn_get_dst(conn), peerId); if (peerId == PeerIdHid) { - if (DEVICE_IS_UHK80_RIGHT) { - static const struct bt_le_conn_param conn_params = BT_LE_CONN_PARAM_INIT( - 6, 9, // keep it low, lowest allowed is 6 (7.5ms), lowest supported widely is 9 (11.25ms) - 10, // keeping it higher allows power saving on peripheral when there's nothing to send (keep it under 30 though) - 100 // connection timeout (*10ms) - ); - bt_conn_le_param_update(conn, &conn_params); - - USB_DisableHid(); - } + // USB_DisableHid(); } else { bt_conn_set_security(conn, BT_SECURITY_L4); // continue connection process in in `connectionSecured()` } + + if (DEVICE_IS_UHK80_RIGHT && (peerId == PeerIdHid || peerId == PeerIdUnknown || peerId == PeerIdDongle)) { + BtAdvertise_Start(BtAdvertise_Type()); + } } static void disconnected(struct bt_conn *conn, uint8_t reason) { @@ -188,7 +191,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) { if (DEVICE_IS_UHK80_RIGHT) { if (peerId == PeerIdHid || peerId == PeerIdUnknown) { BtAdvertise_Start(BtAdvertise_Type()); - USB_EnableHid(); + // USB_EnableHid(); } if (peerId == PeerIdDongle) { BtAdvertise_Start(BtAdvertise_Type()); @@ -203,7 +206,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) { } if (DEVICE_IS_UHK80_LEFT && peerId == PeerIdRight) { - BtScan_Start(); + BtAdvertise_Start(BtAdvertise_Type()); } } diff --git a/right/src/host_connection.c b/right/src/host_connection.c index f5a9ef84..14b340d8 100644 --- a/right/src/host_connection.c +++ b/right/src/host_connection.c @@ -1,6 +1,7 @@ #include "host_connection.h" #ifdef __ZEPHYR__ +#include "bt_conn.h" host_connection_t HostConnections[HOST_CONNECTION_COUNT_MAX] = {}; @@ -21,6 +22,13 @@ bool HostConnections_IsKnownBleAddress(const bt_addr_le_t *address) { break; } } + + for (int peerIdx = 0; peerIdx < PeerIdHid; peerIdx++) { + if (bt_addr_le_cmp(address, &Peers[peerIdx].addr) == 0) { + return true; + } + } + return false; }