func NewGonashi() (Gonashi, error) { device, err := gatt.NewDevice(ClientOptions...) if err != nil { return Gonashi{}, err } dp := discovered{ konashiMap{ sync.RWMutex{}, map[string]*Konashi{}, channels.NewOverflowingChannel(1)}, make(chan struct{}), } cn := konashiMap{ sync.RWMutex{}, map[string]*Konashi{}, channels.NewOverflowingChannel(1), } g := Gonashi{device, &dp, &cn} g.device.Handle( gatt.PeripheralDiscovered(g.onPeriphDiscovered), gatt.PeripheralConnected(g.onPeriphConnected), gatt.PeripheralDisconnected(g.onPeriphDisconnected), ) device.Init(func(d gatt.Device, s gatt.State) {}) return g, nil }
func main() { d, err := gatt.NewDevice(option.DefaultClientOptions...) if err != nil { log.Fatalf("Failed to open device, err: %s\n", err) return } // Register handlers. d.Handle(gatt.PeripheralDiscovered(onPeriphDiscovered)) d.Init(onStateChanged) select {} }
func main() { flag.Parse() if len(flag.Args()) != 1 { log.Fatalf("usage: %s [options] peripheral-id\n", os.Args[0]) } d, err := gatt.NewDevice(option.DefaultClientOptions...) if err != nil { log.Fatalf("Failed to open device, err: %s\n", err) return } // Register handlers. d.Handle( gatt.PeripheralDiscovered(onPeriphDiscovered), gatt.PeripheralConnected(onPeriphConnected), gatt.PeripheralDisconnected(onPeriphDisconnected), ) d.Init(onStateChanged) <-done fmt.Println("Done") }