forked from Elara6331/infinitime
Create Init() rather than using init()
This commit is contained in:
parent
75942bdb0c
commit
7fb1fcce68
10
btsetup.go
10
btsetup.go
@ -1,27 +1,27 @@
|
||||
package infinitime
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
bt "github.com/muka/go-bluetooth/api"
|
||||
"github.com/muka/go-bluetooth/bluez/profile/adapter"
|
||||
)
|
||||
|
||||
var defaultAdapter *adapter.Adapter1
|
||||
|
||||
func init() {
|
||||
func Init() {
|
||||
// Get bluez default adapter
|
||||
da, err := bt.GetDefaultAdapter()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Power on command (workaround as go-bluetooth does not have a power on function)
|
||||
exec.Command("bluetoothctl", "power", "on").Start()
|
||||
da.SetPowered(true)
|
||||
|
||||
defaultAdapter = da
|
||||
}
|
||||
|
||||
func Exit() error {
|
||||
if defaultAdapter != nil {
|
||||
defaultAdapter.Close()
|
||||
}
|
||||
return bt.Exit()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user