Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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 <mrpt/utils/utils_defs.h>
14 
15 /*---------------------------------------------------------------
16  Class
17  ---------------------------------------------------------------*/
18 namespace mrpt
19 {
20  namespace hwdrivers
21  {
22  /** Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the system.
23  * \ingroup mrpt_hwdrivers_grp
24  */
26  {
27  private:
28  /** The axis limits:
29  */
30  int m_x_min,m_x_max,m_y_min,m_y_max,m_z_min,m_z_max;
31 
32 
33  #if defined(MRPT_OS_LINUX)
34  int m_joy_fd; //!< File FD for the joystick, or -1 if not open (Linux only)
35  int m_joy_index; //!< The index of the joystick open in m_joy_fd (Linux only)
36  /** Using an event system we only have deltas, need to keep the whole joystick state (Linux only) */
37  vector_bool m_joystate_btns;
38  /** Using an event system we only have deltas, need to keep the whole joystick state (Linux only) */
39  vector_int m_joystate_axes;
40  #endif
41 
42  public:
43  /** Constructor
44  */
45  CJoystick();
46 
47  /** Destructor
48  */
49  virtual ~CJoystick();
50 
51  /** Returns the number of Joysticks in the computer.
52  */
53  static int getJoysticksCount();
54 
55  /** Gets joystick information.
56  *
57  * This method will try first to open the joystick, so you can safely call it while the joystick is plugged and removed arbitrarly.
58  *
59  * \param nJoy The index of the joystick to query: The first one is 0, the second 1, etc... See CJoystick::getJoysticksCount to discover the number of joysticks in the system.
60  * \param x The x axis position, range [-1,1]
61  * \param y The y axis position, range [-1,1]
62  * \param z The z axis position, range [-1,1]
63  * \param buttons Each element will hold true if buttons are pressed. The size of the vector will be set automatically to the number of buttons.
64  * \param raw_x_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
65  * \param raw_y_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
66  * \param raw_z_pos If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
67  *
68  * \return Returns true if successfull, false on error, for example, if joystick is not present.
69  *
70  * \sa setLimits
71  */
72  bool getJoystickPosition(
73  int nJoy,
74  float &x,
75  float &y,
76  float &z,
77  std::vector<bool> &buttons,
78  int *raw_x_pos=NULL,
79  int *raw_y_pos=NULL,
80  int *raw_z_pos=NULL );
81 
82  /** Set the axis limit values, for computing a [-1,1] position index easily (Only required to calibrate analog joystick).
83  * It seems that these values must been calibrated for each joystick model.
84  *
85  * \sa getJoystickPosition
86  */
87  #ifdef MRPT_OS_WINDOWS
88  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 );
89  #else
90  void setLimits( int x_min = -32767,int x_max = 32767, int y_min=-32767,int y_max = 32767,int z_min=-32767,int z_max = 32767);
91  #endif
92  }; // End of class def.
93 
94  } // End of namespace
95 } // End of namespace
96 
97 #endif
GLdouble GLdouble z
Definition: glext.h:3734
std::vector< bool > vector_bool
A type for passing a vector of bools.
Definition: types_simple.h:29
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLenum GLint GLint y
Definition: glext.h:3516
std::vector< int32_t > vector_int
Definition: types_simple.h:23
GLenum GLint x
Definition: glext.h:3516
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the ...
Definition: CJoystick.h:25



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019