添加红外,变焦,广角功能,包括红外色盘调整
This commit is contained in:
@@ -10,6 +10,7 @@ import dji.sdk.keyvalue.value.camera.CameraExposureMode
|
||||
import dji.sdk.keyvalue.value.camera.CameraFocusMode
|
||||
import dji.sdk.keyvalue.value.camera.CameraNightSceneMode
|
||||
import dji.sdk.keyvalue.value.camera.CameraVideoStreamSourceType
|
||||
import dji.sdk.keyvalue.value.camera.CameraThermalPalette
|
||||
import dji.sdk.keyvalue.value.camera.FrameZoomMsg
|
||||
import dji.sdk.keyvalue.value.camera.LiveViewSourceCameraType
|
||||
import dji.sdk.keyvalue.value.camera.TapZoomMode
|
||||
@@ -42,6 +43,13 @@ class CameraControlService(
|
||||
"红外变焦已设置:${"%.1f".format(zoomRatio)}x"
|
||||
)
|
||||
|
||||
suspend fun setThermalPalette(palette: CameraThermalPalette): DjiCommandResult =
|
||||
setValueKey(
|
||||
KeyTools.createCameraKey(DJICameraKey.KeyThermalPalette, cameraIndex, CameraLensType.CAMERA_LENS_THERMAL),
|
||||
palette,
|
||||
"红外色盘已切换:${palette.name}"
|
||||
)
|
||||
|
||||
suspend fun setLens(lens: String): DjiCommandResult {
|
||||
val source = when (lens.normalizeLensName()) {
|
||||
"wide", "normal", "visible", "visible_wide", "camera_lens_wide" -> CameraVideoStreamSourceType.WIDE_CAMERA
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.zklh.dronecontroller.core.media
|
||||
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** Returns a supported adjacent ratio. A missing SDK range must not turn into a guessed command. */
|
||||
internal fun adjacentZoomRatio(current: Double, gears: List<Int>, continuous: Boolean, increase: Boolean): Double? {
|
||||
val supported = gears.filter { it > 0 }.distinct().sorted()
|
||||
if (supported.isEmpty()) return null
|
||||
val minimum = supported.first().toDouble()
|
||||
val maximum = supported.last().toDouble()
|
||||
if (!continuous) return if (increase) supported.firstOrNull { it > current + 0.001 }?.toDouble()
|
||||
else supported.lastOrNull { it < current - 0.001 }?.toDouble()
|
||||
|
||||
val step = if (current < 10.0) 0.5 else 1.0
|
||||
val candidate = ((current + if (increase) step else -step) * 10.0).roundToInt() / 10.0
|
||||
val bounded = candidate.coerceIn(minimum, maximum)
|
||||
return bounded.takeIf { if (increase) it > current + 0.001 else it < current - 0.001 }
|
||||
}
|
||||
@@ -6,6 +6,15 @@ import android.provider.OpenableColumns
|
||||
import java.io.File
|
||||
|
||||
object MissionFileStore {
|
||||
fun copyToMissionCache(context: Context, file: File): File {
|
||||
require(file.isFile && file.canRead()) { "无法读取航线文件" }
|
||||
val outDir = File(context.cacheDir, "missions").apply { mkdirs() }
|
||||
val outFile = File(outDir, safeFileName(file.name))
|
||||
if (file.canonicalFile == outFile.canonicalFile) return file
|
||||
file.inputStream().use { input -> outFile.outputStream().use { input.copyTo(it) } }
|
||||
return outFile
|
||||
}
|
||||
|
||||
fun copyToMissionCache(context: Context, uri: Uri): File {
|
||||
val fileName = queryDisplayName(context, uri)
|
||||
?.takeIf { it.isNotBlank() }
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.zklh.dronecontroller.core.mission
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import java.io.File
|
||||
|
||||
data class MissionBrowseRoot(val name: String, val directory: File, val publicStorage: Boolean)
|
||||
|
||||
/** File listing for the in-app route picker. Only approved storage roots are traversed. */
|
||||
object MissionLocalBrowser {
|
||||
private val routeExtensions = setOf("kmz", "kml", "wpml", "zip")
|
||||
|
||||
fun roots(context: Context): List<MissionBrowseRoot> {
|
||||
val result = mutableListOf(
|
||||
MissionBrowseRoot("已导入航线", File(context.cacheDir, "missions").apply { mkdirs() }, false),
|
||||
MissionBrowseRoot("App 文件", context.filesDir, false)
|
||||
)
|
||||
val primary = Environment.getExternalStorageDirectory()
|
||||
result += MissionBrowseRoot("下载", File(primary, "Download"), true)
|
||||
result += MissionBrowseRoot("文档", File(primary, "Documents"), true)
|
||||
result += MissionBrowseRoot("设备存储", primary, true)
|
||||
context.getExternalFilesDirs(null).filterNotNull().forEachIndexed { index, dir ->
|
||||
val path = dir.absolutePath.substringBefore("${File.separator}Android${File.separator}data${File.separator}")
|
||||
if (path != dir.absolutePath && path != primary.absolutePath) {
|
||||
result += MissionBrowseRoot("外置存储 ${index + 1}", File(path), true)
|
||||
}
|
||||
}
|
||||
return result.distinctBy { it.directory.canonicalPath }
|
||||
}
|
||||
|
||||
fun canBrowse(root: MissionBrowseRoot): Boolean = !root.publicStorage ||
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.R || Environment.isExternalStorageManager()
|
||||
|
||||
fun contains(root: MissionBrowseRoot, file: File): Boolean {
|
||||
val base = root.directory.canonicalPath.trimEnd(File.separatorChar)
|
||||
val path = file.canonicalPath
|
||||
return path == base || path.startsWith(base + File.separator)
|
||||
}
|
||||
|
||||
fun list(root: MissionBrowseRoot, directory: File): List<File> {
|
||||
require(canBrowse(root)) { "需要允许读取设备文件" }
|
||||
require(contains(root, directory) && directory.isDirectory) { "无法打开此文件夹" }
|
||||
val files = directory.listFiles() ?: error("无法读取此文件夹,请检查存储权限")
|
||||
return files.asSequence().filter { file ->
|
||||
file.canRead() && contains(root, file) &&
|
||||
(file.isDirectory || file.isFile && file.extension.lowercase() in routeExtensions)
|
||||
}.sortedWith(compareBy<File> { !it.isDirectory }.thenBy { it.name.lowercase() }).take(1000).toList()
|
||||
}
|
||||
|
||||
fun canSelect(root: MissionBrowseRoot, file: File): Boolean =
|
||||
contains(root, file) && file.isFile && file.canRead() && file.extension.lowercase() in routeExtensions
|
||||
}
|
||||
+1
@@ -33,6 +33,7 @@ internal class CameraStreamCapabilities(private val publish: (Map<String, List<S
|
||||
}
|
||||
KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyConnection, camera), holder, true) { _, connected ->
|
||||
if (connected == false) update(camera.name, emptyList())
|
||||
if (connected == true) refresh()
|
||||
}
|
||||
}.onFailure { Log.d("CloudCameraCapacity", "source range unavailable: $camera", it) }
|
||||
}
|
||||
|
||||
+28
-2
@@ -14,6 +14,10 @@ import dji.sdk.keyvalue.key.PayloadKey
|
||||
import dji.sdk.keyvalue.key.ProductKey
|
||||
import dji.sdk.keyvalue.key.RemoteControllerKey
|
||||
import dji.sdk.keyvalue.value.camera.CameraType
|
||||
import dji.sdk.keyvalue.value.camera.CameraThermalPalette
|
||||
import dji.sdk.keyvalue.value.camera.CameraVideoStreamSourceType
|
||||
import dji.sdk.keyvalue.value.camera.ZoomRatiosRange
|
||||
import dji.sdk.keyvalue.value.common.CameraLensType
|
||||
import dji.sdk.keyvalue.key.RtkMobileStationKey
|
||||
import dji.sdk.keyvalue.value.camera.CameraWorkMode
|
||||
import dji.sdk.keyvalue.value.camera.CameraMode
|
||||
@@ -171,6 +175,13 @@ data class TelemetrySnapshot(
|
||||
val storageRemain: Int = 0,
|
||||
val zoomFactor: Double = 1.0,
|
||||
val irZoomFactor: Double = 1.0,
|
||||
val cameraStreamSource: String = "",
|
||||
val visibleZoomGears: List<Int> = emptyList(),
|
||||
val visibleZoomContinuous: Boolean = false,
|
||||
val thermalZoomGears: List<Int> = emptyList(),
|
||||
val thermalZoomContinuous: Boolean = false,
|
||||
val thermalPalette: String = "",
|
||||
val thermalPaletteRange: List<String> = emptyList(),
|
||||
val gimbalPitch: Double = 0.0,
|
||||
val gimbalRoll: Double = 0.0,
|
||||
val gimbalYaw: Double = 0.0,
|
||||
@@ -834,10 +845,25 @@ class TelemetryRepository(
|
||||
listenSafely("KeyInternalStorageRemainSpace", KeyTools.createKey(DJICameraKey.KeyInternalStorageRemainSpace, cameraIndex)) { remain: Int? ->
|
||||
if ((remain ?: 0) > 0) updateStorage(total = null, remain = remain)
|
||||
}
|
||||
listenSafely("KeyCameraZoomRatios", KeyTools.createKey(CameraKey.KeyCameraZoomRatios, cameraIndex)) { zoom: Double? ->
|
||||
listenSafely("KeyCameraVideoStreamSource", KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, cameraIndex)) { source: CameraVideoStreamSourceType? ->
|
||||
_state.update { it.copy(cameraStreamSource = source?.name.orEmpty()) }
|
||||
}
|
||||
listenSafely("KeyCameraZoomRatiosRange", KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatiosRange, cameraIndex, CameraLensType.CAMERA_LENS_ZOOM)) { range: ZoomRatiosRange? ->
|
||||
_state.update { it.copy(visibleZoomGears = range?.gears?.toList().orEmpty(), visibleZoomContinuous = range?.isContinuous == true) }
|
||||
}
|
||||
listenSafely("KeyThermalZoomRatiosRange", KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatiosRange, cameraIndex, CameraLensType.CAMERA_LENS_THERMAL)) { range: ZoomRatiosRange? ->
|
||||
_state.update { it.copy(thermalZoomGears = range?.gears?.toList().orEmpty(), thermalZoomContinuous = range?.isContinuous == true) }
|
||||
}
|
||||
listenSafely("KeyThermalPaletteRange", KeyTools.createCameraKey(DJICameraKey.KeyThermalPaletteRange, cameraIndex, CameraLensType.CAMERA_LENS_THERMAL)) { palettes: List<CameraThermalPalette>? ->
|
||||
_state.update { it.copy(thermalPaletteRange = palettes.orEmpty().map { palette -> palette.name }) }
|
||||
}
|
||||
listenSafely("KeyThermalPalette", KeyTools.createCameraKey(DJICameraKey.KeyThermalPalette, cameraIndex, CameraLensType.CAMERA_LENS_THERMAL)) { palette: CameraThermalPalette? ->
|
||||
_state.update { it.copy(thermalPalette = palette?.name.orEmpty()) }
|
||||
}
|
||||
listenSafely("KeyCameraZoomRatios", KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, cameraIndex, CameraLensType.CAMERA_LENS_ZOOM)) { zoom: Double? ->
|
||||
_state.update { it.copy(zoomFactor = zoom?.takeIf { value -> value > 0.0 } ?: it.zoomFactor, error = null) }
|
||||
}
|
||||
listenSafely("KeyThermalZoomRatios", KeyTools.createKey(CameraKey.KeyThermalZoomRatios, cameraIndex)) { zoom: Double? ->
|
||||
listenSafely("KeyThermalZoomRatios", KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios, cameraIndex, CameraLensType.CAMERA_LENS_THERMAL)) { zoom: Double? ->
|
||||
_state.update { it.copy(irZoomFactor = zoom?.takeIf { value -> value > 0.0 } ?: it.irZoomFactor, error = null) }
|
||||
}
|
||||
listenSafely("KeyLaserMeasureInformation", KeyTools.createKey(DJICameraKey.KeyLaserMeasureInformation, cameraIndex)) { info: LaserMeasureInformation? ->
|
||||
|
||||
@@ -56,6 +56,8 @@ import androidx.compose.material.icons.filled.Shield
|
||||
import androidx.compose.material.icons.filled.Videocam
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -91,6 +93,9 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import dji.sdk.keyvalue.value.camera.CameraThermalPalette
|
||||
import com.zklh.dronecontroller.core.media.CameraControlService
|
||||
import com.zklh.dronecontroller.core.media.adjacentZoomRatio
|
||||
import com.zklh.dronecontroller.core.cloud.CloudCommandExecutor
|
||||
import com.zklh.dronecontroller.core.cloud.CloudLoginClient
|
||||
import com.zklh.dronecontroller.core.cloud.CloudLoginRequest
|
||||
@@ -109,6 +114,7 @@ import com.zklh.dronecontroller.core.livestream.LiveStreamingService
|
||||
import com.zklh.dronecontroller.core.media.CameraMediaService
|
||||
import com.zklh.dronecontroller.core.mission.MissionAction
|
||||
import com.zklh.dronecontroller.core.mission.MissionFileStore
|
||||
import com.zklh.dronecontroller.core.mission.MissionLocalBrowser
|
||||
import com.zklh.dronecontroller.core.mission.MissionPlan
|
||||
import com.zklh.dronecontroller.core.mission.MissionUploadUpdate
|
||||
import com.zklh.dronecontroller.core.mission.MissionWaypoint
|
||||
@@ -308,7 +314,6 @@ private fun DroneControllerContent() {
|
||||
|
||||
var page by remember { mutableStateOf(PilotPage.Home) }
|
||||
var preflightReturnPage by remember { mutableStateOf(PilotPage.Home) }
|
||||
BackHandler(enabled = page != PilotPage.Home) { page = when (page) { PilotPage.ThirdPartyCloud -> PilotPage.Cloud; PilotPage.Preflight -> preflightReturnPage; else -> PilotPage.Home } }
|
||||
var flightMode by remember { mutableStateOf(FlightMode.Camera) }
|
||||
var commandMessage by remember { mutableStateOf("待机,等待设备连接") }
|
||||
var flightActionStatus by remember { mutableStateOf("") }
|
||||
@@ -317,6 +322,18 @@ private fun DroneControllerContent() {
|
||||
var missionId by remember { mutableStateOf("") }
|
||||
var uploadUpdate by remember { mutableStateOf(MissionUploadUpdate()) }
|
||||
var showMissionPanel by remember { mutableStateOf(false) }
|
||||
var showMissionFilePicker by remember { mutableStateOf(false) }
|
||||
val cameraControl = remember { CameraControlService() }
|
||||
var cameraControlBusy by remember { mutableStateOf(false) }
|
||||
BackHandler(enabled = showMissionFilePicker || page != PilotPage.Home) {
|
||||
when {
|
||||
showMissionFilePicker -> showMissionFilePicker = false
|
||||
page == PilotPage.Flight && showMissionPanel -> showMissionPanel = false
|
||||
page == PilotPage.ThirdPartyCloud -> page = PilotPage.Cloud
|
||||
page == PilotPage.Preflight -> page = preflightReturnPage
|
||||
else -> page = PilotPage.Home
|
||||
}
|
||||
}
|
||||
var stickPower by remember { mutableStateOf(Stick.MAX_STICK_POSITION_ABS) }
|
||||
var thirdCloudUrl by remember { mutableStateOf(savedCloudLoginConfig.url) }
|
||||
var thirdCloudTenantName by remember { mutableStateOf(savedCloudLoginConfig.tenantName) }
|
||||
@@ -340,6 +357,16 @@ private fun DroneControllerContent() {
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun applySelectedMission(file: File) {
|
||||
missionPath = file.absolutePath
|
||||
missionRevision++
|
||||
uploadUpdate = MissionUploadUpdate()
|
||||
missionId = waypointMission.missionIdFromPath(file.absolutePath)
|
||||
commandMessage = "航线文件已载入"
|
||||
showMissionPanel = true
|
||||
toast(commandMessage)
|
||||
}
|
||||
|
||||
val missionPicker = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.OpenDocument()
|
||||
) { uri ->
|
||||
@@ -347,15 +374,7 @@ private fun DroneControllerContent() {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val result = runCatching { MissionFileStore.copyToMissionCache(context, uri) }
|
||||
withContext(Dispatchers.Main) {
|
||||
result.onSuccess { file ->
|
||||
missionPath = file.absolutePath
|
||||
missionRevision++
|
||||
uploadUpdate = MissionUploadUpdate()
|
||||
missionId = waypointMission.missionIdFromPath(file.absolutePath)
|
||||
commandMessage = "航线文件已载入"
|
||||
showMissionPanel = true
|
||||
toast(commandMessage)
|
||||
}.onFailure { error ->
|
||||
result.onSuccess(::applySelectedMission).onFailure { error ->
|
||||
commandMessage = error.message ?: error.toString()
|
||||
toast(commandMessage)
|
||||
}
|
||||
@@ -533,14 +552,7 @@ private fun DroneControllerContent() {
|
||||
}
|
||||
}
|
||||
val pickMission: () -> Unit = {
|
||||
missionPicker.launch(
|
||||
arrayOf(
|
||||
"application/vnd.google-earth.kmz",
|
||||
"application/zip",
|
||||
"application/octet-stream",
|
||||
"*/*"
|
||||
)
|
||||
)
|
||||
showMissionFilePicker = true
|
||||
}
|
||||
val uploadMission: () -> Unit = {
|
||||
if (missionPath.isBlank()) {
|
||||
@@ -953,6 +965,7 @@ private fun DroneControllerContent() {
|
||||
liveStreaming = liveState.streaming,
|
||||
liveBusy = liveState.busy,
|
||||
cameraRecording = cameraRecording,
|
||||
cameraControlBusy = cameraControlBusy,
|
||||
laserFillLightEnabled = laserFillLightEnabled,
|
||||
showMissionPanel = showMissionPanel,
|
||||
onBack = { page = PilotPage.Home },
|
||||
@@ -980,11 +993,36 @@ private fun DroneControllerContent() {
|
||||
onSendStick = { position ->
|
||||
virtualStick.sendStickPosition(position)
|
||||
},
|
||||
onZoomChange = { ratio ->
|
||||
scope.launch {
|
||||
val result = com.zklh.dronecontroller.core.media.CameraControlService(cameraMedia.currentCameraIndex()).setVisibleZoomRatio(ratio)
|
||||
commandMessage = result.message
|
||||
if (!result.success) toast(commandMessage)
|
||||
onCameraSourceChange = { source ->
|
||||
if (!cameraControlBusy) scope.launch {
|
||||
cameraControlBusy = true
|
||||
try {
|
||||
val result = cameraControl.setLens(source)
|
||||
commandMessage = result.message
|
||||
if (!result.success) toast(commandMessage)
|
||||
} finally { cameraControlBusy = false }
|
||||
}
|
||||
},
|
||||
onZoomChange = { thermal, ratio ->
|
||||
if (!cameraControlBusy) scope.launch {
|
||||
cameraControlBusy = true
|
||||
try {
|
||||
val result = if (thermal) cameraControl.setThermalZoomRatio(ratio)
|
||||
else cameraControl.setVisibleZoomRatio(ratio)
|
||||
commandMessage = result.message
|
||||
if (!result.success) toast(commandMessage)
|
||||
} finally { cameraControlBusy = false }
|
||||
}
|
||||
},
|
||||
onThermalPaletteChange = { palette ->
|
||||
if (!cameraControlBusy) scope.launch {
|
||||
cameraControlBusy = true
|
||||
try {
|
||||
val selected = CameraThermalPalette.valueOf(palette)
|
||||
val result = cameraControl.setThermalPalette(selected)
|
||||
commandMessage = result.message
|
||||
if (!result.success) toast(commandMessage)
|
||||
} finally { cameraControlBusy = false }
|
||||
}
|
||||
},
|
||||
onTakePhoto = takePhoto,
|
||||
@@ -994,6 +1032,27 @@ private fun DroneControllerContent() {
|
||||
onToast = ::toast
|
||||
)
|
||||
}
|
||||
if (showMissionFilePicker) PilotMissionFilePicker(
|
||||
onSelect = { root, file ->
|
||||
if (MissionLocalBrowser.canSelect(root, file)) {
|
||||
showMissionFilePicker = false
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val result = runCatching { MissionFileStore.copyToMissionCache(context, file) }
|
||||
withContext(Dispatchers.Main) {
|
||||
result.onSuccess(::applySelectedMission).onFailure { error ->
|
||||
commandMessage = error.message ?: "无法读取航线文件"
|
||||
toast(commandMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onSystemFiles = {
|
||||
showMissionFilePicker = false
|
||||
missionPicker.launch(arrayOf("application/vnd.google-earth.kmz", "application/zip", "application/octet-stream", "*/*"))
|
||||
},
|
||||
onClose = { showMissionFilePicker = false }
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -1047,6 +1106,7 @@ private fun FlightScreen(
|
||||
liveStreaming: Boolean,
|
||||
liveBusy: Boolean,
|
||||
cameraRecording: Boolean,
|
||||
cameraControlBusy: Boolean,
|
||||
laserFillLightEnabled: Boolean,
|
||||
showMissionPanel: Boolean,
|
||||
onBack: () -> Unit,
|
||||
@@ -1068,7 +1128,9 @@ private fun FlightScreen(
|
||||
onToggleSimulator: () -> Unit,
|
||||
onToggleLiveStream: () -> Unit,
|
||||
onSendStick: (StickPosition) -> Unit,
|
||||
onZoomChange: (Double) -> Unit,
|
||||
onCameraSourceChange: (String) -> Unit,
|
||||
onZoomChange: (Boolean, Double) -> Unit,
|
||||
onThermalPaletteChange: (String) -> Unit,
|
||||
onTakePhoto: () -> Unit,
|
||||
onToggleRecord: () -> Unit,
|
||||
onToggleLaserFillLight: () -> Unit,
|
||||
@@ -1220,6 +1282,9 @@ private fun FlightScreen(
|
||||
Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||
if (camera) DjiCameraLivePreview(sdkState.productConnected, Modifier.fillMaxSize())
|
||||
else PilotMap(sdkState.productConnected, telemetry, Modifier.fillMaxSize(), missionPreview.preview, controlsLeading = true, onConfigure = { showMapSettings = true })
|
||||
if (camera) PilotCameraLensControls(sdkState.productConnected, cameraControlBusy, telemetry,
|
||||
onCameraSourceChange, onZoomChange, onThermalPaletteChange,
|
||||
Modifier.align(Alignment.TopEnd).padding(12.dp))
|
||||
PilotSwapPreview(camera, sdkState.productConnected, telemetry, missionPreview.preview, onToggleFlightMode,
|
||||
Modifier.align(Alignment.BottomStart).padding(12.dp).size(155.dp, 88.dp))
|
||||
}
|
||||
@@ -1246,6 +1311,9 @@ private fun FlightScreen(
|
||||
if (camera) {
|
||||
DjiCameraLivePreview(sdkState.productConnected, Modifier.fillMaxSize())
|
||||
FocusFrame(compact, Modifier.align(Alignment.Center))
|
||||
PilotCameraLensControls(sdkState.productConnected, cameraControlBusy, telemetry,
|
||||
onCameraSourceChange, onZoomChange, onThermalPaletteChange,
|
||||
Modifier.align(Alignment.TopEnd).padding(12.dp))
|
||||
Surface(Modifier.align(Alignment.TopStart).padding(12.dp), color = Color(0xB829435C), shape = RoundedCornerShape(8.dp)) {
|
||||
Row(Modifier.padding(horizontal = 12.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.size(10.dp).background(if (cameraRecording) PilotDanger else PilotMuted, CircleShape))
|
||||
@@ -1266,15 +1334,6 @@ private fun FlightScreen(
|
||||
PilotTool(Icons.Filled.Image, "相册") { showMedia = true }
|
||||
PilotTool(Icons.Filled.Panorama, "全景", active = cameraQuickAction == CameraQuickAction.Panorama, enabled = sdkState.productConnected) { changeCameraQuickAction(CameraQuickAction.Panorama) }
|
||||
PilotTool(Icons.Filled.Lightbulb, "补光灯", active = laserFillLightEnabled, enabled = sdkState.productConnected, onClick = onToggleLaserFillLight)
|
||||
if (camera) {
|
||||
Surface(color = Color(0xFF405873), shape = RoundedCornerShape(7.dp)) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Text(if (sdkState.productConnected) "${instrumentNumber(telemetry.zoomFactor)}x" else "—", color = Color.White, fontSize = 11.sp, modifier = Modifier.padding(top = 8.dp))
|
||||
IconButton(onClick = { onZoomChange((telemetry.zoomFactor + 1).coerceAtMost(200.0)) }, enabled = sdkState.productConnected) { Icon(Icons.Filled.Add, "增加相机变焦", tint = Color.White) }
|
||||
IconButton(onClick = { onZoomChange((telemetry.zoomFactor - 1).coerceAtLeast(1.0)) }, enabled = sdkState.productConnected) { Icon(Icons.Filled.Remove, "减小相机变焦", tint = Color.White) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(Modifier.fillMaxWidth().height(wheelSize + 12.dp).padding(horizontal = 20.dp, vertical = 6.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
@@ -1320,6 +1379,100 @@ private fun PilotSwapPreview(cameraMain: Boolean, connected: Boolean, telemetry:
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PilotCameraLensControls(
|
||||
connected: Boolean,
|
||||
busy: Boolean,
|
||||
telemetry: TelemetrySnapshot,
|
||||
onSourceChange: (String) -> Unit,
|
||||
onZoomChange: (Boolean, Double) -> Unit,
|
||||
onPaletteChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val sources = telemetry.cameraStreamSources["LEFT_OR_MAIN"].orEmpty()
|
||||
val choices = listOf("WIDE_CAMERA" to "广角", "ZOOM_CAMERA" to "变焦", "INFRARED_CAMERA" to "红外")
|
||||
.filter { it.first in sources }
|
||||
val source = telemetry.cameraStreamSource
|
||||
val thermal = source == "INFRARED_CAMERA"
|
||||
val zoom = source == "ZOOM_CAMERA"
|
||||
val gears = if (thermal) telemetry.thermalZoomGears else telemetry.visibleZoomGears
|
||||
val continuous = if (thermal) telemetry.thermalZoomContinuous else telemetry.visibleZoomContinuous
|
||||
val ratio = if (thermal) telemetry.irZoomFactor else telemetry.zoomFactor
|
||||
val lower = if (zoom || thermal) adjacentZoomRatio(ratio, gears, continuous, false) else null
|
||||
val higher = if (zoom || thermal) adjacentZoomRatio(ratio, gears, continuous, true) else null
|
||||
var showPalettes by remember { mutableStateOf(false) }
|
||||
|
||||
Surface(modifier.width(198.dp), color = Color(0xCB1C344B), shape = RoundedCornerShape(9.dp)) {
|
||||
Column(Modifier.padding(8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("相机镜头", color = Color.White, fontSize = 11.sp, fontWeight = FontWeight.SemiBold)
|
||||
if (choices.isEmpty()) {
|
||||
Text(if (connected) "当前相机没有可切换的镜头" else "等待相机连接", color = Color(0xFFE0E8F0), fontSize = 10.sp, lineHeight = 13.sp)
|
||||
} else {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
choices.forEach { (value, label) ->
|
||||
val active = source == value
|
||||
Text(label, color = if (connected) Color.White else PilotMuted, fontSize = 11.sp,
|
||||
modifier = Modifier.background(if (active) Color(0xFF3285C7) else Color(0x664E6B83), RoundedCornerShape(5.dp))
|
||||
.clickable(enabled = connected && !busy && !active) { onSourceChange(value.removeSuffix("_CAMERA").lowercase().let { if (it == "infrared") "ir" else it }) }
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (zoom || thermal) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("倍率", color = Color.White, fontSize = 10.sp)
|
||||
Text("−", color = if (lower != null && !busy) Color.White else PilotMuted, fontSize = 18.sp,
|
||||
modifier = Modifier.clickable(enabled = connected && !busy && lower != null) { lower?.let { onZoomChange(thermal, it) } }
|
||||
.padding(horizontal = 5.dp))
|
||||
Text("${instrumentNumber(ratio)}x", color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text("+", color = if (higher != null && !busy) Color.White else PilotMuted, fontSize = 17.sp,
|
||||
modifier = Modifier.clickable(enabled = connected && !busy && higher != null) { higher?.let { onZoomChange(thermal, it) } }
|
||||
.padding(horizontal = 5.dp))
|
||||
}
|
||||
if (gears.isEmpty()) Text("设备未上报可调倍率", color = PilotMuted, fontSize = 9.sp)
|
||||
}
|
||||
if (thermal) {
|
||||
Box {
|
||||
val paletteName = thermalPaletteLabel(telemetry.thermalPalette)
|
||||
Text("色盘 $paletteName ▾", color = if (telemetry.thermalPaletteRange.isNotEmpty()) Color.White else PilotMuted,
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.clickable(enabled = connected && !busy && telemetry.thermalPaletteRange.isNotEmpty()) { showPalettes = true }
|
||||
.padding(vertical = 4.dp))
|
||||
DropdownMenu(expanded = showPalettes, onDismissRequest = { showPalettes = false }) {
|
||||
telemetry.thermalPaletteRange.forEach { palette ->
|
||||
DropdownMenuItem(text = { Text(thermalPaletteLabel(palette)) }, onClick = {
|
||||
showPalettes = false
|
||||
if (palette != telemetry.thermalPalette) onPaletteChange(palette)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun thermalPaletteLabel(value: String): String = when (value) {
|
||||
"WHITE_HOT" -> "白热"
|
||||
"BLACK_HOT" -> "黑热"
|
||||
"RED_HOT" -> "红热"
|
||||
"GREEN_HOT" -> "绿热"
|
||||
"FUSION" -> "融合"
|
||||
"RAINBOW" -> "彩虹"
|
||||
"RAINBOW2" -> "彩虹 2"
|
||||
"IRONBOW1" -> "铁红 1"
|
||||
"IRONBOW2" -> "铁红 2"
|
||||
"ICE_FIRE" -> "冰火"
|
||||
"SEPIA" -> "棕褐"
|
||||
"GLOWBOW" -> "辉光"
|
||||
"HOT_SPOT" -> "热点"
|
||||
"COLD_SPOT" -> "冷点"
|
||||
"GRAY" -> "灰度"
|
||||
"METAL" -> "金属"
|
||||
"" -> "读取中"
|
||||
else -> value.replace('_', ' ')
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FlightStickWheel(
|
||||
title: String,
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Description
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.zklh.dronecontroller.core.mission.MissionBrowseRoot
|
||||
import com.zklh.dronecontroller.core.mission.MissionLocalBrowser
|
||||
import java.io.File
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
private data class MissionFolderContents(val files: List<File> = emptyList(), val error: String? = null, val loading: Boolean = false)
|
||||
|
||||
/** Always has an in-app cancel action, including before a file has been selected. */
|
||||
@Composable
|
||||
internal fun PilotMissionFilePicker(onSelect: (MissionBrowseRoot, File) -> Unit, onSystemFiles: () -> Unit, onClose: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val roots = remember(context) { MissionLocalBrowser.roots(context) }
|
||||
var root by remember { mutableStateOf<MissionBrowseRoot?>(null) }
|
||||
var directory by remember { mutableStateOf<File?>(null) }
|
||||
var refresh by remember { mutableIntStateOf(0) }
|
||||
val accessLauncher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { refresh++ }
|
||||
val currentRoot = root
|
||||
val currentDirectory = directory
|
||||
val contents by produceState(MissionFolderContents(), currentRoot, currentDirectory, refresh) {
|
||||
value = MissionFolderContents(loading = currentRoot != null && currentDirectory != null)
|
||||
if (currentRoot != null && currentDirectory != null) {
|
||||
value = withContext(Dispatchers.IO) {
|
||||
runCatching { MissionFolderContents(MissionLocalBrowser.list(currentRoot, currentDirectory)) }
|
||||
.getOrElse { MissionFolderContents(error = it.message ?: "无法读取此文件夹") }
|
||||
}
|
||||
}
|
||||
}
|
||||
fun goUp() {
|
||||
val selectedRoot = root
|
||||
val selectedDirectory = directory
|
||||
if (selectedRoot == null || selectedDirectory == null || selectedDirectory.canonicalFile == selectedRoot.directory.canonicalFile) {
|
||||
root = null
|
||||
directory = null
|
||||
} else directory = selectedDirectory.parentFile?.takeIf { MissionLocalBrowser.contains(selectedRoot, it) }
|
||||
?: selectedRoot.directory
|
||||
}
|
||||
Dialog(onDismissRequest = onClose, properties = DialogProperties(usePlatformDefaultWidth = false)) {
|
||||
Surface(Modifier.fillMaxWidth(0.9f).widthIn(max = 760.dp).fillMaxHeight(0.85f), shape = androidx.compose.foundation.shape.RoundedCornerShape(12.dp), color = PilotDesign.Background) {
|
||||
Column {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
IconButton(onClick = { if (root == null) onClose() else goUp() }) {
|
||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, "返回", tint = PilotDesign.Ink)
|
||||
}
|
||||
Column(Modifier.weight(1f).padding(start = 4.dp)) {
|
||||
Text("选择航线", color = PilotDesign.Ink, fontSize = 18.sp)
|
||||
Text(directory?.name ?: "选择存储位置", color = PilotDesign.Muted, fontSize = 11.sp,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
TextButton(onClick = onClose) { Text("取消选择") }
|
||||
}
|
||||
HorizontalDivider(color = PilotDesign.Line)
|
||||
LazyColumn(Modifier.weight(1f).fillMaxWidth(), contentPadding = PaddingValues(12.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
if (currentRoot == null) {
|
||||
items(roots) { item ->
|
||||
FilePickerRow(item.name, "浏览本机航线文件", true) {
|
||||
root = item
|
||||
directory = item.directory
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (contents.loading) item { Text("正在读取文件…", color = PilotDesign.Muted, modifier = Modifier.padding(8.dp)) }
|
||||
contents.error?.let { error ->
|
||||
item { Text(error, color = PilotDesign.Red, modifier = Modifier.padding(8.dp), fontSize = 12.sp) }
|
||||
}
|
||||
if (contents.error != null && currentRoot.publicStorage && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !MissionLocalBrowser.canBrowse(currentRoot)) {
|
||||
item {
|
||||
OutlinedButton(onClick = {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
Uri.parse("package:${context.packageName}"))
|
||||
runCatching { accessLauncher.launch(intent) }
|
||||
.onFailure { accessLauncher.launch(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)) }
|
||||
}) { Text("允许浏览设备文件") }
|
||||
}
|
||||
}
|
||||
if (!contents.loading && contents.error == null && contents.files.isEmpty()) {
|
||||
item { Text("此处没有 KMZ / KML / WPML / ZIP 航线文件", color = PilotDesign.Muted, modifier = Modifier.padding(8.dp), fontSize = 12.sp) }
|
||||
}
|
||||
items(contents.files, key = { it.absolutePath }) { file ->
|
||||
FilePickerRow(file.name,
|
||||
if (file.isDirectory) "文件夹" else "${(file.length() / 1024.0).toInt()} KB",
|
||||
file.isDirectory) {
|
||||
if (file.isDirectory) directory = file
|
||||
else if (MissionLocalBrowser.canSelect(currentRoot, file)) onSelect(currentRoot, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalDivider(color = PilotDesign.Line)
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 7.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
TextButton(onClick = onSystemFiles) { Text("从其他来源导入") }
|
||||
Spacer(Modifier.weight(1f))
|
||||
OutlinedButton(onClick = onClose) { Text("返回飞行控制") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FilePickerRow(name: String, detail: String, folder: Boolean, onClick: () -> Unit) {
|
||||
Surface(onClick = onClick, color = Color.White, shape = androidx.compose.foundation.shape.RoundedCornerShape(6.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
Row(Modifier.padding(horizontal = 12.dp, vertical = 10.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(if (folder) Icons.Default.Folder else Icons.Default.Description, null, tint = PilotDesign.Blue, modifier = Modifier.size(20.dp))
|
||||
Column(Modifier.padding(start = 10.dp).weight(1f)) {
|
||||
Text(name, fontSize = 12.sp, color = PilotDesign.Ink, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(detail, fontSize = 10.sp, color = PilotDesign.Muted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,8 @@ internal fun PilotMissionPanel(connected: Boolean, telemetry: TelemetrySnapshot,
|
||||
Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Row(Modifier.height(28.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text("航线任务", color = PilotDesign.Ink, fontSize = 20.sp, lineHeight = 26.sp, fontWeight = FontWeight.Bold, modifier = Modifier.weight(1f))
|
||||
IconButton(onClick = onClose, modifier = Modifier.size(28.dp)) { Icon(Icons.Default.Close, "关闭航线任务", tint = PilotDesign.Ink, modifier = Modifier.size(21.dp)) }
|
||||
TextButton(onClick = onClose, contentPadding = PaddingValues(horizontal = 6.dp, vertical = 0.dp)) { Text("返回", fontSize = 11.sp) }
|
||||
IconButton(onClick = onClose, modifier = Modifier.size(36.dp)) { Icon(Icons.Default.Close, "关闭航线任务", tint = PilotDesign.Ink, modifier = Modifier.size(21.dp)) }
|
||||
}
|
||||
Row(Modifier.fillMaxWidth()) {
|
||||
listOf("文件导入", "任务信息", "航点列表", "任务设置").forEachIndexed { index, title ->
|
||||
|
||||
Reference in New Issue
Block a user