class mrpt::hwdrivers::CJoystick
Overview
Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the system.
New in MRPT 2.13.0: the API changed to support an arbitrary number of input axes.
#include <mrpt/hwdrivers/CJoystick.h> class CJoystick { public: // structs struct State; // construction CJoystick(); // methods bool getJoystickPosition(int nJoy, State& output); void setLimits(const std::vector<int>& minPerAxis, const std::vector<int>& maxPerAxis); static int getJoysticksCount(); };
Construction
CJoystick()
Constructor.
Methods
bool getJoystickPosition(int nJoy, State& output)
Gets joystick information.
This method will try first to open the joystick, so you can safely call it while the joystick is plugged and removed arbitrarly.
Parameters:
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. |
x |
The x axis position, range [-1,1] |
y |
The y axis position, range [-1,1] |
z |
The z axis position, range [-1,1] |
buttons |
Each element will hold true if buttons are pressed. The size of the vector will be set automatically to the number of buttons. |
raw_x_pos |
If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder. |
raw_y_pos |
If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder. |
raw_z_pos |
If it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder. |
Returns:
Returns true if successfull, false on error, for example, if joystick is not present.
See also:
void setLimits( const std::vector<int>& minPerAxis, const std::vector<int>& maxPerAxis )
Set the axis limit values, for computing a [-1,1] position index easily Only required to calibrate analog joystick.
It seems that these values must been calibrated for each joystick model.
Default values:
Windows: [0, 0xFFFF]
Linux: [-32767,32767]
See also:
static int getJoysticksCount()
Returns the number of Joysticks in the computer.