feat(bluetooth): conditional RSSI polling (#3489)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-10-16 21:08:41 -05:00 committed by GitHub
parent c3ede38b4c
commit 3dbfd81b43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 13 deletions

View file

@ -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}")
}
}
}
}
}

View file

@ -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