Skip to content

Commit

Permalink
Fancied up the signal data within the NodeItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-0410 committed Nov 21, 2024
1 parent 900525a commit 0926e02
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
19 changes: 9 additions & 10 deletions app/src/main/java/com/geeksville/mesh/ui/SignalInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.geeksville.mesh.R
import com.geeksville.mesh.database.entity.NodeEntity
import com.geeksville.mesh.ui.components.NodeSignalQuality
import com.geeksville.mesh.ui.preview.NodeEntityPreviewParameterProvider
import com.geeksville.mesh.ui.theme.AppTheme

Expand All @@ -21,7 +22,7 @@ fun signalInfo(
modifier: Modifier = Modifier,
node: NodeEntity,
isThisNode: Boolean
): Boolean {
) {
val text = if (isThisNode) {
stringResource(R.string.channel_air_util).format(
node.deviceMetrics.channelUtilization,
Expand All @@ -40,24 +41,22 @@ fun signalInfo(
if (node.channel > 0) {
add("ch:${node.channel}")
}
if (node.hopsAway <= 0) {
if (node.snr < MAX_VALID_SNR && node.rssi < MAX_VALID_RSSI) {
add("RSSI: %d SNR: %.1f".format(node.rssi, node.snr))
}
}
if (node.hopsAway != 0) add(hopsString)
}.joinToString(" | ")
}
return if (text.isNotEmpty()) {
if (text.isNotEmpty()) {
Text(
modifier = modifier,
text = text,
color = MaterialTheme.colors.onSurface,
fontSize = MaterialTheme.typography.button.fontSize
)
true
} else {
false
}
/* We only know the Signal Quality from direct nodes aka 0 hop. */
if (node.hopsAway <= 0) {
if (node.snr < MAX_VALID_SNR && node.rssi < MAX_VALID_RSSI) {
NodeSignalQuality(node.snr, node.rssi)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ private enum class Quality(
}

/**
* Displays the `snr` and `rssi` with color depending on the value respectively.
* Displays the `snr` and `rssi` color coded based on the signal quality, along with
* a human readable description and related icon.
*/
@Composable
fun NodeSignalQuality(snr: Float, rssi: Int) {
val quality = determineSignalQuality(snr, rssi)
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Snr(snr)
Rssi(rssi)
Text(text = "${stringResource(R.string.signal)} ${stringResource(quality.nameRes)}")
Icon(
imageVector = quality.imageVector,
contentDescription = stringResource(R.string.signal_quality),
tint = quality.color
)
}
}

/**
* Displays the `snr` and `rssi` with color depending on the values respectively.
*/
@Composable
fun SnrAndRssi(snr: Float, rssi: Int){
Expand All @@ -55,7 +78,7 @@ fun SnrAndRssi(snr: Float, rssi: Int){
}

/**
* Displays a signal indicator based on `snr` and `rssi`.
* Displays a human readable description and icon representing the signal quality.
*/
@Composable
fun LoraSignalIndicator(snr: Float, rssi: Int) {
Expand Down

0 comments on commit 0926e02

Please sign in to comment.