mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-23 08:34:20 +01:00
Observer connection status after successfull service discovery
This commit is contained in:
@@ -92,25 +92,25 @@ internal class UARTService : NotificationService() {
|
||||
private fun startGattClient(device: ServerDevice) = lifecycleScope.launch {
|
||||
client = ClientBleGatt.connect(this@UARTService, device, logger = { p, s -> repository.log(p, s) })
|
||||
|
||||
client.requestMtu(Mtu.max)
|
||||
|
||||
client.connectionStateWithStatus
|
||||
.filterNotNull()
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.onEach { stopIfDisconnected(it.state, it.status) }
|
||||
.filterNotNull()
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (!client.isConnected) {
|
||||
return@launch
|
||||
}
|
||||
|
||||
client.requestMtu(Mtu.max)
|
||||
|
||||
try {
|
||||
val services = client.discoverServices()
|
||||
configureGatt(services)
|
||||
} catch (e: Exception) {
|
||||
repository.onMissingServices()
|
||||
}
|
||||
|
||||
client.connectionStateWithStatus
|
||||
.filterNotNull()
|
||||
.onEach { repository.onConnectionStateChanged(it) }
|
||||
.onEach { stopIfDisconnected(it.state, it.status) }
|
||||
.filterNotNull()
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
|
||||
private suspend fun configureGatt(services: ClientBleGattServices) {
|
||||
|
||||
Reference in New Issue
Block a user