import { showNotify } from 'vant';
|
import {
|
postPayloadAuth,
|
postPayloadCommands,
|
PayloadCommandsEnum,
|
PostCameraModeBody,
|
PostCameraFocalLengthBody,
|
PostGimbalResetBody,
|
PostCameraAimBody,
|
} from '@/api/drone-control/payload'
|
import { ControlSource } from '@/types/device'
|
|
export function usePayloadControl() {
|
function checkPayloadAuth(controlSource?: ControlSource) {
|
if (controlSource !== ControlSource.A) {
|
// Message.error('Get Payload Control first')
|
showNotify({ type: 'danger', message: '请先获取负载控制' })
|
return false;
|
}
|
return true;
|
}
|
|
function authPayload(sn='', payloadIndx='') {
|
return postPayloadAuth(sn, {
|
payload_index: payloadIndx,
|
});
|
}
|
|
async function resetGimbal(sn='', data={}) {
|
const { code } = await postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.GimbalReset,
|
data: data,
|
});
|
if (code === 0) {
|
showNotify({ type: 'success', message: '万向节复位成功' })
|
}
|
}
|
|
async function switchCameraMode(sn='', data={}) {
|
const { code } = await postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraModeSwitch,
|
data: data,
|
});
|
if (code === 0) {
|
return true;
|
} else {
|
showNotify({ type: 'warning', message: '拍照或者录像失败,请重试!' })
|
return false;
|
}
|
}
|
|
async function takeCameraPhoto(sn='', payloadIndx='', cameraType='') {
|
const { code } = await postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraPhotoTake,
|
data: {
|
payload_index: payloadIndx,
|
camera_type: cameraType,
|
},
|
});
|
if (code === 0) {
|
showNotify({ type: 'success', message: '拍照成功' })
|
return true;
|
} else {
|
showNotify({ type: 'warning', message: '拍照失败,请重试!' })
|
return false;
|
}
|
}
|
|
async function startCameraRecording(sn='', payloadIndx='') {
|
return postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraRecordingStart,
|
data: {
|
payload_index: payloadIndx,
|
},
|
});
|
}
|
|
async function stopCameraRecording(sn='', payloadIndx='') {
|
return postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraRecordingStop,
|
data: {
|
payload_index: payloadIndx,
|
},
|
});
|
}
|
|
async function changeCameraFocalLength(sn='', data={},isZoom=false, strZoom='') {
|
const { code } = await postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraFocalLengthSet,
|
data: data,
|
});
|
if (strZoom == '复原' || strZoom == '变焦复原') {
|
// ElMessage.success('切换成功');
|
} else if (isZoom) {
|
showNotify({ type: 'success', message: '放大成功' })
|
} else {
|
showNotify({ type: 'success', message: '缩小成功' })
|
}
|
}
|
|
async function cameraAim(sn='', data={}) {
|
const { code } = await postPayloadCommands(sn, {
|
cmd: PayloadCommandsEnum.CameraAim,
|
data: data,
|
});
|
if (code === 0) {
|
showNotify({ type: 'success', message: '缩放目标成功' })
|
}
|
}
|
|
return {
|
checkPayloadAuth,
|
authPayload,
|
resetGimbal,
|
switchCameraMode,
|
takeCameraPhoto,
|
startCameraRecording,
|
stopCameraRecording,
|
changeCameraFocalLength,
|
cameraAim,
|
};
|
}
|