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

View File

@ -213,20 +213,18 @@ func (b *BLE) setState(x ns.CBManagerState) {
defer b.Unlock() defer b.Unlock()
b.state = x b.state = x
if b.ready && b.wantScan { if b.ready && b.wantScan {
go func() { fmt.Printf("Go: Scanning\n")
fmt.Printf("Go: Scanning\n") b.cm.ScanForPeripheralsWithServices(nil, nil)
b.cm.ScanForPeripheralsWithServices(nil, nil) b.wantScan = false
}()
} }
} }
func (b *BLE) Scan() { func (b *BLE) Scan() {
b.Lock() b.Lock()
defer b.Unlock()
if b.state != (ns.CBManagerState)(ns.CBManagerStatePoweredOn) { if b.state != (ns.CBManagerState)(ns.CBManagerStatePoweredOn) {
b.wantScan = true b.wantScan = true
b.Unlock()
} else { } else {
b.Unlock()
fmt.Printf("Go: Scanning\n") fmt.Printf("Go: Scanning\n")
b.cm.ScanForPeripheralsWithServices(nil, nil) b.cm.ScanForPeripheralsWithServices(nil, nil)
} }
@ -244,7 +242,8 @@ func (b *BLE) StopScan() {
} }
func connectTracker(b *BLE, x ConnectionListItem) { 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 { select {
case <-b.connections.close: case <-b.connections.close:
fmt.Printf("Closing connection to %s\n", x.p.Name) fmt.Printf("Closing connection to %s\n", x.p.Name)
@ -290,13 +289,13 @@ func (b *BLE) Connect(p Peripheral) {
b.connections.Add(item) b.connections.Add(item)
go connectTracker(b, item) go connectTracker(b, item)
//time.Sleep(time.Second/10) //time.Sleep(time.Second/10)
fmt.Printf("BLE.Connect(): calling cm.ConnectPeripheral(%p)\n", p.p.Ptr())
b.cm.ConnectPeripheral(p.p, nil) b.cm.ConnectPeripheral(p.p, nil)
fmt.Printf("cm.ConnectPeripheral() returned\n") fmt.Printf("BLE.Connect() returned\n")
} }
func updateState(c *ns.CBCentralManager) { func updateState(c *ns.CBCentralManager) {
b := cdLookup[c.Ptr()] b := cdLookup[c.Ptr()]
fmt.Printf("Go: did update state\n")
st := c.CBManager.State() st := c.CBManager.State()
if st == (ns.CBManagerState)(ns.CBManagerStatePoweredOn) { if st == (ns.CBManagerState)(ns.CBManagerStatePoweredOn) {
b.ready = true b.ready = true