From 56813159c4231ed79fbc08de9378a8eb9b87e0b7 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 10 Dec 2019 09:04:58 -0500 Subject: [PATCH] Bug fix: save java peripheral object in goOnConnect(). --- ble_android.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ble_android.go b/ble_android.go index ca39f74..8b4b773 100644 --- a/ble_android.go +++ b/ble_android.go @@ -277,7 +277,7 @@ func goOnScan(cname, cid *C.char, rssi C.int, dev C.jobject) { func goOnConnect(p C.jobject, cid *C.char) { id := C.GoString(cid) - peripheral := gBLE.retrievePeripheral(id) + peripheral := gBLE.retrievePeripheral(id, p) if peripheral.peripheral == 0 { log.Printf("goOnConnect(): peripheral == null") @@ -371,15 +371,22 @@ func goOnCharacteristicChanged(cid, ccuuid *C.char, char C.jobject, cvalue *C.ch // internal convenience functions -func (b *BLE) retrievePeripheral(id string) Peripheral { +func (b *BLE) retrievePeripheral(id string, devs ...C.jobject) Peripheral { + var dev C.jobject + if len(devs) > 0 { + dev = devs[0] + } + found := false var peripheral Peripheral gBLE.peripherals.Lock() - for _, item := range gBLE.peripherals.items { + for i, item := range gBLE.peripherals.items { if item.p.Identifier == id { peripheral = item.p + peripheral.peripheral = dev found = true + gBLE.peripherals.items[i].p = peripheral break } }