|
Instrument Neutral Distributed Interface INDI 2.2.5
|
The JoyStickDriver class provides basic functionality to read events from supported game pads under Linux. 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 () |
| uint32_t | getVersion () |
| uint8_t | getNumOfAxes () |
| uint8_t | getNumrOfButtons () |
| uint8_t | getNumOfJoysticks () |
| getNumOfJoysticks Returns the number of proper analog-stick / hat pairs found via JSIOCGAXMAP. Falls back to axes/2 if the ioctl is unavailable. | |
| uint8_t | getAxisAbsCode (int axis) const |
getAxisAbsCode Returns the ABS_* event code for axis, or 0xFF if the axis map is not available. | |
| JoyAxisType | getAxisType (int axis) const |
getAxisType Returns the classified type of axis. | |
| const char * | getAxisLabel (int axis) const |
getAxisLabel Returns a human-readable label for axis (e.g. "Left-Stick X", "L2 Trigger", "D-pad X"). | |
| const JoyAxisPair * | getJoystickPair (int n) const |
getJoystickPair Returns the axis-pair descriptor for joystick n, or nullptr if out of range. | |
| joystick_position | joystickPosition (int n) |
| bool | buttonPressed (int n) |
| void | setJoystickCallback (joystickFunc joystickCallback) |
| void | setAxisCallback (axisFunc axisCallback) |
| void | setButtonCallback (buttonFunc buttonCallback) |
| void | setAxisCalibration (int axis, int center, int minVal, int maxVal) |
| setAxisCalibration Set piecewise-linear calibration for one axis. | |
| void | setAxisReversed (int axis, bool reversed) |
| setAxisReversed Enable or disable reversal for a single axis. | |
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.
The driver uses JSIOCGAXMAP to correctly identify analog sticks, triggers and d-pads. Joystick pairs (magnitude + angle) are only generated for genuine stick/hat axis pairs; trigger axes appear only as raw axis values.
Each joystick has a normalised magnitude [0, 1] and a compass angle (N = 0°, E = 90°, S = 180°, W = 270°).
Definition at line 112 of file joystickdriver.h.
| typedef std::function<void(int axis_n, double value)> JoyStickDriver::axisFunc |
Definition at line 119 of file joystickdriver.h.
| typedef std::function<void(int button_n, int value)> JoyStickDriver::buttonFunc |
Definition at line 120 of file joystickdriver.h.
| typedef std::function<void(int joystick_n, double mag, double angle)> JoyStickDriver::joystickFunc |
Definition at line 118 of file joystickdriver.h.
| JoyStickDriver::JoyStickDriver | ( | ) |
Definition at line 60 of file joystickdriver.cpp.
| JoyStickDriver::~JoyStickDriver | ( | ) |
Definition at line 75 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 548 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 554 of file joystickdriver.cpp.
| bool JoyStickDriver::buttonPressed | ( | int | n | ) |
Definition at line 393 of file joystickdriver.cpp.
| bool JoyStickDriver::Connect | ( | ) |
Definition at line 86 of file joystickdriver.cpp.
| bool JoyStickDriver::Disconnect | ( | ) |
Definition at line 138 of file joystickdriver.cpp.
| uint8_t JoyStickDriver::getAxisAbsCode | ( | int | axis | ) | const |
getAxisAbsCode Returns the ABS_* event code for axis, or 0xFF if the axis map is not available.
Definition at line 349 of file joystickdriver.cpp.
| const char * JoyStickDriver::getAxisLabel | ( | int | axis | ) | const |
getAxisLabel Returns a human-readable label for axis (e.g. "Left-Stick X", "L2 Trigger", "D-pad X").
Definition at line 363 of file joystickdriver.cpp.
| JoyAxisType JoyStickDriver::getAxisType | ( | int | axis | ) | const |
getAxisType Returns the classified type of axis.
Definition at line 356 of file joystickdriver.cpp.
| const JoyAxisPair * JoyStickDriver::getJoystickPair | ( | int | n | ) | const |
getJoystickPair Returns the axis-pair descriptor for joystick n, or nullptr if out of range.
Definition at line 370 of file joystickdriver.cpp.
| const char * JoyStickDriver::getName | ( | ) |
Definition at line 321 of file joystickdriver.cpp.
| uint8_t JoyStickDriver::getNumOfAxes | ( | ) |
Definition at line 329 of file joystickdriver.cpp.
| uint8_t JoyStickDriver::getNumOfJoysticks | ( | ) |
getNumOfJoysticks Returns the number of proper analog-stick / hat pairs found via JSIOCGAXMAP. Falls back to axes/2 if the ioctl is unavailable.
Definition at line 338 of file joystickdriver.cpp.
| uint8_t JoyStickDriver::getNumrOfButtons | ( | ) |
Definition at line 333 of file joystickdriver.cpp.
| uint32_t JoyStickDriver::getVersion | ( | ) |
Definition at line 325 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 541 of file joystickdriver.cpp.
| joystick_position JoyStickDriver::joystickPosition | ( | int | n | ) |
Definition at line 493 of file joystickdriver.cpp.
|
staticprotected |
Definition at line 402 of file joystickdriver.cpp.
|
protected |
Definition at line 409 of file joystickdriver.cpp.
| void JoyStickDriver::setAxisCalibration | ( | int | axis, |
| int | center, | ||
| int | minVal, | ||
| int | maxVal | ||
| ) |
setAxisCalibration Set piecewise-linear calibration for one axis.
Maps [minVal .. center .. maxVal] → [-1 .. 0 .. +1].
| axis | Zero-based axis index. |
| center | Raw value at rest / center. |
| minVal | Raw value at full negative deflection. |
| maxVal | Raw value at full positive deflection. |
Definition at line 377 of file joystickdriver.cpp.
| void JoyStickDriver::setAxisCallback | ( | axisFunc | axisCallback | ) |
Definition at line 303 of file joystickdriver.cpp.
| void JoyStickDriver::setAxisReversed | ( | int | axis, |
| bool | reversed | ||
| ) |
setAxisReversed Enable or disable reversal for a single axis.
When reversed, the raw axis value is negated before calibration is applied. This mirrors the physical axis so that, for example, pushing a stick UP produces a positive normalised value even if the hardware reports negative values for that direction.
| axis | Zero-based axis index. |
| reversed | true to negate the raw value, false for normal polarity. |
Definition at line 386 of file joystickdriver.cpp.
| void JoyStickDriver::setButtonCallback | ( | buttonFunc | buttonCallback | ) |
Definition at line 307 of file joystickdriver.cpp.
| void JoyStickDriver::setJoystickCallback | ( | joystickFunc | joystickCallback | ) |
Definition at line 299 of file joystickdriver.cpp.
| void JoyStickDriver::setPoll | ( | int | ms | ) |
Definition at line 316 of file joystickdriver.cpp.
| void JoyStickDriver::setPort | ( | const char * | port | ) |
Definition at line 312 of file joystickdriver.cpp.
|
protected |
Definition at line 211 of file joystickdriver.h.
|
protected |
Definition at line 210 of file joystickdriver.h.
|
protected |
Definition at line 209 of file joystickdriver.h.