49f8082e4b
There used to be GAP events (connect/disconnect). The main purpose for these events was to allow applications to re-start advertisement when a connection was lost - on nrf. Unfortunately things work differently on Linux, which already has this behavior and for which I haven't yet implemented these events. Therefore I have removed these events and instead added code to automatically restart advertisement on connection loss. Supporting multiple (incoming) connections as a peripheral would be useful, but is not currently supported.
35 lines
827 B
Go
35 lines
827 B
Go
// +build !baremetal
|
|
|
|
package bluetooth
|
|
|
|
import (
|
|
"github.com/muka/go-bluetooth/api"
|
|
"github.com/muka/go-bluetooth/bluez/profile/adapter"
|
|
)
|
|
|
|
type Adapter struct {
|
|
adapter *adapter.Adapter1
|
|
id string
|
|
cancelScan func()
|
|
defaultAdvertisement *Advertisement
|
|
}
|
|
|
|
// 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{}
|
|
|
|
// Enable configures the BLE stack. It must be called before any
|
|
// Bluetooth-related calls (unless otherwise indicated).
|
|
func (a *Adapter) Enable() (err error) {
|
|
if a.id == "" {
|
|
a.adapter, err = api.GetDefaultAdapter()
|
|
if err != nil {
|
|
return
|
|
}
|
|
a.id, err = a.adapter.GetAdapterID()
|
|
}
|
|
return nil
|
|
}
|