From ec02bc7bcc2b1a53e0a69d255000d5d7eb76c460 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 25 Oct 2019 09:09:54 -0400 Subject: [PATCH] Some debug output, and turn off BLE.wantScan when scanning starts. --- ble_darwin.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ble_darwin.go b/ble_darwin.go index 2007292..5607b77 100644 --- a/ble_darwin.go +++ b/ble_darwin.go @@ -213,20 +213,18 @@ func (b *BLE) setState(x ns.CBManagerState) { defer b.Unlock() b.state = x if b.ready && b.wantScan { - go func() { - fmt.Printf("Go: Scanning\n") - b.cm.ScanForPeripheralsWithServices(nil, nil) - }() + fmt.Printf("Go: Scanning\n") + b.cm.ScanForPeripheralsWithServices(nil, nil) + b.wantScan = false } } func (b *BLE) Scan() { b.Lock() + defer b.Unlock() if b.state != (ns.CBManagerState)(ns.CBManagerStatePoweredOn) { b.wantScan = true - b.Unlock() } else { - b.Unlock() fmt.Printf("Go: Scanning\n") b.cm.ScanForPeripheralsWithServices(nil, nil) } @@ -244,7 +242,8 @@ func (b *BLE) StopScan() { } func connectTracker(b *BLE, x ConnectionListItem) { - tick := time.NewTicker(time.Second * 30) + fmt.Printf("connectTracker(): %s\n", x.p.Name) + tick := time.NewTicker(time.Second * 5) select { case <-b.connections.close: fmt.Printf("Closing connection to %s\n", x.p.Name) @@ -290,13 +289,13 @@ func (b *BLE) Connect(p Peripheral) { b.connections.Add(item) go connectTracker(b, item) //time.Sleep(time.Second/10) + fmt.Printf("BLE.Connect(): calling cm.ConnectPeripheral(%p)\n", p.p.Ptr()) b.cm.ConnectPeripheral(p.p, nil) - fmt.Printf("cm.ConnectPeripheral() returned\n") + fmt.Printf("BLE.Connect() returned\n") } func updateState(c *ns.CBCentralManager) { b := cdLookup[c.Ptr()] - fmt.Printf("Go: did update state\n") st := c.CBManager.State() if st == (ns.CBManagerState)(ns.CBManagerStatePoweredOn) { b.ready = true