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 
61 class SDLJoypad :
63  // public yarp::dev::IJoypadController,
65 {
66  typedef std::vector<SDLJoypadImpl::stick> stickVector;
67 
68  SDL_Event m_event;
69  std::vector<SDL_Joystick*> m_device;
70  unsigned int m_buttonCount {0};
71  unsigned int m_axisCount {0};
72  unsigned int m_stickCount {0};
73  unsigned int m_touchCount {0};
74  unsigned int m_ballCount {0};
75  unsigned int m_hatCount {0};
76  bool m_allJoypad;
77  stickVector m_sticks;
78  std::vector<bool> m_axes;
79  double m_actionTimestamp;
80 
81  void updateJoypad();
82  void pollActions();
83  bool parseStickInfo(const yarp::os::Searchable& cfg);
84  bool getPureAxis(unsigned int axis_id, double& value);
85 public:
86 
88  virtual ~SDLJoypad();
89  //DeviceDriver
90  bool open(yarp::os::Searchable& config) override;
91  bool close() override;
92 
93  //IJoypadController
94  bool getRawAxisCount(unsigned int& axis_count) override;
95 
96  bool getRawButtonCount(unsigned int& button_count) override;
97 
98  bool getRawHatCount(unsigned int& hat_count) override;
99 
100  bool getRawTrackballCount(unsigned int& trackball_count) override;
101 
102  bool getRawTouchSurfaceCount(unsigned int& touch_count) override;
103 
104  bool getRawStickCount(unsigned int& stick_count) override;
105 
106  bool getRawStickDoF(unsigned int stick_id, unsigned int& DoF) override;
107 
108  bool getRawButton(unsigned int button_id, float& value) override;
109 
110  bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector& value) override;
111 
112  bool getRawHat(unsigned int hat_id, unsigned char& value) override;
113 
114  bool getRawAxis(unsigned int axis_id, double& value) override;
115 
116  bool getRawStick(unsigned int stick_id, yarp::sig::Vector& value, JoypadCtrl_coordinateMode coordinate_mode) override;
117 
118  bool getRawTouch(unsigned int touch_id, yarp::sig::Vector& value) override;
119 };
120 
121 
122 #endif //#define SDLJOYPAD_H
yarp::dev::IJoypadController::JoypadCtrl_coordinateMode
JoypadCtrl_coordinateMode
Definition: IJoypadController.h:37
SDLJoypad::getRawStickCount
bool getRawStickCount(unsigned int &stick_count) override
Definition: SDLJoypad.cpp:297
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
SDLJoypad::~SDLJoypad
virtual ~SDLJoypad()
SDLJoypad::getRawTrackballCount
bool getRawTrackballCount(unsigned int &trackball_count) override
Definition: SDLJoypad.cpp:279
SDLJoypad::getRawStickDoF
bool getRawStickDoF(unsigned int stick_id, unsigned int &DoF) override
Definition: SDLJoypad.cpp:303
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
SDLJoypad::getRawTrackball
bool getRawTrackball(unsigned int trackball_id, yarp::sig::Vector &value) override
Definition: SDLJoypad.cpp:432
SDLJoypad::close
bool close() override
Close the DeviceDriver.
Definition: SDLJoypad.cpp:262
SDLJoypad::getRawAxisCount
bool getRawAxisCount(unsigned int &axis_count) override
Definition: SDLJoypad.cpp:267
yarp::dev::IJoypadEventDriven
Definition: IJoypadController.h:209
SDLJoypad::getRawButton
bool getRawButton(unsigned int button_id, float &value) override
Definition: SDLJoypad.cpp:314
SDLJoypadImpl::stick::deadZone
float deadZone
Definition: SDLJoypad.h:37
SDLJoypad::SDLJoypad
SDLJoypad()
SDLJoypadImpl::stick
Definition: SDLJoypad.h:35
SDLJoypad
SDLJoypad: Device that reads inputs of Joypads compatible with the SDL library.
Definition: SDLJoypad.h:65
yarp::sig::VectorOf< double >
SDLJoypad::getRawTouchSurfaceCount
bool getRawTouchSurfaceCount(unsigned int &touch_count) override
Definition: SDLJoypad.cpp:291
SDLJoypad::getRawTouch
bool getRawTouch(unsigned int touch_id, yarp::sig::Vector &value) override
Definition: SDLJoypad.cpp:405
SDLJoypadImpl
Definition: SDLJoypad.h:29
SDLJoypad::getRawButtonCount
bool getRawButtonCount(unsigned int &button_count) override
Definition: SDLJoypad.cpp:273
SDLJoypad::getRawHat
bool getRawHat(unsigned int hat_id, unsigned char &value) override
Definition: SDLJoypad.cpp:410
SDLJoypad::getRawAxis
bool getRawAxis(unsigned int axis_id, double &value) override
Definition: SDLJoypad.cpp:363
SDLJoypad::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: SDLJoypad.cpp:44
SDLJoypad::getRawHatCount
bool getRawHatCount(unsigned int &hat_count) override
Definition: SDLJoypad.cpp:285
SDLJoypadImpl::stick::direction
std::vector< int > direction
Definition: SDLJoypad.h:38
SDLJoypad::getRawStick
bool getRawStick(unsigned int stick_id, yarp::sig::Vector &value, JoypadCtrl_coordinateMode coordinate_mode) override
Definition: SDLJoypad.cpp:379
IJoypadController.h
SDLJoypadImpl::stick::axes_ids
std::vector< unsigned int > axes_ids
Definition: SDLJoypad.h:36
DeviceDriver.h