mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-15 22:54:00 +00:00
Address PR feedback, fix axis button thresholding
This commit is contained in:
parent
e3253b5f18
commit
b57475887b
3 changed files with 21 additions and 57 deletions
|
@ -385,51 +385,25 @@ const std::array<GCState, 4>& Adapter::GetPadState() const {
|
|||
return state;
|
||||
}
|
||||
|
||||
int Adapter::GetOriginValue(int port, int axis) {
|
||||
// TODO: perhaps place stick statuses into an array in PadStatus
|
||||
const PadAxes padaxis = static_cast<PadAxes>(axis);
|
||||
if (padaxis == PadAxes::StickX) {
|
||||
return origin_status[port].stick_x;
|
||||
}
|
||||
if (padaxis == PadAxes::StickY) {
|
||||
return origin_status[port].stick_y;
|
||||
}
|
||||
if (padaxis == PadAxes::SubstickX) {
|
||||
return origin_status[port].substick_x;
|
||||
}
|
||||
if (padaxis == PadAxes::SubstickY) {
|
||||
return origin_status[port].substick_x;
|
||||
}
|
||||
if (padaxis == PadAxes::TriggerLeft) {
|
||||
return origin_status[port].trigger_left;
|
||||
}
|
||||
if (padaxis == PadAxes::TriggerRight) {
|
||||
return origin_status[port].trigger_right;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int Adapter::GetOriginValue(int port, int axis) const {
|
||||
const auto& status = origin_status[port];
|
||||
|
||||
const int Adapter::GetOriginValue(int port, int axis) const {
|
||||
const PadAxes padaxis = static_cast<PadAxes>(axis);
|
||||
if (padaxis == PadAxes::StickX) {
|
||||
return origin_status[port].stick_x;
|
||||
switch (static_cast<PadAxes>(axis)) {
|
||||
case PadAxes::StickX:
|
||||
return status.stick_x;
|
||||
case PadAxes::StickY:
|
||||
return status.stick_y;
|
||||
case PadAxes::SubstickX:
|
||||
return status.substick_x;
|
||||
case PadAxes::SubstickY:
|
||||
return status.substick_y;
|
||||
case PadAxes::TriggerLeft:
|
||||
return status.trigger_left;
|
||||
case PadAxes::TriggerRight:
|
||||
return status.trigger_right;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
if (padaxis == PadAxes::StickY) {
|
||||
return origin_status[port].stick_y;
|
||||
}
|
||||
if (padaxis == PadAxes::SubstickX) {
|
||||
return origin_status[port].substick_x;
|
||||
}
|
||||
if (padaxis == PadAxes::SubstickY) {
|
||||
return origin_status[port].substick_x;
|
||||
}
|
||||
if (padaxis == PadAxes::TriggerLeft) {
|
||||
return origin_status[port].trigger_left;
|
||||
}
|
||||
if (padaxis == PadAxes::TriggerRight) {
|
||||
return origin_status[port].trigger_right;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace GCAdapter
|
||||
|
|
|
@ -96,8 +96,7 @@ public:
|
|||
std::array<GCState, 4>& GetPadState();
|
||||
const std::array<GCState, 4>& GetPadState() const;
|
||||
|
||||
int GetOriginValue(int port, int axis);
|
||||
const int GetOriginValue(int port, int axis) const;
|
||||
int GetOriginValue(int port, int axis) const;
|
||||
|
||||
private:
|
||||
GCPadStatus GetPadStatus(int port, const std::array<u8, 37>& adapter_payload);
|
||||
|
|
|
@ -34,13 +34,7 @@ public:
|
|||
explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_,
|
||||
GCAdapter::Adapter* adapter)
|
||||
: port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_),
|
||||
gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {
|
||||
// L/R triggers range is only in positive direction beginning near 0
|
||||
// 0.0 threshold equates to near half trigger press, but threshold accounts for variability.
|
||||
if (axis > 3) {
|
||||
threshold *= -0.5;
|
||||
}
|
||||
}
|
||||
gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {}
|
||||
|
||||
bool GetStatus() const override {
|
||||
const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis);
|
||||
|
@ -152,14 +146,11 @@ public:
|
|||
|
||||
float GetAxis(int axis) const {
|
||||
std::lock_guard lock{mutex};
|
||||
const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y;
|
||||
// division is not by a perfect 128 to account for some variance in center location
|
||||
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
|
||||
// [20-230]
|
||||
if (axis % 2 == 0) {
|
||||
return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_x) / 95.0f;
|
||||
} else {
|
||||
return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_y) / 95.0f;
|
||||
}
|
||||
return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f;
|
||||
}
|
||||
|
||||
std::pair<float, float> GetAnalog(int axis_x, int axis_y) const {
|
||||
|
|
Loading…
Reference in a new issue