mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(bluetooth): conditional RSSI polling (#3489)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
c3ede38b4c
commit
3dbfd81b43
5 changed files with 47 additions and 13 deletions
|
|
@ -158,14 +158,18 @@ constructor(
|
|||
@Suppress("LoopWithTooManyJumpStatements", "MagicNumber")
|
||||
val pollingJob =
|
||||
service.serviceScope.handledLaunch {
|
||||
while (true) {
|
||||
try {
|
||||
delay(2500) // Poll every 5 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}")
|
||||
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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,13 @@ constructor(
|
|||
private val _currentDeviceAddressFlow = MutableStateFlow(radioPrefs.devAddr)
|
||||
val currentDeviceAddressFlow: StateFlow<String?> = _currentDeviceAddressFlow.asStateFlow()
|
||||
|
||||
private val _isRssiPollingEnabled = MutableStateFlow(false)
|
||||
val isRssiPollingEnabled: StateFlow<Boolean> = _isRssiPollingEnabled.asStateFlow()
|
||||
|
||||
fun setRssiPolling(enabled: Boolean) {
|
||||
_isRssiPollingEnabled.value = enabled
|
||||
}
|
||||
|
||||
private val logSends = false
|
||||
private val logReceives = false
|
||||
private lateinit var sentPacketsLog: BinaryLogFile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue