mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
properly mark when we are disconnected
This commit is contained in:
parent
e94c059acb
commit
7cca69be0d
3 changed files with 17 additions and 4 deletions
|
|
@ -326,6 +326,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
|||
ignoreException {
|
||||
s.closeConnection()
|
||||
}
|
||||
service.onDisconnect(false) // assume we will fail
|
||||
delay(1000) // Give some nasty time for buggy BLE stacks to shutdown (500ms was not enough)
|
||||
reconnectJob = null // Any new reconnect requests after this will be allowed to run
|
||||
warn("Attempting reconnect")
|
||||
|
|
@ -364,7 +365,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
|||
isFirstSend = true
|
||||
|
||||
// Now tell clients they can (finally use the api)
|
||||
service.broadcastConnectionChanged(true, isPermanent = false)
|
||||
service.onConnect()
|
||||
|
||||
// Immediately broadcast any queued packets sitting on the device
|
||||
doReadFromRadio(true)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class RadioInterfaceService : Service(), Logging {
|
|||
startInterface() // If bluetooth just got turned on, try to restart our ble link
|
||||
}
|
||||
|
||||
fun broadcastConnectionChanged(isConnected: Boolean, isPermanent: Boolean) {
|
||||
private fun broadcastConnectionChanged(isConnected: Boolean, isPermanent: Boolean) {
|
||||
debug("Broadcasting connection=$isConnected")
|
||||
val intent = Intent(RADIO_CONNECTED_ACTION)
|
||||
intent.putExtra(EXTRA_CONNECTED, isConnected)
|
||||
|
|
@ -163,8 +163,20 @@ class RadioInterfaceService : Service(), Logging {
|
|||
)
|
||||
}
|
||||
|
||||
private var isConnected = false
|
||||
|
||||
fun onConnect() {
|
||||
if (!isConnected) {
|
||||
isConnected = true
|
||||
broadcastConnectionChanged(true, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun onDisconnect(isPermanent: Boolean) {
|
||||
broadcastConnectionChanged(false, isPermanent)
|
||||
if (isConnected) {
|
||||
isConnected = false
|
||||
broadcastConnectionChanged(false, isPermanent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class SerialInterface(private val service: RadioInterfaceService, val address: S
|
|||
io.writeAsync(wakeBytes)
|
||||
|
||||
// Now tell clients they can (finally use the api)
|
||||
service.broadcastConnectionChanged(true, isPermanent = false)
|
||||
service.onConnect()
|
||||
}
|
||||
} else {
|
||||
errormsg("Can't find device")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue