YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
SDLJoypad.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#ifndef SDLJOYPAD_H
7#define SDLJOYPAD_H
8
11#include <SDL.h>
12#include <vector>
13
14
15
16namespace SDLJoypadImpl {
17 struct stick;
18}
19
20
22{
23 std::vector<unsigned int> axes_ids;
24 float deadZone;
25 std::vector<int> direction;
26};
27
29{
30 public:
34
35 const std::string buttActionGroupName="BUTTON_EXECUTE";
36 bool parseActions(const yarp::os::Searchable& cfg, size_t maxButtons, int *count = nullptr);
37 bool executeAction(int action_id);
38 bool actionDetected(int button_id);
39};
40
41
61class SDLJoypad :
64{
65 typedef std::vector<SDLJoypadImpl::stick> stickVector;
66
67 SDL_Event m_event;
68 std::vector<SDL_Joystick*> m_device;
69 unsigned int m_buttonCount {0};
70 unsigned int m_axisCount {0};
71 unsigned int m_stickCount {0};
72 unsigned int m_touchCount {0};
73 unsigned int m_ballCount {0};
74 unsigned int m_hatCount {0};
75 bool m_allJoypad;
76 stickVector m_sticks;
77 std::vector<bool> m_axes;
78 double m_actionTimestamp;
79
80 void updateJoypad();
81 void pollActions();
82 bool parseStickInfo(const yarp::os::Searchable& cfg);
83 yarp::dev::ReturnValue getPureAxis(size_t axis_id, double& value);
84
85private:
86 JoystickActionsHandler m_actionsHandler;
87
88public:
89
91 virtual ~SDLJoypad();
92 //DeviceDriver
93 bool open(yarp::os::Searchable& config) override;
94 bool close() override;
95
96 //IJoypadController
97 yarp::dev::ReturnValue getAxisCount(size_t& axis_count) override;
98 yarp::dev::ReturnValue getButtonCount(size_t& button_count) override;
99 yarp::dev::ReturnValue getHatCount(size_t& hat_count) override;
100 yarp::dev::ReturnValue getTrackballCount(size_t& trackball_count) override;
101 yarp::dev::ReturnValue getTouchSurfaceCount(size_t& touch_count) override;
102 yarp::dev::ReturnValue getStickCount(size_t& stick_count) override;
103 yarp::dev::ReturnValue getButton(size_t button_id, double& value) override;
104 yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData& value) override;
105 yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char& value) override;
106 yarp::dev::ReturnValue getAxis(size_t axis_id, double& value) override;
107 yarp::dev::ReturnValue getStick(size_t stick_id, yarp::dev::StickData& value, JoypadCtrl_coordinateMode coordinate_mode) override;
108 yarp::dev::ReturnValue getTouch(size_t touch_id, std::vector<yarp::dev::TouchData>& value) override;
109};
110
111
112#endif //#define SDLJOYPAD_H
const std::string buttActionGroupName
Definition SDLJoypad.h:35
std::map< int, std::string > m_actions
Definition SDLJoypad.h:33
bool parseActions(const yarp::os::Searchable &cfg, size_t maxButtons, int *count=nullptr)
bool executeAction(int action_id)
~JoystickActionsHandler()=default
JoystickActionsHandler()=default
bool actionDetected(int button_id)
SDLJoypad: Device that reads inputs of Joypads compatible with the SDL library.
Definition SDLJoypad.h:64
yarp::dev::ReturnValue getAxis(size_t axis_id, double &value) override
Get the value of an axis if present, return false otherwise.
yarp::dev::ReturnValue getHat(size_t hat_id, unsigned char &value) override
Get the value of an Hat.
yarp::dev::ReturnValue getAxisCount(size_t &axis_count) override
Get number of axes.
yarp::dev::ReturnValue getHatCount(size_t &hat_count) override
Get number of hats.
yarp::dev::ReturnValue getTrackball(size_t trackball_id, yarp::dev::TrackballData &value) override
Get the axes change of a Trackball.
yarp::dev::ReturnValue getTouchSurfaceCount(size_t &touch_count) override
Get the number of touch surface.
yarp::dev::ReturnValue getButton(size_t button_id, double &value) override
Get the value of a button.
yarp::dev::ReturnValue getStick(size_t stick_id, yarp::dev::StickData &value, JoypadCtrl_coordinateMode coordinate_mode) override
Get the value of a stick if present, return false otherwise.
yarp::dev::ReturnValue getTrackballCount(size_t &trackball_count) override
Get number of trackballs.
yarp::dev::ReturnValue getButtonCount(size_t &button_count) override
Get number of buttons.
virtual ~SDLJoypad()
yarp::dev::ReturnValue getStickCount(size_t &stick_count) override
Get the number of the sticks.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition SDLJoypad.cpp:30
yarp::dev::ReturnValue getTouch(size_t touch_id, std::vector< yarp::dev::TouchData > &value) override
Get the value of a touch if present, return false otherwise.
Interface implemented by all device drivers.
A base class for nested structures that can be searched.
Definition Searchable.h:31
std::vector< unsigned int > axes_ids
Definition SDLJoypad.h:23
std::vector< int > direction
Definition SDLJoypad.h:25
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARGS(...)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:339