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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020