TR-mbed 1.0
Loading...
Searching...
No Matches
DJIRemote.h
Go to the documentation of this file.
1#include "mbed.h"
2
3#ifndef DJI_REMOTE
4#define DJI_REMOTE
9class Remote
10
11{
12public:
13 Remote(PinName dbus);
14
15
26
30 enum class Switch
31 {
34 };
35
39 enum class SwitchState
40 {
41 UNKNOWN,
42 DOWN,
43 MID,
44 UP
45 };
46
50 enum class Key
51 {
52 W = 0,
53 S,
54 A,
55 D,
56 SHIFT,
57 CTRL,
58 Q,
59 E,
60 R,
61 F,
62 G,
63 Z,
64 X,
65 C,
66 V,
67 B
68 };
69
73 void initialize();
74
79 void read();
80
87 __attribute__((unused)) bool isConnected() const;
88
92 float getChannel(Channel ch) const;
93
94 int16_t getChannelInt(Channel ch) const;
95
96 void printAxisData() const;
97
98 void dumpInfo() const;
99
104
108 int16_t getMouseX() const;
109
113 int16_t getMouseY() const;
114
118 int16_t getMouseZ() const;
119
123 bool getMouseL() const;
124
128 bool getMouseR() const;
129
133 bool keyPressed(Key key) const;
134
138 int16_t getWheel() const;
139
143 uint32_t getUpdateCounter() const;
144
147 bool unfiltered = false;
148
149 inline int leftX() const{
150 return remote.leftHorizontal;
151 }
152
153 inline int leftY() const{
154 return remote.leftVertical;
155 }
156
157 inline int rightX() const{
158 return remote.rightHorizontal;
159 }
160
161 inline int rightY() const{
162 return remote.rightVertical;
163 }
164
166 return remote.leftSwitch;
167 }
168
170 return remote.rightSwitch;
171 }
172
173private:
174
175 BufferedSerial receiver;
176 Timer readTimer;
177
178 static const int REMOTE_BUF_LEN = 18;
179 static const int REMOTE_READ_TIMEOUT = 6;
180 static const int REMOTE_DISCONNECT_TIMEOUT = 200;
181 static const int REMOTE_INT_PRI = 12;
182 static constexpr float STICK_MAX_VALUE = 660.0f;
183
185 struct RemoteInfo
186 {
187 uint32_t updateCounter = 0;
188 int16_t rightHorizontal = 0;
189 int16_t rightVertical = 0;
190 int16_t leftHorizontal = 0;
191 int16_t leftVertical = 0;
193 SwitchState rightSwitch = SwitchState::UNKNOWN;
194 struct
195 {
196 int16_t x = 0;
197 int16_t y = 0;
198 int16_t z = 0;
199 bool l = false;
200 bool r = false;
201 } mouse;
202 uint16_t key = 0;
203 int16_t wheel = 0;
204 };
205
206 RemoteInfo remote;
207
208 static void switchToState(RemoteInfo *remote);
209
210 bool badData(const uint8_t rxBuffer[], RemoteInfo *remote);
211
213 bool connected = false;
214
216 uint8_t rxBuffer[REMOTE_BUF_LEN]{0};
217
219 uint32_t lastRead = 0;
220
222 uint8_t currentBufferIndex = 0;
223
225 void parseBuffer();
226
228 void clearRxBuffer();
229
231 void reset();
232
233}; // class Remote
234#endif
235
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
Definition DJIRemote.h:11
Channel
Definition DJIRemote.h:20
void printAxisData() const
int16_t getWheel() const
int16_t getMouseZ() const
void initialize()
Definition DJIRemote.cpp:16
__attribute__((unused)) bool isConnected() const
long badDataChainNumber
Definition DJIRemote.h:145
int leftX() const
Definition DJIRemote.h:149
Remote::SwitchState rightSwitch() const
Definition DJIRemote.h:169
int16_t getMouseX() const
SwitchState getSwitch(Switch sw) const
int leftY() const
Definition DJIRemote.h:153
bool getMouseL() const
int16_t getChannelInt(Channel ch) const
int rightY() const
Definition DJIRemote.h:161
long goodDataChainNumber
Definition DJIRemote.h:146
bool keyPressed(Key key) const
void dumpInfo() const
void read()
Definition DJIRemote.cpp:19
uint32_t getUpdateCounter() const
Definition DJIRemote.cpp:262
int16_t getMouseY() const
float getChannel(Channel ch) const
bool unfiltered
Definition DJIRemote.h:147
Switch
Definition DJIRemote.h:31
int rightX() const
Definition DJIRemote.h:157
Remote::SwitchState leftSwitch() const
Definition DJIRemote.h:165
bool getMouseR() const
Key
Definition DJIRemote.h:51
SwitchState
Definition DJIRemote.h:40
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition gnuplot_common_settings.hh:12
Scalar * y
Definition level1_cplx_impl.h:124
::int16_t int16_t
Definition Meta.h:55
::uint16_t uint16_t
Definition Meta.h:54
::uint32_t uint32_t
Definition Meta.h:56
::uint8_t uint8_t
Definition Meta.h:52