Skip to content

Commit

Permalink
Controller: Add GetVibrationMotorState()
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 13, 2025
1 parent aaf2a4b commit dd7fd32
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core/analog_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ float AnalogController::GetBindState(u32 index) const
}
}

float AnalogController::GetVibrationMotorState(u32 index) const
{
return ((index < m_motor_state.size()) ? m_motor_state[index] : 0) * (1.0f / 255.0f);
}

void AnalogController::SetBindState(u32 index, float value)
{
if (index == static_cast<s32>(Button::Analog))
Expand Down
1 change: 1 addition & 0 deletions src/core/analog_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AnalogController final : public Controller
bool DoState(StateWrapper& sw, bool ignore_input_state) override;

float GetBindState(u32 index) const override;
float GetVibrationMotorState(u32 index) const override;
void SetBindState(u32 index, float value) override;
u32 GetButtonStateBits() const override;
std::optional<u32> GetAnalogInputBytes() const override;
Expand Down
5 changes: 5 additions & 0 deletions src/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ u32 Controller::GetButtonStateBits() const
return 0;
}

float Controller::GetVibrationMotorState(u32 index) const
{
return 0.0f;
}

bool Controller::InAnalogMode() const
{
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/core/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Controller
/// Returns a bitmask of the current button states, 1 = on.
virtual u32 GetButtonStateBits() const;

/// Returns the current state of the specified vibration motor.
virtual float GetVibrationMotorState(u32 index) const;

/// Returns true if the controller supports analog mode, and it is active.
virtual bool InAnalogMode() const;

Expand Down
19 changes: 17 additions & 2 deletions src/core/jogcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ float JogCon::GetBindState(u32 index) const
}
}

float JogCon::GetVibrationMotorState(u32 index) const
{
return (index == 0) ? m_last_strength : 0.0f;
}

void JogCon::SetBindState(u32 index, float value)
{
if (index == static_cast<u32>(Button::Mode))
Expand Down Expand Up @@ -275,7 +280,13 @@ void JogCon::SetMotorDirection(u8 direction_command, u8 strength)
DEV_LOG("Stop motor");
if (m_force_feedback_device)
m_force_feedback_device->DisableForce(ForceFeedbackDevice::Effect::Constant);
InputManager::SetPadVibrationIntensity(m_index, 0.0f, 0.0f);

if (m_last_strength != 0.0f)
{
m_last_strength = 0.0f;
InputManager::SetPadVibrationIntensity(m_index, 0.0f, 0.0f);
}

return;
}

Expand All @@ -290,7 +301,11 @@ void JogCon::SetMotorDirection(u8 direction_command, u8 strength)
m_force_feedback_device->SetConstantForce(ffb_value);
}

InputManager::SetPadVibrationIntensity(m_index, f_strength, 0.0f);
if (f_strength != m_last_strength)
{
m_last_strength = f_strength;
InputManager::SetPadVibrationIntensity(m_index, f_strength, 0.0f);
}
}

void JogCon::UpdateSteeringHold()
Expand Down
6 changes: 5 additions & 1 deletion src/core/jogcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class JogCon final : public Controller
bool DoState(StateWrapper& sw, bool apply_input_state) override;

float GetBindState(u32 index) const override;
float GetVibrationMotorState(u32 index) const override;
void SetBindState(u32 index, float value) override;
u32 GetButtonStateBits() const override;
u32 GetInputOverlayIconColor() const override;
Expand Down Expand Up @@ -146,6 +147,9 @@ class JogCon final : public Controller
float m_analog_sensitivity = 1.33f;
float m_button_deadzone = 0.0f;

std::string m_force_feedback_device_name;
float m_last_strength = 0.0f;

std::unique_ptr<ForceFeedbackDevice> m_force_feedback_device;

std::string m_force_feedback_device_name;
};
5 changes: 5 additions & 0 deletions src/core/negcon_rumble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ float NeGconRumble::GetBindState(u32 index) const
}
}

float NeGconRumble::GetVibrationMotorState(u32 index) const
{
return ((index < m_motor_state.size()) ? m_motor_state[index] : 0) * (1.0f / 255.0f);
}

void NeGconRumble::SetBindState(u32 index, float value)
{
if (index == static_cast<s32>(Button::Analog))
Expand Down
1 change: 1 addition & 0 deletions src/core/negcon_rumble.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class NeGconRumble final : public Controller
bool DoState(StateWrapper& sw, bool apply_input_state) override;

float GetBindState(u32 index) const override;
float GetVibrationMotorState(u32 index) const override;
void SetBindState(u32 index, float value) override;

void ResetTransferState() override;
Expand Down

0 comments on commit dd7fd32

Please sign in to comment.