mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: Remove Bluetooth RSSI feature (#3504)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
ead69c7085
commit
894da7a02a
7 changed files with 0 additions and 83 deletions
|
|
@ -35,13 +35,7 @@ import dagger.assisted.Assisted
|
|||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import org.meshtastic.core.analytics.platform.PlatformAnalytics
|
||||
import org.meshtastic.core.model.util.anonymize
|
||||
import timber.log.Timber
|
||||
|
|
@ -145,50 +139,6 @@ constructor(
|
|||
|
||||
private lateinit var fromNum: BluetoothGattCharacteristic
|
||||
|
||||
/**
|
||||
* RSSI flow, which polls the remote device for RSSI only when there are active subscribers. The polling stops
|
||||
* automatically when the last collector stops.
|
||||
*/
|
||||
val rssiFlow: StateFlow<Int?> =
|
||||
callbackFlow {
|
||||
// Initial read for faster UI update
|
||||
safe?.asyncReadRemoteRssi { first -> first.getOrNull()?.let { trySend(it) } }
|
||||
|
||||
// Launch the polling loop on the service scope
|
||||
@Suppress("LoopWithTooManyJumpStatements", "MagicNumber")
|
||||
val pollingJob =
|
||||
service.serviceScope.handledLaunch {
|
||||
service.isRssiPollingEnabled.collect { isEnabled ->
|
||||
if (isEnabled) {
|
||||
while (true) {
|
||||
try {
|
||||
delay(10000) // Poll every 10 seconds
|
||||
safe?.asyncReadRemoteRssi { res -> res.getOrNull()?.let { trySend(it) } }
|
||||
} catch (ex: CancellationException) {
|
||||
break // Stop polling on cancellation
|
||||
} catch (ex: Exception) {
|
||||
Timber.d("RSSI polling error: ${ex.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This block executes when the last collector stops.
|
||||
awaitClose {
|
||||
pollingJob.cancel()
|
||||
// Clear the value when the flow is closed (no active subscribers).
|
||||
trySend(null)
|
||||
}
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.stateIn(
|
||||
scope = service.serviceScope,
|
||||
// Keep the polling running for 5 seconds after the last collector disappears
|
||||
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000),
|
||||
initialValue = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* If we think we are connected, but we don't hear anything from the device, we might be in a zombie state. This
|
||||
* function forces a read of a characteristic to see if we are really connected.
|
||||
|
|
|
|||
|
|
@ -106,10 +106,6 @@ constructor(
|
|||
|
||||
private var radioIf: IRadioInterface = NopInterface("")
|
||||
|
||||
// Expose current bluetooth RSSI (null if not connected or not BLE)
|
||||
private val _bluetoothRssi = MutableStateFlow<Int?>(null)
|
||||
val bluetoothRssi: StateFlow<Int?> = _bluetoothRssi.asStateFlow()
|
||||
|
||||
/**
|
||||
* true if we have started our interface
|
||||
*
|
||||
|
|
@ -273,13 +269,6 @@ constructor(
|
|||
}
|
||||
|
||||
radioIf = interfaceFactory.createInterface(address)
|
||||
|
||||
// If the new interface is bluetooth, collect its RSSI flow
|
||||
if (radioIf is BluetoothInterface) {
|
||||
(radioIf as BluetoothInterface).rssiFlow.onEach { _bluetoothRssi.emit(it) }.launchIn(serviceScope)
|
||||
} else {
|
||||
_bluetoothRssi.value = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -306,7 +295,6 @@ constructor(
|
|||
if (r !is NopInterface) {
|
||||
onDisconnect(isPermanent = true) // Tell any clients we are now offline
|
||||
}
|
||||
_bluetoothRssi.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue