Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Fix some pairing-related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
kareltucek committed Nov 13, 2024
1 parent 28b254f commit 378575a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions device/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions device/src/bt_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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());
Expand All @@ -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());
}
}

Expand Down
8 changes: 8 additions & 0 deletions right/src/host_connection.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "host_connection.h"
#include "bt_conn.h"

#ifdef __ZEPHYR__

Expand All @@ -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;
}

Expand Down

0 comments on commit 378575a

Please sign in to comment.