Merge pull request #58 from geeksville/dev

misc autobugs
This commit is contained in:
Kevin Hester 2020-06-17 14:35:51 -07:00 committed by GitHub
commit 064606fb47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -608,7 +608,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
cont: Continuation<Unit>
) = queueWork("reqMtu", cont, 5 * 1000) {
isSettingMtu = true
gatt!!.requestMtu(len)
gatt?.requestMtu(len) ?: false
}
fun asyncRequestMtu(
@ -629,7 +629,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
) = queueWork("writeC ${c.uuid}", cont) {
currentReliableWrite = null
c.value = v
gatt!!.writeCharacteristic(c)
gatt?.writeCharacteristic(c) ?: false
}
fun asyncWriteCharacteristic(
@ -653,7 +653,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
) = queueWork("rwriteC ${c.uuid}", cont) {
logAssert(gatt!!.beginReliableWrite())
currentReliableWrite = c.value.clone()
gatt!!.writeCharacteristic(c)
gatt?.writeCharacteristic(c) ?: false
}
/* fun asyncWriteReliable(

View file

@ -16,6 +16,7 @@ import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager
import android.os.Bundle
import android.os.ParcelUuid
import android.os.RemoteException
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -429,10 +430,16 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging {
/// Change to a new macaddr selection, updating GUI and radio
fun changeScanSelection(context: MainActivity, newAddr: String) {
info("Changing device to ${newAddr.anonymize}")
selectedAddress = newAddr
changeDeviceSelection(context, newAddr)
devices.value = devices.value // Force a GUI update
try {
info("Changing device to ${newAddr.anonymize}")
changeDeviceSelection(context, newAddr)
selectedAddress =
newAddr // do this after changeDeviceSelection, so if it throws the change will be discarded
devices.value = devices.value // Force a GUI update
} catch (ex: RemoteException) {
errormsg("Failed talking to service, probably it is shutting down $ex.message")
// ignore the failure and the GUI won't be updating anyways
}
}
}