Instrument Neutral Distributed Interface INDI  2.0.2
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
JoyStickDriver Class Reference

The JoyStickDriver class provides basic functionality to read events from supported game pads under Linux. It provides functions to read the button, axis, and joystick status and values. By definition, a joystick is the combination of two axis. A game pad may have one or more joysticks depending on the number of reported axis. You can utilize the class in an event driven fashion by using callbacks. The callbacks have a specific signature and must be set. Alternatively, you may query the status and position of the buttons & axis at any time as well. More...

#include <joystickdriver.h>

Public Types

typedef std::function< void(int joystick_n, double mag, double angle)> joystickFunc
 
typedef std::function< void(int axis_n, double value)> axisFunc
 
typedef std::function< void(int button_n, int value)> buttonFunc
 

Public Member Functions

 JoyStickDriver ()
 
 ~JoyStickDriver ()
 
bool Connect ()
 
bool Disconnect ()
 
void setPort (const char *port)
 
void setPoll (int ms)
 
const char * getName ()
 
__u32 getVersion ()
 
__u8 getNumOfJoysticks ()
 
__u8 getNumOfAxes ()
 
__u8 getNumrOfButtons ()
 
joystick_position joystickPosition (int n)
 
bool buttonPressed (int n)
 
void setJoystickCallback (joystickFunc joystickCallback)
 
void setAxisCallback (axisFunc axisCallback)
 
void setButtonCallback (buttonFunc buttonCallback)
 

Protected Member Functions

void readEv ()
 

Static Protected Member Functions

static void joystickEvent (int joystick_n, double mag, double angle)
 
static void axisEvent (int axis_n, int value)
 
static void buttonEvent (int button_n, int value)
 
static void * loop (void *obj)
 

Protected Attributes

joystickFunc joystickCallbackFunc
 
buttonFunc buttonCallbackFunc
 
axisFunc axisCallbackFunc
 

Detailed Description

The JoyStickDriver class provides basic functionality to read events from supported game pads under Linux. It provides functions to read the button, axis, and joystick status and values. By definition, a joystick is the combination of two axis. A game pad may have one or more joysticks depending on the number of reported axis. You can utilize the class in an event driven fashion by using callbacks. The callbacks have a specific signature and must be set. Alternatively, you may query the status and position of the buttons & axis at any time as well.

Since the class runs a non-blocking thread, the thread goes to sleep when there are no events detected in order to reduce CPU utilization. The sleep period is set by default to 100 milliseconds and can be adjusted by the \i setPoll function.

Each joystick has a normalized magnitude [0 to 1] and an angle. The magnitude is 0 when the stick is not depressed, and 1 when depressed all the way. The angles are measured counter clock wise [0 to 360] with right/east direction being zero.

The axis value is reported in raw values [-32767.0 to 32767.0].

The buttons are either off (0) or on (1)

Definition at line 66 of file joystickdriver.h.

Member Typedef Documentation

◆ axisFunc

typedef std::function<void(int axis_n, double value)> JoyStickDriver::axisFunc

Definition at line 73 of file joystickdriver.h.

◆ buttonFunc

typedef std::function<void(int button_n, int value)> JoyStickDriver::buttonFunc

Definition at line 74 of file joystickdriver.h.

◆ joystickFunc

typedef std::function<void(int joystick_n, double mag, double angle)> JoyStickDriver::joystickFunc

Definition at line 72 of file joystickdriver.h.

Constructor & Destructor Documentation

◆ JoyStickDriver()

JoyStickDriver::JoyStickDriver ( )

Definition at line 29 of file joystickdriver.cpp.

◆ ~JoyStickDriver()

JoyStickDriver::~JoyStickDriver ( )

Definition at line 44 of file joystickdriver.cpp.

Member Function Documentation

◆ axisEvent()

void JoyStickDriver::axisEvent ( int  axis_n,
int  value 
)
staticprotected

Definition at line 223 of file joystickdriver.cpp.

◆ buttonEvent()

void JoyStickDriver::buttonEvent ( int  button_n,
int  value 
)
staticprotected

Definition at line 229 of file joystickdriver.cpp.

◆ buttonPressed()

bool JoyStickDriver::buttonPressed ( int  n)

Definition at line 206 of file joystickdriver.cpp.

◆ Connect()

bool JoyStickDriver::Connect ( )

Definition at line 71 of file joystickdriver.cpp.

◆ Disconnect()

bool JoyStickDriver::Disconnect ( )

Definition at line 92 of file joystickdriver.cpp.

◆ getName()

const char * JoyStickDriver::getName ( )

Definition at line 235 of file joystickdriver.cpp.

◆ getNumOfAxes()

__u8 JoyStickDriver::getNumOfAxes ( )

Definition at line 258 of file joystickdriver.cpp.

◆ getNumOfJoysticks()

__u8 JoyStickDriver::getNumOfJoysticks ( )

Definition at line 245 of file joystickdriver.cpp.

◆ getNumrOfButtons()

__u8 JoyStickDriver::getNumrOfButtons ( )

Definition at line 263 of file joystickdriver.cpp.

◆ getVersion()

__u32 JoyStickDriver::getVersion ( )

Definition at line 240 of file joystickdriver.cpp.

◆ joystickEvent()

void JoyStickDriver::joystickEvent ( int  joystick_n,
double  mag,
double  angle 
)
staticprotected

Definition at line 216 of file joystickdriver.cpp.

◆ joystickPosition()

joystick_position JoyStickDriver::joystickPosition ( int  n)

Definition at line 151 of file joystickdriver.cpp.

◆ loop()

void * JoyStickDriver::loop ( void *  obj)
staticprotected

Definition at line 106 of file joystickdriver.cpp.

◆ readEv()

void JoyStickDriver::readEv ( )
protected

Definition at line 113 of file joystickdriver.cpp.

◆ setAxisCallback()

void JoyStickDriver::setAxisCallback ( axisFunc  axisCallback)

Definition at line 56 of file joystickdriver.cpp.

◆ setButtonCallback()

void JoyStickDriver::setButtonCallback ( buttonFunc  buttonCallback)

Definition at line 61 of file joystickdriver.cpp.

◆ setJoystickCallback()

void JoyStickDriver::setJoystickCallback ( joystickFunc  joystickCallback)

Definition at line 51 of file joystickdriver.cpp.

◆ setPoll()

void JoyStickDriver::setPoll ( int  ms)

Definition at line 211 of file joystickdriver.cpp.

◆ setPort()

void JoyStickDriver::setPort ( const char *  port)

Definition at line 66 of file joystickdriver.cpp.

Member Data Documentation

◆ axisCallbackFunc

axisFunc JoyStickDriver::axisCallbackFunc
protected

Definition at line 105 of file joystickdriver.h.

◆ buttonCallbackFunc

buttonFunc JoyStickDriver::buttonCallbackFunc
protected

Definition at line 104 of file joystickdriver.h.

◆ joystickCallbackFunc

joystickFunc JoyStickDriver::joystickCallbackFunc
protected

Definition at line 103 of file joystickdriver.h.


The documentation for this class was generated from the following files: