GCPad: Clean up Motor/Rumble interfaces

Remove the duplication here and just have one Rumble interface that
takes a single strength parameter.
This commit is contained in:
Jasper St. Pierre 2014-11-15 01:57:49 -08:00
parent f2787f620e
commit e43ad58a3a
6 changed files with 26 additions and 59 deletions

View File

@ -78,54 +78,14 @@ void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus)
((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus); ((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus);
} }
// __________________________________________________________________________________________________ void Rumble(u8 _numPAD, const ControlState strength)
// Function: Rumble
// Purpose: Pad rumble!
// input: _numPad - Which pad to rumble.
// _uType - Command type (Stop=0, Rumble=1, Stop Hard=2).
// _uStrength - Strength of the Rumble
// output: none
//
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{ {
std::unique_lock<std::recursive_mutex> lk(s_config.controls_lock, std::try_to_lock); std::unique_lock<std::recursive_mutex> lk(s_config.controls_lock, std::try_to_lock);
if (lk.owns_lock()) if (!lk.owns_lock())
{ return;
// TODO: this has potential to not stop rumble if user is messing with GUI at the perfect time
// set rumble
if (1 == _uType && _uStrength > 2)
{
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(255);
}
else
{
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(0);
}
}
}
// __________________________________________________________________________________________________ ((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(strength);
// Function: Motor
// Purpose: For devices with constant Force feedback
// input: _numPAD - The pad to operate on
// _uType - 06 = Motor On, 04 = Motor Off
// _uStrength - 00 = Left Strong, 127 = Left Weak, 128 = Right Weak, 255 = Right Strong
// output: none
//
void Motor(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{
std::unique_lock<std::recursive_mutex> lk(s_config.controls_lock, std::try_to_lock);
if (lk.owns_lock())
{
// TODO: this has potential to not stop rumble if user is messing with GUI at the perfect time
// set rumble
if (_uType == 6)
{
((GCPad*)s_config.controllers[ _numPAD ])->SetMotor(_uStrength);
}
}
} }
bool GetMicButton(u8 pad) bool GetMicButton(u8 pad)

View File

@ -17,8 +17,7 @@ void Initialize(void* const hwnd);
InputConfig* GetConfig(); InputConfig* GetConfig();
void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus); void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus);
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength); void Rumble(u8 _numPAD, const ControlState strength);
void Motor(u8 _numPAD, unsigned int _uType, unsigned int _uStrength);
bool GetMicButton(u8 pad); bool GetMicButton(u8 pad);
} }

View File

@ -120,16 +120,9 @@ void GCPad::GetInput(GCPadStatus* const pad)
pad->triggerRight = static_cast<u8>(triggers[1] * 0xFF); pad->triggerRight = static_cast<u8>(triggers[1] * 0xFF);
} }
void GCPad::SetMotor(const u8 on) void GCPad::SetOutput(const ControlState strength)
{ {
// map 0..255 to -1.0..1.0 m_rumble->controls[0]->control_ref->State(strength);
ControlState force = on / 127.5 - 1;
m_rumble->controls[0]->control_ref->State(force);
}
void GCPad::SetOutput(const u8 on)
{
m_rumble->controls[0]->control_ref->State(on);
} }
void GCPad::LoadDefaults(const ControllerInterface& ciface) void GCPad::LoadDefaults(const ControllerInterface& ciface)

View File

@ -14,8 +14,7 @@ public:
GCPad(const unsigned int index); GCPad(const unsigned int index);
void GetInput(GCPadStatus* const pad); void GetInput(GCPadStatus* const pad);
void SetOutput(const u8 on); void SetOutput(const ControlState strength);
void SetMotor(const u8 on);
bool GetMicButton() const; bool GetMicButton() const;

View File

@ -249,7 +249,12 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber);
if (numPAD < 4) if (numPAD < 4)
Pad::Rumble(numPAD, uType, uStrength); {
if (uType == 1 && uStrength > 2)
Pad::Rumble(numPAD, 1.0);
else
Pad::Rumble(numPAD, 0.0);
}
if (!_Poll) if (!_Poll)
{ {

View File

@ -22,7 +22,18 @@ void CSIDevice_GCSteeringWheel::SendCommand(u32 _Cmd, u8 _Poll)
const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber); const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber);
if (numPAD < 4) if (numPAD < 4)
Pad::Motor(numPAD, uType, uStrength); {
if (uType == 0x06)
{
// map 0..255 to -1.0..1.0
ControlState strength = uStrength / 127.5 - 1;
Pad::Rumble(numPAD, strength);
}
else
{
Pad::Rumble(numPAD, 0);
}
}
if (!_Poll) if (!_Poll)
{ {