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

@ -38,6 +38,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -116,6 +117,11 @@ fun ConnectionsScreen(
val recentTcpDevices by scanModel.recentTcpDevicesForUi.collectAsStateWithLifecycle()
val usbDevices by scanModel.usbDevicesForUi.collectAsStateWithLifecycle()
DisposableEffect(Unit) {
connectionsViewModel.onStart()
onDispose { connectionsViewModel.onStop() }
}
/* Animate waiting for the configurations */
var isWaiting by remember { mutableStateOf(false) }
if (isWaiting) {

View file

@ -19,6 +19,7 @@ package com.geeksville.mesh.ui.connections
import androidx.lifecycle.ViewModel
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
import com.geeksville.mesh.repository.radio.RadioInterfaceService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@ -39,10 +40,19 @@ class ConnectionsViewModel
constructor(
radioConfigRepository: RadioConfigRepository,
serviceRepository: ServiceRepository,
private val radioInterfaceService: RadioInterfaceService,
nodeRepository: NodeRepository,
bluetoothRepository: BluetoothRepository,
private val uiPrefs: UiPrefs,
) : ViewModel() {
fun onStart() {
radioInterfaceService.setRssiPolling(true)
}
fun onStop() {
radioInterfaceService.setRssiPolling(false)
}
val localConfig: StateFlow<LocalConfig> =
radioConfigRepository.localConfigFlow.stateInWhileSubscribed(initialValue = LocalConfig.getDefaultInstance())