mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
@ -107,7 +107,8 @@ void Guitar::Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// slider bar
|
// slider bar
|
||||||
if (m_slider_bar->controls[0]->control_ref->BoundCount())
|
if (m_slider_bar->controls[0]->control_ref->BoundCount() &&
|
||||||
|
m_slider_bar->controls[1]->control_ref->BoundCount())
|
||||||
{
|
{
|
||||||
const ControllerEmu::Slider::StateData slider_data = m_slider_bar->GetState();
|
const ControllerEmu::Slider::StateData slider_data = m_slider_bar->GetState();
|
||||||
|
|
||||||
|
@ -17,10 +17,11 @@ void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att)
|
|||||||
|
|
||||||
u32 Attachments::GetSelectedAttachment() const
|
u32 Attachments::GetSelectedAttachment() const
|
||||||
{
|
{
|
||||||
const u32 value = m_selection_value.GetValue();
|
// This is originally an int, treat it as such
|
||||||
|
const int value = m_selection_value.GetValue();
|
||||||
|
|
||||||
if (value < m_attachments.size())
|
if (value > 0 && static_cast<size_t>(value) < m_attachments.size())
|
||||||
return value;
|
return u32(value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,12 @@
|
|||||||
|
|
||||||
#include "InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.h"
|
#include "InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||||
#include "InputCommon/ControlReference/ControlReference.h"
|
|
||||||
#include "InputCommon/ControllerEmu/Control/Control.h"
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
||||||
#include "InputCommon/ControllerEmu/Control/Input.h"
|
|
||||||
|
|
||||||
namespace ControllerEmu
|
namespace ControllerEmu
|
||||||
{
|
{
|
||||||
@ -25,9 +24,15 @@ IMUAccelerometer::IMUAccelerometer(std::string name_, std::string ui_name_)
|
|||||||
AddInput(Translate, _trans("Backward"));
|
AddInput(Translate, _trans("Backward"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IMUAccelerometer::AreInputsBound() const
|
||||||
|
{
|
||||||
|
return std::all_of(controls.begin(), controls.end(),
|
||||||
|
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const
|
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const
|
||||||
{
|
{
|
||||||
if (controls[0]->control_ref->BoundCount() == 0)
|
if (!AreInputsBound())
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|
||||||
StateData state;
|
StateData state;
|
||||||
|
@ -20,5 +20,7 @@ public:
|
|||||||
IMUAccelerometer(std::string name, std::string ui_name);
|
IMUAccelerometer(std::string name, std::string ui_name);
|
||||||
|
|
||||||
std::optional<StateData> GetState() const;
|
std::optional<StateData> GetState() const;
|
||||||
|
|
||||||
|
bool AreInputsBound() const;
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "InputCommon/ControlReference/ControlReference.h"
|
#include "InputCommon/ControlReference/ControlReference.h"
|
||||||
#include "InputCommon/ControllerEmu/Control/Control.h"
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
||||||
#include "InputCommon/ControllerEmu/Control/Input.h"
|
|
||||||
|
|
||||||
namespace ControllerEmu
|
namespace ControllerEmu
|
||||||
{
|
{
|
||||||
@ -52,13 +51,13 @@ IMUGyroscope::IMUGyroscope(std::string name_, std::string ui_name_)
|
|||||||
3, 0, 30);
|
3, 0, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMUGyroscope::RestartCalibration() const
|
void IMUGyroscope::RestartCalibration()
|
||||||
{
|
{
|
||||||
m_calibration_period_start = Clock::now();
|
m_calibration_period_start = Clock::now();
|
||||||
m_running_calibration.Clear();
|
m_running_calibration.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMUGyroscope::UpdateCalibration(const StateData& state) const
|
void IMUGyroscope::UpdateCalibration(const StateData& state)
|
||||||
{
|
{
|
||||||
const auto now = Clock::now();
|
const auto now = Clock::now();
|
||||||
const auto calibration_period = m_calibration_period_setting.GetValue();
|
const auto calibration_period = m_calibration_period_setting.GetValue();
|
||||||
@ -123,21 +122,36 @@ auto IMUGyroscope::GetRawState() const -> StateData
|
|||||||
controls[4]->GetState() - controls[5]->GetState());
|
controls[4]->GetState() - controls[5]->GetState());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState() const
|
bool IMUGyroscope::AreInputsBound() const
|
||||||
{
|
{
|
||||||
if (std::all_of(controls.begin(), controls.end(),
|
return std::all_of(controls.begin(), controls.end(),
|
||||||
[](const auto& control) { return control->control_ref->BoundCount() == 0; }))
|
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IMUGyroscope::CanCalibrate() const
|
||||||
|
{
|
||||||
|
// If the input gate is disabled, miscalibration to zero values would occur.
|
||||||
|
return ControlReference::GetInputGate();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState(bool update)
|
||||||
|
{
|
||||||
|
if (!AreInputsBound())
|
||||||
|
{
|
||||||
|
if (update)
|
||||||
{
|
{
|
||||||
// Set calibration to zero.
|
// Set calibration to zero.
|
||||||
m_calibration = {};
|
m_calibration = {};
|
||||||
RestartCalibration();
|
RestartCalibration();
|
||||||
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto state = GetRawState();
|
auto state = GetRawState();
|
||||||
|
|
||||||
// If the input gate is disabled, miscalibration to zero values would occur.
|
// Alternatively we could open the control gate around GetRawState() while calibrating,
|
||||||
if (ControlReference::GetInputGate())
|
// but that would imply background input would temporarily be treated differently for our controls
|
||||||
|
if (update && CanCalibrate())
|
||||||
UpdateCalibration(state);
|
UpdateCalibration(state);
|
||||||
|
|
||||||
state -= m_calibration;
|
state -= m_calibration;
|
||||||
|
@ -23,7 +23,8 @@ public:
|
|||||||
IMUGyroscope(std::string name, std::string ui_name);
|
IMUGyroscope(std::string name, std::string ui_name);
|
||||||
|
|
||||||
StateData GetRawState() const;
|
StateData GetRawState() const;
|
||||||
std::optional<StateData> GetState() const;
|
// Also updates the state by default
|
||||||
|
std::optional<StateData> GetState(bool update = true);
|
||||||
|
|
||||||
// Value is in rad/s.
|
// Value is in rad/s.
|
||||||
ControlState GetDeadzone() const;
|
ControlState GetDeadzone() const;
|
||||||
@ -33,14 +34,16 @@ public:
|
|||||||
private:
|
private:
|
||||||
using Clock = std::chrono::steady_clock;
|
using Clock = std::chrono::steady_clock;
|
||||||
|
|
||||||
void RestartCalibration() const;
|
bool AreInputsBound() const;
|
||||||
void UpdateCalibration(const StateData&) const;
|
bool CanCalibrate() const;
|
||||||
|
void RestartCalibration();
|
||||||
|
void UpdateCalibration(const StateData&);
|
||||||
|
|
||||||
SettingValue<double> m_deadzone_setting;
|
SettingValue<double> m_deadzone_setting;
|
||||||
SettingValue<double> m_calibration_period_setting;
|
SettingValue<double> m_calibration_period_setting;
|
||||||
|
|
||||||
mutable StateData m_calibration = {};
|
StateData m_calibration = {};
|
||||||
mutable MathUtil::RunningMean<StateData> m_running_calibration;
|
MathUtil::RunningMean<StateData> m_running_calibration;
|
||||||
mutable Clock::time_point m_calibration_period_start = Clock::now();
|
Clock::time_point m_calibration_period_start = Clock::now();
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
Reference in New Issue
Block a user