Simple Joystick class for interfacing to a joystick. More...
#include <joystick.h>
Classes | |
class | Callback |
Simple Joystick Callback class which can be used to receive automatic joystick updates. More... | |
Public Types | |
enum | Axes { X = 0, Y, Z, R, U, V, POV, PovX, PovY } |
Enumerations for the different axes of a joystick/gamepad. More... | |
enum | Event { None = 0, ButtonDown, ButtonUp } |
Enumerations for the different types of Joystick events. More... | |
Public Member Functions | |
Joystick () | |
Constructor. | |
~Joystick () | |
Destructor. | |
int | Initialize (const unsigned int num=AnyJoystick, const unsigned int freq=25, const std::string &calibrationFile=std::string()) |
Initializes the joystick. | |
int | Shutdown () |
Shutsdown the joystick interface. | |
int | GetAxis (const short int axis) const |
Gets the value of the joystick axis. | |
int | GetPOV () const |
Gets the Point of View (POV) HAT values. | |
int | GetButtonNumber () const |
Gets the number of the current button being pressed. | |
int | GetID () const |
int | RegisterCallback (Joystick::Callback *cb) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time. | |
int | RegisterCallback (void(*func)(const Joystick &jstick, void *args), void *args) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time. | |
int | RegisterCallback (void(*func)(const unsigned int buttonNumber, const Joystick::Event type, void *args), void *args) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time. | |
void | ClearCallbacks () |
Clears callback for automatic updates from joystick. | |
void | PrintJoystickInfo () const |
Prints joystick values to console. | |
bool | IsButtonPressed (const unsigned int num=0) const |
Find out if a button is pressed or a specific button by number. | |
bool | IsConnected () const |
double | GetAxisPercentage (const short int axis, const short int deadzone=0) const |
Gets the value of the joystick axis. | |
unsigned int | GetUpdateFrequencey () const |
Static Public Member Functions | |
static short int | GetAxisFromLetter (const char ch) |
Converts the character letter represening the axis ('x', 'X') to a number identifier such as JOYSTICK_X_AXIS. | |
static char | GetLetterFromAxis (const short int axis) |
Converts the axis number to a charcter. | |
Static Public Attributes | |
static const short int | MinAxisValue = -32767 |
Minimum joystick axis value. | |
static const short int | MaxAxisValue = 32767 |
Maximum joystick axis value. | |
static const short int | MaxAxis = 9 |
Total number of supported joystick axes. | |
static const unsigned int | MaxButtons = 32 |
Maximum number of joystick buttons. | |
static const unsigned short int | PovOff = 65535 |
POV value when POV centered. | |
static const unsigned int | AnyJoystick = UINT_MAX |
Constant for selection of any joystick. | |
Static Protected Member Functions | |
static void | JoystickThreadFunction (void *args) |
Function performed within a thread which continuously reads data from the joystick based on update frequency. | |
static void | CallbackThreadFunction (void *args) |
Method that generates Joystick callbacks in Linux. This is done differently than the windows version of this code because reading from the joystick is a blocking function call. | |
Protected Attributes | |
Thread | mCallbackThread |
Mutex | mJoystickMutex |
I/O protection. | |
Mutex | mJoyCallbackMutex |
Mutex for callbacks. | |
Thread | mJoystickThread |
Thread where data is read from joystick. | |
Callback::Data::List | mCallbacks |
Callbacks to run when joystick updates. | |
int | mID |
Joystick ID number. | |
int | mButtons |
Button values. | |
int * | mpAxis |
Axis data. | |
unsigned int | mUpdateFrequency |
Update frequency. | |
bool | mJoystickConnected |
Connection flag. | |
void * | mpJoyInterface |
Interface to Joystick. |
Simple Joystick class for interfacing to a joystick.
Definition at line 64 of file joystick.h.
Enumerations for the different axes of a joystick/gamepad.
Definition at line 79 of file joystick.h.
Enumerations for the different types of Joystick events.
Definition at line 97 of file joystick.h.
Joystick::Joystick | ( | ) |
Constructor.
Definition at line 123 of file joystick.cpp.
Joystick::~Joystick | ( | ) |
Destructor.
Definition at line 141 of file joystick.cpp.
void Joystick::CallbackThreadFunction | ( | void * | args ) | [static, protected] |
Method that generates Joystick callbacks in Linux. This is done differently than the windows version of this code because reading from the joystick is a blocking function call.
Definition at line 993 of file joystick.cpp.
void Joystick::ClearCallbacks | ( | ) |
Clears callback for automatic updates from joystick.
Definition at line 541 of file joystick.cpp.
int Joystick::GetAxis | ( | const short int | axis ) | const |
Gets the value of the joystick axis.
axis | The axis number, see Axes enumeration. |
Definition at line 360 of file joystick.cpp.
short int Joystick::GetAxisFromLetter | ( | const char | ch ) | [static] |
Converts the character letter represening the axis ('x', 'X') to a number identifier such as JOYSTICK_X_AXIS.
ch | The character represening the axis. Values can be upper or lower case. ('x', 'y', 'z', etc.) |
Definition at line 912 of file joystick.cpp.
double Joystick::GetAxisPercentage | ( | const short int | axis, |
const short int | deadzone = 0 |
||
) | const |
Gets the value of the joystick axis.
axis | The axis number, see Axes enumeration. |
deadzone | Joystick deadzone percentage. [0,100]. |
Definition at line 622 of file joystick.cpp.
int Joystick::GetButtonNumber | ( | ) | const |
Gets the number of the current button being pressed.
Definition at line 410 of file joystick.cpp.
int CxUtils::Joystick::GetID | ( | ) | const [inline] |
Definition at line 157 of file joystick.h.
char Joystick::GetLetterFromAxis | ( | const short int | axis ) | [static] |
Converts the axis number to a charcter.
axis | The axis number. X, Y, Z, R, U, V, etc. |
Definition at line 952 of file joystick.cpp.
int Joystick::GetPOV | ( | ) | const |
Gets the Point of View (POV) HAT values.
Definition at line 386 of file joystick.cpp.
unsigned int CxUtils::Joystick::GetUpdateFrequencey | ( | ) | const [inline] |
Definition at line 169 of file joystick.h.
int Joystick::Initialize | ( | const unsigned int | num = AnyJoystick , |
const unsigned int | freq = 25 , |
||
const std::string & | calibrationFile = std::string() |
||
) |
Initializes the joystick.
num | The joystick ID number. If set to AnyJoystick (default) then function connects to first available joystick. [0,10]. |
freq | Frequency for updates in Hz. [1,50]. |
calibrationFile | Used only in linux with jscalibrator. Specify the calibration file data to correct joystick values. (Optional Field). |
Check for calibratrion data
there is a whole format, I'm just grabbing what I need
Definition at line 170 of file joystick.cpp.
bool Joystick::IsButtonPressed | ( | const unsigned int | num = 0 ) |
const |
Find out if a button is pressed or a specific button by number.
num | Button numberr [1,32], 0 for any button. |
Definition at line 576 of file joystick.cpp.
bool Joystick::IsConnected | ( | ) | const |
Definition at line 606 of file joystick.cpp.
void Joystick::JoystickThreadFunction | ( | void * | args ) | [static, protected] |
Function performed within a thread which continuously reads data from the joystick based on update frequency.
Definition at line 655 of file joystick.cpp.
void Joystick::PrintJoystickInfo | ( | ) | const |
Prints joystick values to console.
Definition at line 553 of file joystick.cpp.
int Joystick::RegisterCallback | ( | Joystick::Callback * | cb ) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time.
cb | Callback pointer. |
Definition at line 446 of file joystick.cpp.
int Joystick::RegisterCallback | ( | void(*)(const unsigned int buttonNumber, const Joystick::Event type, void *args) | func, |
void * | args | ||
) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time.
func | Function pointer callback to use when buttons are pressed and released. |
args | Additional arugments for the function callback. |
Definition at line 514 of file joystick.cpp.
int Joystick::RegisterCallback | ( | void(*)(const Joystick &jstick, void *args) | func, |
void * | args | ||
) |
Register a callback to receive joystick updates on at a fixed frequency. This will clear any other callbacks, since only one may be registered at a time.
func | Function pointer callback to use when new joystick data is read. |
args | Additional arugments for the function callback. |
Definition at line 480 of file joystick.cpp.
int Joystick::Shutdown | ( | ) |
const unsigned int CxUtils::Joystick::AnyJoystick = UINT_MAX [static] |
Constant for selection of any joystick.
Definition at line 72 of file joystick.h.
const short int CxUtils::Joystick::MaxAxis = 9 [static] |
Total number of supported joystick axes.
Definition at line 69 of file joystick.h.
const short int CxUtils::Joystick::MaxAxisValue = 32767 [static] |
Maximum joystick axis value.
Definition at line 68 of file joystick.h.
const unsigned int CxUtils::Joystick::MaxButtons = 32 [static] |
Maximum number of joystick buttons.
Definition at line 70 of file joystick.h.
int CxUtils::Joystick::mButtons [protected] |
Button values.
Definition at line 181 of file joystick.h.
Callback::Data::List CxUtils::Joystick::mCallbacks [protected] |
Callbacks to run when joystick updates.
Definition at line 179 of file joystick.h.
Thread CxUtils::Joystick::mCallbackThread [protected] |
Definition at line 174 of file joystick.h.
int CxUtils::Joystick::mID [protected] |
Joystick ID number.
Definition at line 180 of file joystick.h.
const short int CxUtils::Joystick::MinAxisValue = -32767 [static] |
Minimum joystick axis value.
Definition at line 67 of file joystick.h.
Mutex CxUtils::Joystick::mJoyCallbackMutex [protected] |
Mutex for callbacks.
Definition at line 177 of file joystick.h.
bool CxUtils::Joystick::mJoystickConnected [protected] |
Connection flag.
Definition at line 184 of file joystick.h.
Mutex CxUtils::Joystick::mJoystickMutex [protected] |
I/O protection.
Definition at line 176 of file joystick.h.
Thread CxUtils::Joystick::mJoystickThread [protected] |
Thread where data is read from joystick.
Definition at line 178 of file joystick.h.
int* CxUtils::Joystick::mpAxis [protected] |
Axis data.
Definition at line 182 of file joystick.h.
void* CxUtils::Joystick::mpJoyInterface [protected] |
Interface to Joystick.
Definition at line 185 of file joystick.h.
unsigned int CxUtils::Joystick::mUpdateFrequency [protected] |
Update frequency.
Definition at line 183 of file joystick.h.
const unsigned short int CxUtils::Joystick::PovOff = 65535 [static] |
POV value when POV centered.
Definition at line 71 of file joystick.h.