From 85e230585a612f06647a8f9f88df24022e9302d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Sun, 3 Nov 2024 13:20:08 +0100 Subject: [PATCH] linux: Allow users to choose between different adapters --- adapter_linux.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/adapter_linux.go b/adapter_linux.go index 8eac7083..2e49b80d 100644 --- a/adapter_linux.go +++ b/adapter_linux.go @@ -26,15 +26,21 @@ type Adapter struct { connectHandler func(device Device, connected bool) } +// NewAdapter creates a new Adapter with the given ID. +// +// Make sure to call Enable() before using it to initialize the adapter. +func NewAdapter(id string) *Adapter { + return &Adapter{ + id: id, + connectHandler: func(device Device, connected bool) {}, + } +} + // DefaultAdapter is the default adapter on the system. On Linux, it is the // first adapter available. // // Make sure to call Enable() before using it to initialize the adapter. -var DefaultAdapter = &Adapter{ - id: defaultAdapter, - connectHandler: func(device Device, connected bool) { - }, -} +var DefaultAdapter = NewAdapter(defaultAdapter) // Enable configures the BLE stack. It must be called before any // Bluetooth-related calls (unless otherwise indicated).