YARP
Yet Another Robot Platform
SDLJoypad.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef SDLJOYPAD_H
20 #define SDLJOYPAD_H
21 
23 #include <yarp/dev/DeviceDriver.h>
24 #include <SDL.h>
25 #include <vector>
26 
27 
28 
29 namespace SDLJoypadImpl {
30  struct stick;
31 }
32 
33 
35 {
36  std::vector<unsigned int> axes_ids;
37  float deadZone;
38  std::vector<int> direction;
39 };
40 
41 
60 class SDLJoypad :
62  // public yarp::dev::IJoypadController,
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  bool getPureAxis(unsigned int axis_id, double& value);
84 public:
85 
87  virtual ~SDLJoypad();
88  //DeviceDriver
89  bool open(yarp::os::Searchable& config) override;
90  bool close() override;
91 
92  //IJoypadController
93  bool getRawAxisCount(unsigned int& axis_count) override;
94 
95  bool getRawButtonCount(unsigned int& button_count) override;
96 
97  bool getRawHatCount(unsigned int& hat_count) override;
98 
99  bool getRawTrackballCount(unsigned int& trackball_count) override;
100 
101  bool getRawTouchSurfaceCount(unsigned int& touch_count) override;
102 
103  bool getRawStickCount(unsigned int& stick_count) override;
104 
105  bool getRawStickDoF(unsigned int stick_id, unsigned int& DoF) override;
106 
107  bool getRawButton(unsigned int button_id, float& value) override;
108 
109  bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector& value) override;
110 
111  bool getRawHat(unsigned int hat_id, unsigned char& value) override;
112 
113  bool getRawAxis(unsigned int axis_id, double& value) override;
114 
115  bool getRawStick(unsigned int stick_id, yarp::sig::Vector& value, JoypadCtrl_coordinateMode coordinate_mode) override;
116 
117  bool getRawTouch(unsigned int touch_id, yarp::sig::Vector& value) override;
118 };
119 
120 
121 #endif //#define SDLJOYPAD_H
Device that reads inputs of Joypads compatible with the SDL library.
Definition: SDLJoypad.h:64
bool getRawAxisCount(unsigned int &axis_count) override
Definition: SDLJoypad.cpp:267
bool getRawButtonCount(unsigned int &button_count) override
Definition: SDLJoypad.cpp:273
bool getRawTouchSurfaceCount(unsigned int &touch_count) override
Definition: SDLJoypad.cpp:291
bool getRawStickDoF(unsigned int stick_id, unsigned int &DoF) override
Definition: SDLJoypad.cpp:303
bool getRawHat(unsigned int hat_id, unsigned char &value) override
Definition: SDLJoypad.cpp:410
virtual ~SDLJoypad()
bool getRawTrackballCount(unsigned int &trackball_count) override
Definition: SDLJoypad.cpp:279
bool close() override
Close the DeviceDriver.
Definition: SDLJoypad.cpp:262
bool getRawButton(unsigned int button_id, float &value) override
Definition: SDLJoypad.cpp:314
bool getRawAxis(unsigned int axis_id, double &value) override
Definition: SDLJoypad.cpp:363
bool getRawStickCount(unsigned int &stick_count) override
Definition: SDLJoypad.cpp:297
bool getRawHatCount(unsigned int &hat_count) override
Definition: SDLJoypad.cpp:285
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: SDLJoypad.cpp:44
bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override
Definition: SDLJoypad.cpp:379
bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override
Definition: SDLJoypad.cpp:432
bool getRawTouch(unsigned int touch_id, yarp::sig::Vector &value) override
Definition: SDLJoypad.cpp:405
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A base class for nested structures that can be searched.
Definition: Searchable.h:69
std::vector< unsigned int > axes_ids
Definition: SDLJoypad.h:36
std::vector< int > direction
Definition: SDLJoypad.h:38