-
Notifications
You must be signed in to change notification settings - Fork 0
/
Api.h
144 lines (116 loc) · 3.46 KB
/
Api.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef API_H
#define API_H
#include <QObject>
#include <QTimerEvent>
#include "Connection.h"
namespace siyi {
class Api : public QObject
{
Q_OBJECT
public:
enum class CameraType {
ZR10,
A8Mini,
A2Mini,
ZR30,
ZT30,
Unknown,
};
FirmwareMessage firmwareMessage;
HardwareIDMessage hardwareIDMessage;
ManualZoomMessage manualZoomMessage;
GimbalAttitudeMessage gimbalAttitudeMessage;
ManualFocusMessage manualFocusMessage;
CameraStatusInfoMessage cameraStatusInfoMessage;
public:
// Instance singleton
static Api& instance(const QString& serverIp = "192.168.144.25", quint16 port = 37260) {
static Api instance(serverIp, port);
return instance;
}
~Api() override;
/**
* @brief Check if Siyi API is initialized
* @return True if Siyi API is initialized, false otherwise
*/
[[nodiscard]] bool initialized() const {
return _cameraType != CameraType::Unknown || !hardwareIDMessage.hardwareID.isEmpty();
}
/**
* @brief Set gimbal angles
* @param pan Pan angle
* @param tilt Tilt angle
* @return True if angles were set, false otherwise
*/
[[nodiscard]] bool setAngles(float pan, float tilt);
/**
* @brief Set gimbal center
* @return True if center was set, false otherwise
*/
[[nodiscard]] bool setGimbalCenter();
/**
* @brief Set gimbal rates
* @param panRate Pan rate
* @param tiltRate Tilt rate
* @return True if rates were set, false otherwise
*/
[[nodiscard]] bool setRates(float panRate, float tiltRate);
/**
* @brief Send take photo message
* @return True if message was sent, false otherwise
*/
[[nodiscard]] bool takePhoto();
/**
* @brief Send start recording video message
* @return True if message was sent, false otherwise
*/
[[nodiscard]] bool toggleRecordingVideo();
/**
* @brief Set camera mode (lock, fpv, follow)
* @return True if message was sent, false otherwise
*/
[[nodiscard]] bool setCameraMode(uint8_t mode);
// Zoom messages
bool zoom(uint8_t zoomValue);
bool zoomDirection(int8_t direction);
// Focus message
bool manualFocus(int8_t direction);
// Camera type
[[nodiscard]] CameraType cameraType() const { return _cameraType; };
signals:
/**
* Signal about gimbal angles need to update
*/
void updateGimbalAngles();
protected:
void timerEvent(QTimerEvent* e) override;
private:
explicit Api(const QString& serverIp = "192.168.144.25", quint16 port = 37260, QObject* parent = nullptr);
/**
* @brief Initialize Siyi API
* @return True if initialization was successful, false otherwise
*/
void init(const QString& serverIp = "192.168.144.25", quint16 port = 37260);
// Additional message handlers that need to be called after hardware ID message parsing
void getCameraType();
private slots:
/**
* @brief Process SDK message
* @param message Message
* @param command Command
*/
void processSdkMessage(const QVariant& message, quint8 command);
signals:
/**
* Send message to camera signal
* @param message
*/
void sendMessage(const QByteArray& message);
private:
Connection* _siyiConnection{nullptr};
MessageBuilder _messageBuilder;
int _gimbalAttitudeTimer{-1};
CameraType _cameraType{CameraType::Unknown};
};
} // namespace siyi
#endif // API_H