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
5
6// I don't like constants being here but also they're robot independent (?)
7// DEGREES PER SECOND AT MAX
8// constexpr float JOYSTICK_SENSITIVITY_YAW_DPS = 180.0;
9// constexpr float JOYSTICK_SENSITIVITY_PITCH_DPS = 180.0;
10
11// Mouse sensitivity initialized
12// constexpr float MOUSE_SENSITIVITY_YAW_DPS = 10.0;
13// constexpr float MOUSE_SENSITIVITY_PITCH_DPS = 10.0;
14
19class Remote
20
21{
22public:
23 Remote(PinName dbus);
24
35
39 enum class Switch
40 {
43 };
44
48 enum class SwitchState
49 {
50 UNKNOWN,
51 DOWN,
52 MID,
53 UP
54 };
55
59 enum class Key
60 {
61 W = 0,
62 S,
63 A,
64 D,
65 SHIFT,
66 CTRL,
67 Q,
68 E,
69 R,
70 F,
71 G,
72 Z,
73 X,
74 C,
75 V,
76 B
77 };
78
82 void initialize();
83
88 void read();
89
96 __attribute__((unused)) bool isConnected() const;
97
101 float getChannel(Channel ch) const;
102
103 int16_t getChannelInt(Channel ch) const;
104
105 void printAxisData() const;
106
107 void dumpInfo() const;
108
112 SwitchState getSwitch(Switch sw) const;
113
117 int16_t getMouseX() const;
118
122 int16_t getMouseY() const;
123
127 int16_t getMouseZ() const;
128
132 bool getMouseL() const;
133
137 bool getMouseR() const;
138
142 bool keyPressed(Key key) const;
143
147 int16_t getWheel() const;
148
152 uint32_t getUpdateCounter() const;
153
156 bool unfiltered = false;
157
158 inline float leftX() const
159 {
160 return remote.leftHorizontal / 660.0;
161 }
162
163 inline float leftY() const
164 {
165 return remote.leftVertical / 660.0;
166 }
167
168 inline float rightX() const
169 {
170 return remote.rightHorizontal / 660.0;
171 }
172
173 inline float rightY() const
174 {
175 return remote.rightVertical / 660.0;
176 }
177
179 {
180 return remote.leftSwitch;
181 }
182
184 {
185 return remote.rightSwitch;
186 }
187
188private:
189 BufferedSerial receiver;
190 Timer readTimer;
191
192 static const int REMOTE_BUF_LEN = 18;
193 static const int REMOTE_READ_TIMEOUT = 6;
194 static const int REMOTE_DISCONNECT_TIMEOUT = 200;
195 static const int REMOTE_INT_PRI = 12;
196 static constexpr float STICK_MAX_VALUE = 660.0f;
197
199 struct RemoteInfo
200 {
201 uint32_t updateCounter = 0;
202 int16_t rightHorizontal = 0;
203 int16_t rightVertical = 0;
204 int16_t leftHorizontal = 0;
205 int16_t leftVertical = 0;
207 SwitchState rightSwitch = SwitchState::UNKNOWN;
208 struct
209 {
210 int16_t x = 0;
211 int16_t y = 0;
212 int16_t z = 0;
213 bool l = false;
214 bool r = false;
215 } mouse;
216 uint16_t key = 0;
217 int16_t wheel = 0;
218 };
219
220 RemoteInfo remote;
221
222 static void switchToState(RemoteInfo *remote);
223
224 bool badData(const uint8_t rxBuffer[], RemoteInfo *remote);
225
227 bool connected = false;
228
230 uint8_t rxBuffer[REMOTE_BUF_LEN]{0};
231
233 uint32_t lastRead = 0;
234
236 uint8_t currentBufferIndex = 0;
237
239 void parseBuffer();
240
242 void clearRxBuffer();
243
245 void reset();
246
247}; // class Remote
248#endif
Definition DJIRemote.h:21
float rightX() const
Definition DJIRemote.h:168
Channel
Definition DJIRemote.h:29
void printAxisData() const
Definition DJIRemote.cpp:109
int16_t getWheel() const
Definition DJIRemote.cpp:136
int16_t getMouseZ() const
Definition DJIRemote.cpp:128
void initialize()
Definition DJIRemote.cpp:16
__attribute__((unused)) bool isConnected() const
long badDataChainNumber
Definition DJIRemote.h:154
Remote::SwitchState rightSwitch() const
Definition DJIRemote.h:183
int16_t getMouseX() const
Definition DJIRemote.cpp:124
bool getMouseL() const
Definition DJIRemote.cpp:130
int16_t getChannelInt(Channel ch) const
Definition DJIRemote.cpp:77
SwitchState getSwitch(Switch sw) const
Definition DJIRemote.cpp:97
long goodDataChainNumber
Definition DJIRemote.h:155
bool keyPressed(Key key) const
Definition DJIRemote.cpp:134
void dumpInfo() const
Definition DJIRemote.cpp:113
float rightY() const
Definition DJIRemote.h:173
void read()
Definition DJIRemote.cpp:19
uint32_t getUpdateCounter() const
Definition DJIRemote.cpp:274
int16_t getMouseY() const
Definition DJIRemote.cpp:126
float getChannel(Channel ch) const
Definition DJIRemote.cpp:61
float leftY() const
Definition DJIRemote.h:163
bool unfiltered
Definition DJIRemote.h:156
Switch
Definition DJIRemote.h:40
Remote::SwitchState leftSwitch() const
Definition DJIRemote.h:178
float leftX() const
Definition DJIRemote.h:158
bool getMouseR() const
Definition DJIRemote.cpp:132
Key
Definition DJIRemote.h:60
SwitchState
Definition DJIRemote.h:49