15#ifndef __JOYSTICK_HH__
16#define __JOYSTICK_HH__
21#define JS_EVENT_BUTTON 0x01
22#define JS_EVENT_AXIS 0x02
23#define JS_EVENT_INIT 0x80
103 void openPath(std::string devicePath,
bool blocking=
false);
140 Joystick(std::string devicePath,
bool blocking);
Encapsulates all data relevant to a sampled joystick event.
Definition: joystick.hpp:29
friend std::ostream & operator<<(std::ostream &os, const JoystickEvent &e)
The ostream inserter needs to be a friend so it can access the internal data structures.
Definition: joystick.cpp:75
bool isInitialState()
Returns true if this event is part of the initial state obtained when the joystick is first connected...
Definition: joystick.hpp:79
unsigned int time
The timestamp of the event, in milliseconds.
Definition: joystick.hpp:40
short value
The value associated with this joystick event.
Definition: joystick.hpp:47
bool isAxis()
Returns true if this event is the result of an axis movement.
Definition: joystick.hpp:70
bool isButton()
Returns true if this event is the result of a button press.
Definition: joystick.hpp:62
unsigned char type
The event type.
Definition: joystick.hpp:52
unsigned char number
The axis/button number.
Definition: joystick.hpp:57
static const short MAX_AXES_VALUE
Maximum value of axes range.
Definition: joystick.hpp:35
static const short MIN_AXES_VALUE
Minimum value of axes range.
Definition: joystick.hpp:32
Represents a joystick device.
Definition: joystick.hpp:101
Joystick(Joystick const &)=delete
Joystick objects cannot be copied.
bool isFound()
Returns true if the joystick was found and may be used, otherwise false.
Definition: joystick.cpp:65
int _fd
Definition: joystick.hpp:105
Joystick(Joystick &&)=default
Joystick objects can be moved.
~Joystick()
Definition: joystick.cpp:70
Joystick()
Initialises an instance for the first joystick: /dev/input/js0.
Definition: joystick.cpp:25
void openPath(std::string devicePath, bool blocking=false)
Definition: joystick.cpp:47
bool sample(JoystickEvent *event)
Attempts to populate the provided JoystickEvent instance with data from the joystick.
Definition: joystick.cpp:53
#define JS_EVENT_INIT
Definition: joystick.hpp:23
std::ostream & operator<<(std::ostream &os, const JoystickEvent &e)
Stream insertion function so you can do this: cout << event << endl;.
Definition: joystick.cpp:75
#define JS_EVENT_BUTTON
Definition: joystick.hpp:21
#define JS_EVENT_AXIS
Definition: joystick.hpp:22