diff options
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r-- | src/joystick.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp index bc4572370..6925ca27e 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -60,7 +60,8 @@ Joystick::Joystick(int no): mCalibrating(false), mCalibrated(false), mButtonsNumber(MAX_BUTTONS), - mUseInactive(false) + mUseInactive(false), + mHaveHats(false) { if (no >= joystickCount) no = joystickCount; @@ -96,6 +97,8 @@ bool Joystick::open() logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick)); logger->log("Buttons: %i", mButtonsNumber); + mHaveHats = (SDL_JoystickNumHats(mJoystick) > 0); + if (mButtonsNumber > MAX_BUTTONS) mButtonsNumber = MAX_BUTTONS; @@ -164,6 +167,20 @@ void Joystick::update() else if (position >= mDownTolerance) mDirection |= DOWN; + if (!mDirection && mHaveHats) + { + // reading only hat 0 + Uint8 hat = SDL_JoystickGetHat(mJoystick, 0); + if (hat & SDL_HAT_RIGHT) + mDirection |= RIGHT; + else if (hat & SDL_HAT_LEFT) + mDirection |= LEFT; + if (hat & SDL_HAT_UP) + mDirection |= UP; + else if (hat & SDL_HAT_DOWN) + mDirection |= DOWN; + } + // Buttons for (int i = 0; i < mButtonsNumber; i++) mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1); |