Create Init() rather than using init()

This commit is contained in:
Elara 2021-11-01 09:19:12 -07:00
parent a19fedf763
commit 52b05385a3

View File

@ -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()
}