FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::Joystick Class Reference

Represents a Joystick and if available the Gamecontroller. More...

#include <joystick.h>

+ Collaboration diagram for FIFE::Joystick:

Public Types

enum  Hat {
  HAT_INVALID = -1, HAT_CENTERED = 0, HAT_UP = 1, HAT_RIGHT = 2,
  HAT_DOWN = 4, HAT_LEFT = 8, HAT_RIGHTUP = 3, HAT_RIGHTDOWN = 6,
  HAT_LEFTUP = 9, HAT_LEFTDOWN = 12
}
 
enum  ContollerAxis {
  CONTOLLER_AXIS_INVALID = -1, CONTOLLER_AXIS_LEFTX, CONTOLLER_AXIS_LEFTY, CONTOLLER_AXIS_RIGHTX,
  CONTOLLER_AXIS_RIGHTY, CONTOLLER_AXIS_TRIGGERLEFT, CONTOLLER_AXIS_TRIGGERRIGHT, CONTOLLER_AXIS_MAX
}
 
enum  ControllerButton {
  CONTOLLER_BUTTON_INVALID = -1, CONTOLLER_BUTTON_A, CONTOLLER_BUTTON_B, CONTOLLER_BUTTON_X,
  CONTOLLER_BUTTON_Y, CONTOLLER_BUTTON_BACK, CONTOLLER_BUTTON_GUIDE, CONTOLLER_BUTTON_START,
  CONTOLLER_BUTTON_LEFTSTICK, CONTOLLER_BUTTON_RIGHTSTICK, CONTOLLER_BUTTON_LEFTSHOULDER, CONTOLLER_BUTTON_RIGHTSHOULDER,
  CONTOLLER_BUTTON_DPAD_UP, CONTOLLER_BUTTON_DPAD_DOWN, CONTOLLER_BUTTON_DPAD_LEFT, CONTOLLER_BUTTON_DPAD_RIGHT,
  CONTOLLER_BUTTON_MAX
}
 

Public Member Functions

 Joystick (int32_t joystickId, int32_t deviceIndex)
 Constructor. More...
 
 ~Joystick ()
 Destructor. More...
 
int32_t getInstanceId () const
 Return the instance id of the joystick. More...
 
int32_t getJoystickId () const
 Sets the instance id of the joystick. More...
 
void setDeviceIndex (int32_t deviceIndex)
 Sets the device index of the joystick. More...
 
int32_t getDeviceIndex () const
 Return the device index of the joystick. More...
 
const std::string & getGuid ()
 Return the GUID of the joystick / gamecontroller class as string. More...
 
const std::string & getName ()
 Return the name of the joystick. More...
 
void open ()
 Opens / activates the joystick and sets values. More...
 
void close ()
 Closes / deactivates the joystick. More...
 
bool isConnected () const
 Indicates if the joystick / gamecontroller is connected. More...
 
bool isController () const
 Indicates if this a controller. More...
 
void openController ()
 Opens / activates the gamecontroller, only possible with valid GUID mapping. More...
 
void closeController ()
 Closes / deactivates the gamecontroller. More...
 
uint8_t getNumberOfAxes () const
 Return the number of axes. More...
 
uint8_t getNumberOfButtons () const
 Return the number of buttons. More...
 
uint8_t getNumberOfHats () const
 Return the number of hats. More...
 
float getAxisValue (int8_t axis) const
 Return the current value for given axis. More...
 
int8_t getHatValue (int8_t hat) const
 Return the hat value (see Hat positions), for given hat index. More...
 
bool isButtonPressed (int8_t button) const
 Return the current value for given axis. More...
 

Private Member Functions

float convertRange (int16_t value) const
 Converts the int16 in -1.0 to 1.0 range. More...
 

Private Attributes

SDL_Joystick * m_joystickHandle
 SDLs joystick handle. More...
 
SDL_GameController * m_controllerHandle
 SDLs controller handle. More...
 
SDL_JoystickID m_instanceId
 SDLs joystick id (different from device index) More...
 
int32_t m_joystickId
 Our joystick id. More...
 
int32_t m_deviceIndex
 SDLs device index. More...
 
std::string m_guidStr
 The GUID as string. More...
 
std::string m_name
 The name of the joystick / controller. More...
 

Detailed Description

Represents a Joystick and if available the Gamecontroller.

Definition at line 39 of file joystick.h.

Member Enumeration Documentation

◆ ContollerAxis

Enumerator
CONTOLLER_AXIS_INVALID 
CONTOLLER_AXIS_LEFTX 
CONTOLLER_AXIS_LEFTY 
CONTOLLER_AXIS_RIGHTX 
CONTOLLER_AXIS_RIGHTY 
CONTOLLER_AXIS_TRIGGERLEFT 
CONTOLLER_AXIS_TRIGGERRIGHT 
CONTOLLER_AXIS_MAX 

Definition at line 57 of file joystick.h.

◆ ControllerButton

Enumerator
CONTOLLER_BUTTON_INVALID 
CONTOLLER_BUTTON_A 
CONTOLLER_BUTTON_B 
CONTOLLER_BUTTON_X 
CONTOLLER_BUTTON_Y 
CONTOLLER_BUTTON_BACK 
CONTOLLER_BUTTON_GUIDE 
CONTOLLER_BUTTON_START 
CONTOLLER_BUTTON_LEFTSTICK 
CONTOLLER_BUTTON_RIGHTSTICK 
CONTOLLER_BUTTON_LEFTSHOULDER 
CONTOLLER_BUTTON_RIGHTSHOULDER 
CONTOLLER_BUTTON_DPAD_UP 
CONTOLLER_BUTTON_DPAD_DOWN 
CONTOLLER_BUTTON_DPAD_LEFT 
CONTOLLER_BUTTON_DPAD_RIGHT 
CONTOLLER_BUTTON_MAX 

Definition at line 69 of file joystick.h.

◆ Hat

Enumerator
HAT_INVALID 
HAT_CENTERED 
HAT_UP 
HAT_RIGHT 
HAT_DOWN 
HAT_LEFT 
HAT_RIGHTUP 
HAT_RIGHTDOWN 
HAT_LEFTUP 
HAT_LEFTDOWN 

Definition at line 43 of file joystick.h.

Constructor & Destructor Documentation

◆ Joystick()

FIFE::Joystick::Joystick ( int32_t  joystickId,
int32_t  deviceIndex 
)

Constructor.

Parameters
joystickIdThe identifier for the Joystick.
deviceIndexThe index number from SDL2.

Definition at line 41 of file joystick.cpp.

◆ ~Joystick()

FIFE::Joystick::~Joystick ( )

Destructor.

Definition at line 52 of file joystick.cpp.

References close().

Member Function Documentation

◆ close()

void FIFE::Joystick::close ( )

Closes / deactivates the joystick.

Definition at line 105 of file joystick.cpp.

References closeController(), m_deviceIndex, m_instanceId, and m_joystickHandle.

Referenced by open(), and ~Joystick().

+ Here is the caller graph for this function:

◆ closeController()

void FIFE::Joystick::closeController ( )

Closes / deactivates the gamecontroller.

Definition at line 132 of file joystick.cpp.

References m_controllerHandle.

Referenced by close(), and openController().

+ Here is the caller graph for this function:

◆ convertRange()

float FIFE::Joystick::convertRange ( int16_t  value) const
private

Converts the int16 in -1.0 to 1.0 range.

Definition at line 201 of file joystick.cpp.

References FIFE::Math< T >::FAbs().

Referenced by getAxisValue().

+ Here is the caller graph for this function:

◆ getAxisValue()

float FIFE::Joystick::getAxisValue ( int8_t  axis) const

Return the current value for given axis.

Parameters
axisFor joysticks the index number, for controller see ContollerAxis.

Definition at line 163 of file joystick.cpp.

References convertRange(), isConnected(), isController(), m_controllerHandle, and m_joystickHandle.

◆ getDeviceIndex()

int32_t FIFE::Joystick::getDeviceIndex ( ) const

Return the device index of the joystick.

Definition at line 68 of file joystick.cpp.

References m_deviceIndex.

◆ getGuid()

const std::string & FIFE::Joystick::getGuid ( )

Return the GUID of the joystick / gamecontroller class as string.

Definition at line 72 of file joystick.cpp.

References m_guidStr.

Referenced by FIFE::JoystickManager::addControllerGuid(), and FIFE::JoystickManager::removeControllerGuid().

+ Here is the caller graph for this function:

◆ getHatValue()

int8_t FIFE::Joystick::getHatValue ( int8_t  hat) const

Return the hat value (see Hat positions), for given hat index.

Definition at line 176 of file joystick.cpp.

References HAT_INVALID, isConnected(), and m_joystickHandle.

◆ getInstanceId()

int32_t FIFE::Joystick::getInstanceId ( ) const

Return the instance id of the joystick.

Definition at line 56 of file joystick.cpp.

References m_instanceId.

Referenced by FIFE::JoystickManager::addJoystick(), and FIFE::JoystickManager::processJoystickEvent().

+ Here is the caller graph for this function:

◆ getJoystickId()

int32_t FIFE::Joystick::getJoystickId ( ) const

Sets the instance id of the joystick.

Definition at line 60 of file joystick.cpp.

References m_joystickId.

Referenced by FIFE::JoystickManager::addJoystick().

+ Here is the caller graph for this function:

◆ getName()

const std::string & FIFE::Joystick::getName ( )

Return the name of the joystick.

Definition at line 76 of file joystick.cpp.

References m_name.

◆ getNumberOfAxes()

uint8_t FIFE::Joystick::getNumberOfAxes ( ) const

Return the number of axes.

Definition at line 139 of file joystick.cpp.

References isConnected(), and m_joystickHandle.

◆ getNumberOfButtons()

uint8_t FIFE::Joystick::getNumberOfButtons ( ) const

Return the number of buttons.

Definition at line 147 of file joystick.cpp.

References isConnected(), and m_joystickHandle.

◆ getNumberOfHats()

uint8_t FIFE::Joystick::getNumberOfHats ( ) const

Return the number of hats.

Definition at line 155 of file joystick.cpp.

References isConnected(), and m_joystickHandle.

◆ isButtonPressed()

bool FIFE::Joystick::isButtonPressed ( int8_t  button) const

Return the current value for given axis.

Parameters
buttonFor joysticks the index number, for controller see ControllerButton.

Definition at line 183 of file joystick.cpp.

References isConnected(), isController(), m_controllerHandle, and m_joystickHandle.

◆ isConnected()

bool FIFE::Joystick::isConnected ( ) const

Indicates if the joystick / gamecontroller is connected.

Definition at line 115 of file joystick.cpp.

References m_joystickHandle.

Referenced by getAxisValue(), getHatValue(), getNumberOfAxes(), getNumberOfButtons(), getNumberOfHats(), and isButtonPressed().

+ Here is the caller graph for this function:

◆ isController()

bool FIFE::Joystick::isController ( ) const

Indicates if this a controller.

Definition at line 119 of file joystick.cpp.

References m_controllerHandle.

Referenced by FIFE::JoystickManager::addControllerGuid(), getAxisValue(), isButtonPressed(), open(), FIFE::JoystickManager::processJoystickEvent(), and FIFE::JoystickManager::removeControllerGuid().

+ Here is the caller graph for this function:

◆ open()

void FIFE::Joystick::open ( )

Opens / activates the joystick and sets values.

Definition at line 80 of file joystick.cpp.

References close(), isController(), m_deviceIndex, m_guidStr, m_instanceId, m_joystickHandle, m_name, and openController().

Referenced by FIFE::JoystickManager::addJoystick().

+ Here is the caller graph for this function:

◆ openController()

void FIFE::Joystick::openController ( )

Opens / activates the gamecontroller, only possible with valid GUID mapping.

Definition at line 123 of file joystick.cpp.

References closeController(), m_controllerHandle, and m_deviceIndex.

Referenced by open().

+ Here is the caller graph for this function:

◆ setDeviceIndex()

void FIFE::Joystick::setDeviceIndex ( int32_t  deviceIndex)

Sets the device index of the joystick.

Definition at line 64 of file joystick.cpp.

References m_deviceIndex.

Referenced by FIFE::JoystickManager::addJoystick().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_controllerHandle

SDL_GameController* FIFE::Joystick::m_controllerHandle
private

SDLs controller handle.

Definition at line 181 of file joystick.h.

Referenced by closeController(), getAxisValue(), isButtonPressed(), isController(), and openController().

◆ m_deviceIndex

int32_t FIFE::Joystick::m_deviceIndex
private

SDLs device index.

Definition at line 187 of file joystick.h.

Referenced by close(), getDeviceIndex(), open(), openController(), and setDeviceIndex().

◆ m_guidStr

std::string FIFE::Joystick::m_guidStr
private

The GUID as string.

Definition at line 189 of file joystick.h.

Referenced by getGuid(), and open().

◆ m_instanceId

SDL_JoystickID FIFE::Joystick::m_instanceId
private

SDLs joystick id (different from device index)

Definition at line 183 of file joystick.h.

Referenced by close(), getInstanceId(), and open().

◆ m_joystickHandle

SDL_Joystick* FIFE::Joystick::m_joystickHandle
private

◆ m_joystickId

int32_t FIFE::Joystick::m_joystickId
private

Our joystick id.

Definition at line 185 of file joystick.h.

Referenced by getJoystickId().

◆ m_name

std::string FIFE::Joystick::m_name
private

The name of the joystick / controller.

Definition at line 191 of file joystick.h.

Referenced by getName(), and open().


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