Skip to content

Commit

Permalink
Implement connection manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
kareltucek committed Dec 15, 2024
1 parent 2734a11 commit b348832
Show file tree
Hide file tree
Showing 43 changed files with 1,151 additions and 311 deletions.
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ function processArguments() {
DEVICES="$DEVICES uhk-80-left uhk-80-right uhk-dongle"
shift
;;
clean|setup|update|build|make|flash|flashUsb|shell|release)
clean|setup|update|build|make|flash|shell|release)
ACTIONS="$ACTIONS $1"
TARGET_TMUX_SESSION=$BUILD_SESSION_NAME
shift
;;
flashUsb)
ACTIONS="$ACTIONS make $1"
TARGET_TMUX_SESSION=$BUILD_SESSION_NAME
shift
;;
addrline)
shift
ADDR=$1
Expand Down Expand Up @@ -357,7 +362,7 @@ function run() {
if [ `echo $DEVICES | wc -w` -gt 1 ]
then
runPerDevice
elif [ `echo $DEVICES | wc -w` -eq 0 ]
elif [ `echo $DEVICES | wc -w` -le 1 ]
then
performActions $DEVICES
else
Expand Down
2 changes: 2 additions & 0 deletions device/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=5
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="UHK 80"
CONFIG_BT_DEVICE_APPEARANCE=961
CONFIG_BT_CTLR_SDC_PERIPHERAL_COUNT=3
CONFIG_BT_FILTER_ACCEPT_LIST=y

CONFIG_BT_BAS=y

Expand Down
29 changes: 28 additions & 1 deletion device/src/bt_advertise.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "bt_advertise.h"
#include <bluetooth/services/nus.h>
#include <zephyr/bluetooth/gatt.h>
#include "bt_conn.h"
#include "connections.h"
#include "device.h"
#include "legacy/event_scheduler.h"

#undef DEVICE_NAME
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
Expand Down Expand Up @@ -38,8 +41,26 @@ static const struct bt_data sdHid[] = {SD_HID_DATA};

static const struct bt_data sdNusHid[] = {SD_NUS_DATA SD_HID_DATA};

static struct bt_le_adv_param advertisementParams[] = BT_LE_ADV_CONN;

static void setFilters() {
bt_le_filter_accept_list_clear();
if (DEVICE_IS_UHK80_RIGHT) {
if (BtConn_UnusedPeripheralConnectionCount() <= 1 && SelectedHostConnectionId != ConnectionId_Invalid) {
printk("Setting an advertising filter to connection %d\n", SelectedHostConnectionId);
bt_le_filter_accept_list_add(&HostConnection(SelectedHostConnectionId)->bleAddress);
advertisementParams->options = BT_LE_ADV_OPT_FILTER_CONN;
} else {
printk("Setting no advertising filter\n");
advertisementParams->options = BT_LE_ADV_OPT_NONE;
}
}
}

void BtAdvertise_Start(uint8_t adv_type)
{
setFilters();

int err;
const char *adv_type_string;
if (adv_type == (ADVERTISE_NUS | ADVERTISE_HID)) {
Expand All @@ -63,6 +84,8 @@ void BtAdvertise_Start(uint8_t adv_type)
printk("%s advertising continued\n", adv_type_string);
} else {
printk("%s advertising failed to start (err %d)\n", adv_type_string, err);
BtConn_ReviseConnections();
EventScheduler_Schedule(CurrentTime + 1000, EventSchedulerEvent_BtStartAdvertisement, "BtStartAdvertisement");
}
}

Expand All @@ -80,7 +103,11 @@ uint8_t BtAdvertise_Type() {
case DeviceId_Uhk80_Left:
return ADVERTISE_NUS;
case DeviceId_Uhk80_Right:
return ADVERTISE_NUS | ADVERTISE_HID;
if (BtConn_UnusedPeripheralConnectionCount() > 0) {
return ADVERTISE_NUS | ADVERTISE_HID;
} else {
return 0;
}
case DeviceId_Uhk_Dongle:
return 0;
default:
Expand Down
Loading

0 comments on commit b348832

Please sign in to comment.