Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
remote.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_REMOTE_HPP_
25#define TAPROOT_REMOTE_HPP_
26
27#include <cstdint>
28
29#ifndef PLATFORM_HOSTED
30#include "modm/platform.hpp"
31#endif
32
33#include "tap/util_macros.hpp"
34
35namespace tap
36{
37class Drivers;
38}
39
41{
50class Remote
51{
52public:
53 Remote(Drivers *drivers) : drivers(drivers) {}
55 mockable ~Remote() = default;
56
68
72 enum class Switch
73 {
76 };
77
81 enum class SwitchState
82 {
83 UNKNOWN = 0,
84 UP = 1,
85 DOWN = 2,
86 MID = 3,
87 };
88
92 enum class Key
93 {
94 W = 0,
95 S,
96 A,
97 D,
98 SHIFT,
99 CTRL,
100 Q,
101 E,
102 R,
103 F,
104 G,
105 Z,
106 X,
107 C,
108 V,
109 B
110 };
111
115 mockable void initialize();
116
121 mockable void read();
122
129 mockable bool isConnected() const;
130
134 mockable float getChannel(Channel ch) const;
135
140
144 mockable inline int16_t getMouseX() const { return remote.mouse.x; }
145
149 mockable inline int16_t getMouseY() const { return remote.mouse.y; }
150
154 mockable inline int16_t getMouseZ() const { return remote.mouse.z; }
155
159 mockable inline bool getMouseL() const { return remote.mouse.l; }
160
164 mockable inline bool getMouseR() const { return remote.mouse.r; }
165
169 mockable inline bool keyPressed(Key key) const
170 {
171 return (remote.key & (1 << static_cast<uint8_t>(key))) != 0;
172 }
173
177 mockable uint32_t getUpdateCounter() const;
178
179private:
180 static const int REMOTE_BUF_LEN = 18;
181 static const int REMOTE_READ_TIMEOUT = 6;
182 static const int REMOTE_DISCONNECT_TIMEOUT = 100;
183 static const int REMOTE_INT_PRI = 12;
184 static constexpr float ANALOG_MAX_VALUE = 660.0f;
185
187 struct RemoteInfo
188 {
189 uint32_t updateCounter = 0;
190 int16_t rightHorizontal = 0;
191 int16_t rightVertical = 0;
192 int16_t leftHorizontal = 0;
193 int16_t leftVertical = 0;
195 SwitchState rightSwitch = SwitchState::UNKNOWN;
197 struct
198 {
199 int16_t x = 0;
200 int16_t y = 0;
201 int16_t z = 0;
202 bool l = false;
203 bool r = false;
204 } mouse;
205 uint16_t key = 0;
206 int16_t wheel = 0;
207 };
208
209 Drivers *drivers;
210
211 RemoteInfo remote;
212
214 bool connected = false;
215
217 uint8_t rxBuffer[REMOTE_BUF_LEN]{0};
218
220 uint32_t lastRead = 0;
221
223 uint8_t currentBufferIndex = 0;
224
226 void parseBuffer();
227
229 void clearRxBuffer();
230
232 void reset();
233}; // class Remote
234
235} // namespace tap::communication::serial
236
237#endif // TAPROOT_REMOTE_HPP_
Definition drivers.hpp:70
Definition remote.hpp:51
Switch
Definition remote.hpp:73
Key
Definition remote.hpp:93
Channel
Definition remote.hpp:61
Remote(Drivers *drivers)
Definition remote.hpp:53
mockable bool isConnected() const
Definition remote.cpp:72
mockable bool getMouseL() const
Definition remote.hpp:159
mockable int16_t getMouseY() const
Definition remote.hpp:149
mockable void initialize()
Definition remote.cpp:36
mockable bool keyPressed(Key key) const
Definition remote.hpp:169
mockable float getChannel(Channel ch) const
Definition remote.cpp:74
mockable SwitchState getSwitch(Switch sw) const
Definition remote.cpp:92
mockable int16_t getMouseZ() const
Definition remote.hpp:154
SwitchState
Definition remote.hpp:82
mockable void read()
Definition remote.cpp:41
mockable bool getMouseR() const
Definition remote.hpp:164
mockable int16_t getMouseX() const
Definition remote.hpp:144
mockable uint32_t getUpdateCounter() const
Definition remote.cpp:191
Definition dji_serial.cpp:41
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
fang::Drivers & drivers
Definition robot_singleton.cpp:45
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27