diff --git a/src/input/gamepad_config.cpp b/src/input/gamepad_config.cpp index ac2ea3978..19c6189b1 100644 --- a/src/input/gamepad_config.cpp +++ b/src/input/gamepad_config.cpp @@ -64,6 +64,7 @@ GamepadConfig::GamepadConfig( const std::string &name, m_deadzone = 4096; m_desensitize = false; m_use_force_feedback = true; + m_auto_center = 20; setDefaultBinds(); } // GamepadConfig @@ -77,6 +78,7 @@ GamepadConfig::GamepadConfig() : DeviceConfig() m_deadzone = 4096; m_desensitize = false; m_use_force_feedback = true; + m_auto_center = 20; setDefaultBinds(); } // GamepadConfig @@ -90,6 +92,7 @@ bool GamepadConfig::load(const XMLNode *config) config->get("deadzone", &m_deadzone ); config->get("desensitize", &m_desensitize ); config->get("force-feedback", &m_use_force_feedback); + config->get("auto-center", &m_auto_center); bool ok = DeviceConfig::load(config); if(getName()=="") @@ -111,6 +114,7 @@ void GamepadConfig::save (std::ofstream& stream) stream << "\n\n"; diff --git a/src/input/gamepad_config.hpp b/src/input/gamepad_config.hpp index ea38c6fff..d0b992fef 100644 --- a/src/input/gamepad_config.hpp +++ b/src/input/gamepad_config.hpp @@ -60,6 +60,7 @@ private: bool m_desensitize; bool m_use_force_feedback; + int m_auto_center; std::map, int> m_sdl_mapping; @@ -124,6 +125,10 @@ public: bool useForceFeedback() const { return m_use_force_feedback; } // ------------------------------------------------------------------------ void setForceFeedback(bool val) { m_use_force_feedback = val; } + // ------------------------------------------------------------------------ + int getAutoCenterStrength() const { return m_auto_center; } + // ------------------------------------------------------------------------ + void setAutoCenter(bool val) { m_auto_center = val; } }; // class GamepadConfig #endif diff --git a/src/input/gamepad_device.cpp b/src/input/gamepad_device.cpp index 9e5f140b9..453f47a03 100644 --- a/src/input/gamepad_device.cpp +++ b/src/input/gamepad_device.cpp @@ -246,3 +246,9 @@ bool GamePadDevice::useForceFeedback() const { return static_cast(m_configuration)->useForceFeedback(); } // useForceFeedback + +// ---------------------------------------------------------------------------- +int GamePadDevice::getAutoCenterStrength() const +{ + return static_cast(m_configuration)->getAutoCenterStrength(); +} // shouldAutoCenter diff --git a/src/input/gamepad_device.hpp b/src/input/gamepad_device.hpp index e01eb218b..a6dbd6fab 100644 --- a/src/input/gamepad_device.hpp +++ b/src/input/gamepad_device.hpp @@ -62,6 +62,7 @@ public: // ------------------------------------------------------------------------ void setIrrIndex(int i ) { m_irr_index = i; } bool useForceFeedback() const; + int getAutoCenterStrength() const; }; // class GamepadDevice #endif diff --git a/src/input/sdl_controller.cpp b/src/input/sdl_controller.cpp index 6be4a3723..7ac80b518 100644 --- a/src/input/sdl_controller.cpp +++ b/src/input/sdl_controller.cpp @@ -179,12 +179,6 @@ SDLController::SDLController(int device_id) cfg->initSDLMapping(); cfg->setPlugged(); -#if SDL_VERSION_ATLEAST(1,3,0) - m_haptic = SDL_HapticOpenFromJoystick(m_joystick); - if (m_haptic) - SDL_HapticRumbleInit(m_haptic); -#endif - for (int i = 0; i < dm->getGamePadAmount(); i++) { GamePadDevice* d = dm->getGamePad(i); @@ -196,7 +190,7 @@ SDLController::SDLController(int device_id) d->setConfiguration(cfg); if (created) dm->save(); - return; + goto finish; } } @@ -204,6 +198,16 @@ SDLController::SDLController(int device_id) dm->addGamepad(m_gamepad); if (created) dm->save(); + +finish: +#if SDL_VERSION_ATLEAST(1,3,0) + m_haptic = SDL_HapticOpenFromJoystick(m_joystick); + if (m_haptic) + { + SDL_HapticRumbleInit(m_haptic); + updateAutoCenter(getGamePadDevice()->getAutoCenterStrength()); + } +#endif } // SDLController // ---------------------------------------------------------------------------- @@ -277,6 +281,14 @@ void SDLController::doRumble(float strength_low, float strength_high, uint32_t d } } +#if SDL_VERSION_ATLEAST(1,3,0) +void SDLController::updateAutoCenter(int state) +{ + m_auto_center = state; + SDL_HapticSetAutocenter(m_haptic, m_auto_center); +} +#endif + // ---------------------------------------------------------------------------- #ifdef ANDROID void SDLController::handleDirectScanCode(const SDL_Event& event) diff --git a/src/input/sdl_controller.hpp b/src/input/sdl_controller.hpp index 358112309..48d4373de 100644 --- a/src/input/sdl_controller.hpp +++ b/src/input/sdl_controller.hpp @@ -45,6 +45,7 @@ private: #if SDL_VERSION_ATLEAST(1,3,0) SDL_Haptic* m_haptic; + int m_auto_center; #endif int m_buttons; @@ -63,6 +64,10 @@ private: #ifdef ANDROID void handleDirectScanCode(const SDL_Event& event); #endif + +#if SDL_VERSION_ATLEAST(1,3,0) + void updateAutoCenter(int state); +#endif public: // ------------------------------------------------------------------------ SDLController(int device_id);