refactor(ui): 重构无人机控制器界面组件结构
- 将 HomeScreen 组件重命名为 PilotHomeScreen 并调整参数 - 移除大量内联的 UI 组件实现,改为独立的可复用组件 - 优化地图预览显示逻辑,更新为更简洁的定位信息展示 - 重构飞行控制面板布局,调整尺寸和间距参数 - 添加更多菜单选项,整合飞前检查等功能入口 - 更新遥测数据显示组件,优化仪表盘读数展示 - 调整按钮样式和交互效果,改进视觉反馈 - 优化响应式布局计算,提升不同屏幕尺寸适配效果
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import dji.sdk.keyvalue.key.DJIKey
|
||||
import dji.sdk.keyvalue.key.FlightControllerKey
|
||||
import dji.sdk.keyvalue.key.GimbalKey
|
||||
import dji.sdk.keyvalue.key.KeyTools
|
||||
import dji.sdk.keyvalue.value.common.ComponentIndexType
|
||||
import dji.v5.manager.KeyManager
|
||||
import dji.v5.manager.aircraft.perception.PerceptionManager
|
||||
import dji.v5.manager.aircraft.perception.data.ObstacleData
|
||||
import dji.v5.manager.aircraft.perception.data.PerceptionInfo
|
||||
import dji.v5.manager.aircraft.perception.listener.ObstacleDataListener
|
||||
import dji.v5.manager.aircraft.perception.listener.PerceptionInformationListener
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
/** Independent read-only UI subscriptions; never enables control or changes aircraft settings. */
|
||||
@Composable
|
||||
internal fun rememberFlightInstrumentReadings(connected: Boolean, cameraComponent: String): FlightInstrumentReadings {
|
||||
val readings = remember(connected, cameraComponent) { MutableStateFlow(FlightInstrumentReadings()) }
|
||||
DisposableEffect(connected, cameraComponent) {
|
||||
val owner = Any()
|
||||
var active = true
|
||||
val lock = Any()
|
||||
var obstacleData: ObstacleData? = null
|
||||
var perceptionInfo: PerceptionInfo? = null
|
||||
fun updateObstacles() {
|
||||
val info = perceptionInfo
|
||||
val data = obstacleData
|
||||
val sectors = instrumentObstacleSectors(data?.horizontalObstacleDistance?.toList().orEmpty(), data?.horizontalAngleInterval ?: 0)
|
||||
val obstacles = InstrumentObstacles(
|
||||
front = sectors[0].takeIf { info?.forwardObstacleAvoidanceWorking == true },
|
||||
right = sectors[1].takeIf { info?.rightSideObstacleAvoidanceWorking == true },
|
||||
back = sectors[2].takeIf { info?.backwardObstacleAvoidanceWorking == true },
|
||||
left = sectors[3].takeIf { info?.leftSideObstacleAvoidanceWorking == true },
|
||||
up = instrumentObstacleDistance(data?.upwardObstacleDistance).takeIf { info?.upwardObstacleAvoidanceWorking == true },
|
||||
down = instrumentObstacleDistance(data?.downwardObstacleDistance).takeIf { info?.downwardObstacleAvoidanceWorking == true }
|
||||
)
|
||||
readings.update { it.copy(obstacles = obstacles) }
|
||||
}
|
||||
val perception = if (connected) runCatching { PerceptionManager.getInstance() }.getOrNull() else null
|
||||
val obstacleListener = ObstacleDataListener { data ->
|
||||
synchronized(lock) {
|
||||
if (active) { obstacleData = data; updateObstacles() }
|
||||
}
|
||||
}
|
||||
val perceptionListener = PerceptionInformationListener { info ->
|
||||
synchronized(lock) {
|
||||
if (active) { perceptionInfo = info; updateObstacles() }
|
||||
}
|
||||
}
|
||||
fun <T> observe(key: DJIKey<T>, change: FlightInstrumentReadings.(T?) -> FlightInstrumentReadings) {
|
||||
// Unsupported keys keep null instead of masquerading as zero.
|
||||
runCatching {
|
||||
KeyManager.getInstance().listen(key, owner, true) { _, value ->
|
||||
synchronized(lock) {
|
||||
if (active) readings.update { it.change(value) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (connected) {
|
||||
runCatching { perception?.addPerceptionInformationListener(perceptionListener) }
|
||||
runCatching { perception?.addObstacleDataListener(obstacleListener) }
|
||||
observe(KeyTools.createKey(FlightControllerKey.KeyAltitude)) { copy(relativeAltitude = it) }
|
||||
observe(KeyTools.createKey(FlightControllerKey.KeyHeightAboveSeaLevel)) { copy(seaLevelAltitude = it?.height) }
|
||||
observe(KeyTools.createKey(FlightControllerKey.KeyCompassHeading)) { copy(heading = instrumentHeading(it)) }
|
||||
observe(KeyTools.createKey(FlightControllerKey.KeyAircraftVelocity)) {
|
||||
copy(horizontalSpeed = it?.let { v -> instrumentHorizontalSpeed(v.x, v.y) }, climbSpeed = instrumentClimbSpeed(it?.z))
|
||||
}
|
||||
observe(KeyTools.createKey(FlightControllerKey.KeyWindSpeed)) { copy(windSpeed = instrumentWindSpeed(it)) }
|
||||
val component = ComponentIndexType.values().firstOrNull { it.name == cameraComponent } ?: ComponentIndexType.LEFT_OR_MAIN
|
||||
observe(KeyTools.createKey(GimbalKey.KeyGimbalAttitude, component)) { copy(gimbalPitch = it?.pitch) }
|
||||
}
|
||||
onDispose {
|
||||
synchronized(lock) { active = false }
|
||||
runCatching { KeyManager.getInstance().cancelListen(owner) }
|
||||
runCatching { perception?.removeObstacleDataListener(obstacleListener) }
|
||||
runCatching { perception?.removePerceptionInformationListener(perceptionListener) }
|
||||
}
|
||||
}
|
||||
val current by readings.collectAsState()
|
||||
return current
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import java.util.Locale
|
||||
import kotlin.math.hypot
|
||||
|
||||
/** Presentation values only. Null means the SDK has not supplied a usable reading. */
|
||||
internal data class FlightInstrumentReadings(
|
||||
val relativeAltitude: Double? = null,
|
||||
val seaLevelAltitude: Double? = null,
|
||||
val heading: Double? = null,
|
||||
val horizontalSpeed: Double? = null,
|
||||
val climbSpeed: Double? = null,
|
||||
val windSpeed: Double? = null,
|
||||
val gimbalPitch: Double? = null,
|
||||
val obstacles: InstrumentObstacles = InstrumentObstacles()
|
||||
)
|
||||
|
||||
internal data class InstrumentObstacles(
|
||||
val front: Double? = null,
|
||||
val right: Double? = null,
|
||||
val back: Double? = null,
|
||||
val left: Double? = null,
|
||||
val up: Double? = null,
|
||||
val down: Double? = null
|
||||
)
|
||||
|
||||
internal fun instrumentObstacleDistance(millimeters: Int?): Double? =
|
||||
millimeters?.takeIf { it > 0 && it < Int.MAX_VALUE }?.div(1000.0)
|
||||
|
||||
/** Body-relative quadrants: SDK/UXSDK start at the nose and proceed clockwise. */
|
||||
internal fun instrumentObstacleSectors(distances: List<Int>, interval: Int): List<Double?> {
|
||||
if (interval !in 1..90 || distances.size.toLong() * interval != 360L) return List(4) { null }
|
||||
val sectors = MutableList<Double?>(4) { null }
|
||||
distances.forEachIndexed { index, distance ->
|
||||
val sector = ((index * interval + 45) % 360) / 90
|
||||
val meters = instrumentObstacleDistance(distance)
|
||||
if (meters != null && (sectors[sector] == null || meters < sectors[sector]!!)) sectors[sector] = meters
|
||||
}
|
||||
return sectors
|
||||
}
|
||||
|
||||
internal fun instrumentNumber(value: Double?, decimals: Int = 1): String =
|
||||
value?.takeIf { it.isFinite() }?.let {
|
||||
// Avoid displaying negative zero when the aircraft is stationary.
|
||||
String.format(Locale.US, "%.${decimals}f", if (it == 0.0) 0.0 else it)
|
||||
} ?: "—"
|
||||
|
||||
internal fun instrumentHeading(value: Double?): Double? =
|
||||
value?.takeIf { it.isFinite() }?.let { ((it % 360.0) + 360.0) % 360.0 }
|
||||
|
||||
internal fun instrumentHorizontalSpeed(x: Double, y: Double): Double? =
|
||||
hypot(x, y).takeIf { it.isFinite() }
|
||||
|
||||
// DJI SpeedDisplayWidget uses dm/s; VerticalVelocityWidget uses negative Z for ascent.
|
||||
internal fun instrumentWindSpeed(raw: Int?): Double? = raw?.takeIf { it >= 0 }?.div(10.0)
|
||||
internal fun instrumentClimbSpeed(z: Double?): Double? = z?.takeIf { it.isFinite() }?.let { -it }
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.zklh.dronecontroller.core.msdk.DroneSdkState
|
||||
import com.zklh.dronecontroller.core.telemetry.TelemetrySnapshot
|
||||
|
||||
private val HomeBackground = Color(0xFF090D12)
|
||||
private val HomeCardColor = Color(0xE6151C24)
|
||||
private val HomeSecondary = Color(0xFFA2AFBF)
|
||||
private val HomeAccent = Color(0xFF3C91FF)
|
||||
private val HomeOnline = Color(0xFF42D6AC)
|
||||
|
||||
@Composable
|
||||
internal fun PilotHomeScreen(
|
||||
sdkState: DroneSdkState,
|
||||
telemetry: TelemetrySnapshot,
|
||||
commandMessage: String,
|
||||
cloudConnected: Boolean,
|
||||
cloudTenantName: String,
|
||||
cloudUsername: String,
|
||||
onOpenCloud: () -> Unit,
|
||||
onOpenPreflight: () -> Unit,
|
||||
onOpenMission: () -> Unit,
|
||||
onEnterFlight: () -> Unit,
|
||||
onRetryConnect: () -> Unit
|
||||
) {
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(HomeBackground)) {
|
||||
val compact = maxHeight < 560.dp
|
||||
val pad = if (compact) 14.dp else 20.dp
|
||||
val gap = if (compact) 10.dp else 14.dp
|
||||
Column(Modifier.fillMaxSize().padding(pad), verticalArrangement = Arrangement.spacedBy(gap)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Navigation, null, tint = HomeAccent, modifier = Modifier.size(26.dp))
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Text("飞行工作台", color = Color.White, fontWeight = FontWeight.Bold, fontSize = if (compact) 20.sp else 24.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
HomeConnectionBadge(if (sdkState.productLinkConnected) "遥控器已连接" else "等待连接遥控器", sdkState.productLinkConnected)
|
||||
}
|
||||
Row(Modifier.weight(1f).fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(gap)) {
|
||||
Surface(color = HomeCardColor, shape = RoundedCornerShape(8.dp), border = BorderStroke(1.dp, Color.White.copy(alpha = 0.08f)), modifier = Modifier.weight(0.62f).fillMaxHeight()) {
|
||||
Column(Modifier.padding(pad).verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(gap)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("当前设备", color = HomeSecondary, fontSize = 13.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
HomeConnectionBadge(if (sdkState.productConnected) "已连接" else "未连接", sdkState.productConnected)
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
||||
AircraftIllustration(Modifier.weight(0.42f).height(if (compact) 96.dp else 142.dp))
|
||||
Column(Modifier.weight(0.54f).padding(start = 12.dp), verticalArrangement = Arrangement.spacedBy(7.dp)) {
|
||||
Text(
|
||||
if (sdkState.productConnected) telemetry.productType.replace('_', ' ').ifBlank { "无人机已连接" } else "等待无人机连接",
|
||||
color = Color.White, fontSize = if (compact) 20.sp else 26.sp, fontWeight = FontWeight.Bold,
|
||||
maxLines = 2, overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text("SN ${sdkState.aircraftSerialNumber.ifBlank { "—" }}", color = HomeSecondary, fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(telemetry.remoteControllerType.replace('_', ' ').ifBlank { "遥控器" }, color = HomeSecondary, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
HorizontalDivider(color = Color.White.copy(alpha = 0.07f))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
HomeMetric(Icons.Filled.BatteryFull, "飞行器电量", if (sdkState.productConnected && telemetry.batteryPercent in 0..100) "${telemetry.batteryPercent}%" else "—")
|
||||
HomeMetric(Icons.Filled.MyLocation, "卫星数", if (sdkState.productConnected && telemetry.gpsValid) telemetry.gpsSatelliteCount.toString() else "—")
|
||||
HomeMetric(Icons.Filled.Radio, "遥控链路", if (sdkState.productLinkConnected) "已连接" else "未连接")
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
OutlinedButton(onClick = onOpenPreflight, shape = RoundedCornerShape(8.dp), border = BorderStroke(1.dp, Color(0xFF384659)), colors = ButtonDefaults.outlinedButtonColors(contentColor = Color.White), modifier = Modifier.weight(1f).height(46.dp)) {
|
||||
Icon(Icons.Filled.Shield, null, modifier = Modifier.size(18.dp))
|
||||
Spacer(Modifier.width(7.dp))
|
||||
Text("飞前检查", maxLines = 1)
|
||||
}
|
||||
Button(onClick = { if (!sdkState.productConnected) onRetryConnect(); onEnterFlight() }, shape = RoundedCornerShape(8.dp), colors = ButtonDefaults.buttonColors(containerColor = HomeAccent), modifier = Modifier.weight(1.35f).height(46.dp)) {
|
||||
Text("进入飞行", fontWeight = FontWeight.Bold, fontSize = 16.sp)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(0.38f).fillMaxHeight().verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(gap)) {
|
||||
Surface(color = HomeCardColor, shape = RoundedCornerShape(8.dp), border = BorderStroke(1.dp, Color.White.copy(alpha = 0.08f))) {
|
||||
Column(Modifier.fillMaxWidth().padding(pad), verticalArrangement = Arrangement.spacedBy(if (compact) 12.dp else 20.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Cloud, null, tint = HomeAccent)
|
||||
Spacer(Modifier.width(9.dp))
|
||||
Text("云平台", color = Color.White, fontWeight = FontWeight.Bold, fontSize = 18.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(if (cloudConnected) "已连接" else "未连接", color = if (cloudConnected) HomeOnline else HomeSecondary, fontSize = 12.sp)
|
||||
}
|
||||
HomeDetail("租户", cloudTenantName.ifBlank { "未配置" })
|
||||
HomeDetail("账号", cloudUsername.ifBlank { "未配置" })
|
||||
OutlinedButton(onClick = onOpenCloud, shape = RoundedCornerShape(8.dp), border = BorderStroke(1.dp, Color(0xFF384659)), colors = ButtonDefaults.outlinedButtonColors(contentColor = Color.White), modifier = Modifier.fillMaxWidth().height(42.dp)) {
|
||||
Text("管理云平台")
|
||||
Spacer(Modifier.weight(1f))
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface(onClick = onOpenMission, color = HomeCardColor, shape = RoundedCornerShape(8.dp), border = BorderStroke(1.dp, Color.White.copy(alpha = 0.08f))) {
|
||||
Row(Modifier.fillMaxWidth().padding(pad), verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(Icons.Filled.Route, null, tint = HomeAccent, modifier = Modifier.size(30.dp))
|
||||
Column(Modifier.weight(1f).padding(horizontal = 12.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Text("航线任务", color = Color.White, fontWeight = FontWeight.Bold, fontSize = 17.sp)
|
||||
Text("导入 · 上传 · 执行", color = HomeSecondary, fontSize = 11.sp)
|
||||
}
|
||||
Icon(Icons.AutoMirrored.Filled.KeyboardArrowRight, null, tint = HomeSecondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Icon(Icons.Filled.Radio, null, tint = HomeSecondary, modifier = Modifier.size(16.dp))
|
||||
Text(commandMessage.ifBlank { if (sdkState.isRegistered) "设备服务已就绪" else "正在初始化设备服务" }, color = HomeSecondary, fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
|
||||
if (!sdkState.productConnected) {
|
||||
TextButton(onClick = onRetryConnect, contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp), modifier = Modifier.height(32.dp)) { Text("重试连接", color = HomeAccent, fontSize = 12.sp) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HomeConnectionBadge(text: String, online: Boolean) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Box(Modifier.size(6.dp).background(if (online) HomeOnline else HomeSecondary, CircleShape))
|
||||
Text(text, color = if (online) HomeOnline else HomeSecondary, fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HomeMetric(icon: ImageVector, label: String, value: String) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Icon(icon, null, tint = HomeSecondary, modifier = Modifier.size(14.dp))
|
||||
Text(label, color = HomeSecondary, fontSize = 11.sp)
|
||||
}
|
||||
Text(value, color = Color.White, fontSize = 20.sp, fontWeight = FontWeight.Medium)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HomeDetail(label: String, value: String) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Text(label, color = HomeSecondary, fontSize = 11.sp)
|
||||
Text(value, color = Color.White, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AircraftIllustration(modifier: Modifier) {
|
||||
Canvas(modifier) {
|
||||
val c = center
|
||||
val radius = size.minDimension * 0.43f
|
||||
drawCircle(HomeAccent.copy(alpha = 0.04f), radius, c)
|
||||
drawCircle(HomeAccent.copy(alpha = 0.14f), radius, c, style = Stroke(1.dp.toPx()))
|
||||
listOf(Offset(-0.7f, -0.6f), Offset(0.7f, -0.6f), Offset(-0.7f, 0.6f), Offset(0.7f, 0.6f)).forEach { direction ->
|
||||
val rotor = c + direction * radius
|
||||
drawLine(Color(0xFF7C8A9B), c, rotor, radius * 0.12f, StrokeCap.Round)
|
||||
drawCircle(Color(0xFFACBAC9), radius * 0.14f, rotor)
|
||||
drawLine(Color(0xFFDAE3ED), rotor - Offset(radius * 0.26f, radius * 0.08f), rotor + Offset(radius * 0.26f, radius * 0.08f), radius * 0.06f, StrokeCap.Round)
|
||||
}
|
||||
drawOval(Color(0xFFB6C2D0), topLeft = c - Offset(radius * 0.23f, radius * 0.40f), size = androidx.compose.ui.geometry.Size(radius * 0.46f, radius * 0.8f))
|
||||
drawCircle(Color(0xFF233449), radius * 0.13f, c + Offset(0f, radius * 0.35f))
|
||||
drawCircle(HomeAccent, radius * 0.055f, c + Offset(0f, radius * 0.35f))
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Home · RC landscape", widthDp = 960, heightDp = 540)
|
||||
@Composable
|
||||
private fun PilotHomePreview() {
|
||||
PilotHomeScreen(DroneSdkState(), TelemetrySnapshot(), "等待连接无人机", false, "", "", {}, {}, {}, {}, {})
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.zklh.dronecontroller.core.msdk.DroneSdkState
|
||||
import com.zklh.dronecontroller.core.telemetry.TelemetrySnapshot
|
||||
import com.zklh.dronecontroller.core.telemetry.hasReliableRtkPosition
|
||||
|
||||
/** Read-only checks. The former placeholder sliders never wrote settings to the aircraft. */
|
||||
@Composable
|
||||
internal fun PilotPreflightScreen(sdkState: DroneSdkState, telemetry: TelemetrySnapshot, onClose: () -> Unit) {
|
||||
val connected = sdkState.productConnected
|
||||
fun reading(value: String) = if (connected) value else "—"
|
||||
Column(Modifier.fillMaxSize().background(Color(0xFF0D1118)).padding(20.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text("飞前检查", color = Color.White, fontSize = 24.sp, fontWeight = FontWeight.Bold)
|
||||
Text("设备状态", color = Color(0xFF9CABB9), fontSize = 12.sp)
|
||||
}
|
||||
IconButton(onClick = onClose) { Icon(Icons.Filled.Close, "关闭飞前检查", tint = Color.White) }
|
||||
}
|
||||
Spacer(Modifier.height(18.dp))
|
||||
Row(Modifier.weight(1f).verticalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
CheckCard("连接与定位", listOf(
|
||||
"飞机连接" to if (connected) "已连接" else "未连接",
|
||||
"遥控链路" to if (sdkState.productLinkConnected) "已连接" else "未连接",
|
||||
"卫星数" to reading(if (telemetry.gpsValid) telemetry.gpsSatelliteCount.toString() else "定位不可用"),
|
||||
"返航点" to reading(if (telemetry.homeLocationValid) "已记录" else "未取得"),
|
||||
"RTK" to reading(if (telemetry.hasReliableRtkForCheck()) "定位可用" else if (telemetry.rtkEnabled) "等待定位" else "未启用")
|
||||
), Modifier.weight(1f))
|
||||
CheckCard("电池与设备", listOf(
|
||||
"飞行器电量" to reading(if (telemetry.batteryPercent in 0..100) "${telemetry.batteryPercent}%" else "—"),
|
||||
"遥控器电量" to if (sdkState.productLinkConnected && telemetry.rcBatteryPercent in 0..100) "${telemetry.rcBatteryPercent}%" else "—",
|
||||
"电池温度" to reading(if (telemetry.batteryTemperatureKnown) "${instrumentNumber(telemetry.batteryTemperature)} °C" else "—"),
|
||||
"预计剩余飞行时间" to reading(if (telemetry.remainingFlightTimeKnown) "${telemetry.remainingFlightTime / 60} 分钟" else "—"),
|
||||
"固件版本" to reading(telemetry.firmwareVersion.ifBlank { "—" })
|
||||
), Modifier.weight(1f))
|
||||
}
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Text(sdkState.registerError ?: sdkState.aircraftConnectionDetail, color = Color(0xFF9CABB9), fontSize = 12.sp)
|
||||
Text("起飞前请检查机臂、桨叶及周围环境,并确认返航与避障设置。", color = Color(0xFF9CABB9), fontSize = 12.sp, modifier = Modifier.padding(top = 8.dp))
|
||||
}
|
||||
}
|
||||
|
||||
private fun TelemetrySnapshot.hasReliableRtkForCheck() =
|
||||
hasReliableRtkPosition()
|
||||
|
||||
@Composable
|
||||
private fun CheckCard(title: String, rows: List<Pair<String, String>>, modifier: Modifier) {
|
||||
Surface(color = Color(0xFF171F2A), shape = RoundedCornerShape(16.dp), modifier = modifier) {
|
||||
Column(Modifier.padding(18.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Text(title, color = Color.White, fontSize = 18.sp, fontWeight = FontWeight.Bold)
|
||||
rows.forEach { (label, value) ->
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, color = Color(0xFF9CABB9), fontSize = 13.sp, modifier = Modifier.weight(1f))
|
||||
Text(value, color = Color.White, fontSize = 13.sp, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user