42 m_joystickHandle(NULL),
43 m_controllerHandle(NULL),
45 m_joystickId(joystickId),
46 m_deviceIndex(deviceIndex),
90 SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(
m_deviceIndex);
91 SDL_JoystickGetGUIDString(guid, tmp,
sizeof(tmp));
99 m_name = std::string(name);
101 throw SDLException(SDL_GetError());
172 SDL_GameControllerAxis sdlAxis =
static_cast<SDL_GameControllerAxis
>(axis);
194 SDL_GameControllerButton sdlButton =
static_cast<SDL_GameControllerButton
>(button);
202 float range =
static_cast<float>(value) / 32768.0f;
206 if (range < -0.99f) {
208 }
else if (range > 0.99f) {
bool isConnected() const
Indicates if the joystick / gamecontroller is connected.
int32_t m_joystickId
Our joystick id.
void closeController()
Closes / deactivates the gamecontroller.
int32_t m_deviceIndex
SDLs device index.
uint8_t getNumberOfHats() const
Return the number of hats.
SDL_JoystickID m_instanceId
SDLs joystick id (different from device index)
bool isController() const
Indicates if this a controller.
void close()
Closes / deactivates the joystick.
static Logger _log(LM_AUDIO)
std::string m_name
The name of the joystick / controller.
void setDeviceIndex(int32_t deviceIndex)
Sets the device index of the joystick.
uint8_t getNumberOfAxes() const
Return the number of axes.
bool isButtonPressed(int8_t button) const
Return the current value for given axis.
const std::string & getGuid()
Return the GUID of the joystick / gamecontroller class as string.
int32_t getJoystickId() const
Sets the instance id of the joystick.
Joystick(int32_t joystickId, int32_t deviceIndex)
Constructor.
float convertRange(int16_t value) const
Converts the int16 in -1.0 to 1.0 range.
int32_t getDeviceIndex() const
Return the device index of the joystick.
void openController()
Opens / activates the gamecontroller, only possible with valid GUID mapping.
uint8_t getNumberOfButtons() const
Return the number of buttons.
SDL_GameController * m_controllerHandle
SDLs controller handle.
float getAxisValue(int8_t axis) const
Return the current value for given axis.
const std::string & getName()
Return the name of the joystick.
int32_t getInstanceId() const
Return the instance id of the joystick.
SDL_Joystick * m_joystickHandle
SDLs joystick handle.
void open()
Opens / activates the joystick and sets values.
std::string m_guidStr
The GUID as string.
int8_t getHatValue(int8_t hat) const
Return the hat value (see Hat positions), for given hat index.