bluetooth/adapter_linux.go
Ayke van Laethem 0474d7b750
all: change DefaultAdapter function to global
All initialization can be done in the Enable call. This makes the API a
bit simpler and a bit more consistent between Nordic chips and other BLE
interfaces.
2020-06-01 13:27:56 +02:00

35 lines
784 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
handler func(Event)
cancelScan func()
}
// 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
}