2021-08-20 00:41:09 +00:00
|
|
|
package infinitime
|
|
|
|
|
|
|
|
import (
|
|
|
|
bt "github.com/muka/go-bluetooth/api"
|
|
|
|
"github.com/muka/go-bluetooth/bluez/profile/adapter"
|
|
|
|
)
|
|
|
|
|
|
|
|
var defaultAdapter *adapter.Adapter1
|
|
|
|
|
2021-11-01 16:19:12 +00:00
|
|
|
func Init() {
|
2021-08-20 00:41:09 +00:00
|
|
|
// Get bluez default adapter
|
|
|
|
da, err := bt.GetDefaultAdapter()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-09 15:34:56 +00:00
|
|
|
|
2021-11-01 16:19:12 +00:00
|
|
|
da.SetPowered(true)
|
2021-09-09 15:34:56 +00:00
|
|
|
|
2021-08-20 00:41:09 +00:00
|
|
|
defaultAdapter = da
|
|
|
|
}
|
|
|
|
|
|
|
|
func Exit() error {
|
2021-11-01 16:19:12 +00:00
|
|
|
if defaultAdapter != nil {
|
|
|
|
defaultAdapter.Close()
|
|
|
|
}
|
2021-08-20 00:41:09 +00:00
|
|
|
return bt.Exit()
|
2021-09-09 15:34:56 +00:00
|
|
|
}
|