Main MRPT website > C++ reference for MRPT 1.9.9
CJoystick.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CJOYSTICK_H
10 #define CJOYSTICK_H
11 
12 #include <vector>
13 
14 /*---------------------------------------------------------------
15  Class
16  ---------------------------------------------------------------*/
17 namespace mrpt
18 {
19 namespace hwdrivers
20 {
21 /** Access to joysticks and gamepads (read buttons and position), and request
22  * number of joysticks in the system.
23  * \ingroup mrpt_hwdrivers_grp
24  */
25 class CJoystick
26 {
27  private:
28  /** The axis limits:
29  */
31 
32 #if defined(MRPT_OS_LINUX)
33  /** File FD for the joystick, or -1 if not open (Linux only) */
34  int m_joy_fd;
35  /** The index of the joystick open in m_joy_fd (Linux only) */
36  int m_joy_index;
37  /** Using an event system we only have deltas, need to keep the whole
38  * joystick state (Linux only) */
39  std::vector<bool> m_joystate_btns;
40  /** Using an event system we only have deltas, need to keep the whole
41  * joystick state (Linux only) */
42  std::vector<int> m_joystate_axes;
43 #endif
44 
45  public:
46  /** Constructor
47  */
48  CJoystick();
49 
50  /** Destructor
51  */
52  virtual ~CJoystick();
53 
54  /** Returns the number of Joysticks in the computer.
55  */
56  static int getJoysticksCount();
57 
58  /** Gets joystick information.
59  *
60  * This method will try first to open the joystick, so you can safely call
61  * it while the joystick is plugged and removed arbitrarly.
62  *
63  * \param nJoy The index of the joystick to query: The first one is 0, the
64  * second 1, etc... See CJoystick::getJoysticksCount to discover the number
65  * of joysticks in the system.
66  * \param x The x axis position, range [-1,1]
67  * \param y The y axis position, range [-1,1]
68  * \param z The z axis position, range [-1,1]
69  * \param buttons Each element will hold true if buttons are pressed. The
70  * size of the vector will be set automatically to the number of buttons.
71  * \param raw_x_pos If it is desired the raw integer measurement from
72  * JoyStick, set this pointer to a desired placeholder.
73  * \param raw_y_pos If it is desired the raw integer measurement from
74  * JoyStick, set this pointer to a desired placeholder.
75  * \param raw_z_pos If it is desired the raw integer measurement from
76  * JoyStick, set this pointer to a desired placeholder.
77  *
78  * \return Returns true if successfull, false on error, for example, if
79  * joystick is not present.
80  *
81  * \sa setLimits
82  */
84  int nJoy, float& x, float& y, float& z, std::vector<bool>& buttons,
85  int* raw_x_pos = nullptr, int* raw_y_pos = nullptr,
86  int* raw_z_pos = nullptr);
87 
88 /** Set the axis limit values, for computing a [-1,1] position index easily
89  * (Only required to calibrate analog joystick).
90  * It seems that these values must been calibrated for each joystick model.
91  *
92  * \sa getJoystickPosition
93  */
94 #ifdef _WIN32
95  void setLimits(
96  int x_min = 0, int x_max = 0xFFFF, int y_min = 0, int y_max = 0xFFFF,
97  int z_min = 0, int z_max = 0xFFFF);
98 #else
99  void setLimits(
100  int x_min = -32767, int x_max = 32767, int y_min = -32767,
101  int y_max = 32767, int z_min = -32767, int z_max = 32767);
102 #endif
103 }; // End of class def.
104 
105 } // namespace hwdrivers
106 } // namespace mrpt
107 
108 #endif
mrpt::hwdrivers::CJoystick::m_z_min
int m_z_min
Definition: CJoystick.h:30
mrpt::hwdrivers::CJoystick::CJoystick
CJoystick()
Constructor.
Definition: CJoystick.cpp:52
mrpt::hwdrivers::CJoystick::m_x_min
int m_x_min
The axis limits:
Definition: CJoystick.h:30
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::hwdrivers::CJoystick
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the ...
Definition: CJoystick.h:25
mrpt::hwdrivers::CJoystick::m_y_max
int m_y_max
Definition: CJoystick.h:30
mrpt::hwdrivers::CJoystick::~CJoystick
virtual ~CJoystick()
Destructor.
Definition: CJoystick.cpp:63
mrpt::hwdrivers::CJoystick::setLimits
void setLimits(int x_min=0, int x_max=0xFFFF, int y_min=0, int y_max=0xFFFF, int z_min=0, int z_max=0xFFFF)
Set the axis limit values, for computing a [-1,1] position index easily (Only required to calibrate a...
Definition: CJoystick.cpp:244
mrpt::hwdrivers::CJoystick::m_z_max
int m_z_max
Definition: CJoystick.h:30
mrpt::hwdrivers::CJoystick::getJoysticksCount
static int getJoysticksCount()
Returns the number of Joysticks in the computer.
Definition: CJoystick.cpp:79
z
GLdouble GLdouble z
Definition: glext.h:3872
mrpt::hwdrivers::CJoystick::m_y_min
int m_y_min
Definition: CJoystick.h:30
mrpt::hwdrivers::CJoystick::getJoystickPosition
bool getJoystickPosition(int nJoy, float &x, float &y, float &z, std::vector< bool > &buttons, int *raw_x_pos=nullptr, int *raw_y_pos=nullptr, int *raw_z_pos=nullptr)
Gets joystick information.
Definition: CJoystick.cpp:113
mrpt::hwdrivers::CJoystick::m_x_max
int m_x_max
Definition: CJoystick.h:30
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST