FIFE
be64c707dea6b3250bd4355bf5c825d25920087d
|
Represents a Joystick and if available the Gamecontroller. More...
#include <joystick.h>
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... | |
Represents a Joystick and if available the Gamecontroller.
Definition at line 39 of file joystick.h.
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.
Definition at line 69 of file joystick.h.
enum FIFE::Joystick::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.
FIFE::Joystick::Joystick | ( | int32_t | joystickId, |
int32_t | deviceIndex | ||
) |
Constructor.
joystickId | The identifier for the Joystick. |
deviceIndex | The index number from SDL2. |
Definition at line 41 of file joystick.cpp.
FIFE::Joystick::~Joystick | ( | ) |
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().
void FIFE::Joystick::closeController | ( | ) |
Closes / deactivates the gamecontroller.
Definition at line 132 of file joystick.cpp.
References m_controllerHandle.
Referenced by close(), and openController().
|
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().
float FIFE::Joystick::getAxisValue | ( | int8_t | axis | ) | const |
Return the current value for given axis.
axis | For 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.
int32_t FIFE::Joystick::getDeviceIndex | ( | ) | const |
Return the device index of the joystick.
Definition at line 68 of file joystick.cpp.
References m_deviceIndex.
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().
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.
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().
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().
const std::string & FIFE::Joystick::getName | ( | ) |
uint8_t FIFE::Joystick::getNumberOfAxes | ( | ) | const |
Return the number of axes.
Definition at line 139 of file joystick.cpp.
References isConnected(), and m_joystickHandle.
uint8_t FIFE::Joystick::getNumberOfButtons | ( | ) | const |
Return the number of buttons.
Definition at line 147 of file joystick.cpp.
References isConnected(), and m_joystickHandle.
uint8_t FIFE::Joystick::getNumberOfHats | ( | ) | const |
Return the number of hats.
Definition at line 155 of file joystick.cpp.
References isConnected(), and m_joystickHandle.
bool FIFE::Joystick::isButtonPressed | ( | int8_t | button | ) | const |
Return the current value for given axis.
button | For joysticks the index number, for controller see ControllerButton. |
Definition at line 183 of file joystick.cpp.
References isConnected(), isController(), m_controllerHandle, and m_joystickHandle.
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().
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().
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().
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().
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().
|
private |
SDLs controller handle.
Definition at line 181 of file joystick.h.
Referenced by closeController(), getAxisValue(), isButtonPressed(), isController(), and openController().
|
private |
SDLs device index.
Definition at line 187 of file joystick.h.
Referenced by close(), getDeviceIndex(), open(), openController(), and setDeviceIndex().
|
private |
|
private |
SDLs joystick id (different from device index)
Definition at line 183 of file joystick.h.
Referenced by close(), getInstanceId(), and open().
|
private |
SDLs joystick handle.
Definition at line 179 of file joystick.h.
Referenced by close(), getAxisValue(), getHatValue(), getNumberOfAxes(), getNumberOfButtons(), getNumberOfHats(), isButtonPressed(), isConnected(), and open().
|
private |
|
private |
The name of the joystick / controller.
Definition at line 191 of file joystick.h.