Driver for a Linux joystick. More...
#include <Devices/JoyStick.H>
Public Member Functions | |
JoyStick (OptionManager &mgr, const std::string &descrName="JoyStick", const std::string &tagName="JoyStick", const char *dev="/dev/input/js0") | |
Constructor. | |
void | setListener (rutz::shared_ptr< JoyStickListener > &listener) |
Add a listener. | |
~JoyStick () | |
Destructor. | |
uint | getNumAxes () const |
Get number of axes. | |
uint | getNumButtons () const |
Get number of buttons. | |
int16 | getAxisValue (const uint num) const |
Get value of a given axis. | |
bool | getButtonState (const uint num) const |
Get state of a given button. | |
void | run () |
Should not call this directly -- running in a thread. | |
bool | joystickPlugged () |
Protected Member Functions | |
void | start1 () |
get started | |
void | stop1 () |
get stopped | |
Protected Attributes | |
NModelParam< std::string > | itsDevName |
Name of our device. | |
int | itsFd |
file descriptor for our device | |
bool | itsPlugged |
bool | itsKeepGoing |
tell our thread to keep going | |
std::vector< int16 > | itsAxes |
data from our axes | |
std::vector< bool > | itsButtons |
data from our buttons |
Driver for a Linux joystick.
This is a simple driver for a Linux joystick. There are basically two modes of operation: you can either get the current JoyStick status at any time using getAxisValue() and getButtonState(), or you can register a JoyStickListener using setListener, and the listener will be called each time some change occurs in any of the axes or buttons. Beware that your listener will be called from a thread running in parallel with your main thread.
Definition at line 84 of file JoyStick.H.
JoyStick::JoyStick | ( | OptionManager & | mgr, | |
const std::string & | descrName = "JoyStick" , |
|||
const std::string & | tagName = "JoyStick" , |
|||
const char * | dev = "/dev/input/js0" | |||
) |
Constructor.
Definition at line 62 of file JoyStick.C.
JoyStick::~JoyStick | ( | ) |
Destructor.
Definition at line 78 of file JoyStick.C.
bool JoyStick::getButtonState | ( | const uint | num | ) | const |
uint JoyStick::getNumAxes | ( | ) | const |
uint JoyStick::getNumButtons | ( | ) | const |
void JoyStick::run | ( | ) |
Should not call this directly -- running in a thread.
Definition at line 148 of file JoyStick.C.
References rutz::shared_ptr< T >::get(), itsAxes, itsButtons, itsFd, and itsKeepGoing.
void JoyStick::setListener | ( | rutz::shared_ptr< JoyStickListener > & | listener | ) |
Add a listener.
Definition at line 74 of file JoyStick.C.
void JoyStick::start1 | ( | ) | [protected, virtual] |
get started
Reimplemented from ModelComponent.
Definition at line 82 of file JoyStick.C.
References NModelParam< T >::getVal(), itsAxes, itsButtons, itsDevName, itsFd, and itsKeepGoing.
void JoyStick::stop1 | ( | ) | [protected, virtual] |
get stopped
Reimplemented from ModelComponent.
Definition at line 106 of file JoyStick.C.
References itsFd, and itsKeepGoing.
std::vector<int16> JoyStick::itsAxes [protected] |
data from our axes
Definition at line 128 of file JoyStick.H.
Referenced by getAxisValue(), getNumAxes(), run(), and start1().
std::vector<bool> JoyStick::itsButtons [protected] |
data from our buttons
Definition at line 129 of file JoyStick.H.
Referenced by getButtonState(), getNumButtons(), run(), and start1().
NModelParam<std::string> JoyStick::itsDevName [protected] |
int JoyStick::itsFd [protected] |
file descriptor for our device
Definition at line 125 of file JoyStick.H.
bool JoyStick::itsKeepGoing [protected] |
tell our thread to keep going
Definition at line 127 of file JoyStick.H.