2020-05-30 21:55:20 +03:00
|
|
|
package bluetooth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-ole/go-ole"
|
2020-09-09 16:51:38 +03:00
|
|
|
"tinygo.org/x/bluetooth/winbt"
|
2020-05-30 21:55:20 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Adapter struct {
|
|
|
|
watcher *winbt.IBluetoothLEAdvertisementWatcher
|
2020-09-10 18:17:45 +03:00
|
|
|
|
|
|
|
connectHandler func(device Addresser, connected bool)
|
2020-05-30 21:55:20 +03:00
|
|
|
}
|
|
|
|
|
2020-06-01 14:26:45 +03:00
|
|
|
// DefaultAdapter is the default adapter on the system.
|
|
|
|
//
|
|
|
|
// Make sure to call Enable() before using it to initialize the adapter.
|
2020-09-10 18:17:45 +03:00
|
|
|
var DefaultAdapter = &Adapter{
|
|
|
|
connectHandler: func(device Addresser, connected bool) {
|
|
|
|
return
|
|
|
|
},
|
|
|
|
}
|
2020-05-30 21:55:20 +03:00
|
|
|
|
|
|
|
// Enable configures the BLE stack. It must be called before any
|
|
|
|
// Bluetooth-related calls (unless otherwise indicated).
|
|
|
|
func (a *Adapter) Enable() error {
|
|
|
|
return ole.RoInitialize(1) // initialize with multithreading enabled
|
|
|
|
}
|