Create Init() rather than using init()

This commit is contained in:
Elara 2021-11-01 09:19:12 -07:00
parent 75942bdb0c
commit 7fb1fcce68

View File

@ -1,27 +1,27 @@
package infinitime package infinitime
import ( import (
"os/exec"
bt "github.com/muka/go-bluetooth/api" bt "github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile/adapter" "github.com/muka/go-bluetooth/bluez/profile/adapter"
) )
var defaultAdapter *adapter.Adapter1 var defaultAdapter *adapter.Adapter1
func init() { func Init() {
// Get bluez default adapter // Get bluez default adapter
da, err := bt.GetDefaultAdapter() da, err := bt.GetDefaultAdapter()
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Power on command (workaround as go-bluetooth does not have a power on function) da.SetPowered(true)
exec.Command("bluetoothctl", "power", "on").Start()
defaultAdapter = da defaultAdapter = da
} }
func Exit() error { func Exit() error {
if defaultAdapter != nil {
defaultAdapter.Close()
}
return bt.Exit() return bt.Exit()
} }