Allow setting auto-center property for racing wheels (closes #4636) (#4641)

This commit is contained in:
Mary 2021-10-06 01:24:27 -04:00 committed by GitHub
parent 013b065f2c
commit fe7dd8af14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 7 deletions

View File

@ -64,6 +64,7 @@ GamepadConfig::GamepadConfig( const std::string &name,
m_deadzone = 4096; m_deadzone = 4096;
m_desensitize = false; m_desensitize = false;
m_use_force_feedback = true; m_use_force_feedback = true;
m_auto_center = 20;
setDefaultBinds(); setDefaultBinds();
} // GamepadConfig } // GamepadConfig
@ -77,6 +78,7 @@ GamepadConfig::GamepadConfig() : DeviceConfig()
m_deadzone = 4096; m_deadzone = 4096;
m_desensitize = false; m_desensitize = false;
m_use_force_feedback = true; m_use_force_feedback = true;
m_auto_center = 20;
setDefaultBinds(); setDefaultBinds();
} // GamepadConfig } // GamepadConfig
@ -90,6 +92,7 @@ bool GamepadConfig::load(const XMLNode *config)
config->get("deadzone", &m_deadzone ); config->get("deadzone", &m_deadzone );
config->get("desensitize", &m_desensitize ); config->get("desensitize", &m_desensitize );
config->get("force-feedback", &m_use_force_feedback); config->get("force-feedback", &m_use_force_feedback);
config->get("auto-center", &m_auto_center);
bool ok = DeviceConfig::load(config); bool ok = DeviceConfig::load(config);
if(getName()=="") if(getName()=="")
@ -111,6 +114,7 @@ void GamepadConfig::save (std::ofstream& stream)
stream << "<gamepad name =\"" << getName() stream << "<gamepad name =\"" << getName()
<< "\" deadzone=\"" << m_deadzone << "\" deadzone=\"" << m_deadzone
<< "\" desensitize=\"" << m_desensitize << "\" desensitize=\"" << m_desensitize
<< "\" auto-center=\"" << m_auto_center
<< "\" force-feedback=\"" << m_use_force_feedback << "\" "; << "\" force-feedback=\"" << m_use_force_feedback << "\" ";
DeviceConfig::save(stream); DeviceConfig::save(stream);
stream << "</gamepad>\n\n"; stream << "</gamepad>\n\n";

View File

@ -60,6 +60,7 @@ private:
bool m_desensitize; bool m_desensitize;
bool m_use_force_feedback; bool m_use_force_feedback;
int m_auto_center;
std::map<std::tuple<int, Input::AxisDirection>, int> m_sdl_mapping; std::map<std::tuple<int, Input::AxisDirection>, int> m_sdl_mapping;
@ -124,6 +125,10 @@ public:
bool useForceFeedback() const { return m_use_force_feedback; } bool useForceFeedback() const { return m_use_force_feedback; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setForceFeedback(bool val) { m_use_force_feedback = val; } 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 }; // class GamepadConfig
#endif #endif

View File

@ -246,3 +246,9 @@ bool GamePadDevice::useForceFeedback() const
{ {
return static_cast<GamepadConfig*>(m_configuration)->useForceFeedback(); return static_cast<GamepadConfig*>(m_configuration)->useForceFeedback();
} // useForceFeedback } // useForceFeedback
// ----------------------------------------------------------------------------
int GamePadDevice::getAutoCenterStrength() const
{
return static_cast<GamepadConfig*>(m_configuration)->getAutoCenterStrength();
} // shouldAutoCenter

View File

@ -62,6 +62,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setIrrIndex(int i ) { m_irr_index = i; } void setIrrIndex(int i ) { m_irr_index = i; }
bool useForceFeedback() const; bool useForceFeedback() const;
int getAutoCenterStrength() const;
}; // class GamepadDevice }; // class GamepadDevice
#endif #endif

View File

@ -179,12 +179,6 @@ SDLController::SDLController(int device_id)
cfg->initSDLMapping(); cfg->initSDLMapping();
cfg->setPlugged(); 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++) for (int i = 0; i < dm->getGamePadAmount(); i++)
{ {
GamePadDevice* d = dm->getGamePad(i); GamePadDevice* d = dm->getGamePad(i);
@ -196,7 +190,7 @@ SDLController::SDLController(int device_id)
d->setConfiguration(cfg); d->setConfiguration(cfg);
if (created) if (created)
dm->save(); dm->save();
return; goto finish;
} }
} }
@ -204,6 +198,16 @@ SDLController::SDLController(int device_id)
dm->addGamepad(m_gamepad); dm->addGamepad(m_gamepad);
if (created) if (created)
dm->save(); 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 } // 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 #ifdef ANDROID
void SDLController::handleDirectScanCode(const SDL_Event& event) void SDLController::handleDirectScanCode(const SDL_Event& event)

View File

@ -45,6 +45,7 @@ private:
#if SDL_VERSION_ATLEAST(1,3,0) #if SDL_VERSION_ATLEAST(1,3,0)
SDL_Haptic* m_haptic; SDL_Haptic* m_haptic;
int m_auto_center;
#endif #endif
int m_buttons; int m_buttons;
@ -63,6 +64,10 @@ private:
#ifdef ANDROID #ifdef ANDROID
void handleDirectScanCode(const SDL_Event& event); void handleDirectScanCode(const SDL_Event& event);
#endif #endif
#if SDL_VERSION_ATLEAST(1,3,0)
void updateAutoCenter(int state);
#endif
public: public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
SDLController(int device_id); SDLController(int device_id);