YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
IJoypadController.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_IJOYPADCONTROLLER_H
7#define YARP_DEV_IJOYPADCONTROLLER_H
8
9#include <yarp/sig/Vector.h>
10#include <yarp/dev/api.h>
11#include <yarp/os/Vocab.h>
13#include <yarp/os/Searchable.h>
15#include <map>
16#include <vector>
17#include <string>
18
19#define HAT_ACTIONS_ID_SHIFT 100
20
21namespace yarp::dev {
22class IJoypadController;
23class IJoypadEvent;
24class IJoypadEventDriven;
25}
26
28{
29public:
30 enum JoypadCtrl_coordinateMode {JypCtrlcoord_POLAR = 0, JypCtrlcoord_CARTESIAN = 1};
31
32protected:
34
35 virtual bool parseActions(const yarp::os::Searchable& cfg, int *count = nullptr);
36 virtual bool executeAction(int action_id);
37
38public:
39
43 virtual ~IJoypadController() = default;
44
52 virtual bool eventDriven(bool enable, yarp::dev::IJoypadEvent* event = nullptr){return false;}
53 virtual bool isEventDriven(){return false;}
54
61 virtual bool getAxisCount(unsigned int& axis_count) = 0;
62
69 virtual bool getButtonCount(unsigned int& button_count) = 0;
70
77 virtual bool getTrackballCount(unsigned int& Trackball_count) = 0;
78
85 virtual bool getHatCount(unsigned int& Hat_count) = 0;
86
96 virtual bool getTouchSurfaceCount(unsigned int& touch_count) = 0;
97
104 virtual bool getStickCount(unsigned int& stick_count) = 0;
105
113 virtual bool getStickDoF(unsigned int stick_id, unsigned int& DoF) = 0;
114
125 virtual bool getButton(unsigned int button_id, float& value) = 0;
126
134 virtual bool getTrackball(unsigned int trackball_id, yarp::sig::Vector& value) = 0;
135
143 virtual bool getHat(unsigned int hat_id, unsigned char& value) = 0;
144
154 virtual bool getAxis(unsigned int axis_id, double& value) = 0;
155
165 virtual bool getStick(unsigned int stick_id, yarp::sig::Vector& value, JoypadCtrl_coordinateMode coordinate_mode) = 0;
166
173 virtual bool getTouch(unsigned int touch_id, yarp::sig::Vector& value) = 0;
174};
175
177{
178public:
179 virtual ~IJoypadEvent();
180
181 template <typename T> struct joyData
182 {
183 unsigned int m_id;
185
186 joyData(unsigned int id, const T& datum)
187 {
188 m_id = id;
189 m_datum = datum;
190 }
191 };
192
193 virtual void action(std::vector<joyData<float> > buttons,
194 std::vector<joyData<double> > axes,
195 std::vector<joyData<unsigned char> > hats,
196 std::vector<joyData<yarp::sig::Vector> > trackBalls,
197 std::vector<joyData<yarp::sig::Vector> > sticks,
198 std::vector<joyData<yarp::sig::Vector> > Touch) = 0;
199};
200
201
202
205{
206private:
208 bool EventDrivenEnabled;
209 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<float>) old_buttons;
210 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<double>) old_axes;
211 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<unsigned char>) old_hats;
212 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::sig::Vector>) old_trackballs;
213 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::sig::Vector>) old_sticks;
214 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<yarp::sig::Vector>) old_touches;
215protected:
216 virtual bool getRawAxisCount(unsigned int& axis_count) = 0;
217 virtual bool getRawButtonCount(unsigned int& button_count) = 0;
218 virtual bool getRawTrackballCount(unsigned int& Trackball_count) = 0;
219 virtual bool getRawHatCount(unsigned int& Hat_count) = 0;
220 virtual bool getRawTouchSurfaceCount(unsigned int& touch_count) = 0;
221 virtual bool getRawStickCount(unsigned int& stick_count) = 0;
222 virtual bool getRawStickDoF(unsigned int stick_id, unsigned int& DoF) = 0;
223 virtual bool getRawButton(unsigned int button_id, float& value) = 0;
224 virtual bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector& value) = 0;
225 virtual bool getRawHat(unsigned int hat_id, unsigned char& value) = 0;
226 virtual bool getRawAxis(unsigned int axis_id, double& value) = 0;
227 virtual bool getRawStick(unsigned int stick_id, yarp::sig::Vector& value, JoypadCtrl_coordinateMode coordinate_mode) = 0;
228 virtual bool getRawTouch(unsigned int touch_id, yarp::sig::Vector& value) = 0;
229 using IJoypadController::m_actions;
230 using IJoypadController::executeAction;
231 using IJoypadController::parseActions;
232
233public:
234
235 bool getAxisCount(unsigned int& axis_count) override final;
236 bool getButtonCount(unsigned int& button_count) override final;
237 bool getTrackballCount(unsigned int& Trackball_count) override final;
238 bool getHatCount(unsigned int& Hat_count) override final;
239 bool getTouchSurfaceCount(unsigned int& touch_count) override final;
240 bool getStickCount(unsigned int& stick_count) override final;
241 bool getStickDoF(unsigned int stick_id, unsigned int& DoF) override final;
242 bool getButton(unsigned int button_id, float& value) override final;
243 bool getTrackball(unsigned int trackball_id, yarp::sig::Vector& value) override final;
244 bool getHat(unsigned int hat_id, unsigned char& value) override final;
245 bool getAxis(unsigned int axis_id, double& value) override final;
246 bool getStick(unsigned int stick_id, yarp::sig::Vector& value, JoypadCtrl_coordinateMode coordinate_mode) override final;
247 bool getTouch(unsigned int touch_id, yarp::sig::Vector& value) override final;
249 using IJoypadController::JypCtrlcoord_CARTESIAN;
250 using IJoypadController::JypCtrlcoord_POLAR;
251
252
253
255#ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
256#if defined(_MSC_VER) && _MSC_VER <= 1900 // VS 2015
257 explicit IJoypadEventDriven(YARP_DEPRECATED_MSG("Use IJoypadEventDriven(double)") int rate);
258#else
259 YARP_DEPRECATED_MSG("Use IJoypadEventDriven(double)")
260 explicit IJoypadEventDriven(int rate);
261#endif
262#endif
263 explicit IJoypadEventDriven(double period);
264
265 bool threadInit() override final;
266 void run() override final;
267
268 bool eventDriven(bool enable, yarp::dev::IJoypadEvent* event = nullptr) override;
269 bool isEventDriven() override { return EventDrivenEnabled;}
270};
271
272
273#define YRPJOY_HAT_CENTERED 0x00
274#define YRPJOY_HAT_UP 0x01
275#define YRPJOY_HAT_RIGHT 0x02
276#define YRPJOY_HAT_DOWN 0x04
277#define YRPJOY_HAT_LEFT 0x08
278#define YRPJOY_HAT_RIGHTUP (YRPJOY_HAT_RIGHT|YRPJOY_HAT_UP)
279#define YRPJOY_HAT_RIGHTDOWN (YRPJOY_HAT_RIGHT|YRPJOY_HAT_DOWN)
280#define YRPJOY_HAT_LEFTUP (YRPJOY_HAT_LEFT |YRPJOY_HAT_UP)
281#define YRPJOY_HAT_LEFTDOWN (YRPJOY_HAT_LEFT |YRPJOY_HAT_DOWN)
282
284
294
295#endif //#define YARP_DEV_IJOYPADCONTROLLER_H
296
297//todo list 23/03/2017..
298//1. complete the single port functionality between server and client and test
299//2. complete the rpc_only functionality in the client (add the parameter in the open() and test it)
300//3. sdl hat #define to vocab traduction (just in case they change something)
301//4. SDLJoypad implement stick functionality
302//5. SDLJoypad implement deadband
303//6. SDLJoypad implement button/axis remapping
constexpr yarp::conf::vocab32_t VOCAB_BUTTON
constexpr yarp::conf::vocab32_t VOCAB_IJOYPADCTRL
constexpr yarp::conf::vocab32_t VOCAB_TOUCH
constexpr yarp::conf::vocab32_t VOCAB_HAT
constexpr yarp::conf::vocab32_t VOCAB_TRACKBALL
constexpr yarp::conf::vocab32_t VOCAB_CARTESIAN
constexpr yarp::conf::vocab32_t VOCAB_STICKDOF
constexpr yarp::conf::vocab32_t VOCAB_AXIS
constexpr yarp::conf::vocab32_t VOCAB_POLAR
constexpr yarp::conf::vocab32_t VOCAB_STICK
contains the definition of a Vector type
virtual bool getHatCount(unsigned int &Hat_count)=0
Get number of hats.
virtual bool getTrackballCount(unsigned int &Trackball_count)=0
Get number of trackballs.
virtual bool eventDriven(bool enable, yarp::dev::IJoypadEvent *event=nullptr)
Activate event Driven mode.
std::map< int, std::string > m_actions
virtual bool getTouchSurfaceCount(unsigned int &touch_count)=0
Get the number of touch surface.
virtual bool executeAction(int action_id)
virtual bool getButton(unsigned int button_id, float &value)=0
Get the value of a button.
virtual bool getAxisCount(unsigned int &axis_count)=0
Get number of axes.
virtual bool getAxis(unsigned int axis_id, double &value)=0
Get the value of an axis if present, return false otherwise.
virtual bool getStickCount(unsigned int &stick_count)=0
Get the number of the sticks.
virtual bool getTrackball(unsigned int trackball_id, yarp::sig::Vector &value)=0
Get the axes change of a Trackball.
virtual bool getStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode)=0
Get the value of a stick if present, return false otherwise.
virtual bool parseActions(const yarp::os::Searchable &cfg, int *count=nullptr)
virtual bool getStickDoF(unsigned int stick_id, unsigned int &DoF)=0
Get the Degree Of Freedom count for desired stick.
virtual ~IJoypadController()=default
Destructor.
virtual bool getHat(unsigned int hat_id, unsigned char &value)=0
Get the value of an Hat.
virtual bool getButtonCount(unsigned int &button_count)=0
Get number of buttons.
virtual bool getTouch(unsigned int touch_id, yarp::sig::Vector &value)=0
Get the value of a touch if present, return false otherwise.
virtual bool getRawTouch(unsigned int touch_id, yarp::sig::Vector &value)=0
virtual bool getRawAxis(unsigned int axis_id, double &value)=0
virtual bool getRawHat(unsigned int hat_id, unsigned char &value)=0
virtual bool getRawAxisCount(unsigned int &axis_count)=0
virtual bool getRawTrackballCount(unsigned int &Trackball_count)=0
virtual bool getRawStickDoF(unsigned int stick_id, unsigned int &DoF)=0
virtual bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode)=0
virtual bool getRawButton(unsigned int button_id, float &value)=0
virtual bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value)=0
virtual bool getRawStickCount(unsigned int &stick_count)=0
virtual bool getRawHatCount(unsigned int &Hat_count)=0
virtual bool getRawTouchSurfaceCount(unsigned int &touch_count)=0
virtual bool getRawButtonCount(unsigned int &button_count)=0
virtual void action(std::vector< joyData< float > > buttons, std::vector< joyData< double > > axes, std::vector< joyData< unsigned char > > hats, std::vector< joyData< yarp::sig::Vector > > trackBalls, std::vector< joyData< yarp::sig::Vector > > sticks, std::vector< joyData< yarp::sig::Vector > > Touch)=0
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition compiler.h:2885
std::int32_t vocab32_t
Definition numeric.h:78
For streams capable of holding different kinds of content, check what they actually have.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition Vocab.h:27
The main, catch-all namespace for YARP.
Definition dirs.h:16
joyData(unsigned int id, const T &datum)
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:338
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARGS(...)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:339
#define YARP_dev_API
Definition api.h:18