chenyao
2025-02-26 31b7e874bac09e8a82c938c75e36452580dfddd6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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,
  };
}