Instrument Neutral Distributed Interface INDI
2.0.2
|
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 |
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.
typedef std::function<void(int axis_n, double value)> JoyStickDriver::axisFunc |
Definition at line 73 of file joystickdriver.h.
typedef std::function<void(int button_n, int value)> JoyStickDriver::buttonFunc |
Definition at line 74 of file joystickdriver.h.
typedef std::function<void(int joystick_n, double mag, double angle)> JoyStickDriver::joystickFunc |
Definition at line 72 of file joystickdriver.h.
JoyStickDriver::JoyStickDriver | ( | ) |
Definition at line 29 of file joystickdriver.cpp.
JoyStickDriver::~JoyStickDriver | ( | ) |
Definition at line 44 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 223 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 229 of file joystickdriver.cpp.
bool JoyStickDriver::buttonPressed | ( | int | n | ) |
Definition at line 206 of file joystickdriver.cpp.
bool JoyStickDriver::Connect | ( | ) |
Definition at line 71 of file joystickdriver.cpp.
bool JoyStickDriver::Disconnect | ( | ) |
Definition at line 92 of file joystickdriver.cpp.
const char * JoyStickDriver::getName | ( | ) |
Definition at line 235 of file joystickdriver.cpp.
__u8 JoyStickDriver::getNumOfAxes | ( | ) |
Definition at line 258 of file joystickdriver.cpp.
__u8 JoyStickDriver::getNumOfJoysticks | ( | ) |
Definition at line 245 of file joystickdriver.cpp.
__u8 JoyStickDriver::getNumrOfButtons | ( | ) |
Definition at line 263 of file joystickdriver.cpp.
__u32 JoyStickDriver::getVersion | ( | ) |
Definition at line 240 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 216 of file joystickdriver.cpp.
joystick_position JoyStickDriver::joystickPosition | ( | int | n | ) |
Definition at line 151 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 106 of file joystickdriver.cpp.
|
protected |
Definition at line 113 of file joystickdriver.cpp.
void JoyStickDriver::setAxisCallback | ( | axisFunc | axisCallback | ) |
Definition at line 56 of file joystickdriver.cpp.
void JoyStickDriver::setButtonCallback | ( | buttonFunc | buttonCallback | ) |
Definition at line 61 of file joystickdriver.cpp.
void JoyStickDriver::setJoystickCallback | ( | joystickFunc | joystickCallback | ) |
Definition at line 51 of file joystickdriver.cpp.
void JoyStickDriver::setPoll | ( | int | ms | ) |
Definition at line 211 of file joystickdriver.cpp.
void JoyStickDriver::setPort | ( | const char * | port | ) |
Definition at line 66 of file joystickdriver.cpp.
|
protected |
Definition at line 105 of file joystickdriver.h.
|
protected |
Definition at line 104 of file joystickdriver.h.
|
protected |
Definition at line 103 of file joystickdriver.h.