34#include <linux/joystick.h>
38#define JOYSTICK_DEV "/dev/input/js0"
51#define ABS_THROTTLE 0x06
52#define ABS_RUDDER 0x07
74 std::vector<signed short>
axis;
118 typedef std::function<void(
int joystick_n,
double mag,
double angle)>
joystickFunc;
119 typedef std::function<void(
int axis_n,
double value)>
axisFunc;
120 typedef std::function<void(
int button_n,
int value)>
buttonFunc;
125 void setPort(
const char *port);
202 static void joystickEvent(
int joystick_n,
double mag,
double angle);
203 static void axisEvent(
int axis_n,
int value);
206 static void *
loop(
void *obj);
217 js_event *joystick_ev;
228 std::vector<uint8_t> m_axmap;
231 std::vector<JoyAxisPair> m_stickPairs;
234 std::vector<int> m_axisToPairIndex;
237 std::vector<int> m_calCenter;
238 std::vector<int> m_calMin;
239 std::vector<int> m_calMax;
243 std::vector<bool> m_axisReversed;
246 float normalizeAxis(
int value,
int idx)
const;
249 static JoyAxisType classifyAbsCode(uint8_t absCode);
252 static const char *absCodeLabel(uint8_t code);
255 void buildAxisPairs();
The JoyStickDriver class provides basic functionality to read events from supported game pads under L...
buttonFunc buttonCallbackFunc
static void buttonEvent(int button_n, int value)
uint8_t getNumOfJoysticks()
getNumOfJoysticks Returns the number of proper analog-stick / hat pairs found via JSIOCGAXMAP....
JoyAxisType getAxisType(int axis) const
getAxisType Returns the classified type of axis.
uint8_t getAxisAbsCode(int axis) const
getAxisAbsCode Returns the ABS_* event code for axis, or 0xFF if the axis map is not available.
const JoyAxisPair * getJoystickPair(int n) const
getJoystickPair Returns the axis-pair descriptor for joystick n, or nullptr if out of range.
uint8_t getNumrOfButtons()
static void * loop(void *obj)
void setAxisCalibration(int axis, int center, int minVal, int maxVal)
setAxisCalibration Set piecewise-linear calibration for one axis.
static void axisEvent(int axis_n, int value)
void setButtonCallback(buttonFunc buttonCallback)
void setAxisReversed(int axis, bool reversed)
setAxisReversed Enable or disable reversal for a single axis.
axisFunc axisCallbackFunc
joystickFunc joystickCallbackFunc
std::function< void(int axis_n, double value)> axisFunc
std::function< void(int joystick_n, double mag, double angle)> joystickFunc
void setAxisCallback(axisFunc axisCallback)
static void joystickEvent(int joystick_n, double mag, double angle)
void setJoystickCallback(joystickFunc joystickCallback)
bool buttonPressed(int n)
void setPort(const char *port)
const char * getAxisLabel(int axis) const
getAxisLabel Returns a human-readable label for axis (e.g. "Left-Stick X", "L2 Trigger",...
std::function< void(int button_n, int value)> buttonFunc
joystick_position joystickPosition(int n)
JoyAxisType
Axis type classification inferred from JSIOCGAXMAP.
@ HAT
Digital hat / d-pad (ABS_HAT0X/Y … ABS_HAT3Y)
@ STICK
Analog stick (ABS_X/Y, ABS_RX/RY, throttle, rudder, wheel)
@ TRIGGER
Analog trigger — single-axis input (ABS_Z/RZ, gas, brake)
A matched pair of axis indices that together form a joystick.
bool isHat
True for digital hat / d-pad pairs.
const char * name
Human-readable name (e.g. "Left Stick")
uint8_t absY
ABS_* code for the Y axis.
int i0
Index of the horizontal (X) axis.
uint8_t absX
ABS_* code for the X axis.
int i1
Index of the vertical (Y) axis.
std::vector< signed short > axis
std::vector< signed short > button