BoB robotics
The Brains on Board robotics library
BoBRobotics::HID::JoystickBase< JAxis, JButton > Class Template Referenceabstract

Generic joystick class for Xbox 360 controller, from which JoystickLinux and JoystickWindows classes inherit. More...

#include <joystick_base.h>

Inheritance diagram for BoBRobotics::HID::JoystickBase< JAxis, JButton >:
BoBRobotics::Threadable

Public Member Functions

bool update ()
 Try to read from the joystick. More...
 
void addHandler (AxisHandler handler)
 Add a function to handle joystick axis events.
 
void addHandler (ButtonHandler handler)
 Add a function to handle joystick button events.
 
float getState (JAxis axis) const
 Get the current value for a specified joystick axis.
 
unsigned char getState (JButton button) const
 Get the current state for a specified joystick button. More...
 
bool isDown (JButton button) const
 Whether button is currently being pressed.
 
bool isPressed (JButton button) const
 Whether button has been pressed since last update()
 
bool isReleased (JButton button) const
 Whether button has been released since last update()
 
- Public Member Functions inherited from BoBRobotics::Threadable
virtual void run ()
 Run on the current thread, blocking until process ends.
 
virtual bool isRunning ()
 Check if the run() function has been called.
 
virtual void runInBackground ()
 Run the process on a background thread.
 
virtual void stop ()
 Stop the background thread.
 

Static Public Member Functions

static std::string getName (JAxis axis)
 Get the name of a specified joystick axis.
 
static std::string getName (JButton button)
 Get the name of a specified joystick button.
 

Protected Member Functions

 JoystickBase (float deadZone=0.0f)
 
virtual bool updateState ()=0
 
virtual void runInternal () override
 
void setPressed (JButton button, bool isInitial)
 
void setReleased (JButton button, bool isInitial)
 
void setState (JButton button, uint8_t state, bool isInitial)
 
void setState (JAxis axis, float value, bool isInitial)
 
virtual void runInternal ()=0
 

Static Protected Member Functions

template<class T >
static constexpr size_t toIndex (T value)
 
template<class T >
static constexpr JAxis toAxis (T value)
 
template<class T >
static constexpr JButton toButton (T value)
 
static constexpr float int16_maxf ()
 
static constexpr float int16_absminf ()
 

Detailed Description

template<typename JAxis, typename JButton>
class BoBRobotics::HID::JoystickBase< JAxis, JButton >

Generic joystick class for Xbox 360 controller, from which JoystickLinux and JoystickWindows classes inherit.

The class provides the basic, platform-independent functionality required by JoystickLinux and JoystickWindows.

NOTE: This class should not be used directly; see example in joystick_test.

Member Function Documentation

◆ getState()

template<typename JAxis , typename JButton >
unsigned char BoBRobotics::HID::JoystickBase< JAxis, JButton >::getState ( JButton  button) const
inline

Get the current state for a specified joystick button.

See also
ButtonState

◆ runInternal()

template<typename JAxis , typename JButton >
virtual void BoBRobotics::HID::JoystickBase< JAxis, JButton >::runInternal ( )
inlineoverrideprotectedvirtual

◆ update()

template<typename JAxis , typename JButton >
bool BoBRobotics::HID::JoystickBase< JAxis, JButton >::update ( )
inline

Try to read from the joystick.

Returns
True if one or more events were read from joystick

The documentation for this class was generated from the following file: