Skip to content

Commit

Permalink
GCPad: Clean up Motor/Rumble interfaces
Browse files Browse the repository at this point in the history
Remove the duplication here and just have one Rumble interface that
takes a single strength parameter.
  • Loading branch information
magcius committed Nov 28, 2014
1 parent f2787f6 commit e43ad58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 59 deletions.
48 changes: 4 additions & 44 deletions Source/Core/Core/HW/GCPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,54 +78,14 @@ void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus)
((GCPad*)s_config.controllers[_numPAD])->GetInput(_pPADStatus);
}

// __________________________________________________________________________________________________
// 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)
void Rumble(u8 _numPAD, const ControlState strength)
{
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 (1 == _uType && _uStrength > 2)
{
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(255);
}
else
{
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(0);
}
}
}

// __________________________________________________________________________________________________
// 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())
return;

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);
}
}
((GCPad*)s_config.controllers[ _numPAD ])->SetOutput(strength);
}

bool GetMicButton(u8 pad)
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Core/HW/GCPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ void Initialize(void* const hwnd);
InputConfig* GetConfig();

void GetStatus(u8 _numPAD, GCPadStatus* _pPADStatus);
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength);
void Motor(u8 _numPAD, unsigned int _uType, unsigned int _uStrength);
void Rumble(u8 _numPAD, const ControlState strength);

bool GetMicButton(u8 pad);
}
11 changes: 2 additions & 9 deletions Source/Core/Core/HW/GCPadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,9 @@ void GCPad::GetInput(GCPadStatus* const pad)
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
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);
m_rumble->controls[0]->control_ref->State(strength);
}

void GCPad::LoadDefaults(const ControllerInterface& ciface)
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Core/HW/GCPadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class GCPad : public ControllerEmu

GCPad(const unsigned int index);
void GetInput(GCPadStatus* const pad);
void SetOutput(const u8 on);
void SetMotor(const u8 on);
void SetOutput(const ControlState strength);

bool GetMicButton() const;

Expand Down
7 changes: 6 additions & 1 deletion Source/Core/Core/HW/SI_DeviceGCController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber);

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)
{
Expand Down
13 changes: 12 additions & 1 deletion Source/Core/Core/HW/SI_DeviceGCSteeringWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ void CSIDevice_GCSteeringWheel::SendCommand(u32 _Cmd, u8 _Poll)
const u8 numPAD = NetPlay_InGamePadToLocalPad(ISIDevice::m_iDeviceNumber);

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)
{
Expand Down

0 comments on commit e43ad58

Please sign in to comment.