Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package org.meshtastic.feature.node.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.stringResource
import org.meshtastic.core.common.util.NumberFormatter
import org.meshtastic.core.model.Node
Expand All @@ -34,11 +36,7 @@ import org.meshtastic.core.ui.icon.Voltage
import org.meshtastic.feature.node.model.VectorMetricInfo

/**
* Displays environmental metrics for a node, including temperature, humidity, pressure, and other sensor data.
*
* WARNING: All metrics must be added in pairs (e.g., voltage and current for each channel) due to the display logic,
* which arranges metrics in columns of two. If an odd number of metrics is provided, the UI may not display as
* intended.
* Displays power metrics for a node, grouped by channel with voltage and current readings.
*/
@Composable
@Suppress("LongMethod", "CyclomaticComplexMethod")
Expand All @@ -47,49 +45,49 @@ internal fun PowerMetrics(node: Node) {
with(node.powerMetrics) {
if ((ch1_voltage ?: 0f) != 0f) {
add(
VectorMetricInfo(
Res.string.channel_1,
"${NumberFormatter.format(ch1_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
)
add(
VectorMetricInfo(
Res.string.channel_1,
"${NumberFormatter.format(ch1_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
Pair(
VectorMetricInfo(
Res.string.channel_1,
"${NumberFormatter.format(ch1_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
VectorMetricInfo(
Res.string.channel_1,
"${NumberFormatter.format(ch1_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
),
),
)
}
if ((ch2_voltage ?: 0f) != 0f) {
add(
VectorMetricInfo(
Res.string.channel_2,
"${NumberFormatter.format(ch2_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
)
add(
VectorMetricInfo(
Res.string.channel_2,
"${NumberFormatter.format(ch2_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
Pair(
VectorMetricInfo(
Res.string.channel_2,
"${NumberFormatter.format(ch2_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
VectorMetricInfo(
Res.string.channel_2,
"${NumberFormatter.format(ch2_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
),
),
)
}
if ((ch3_voltage ?: 0f) != 0f) {
add(
VectorMetricInfo(
Res.string.channel_3,
"${NumberFormatter.format(ch3_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
)
add(
VectorMetricInfo(
Res.string.channel_3,
"${NumberFormatter.format(ch3_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
Pair(
VectorMetricInfo(
Res.string.channel_3,
"${NumberFormatter.format(ch3_voltage ?: 0f, 2)}V",
MeshtasticIcons.Voltage,
),
VectorMetricInfo(
Res.string.channel_3,
"${NumberFormatter.format(ch3_current ?: 0f, 1)}mA",
MeshtasticIcons.PowerSupply,
),
),
)
}
Expand All @@ -100,8 +98,19 @@ internal fun PowerMetrics(node: Node) {
horizontalArrangement = Arrangement.SpaceEvenly,
verticalArrangement = Arrangement.SpaceEvenly,
) {
metrics.forEach { metric ->
InfoCard(icon = metric.icon, text = stringResource(metric.label), value = metric.value)
metrics.forEach { (voltageMetric, currentMetric) ->
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
InfoCard(
icon = voltageMetric.icon,
text = stringResource(voltageMetric.label),
value = voltageMetric.value,
)
InfoCard(
icon = currentMetric.icon,
text = stringResource(currentMetric.label),
value = currentMetric.value,
)
}
}
}
}
Loading