Some debug output, and turn off BLE.wantScan when scanning starts.

This commit is contained in:
Greg 2019-10-25 09:09:54 -04:00
parent f53dd7481a
commit ec02bc7bcc
1 changed files with 8 additions and 9 deletions

View File

@ -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