MRPT  2.0.4
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
mrpt::hwdrivers::CJoystick Class Reference

Detailed Description

Access to joysticks and gamepads (read buttons and position), and request number of joysticks in the system.

Definition at line 22 of file CJoystick.h.

#include <mrpt/hwdrivers/CJoystick.h>

Public Member Functions

 CJoystick ()
 Constructor. More...
 
virtual ~CJoystick ()
 Destructor. More...
 
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. More...
 
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 analog joystick). More...
 

Static Public Member Functions

static int getJoysticksCount ()
 Returns the number of Joysticks in the computer. More...
 

Private Attributes

int m_x_min
 The axis limits: More...
 
int m_x_max
 
int m_y_min
 
int m_y_max
 
int m_z_min
 
int m_z_max
 

Constructor & Destructor Documentation

◆ CJoystick()

CJoystick::CJoystick ( )

Constructor.

Definition at line 52 of file CJoystick.cpp.

References setLimits().

Here is the call graph for this function:

◆ ~CJoystick()

CJoystick::~CJoystick ( )
virtual

Destructor.

Definition at line 56 of file CJoystick.cpp.

Member Function Documentation

◆ getJoystickPosition()

bool CJoystick::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.

This method will try first to open the joystick, so you can safely call it while the joystick is plugged and removed arbitrarly.

Parameters
nJoyThe 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.
xThe x axis position, range [-1,1]
yThe y axis position, range [-1,1]
zThe z axis position, range [-1,1]
buttonsEach element will hold true if buttons are pressed. The size of the vector will be set automatically to the number of buttons.
raw_x_posIf it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
raw_y_posIf it is desired the raw integer measurement from JoyStick, set this pointer to a desired placeholder.
raw_z_posIf 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
setLimits

Definition at line 106 of file CJoystick.cpp.

References mrpt::format(), m_x_max, m_x_min, m_y_max, m_y_min, m_z_max, m_z_min, MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ getJoysticksCount()

int CJoystick::getJoysticksCount ( )
static

Returns the number of Joysticks in the computer.

Definition at line 72 of file CJoystick.cpp.

References mrpt::format(), MRPT_END, and MRPT_START.

Here is the call graph for this function:

◆ setLimits()

void CJoystick::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 analog joystick).

Set the axis limit values, for computing a [-1,1] position index easily.

It seems that these values must been calibrated for each joystick model.

See also
getJoystickPosition

Definition at line 237 of file CJoystick.cpp.

References m_x_max, m_x_min, m_y_max, m_y_min, m_z_max, and m_z_min.

Referenced by CJoystick().

Here is the caller graph for this function:

Member Data Documentation

◆ m_x_max

int mrpt::hwdrivers::CJoystick::m_x_max
private

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().

◆ m_x_min

int mrpt::hwdrivers::CJoystick::m_x_min
private

The axis limits:

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().

◆ m_y_max

int mrpt::hwdrivers::CJoystick::m_y_max
private

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().

◆ m_y_min

int mrpt::hwdrivers::CJoystick::m_y_min
private

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().

◆ m_z_max

int mrpt::hwdrivers::CJoystick::m_z_max
private

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().

◆ m_z_min

int mrpt::hwdrivers::CJoystick::m_z_min
private

Definition at line 27 of file CJoystick.h.

Referenced by getJoystickPosition(), and setLimits().




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020