diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 12 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 32 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 1ddb9cdb4..82f97572f 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -144,6 +144,18 @@ void Adapter::Read() { | |||
| 144 | pads[port].axis_value = pads[port].substick_y; | 144 | pads[port].axis_value = pads[port].substick_y; |
| 145 | pad_queue[port].Push(pads[port]); | 145 | pad_queue[port].Push(pads[port]); |
| 146 | } | 146 | } |
| 147 | if (pads[port].trigger_left > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || | ||
| 148 | pads[port].trigger_left < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { | ||
| 149 | pads[port].axis = GCAdapter::PadAxes::TriggerLeft; | ||
| 150 | pads[port].axis_value = pads[port].trigger_left; | ||
| 151 | pad_queue[port].Push(pads[port]); | ||
| 152 | } | ||
| 153 | if (pads[port].trigger_right > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || | ||
| 154 | pads[port].trigger_right < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { | ||
| 155 | pads[port].axis = GCAdapter::PadAxes::TriggerRight; | ||
| 156 | pads[port].axis_value = pads[port].trigger_right; | ||
| 157 | pad_queue[port].Push(pads[port]); | ||
| 158 | } | ||
| 147 | } | 159 | } |
| 148 | PadToState(pads[port], state[port]); | 160 | PadToState(pads[port], state[port]); |
| 149 | } | 161 | } |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index a9de9fedf..a04c507b8 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -34,7 +34,13 @@ public: | |||
| 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, |
| 35 | GCAdapter::Adapter* adapter) | 35 | GCAdapter::Adapter* adapter) |
| 36 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 36 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 37 | gcadapter(adapter) {} | 37 | gcadapter(adapter) { |
| 38 | // L/R triggers range is only in positive direction beginning near 0 | ||
| 39 | // 0.0 threshold equates to near half trigger press, but threshold accounts for variability. | ||
| 40 | if (axis > 3) { | ||
| 41 | threshold *= -0.5; | ||
| 42 | } | ||
| 43 | } | ||
| 38 | 44 | ||
| 39 | bool GetStatus() const override { | 45 | bool GetStatus() const override { |
| 40 | const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; | 46 | const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; |
| @@ -60,10 +66,20 @@ GCButton::~GCButton() = default; | |||
| 60 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { | 66 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { |
| 61 | const int button_id = params.Get("button", 0); | 67 | const int button_id = params.Get("button", 0); |
| 62 | const int port = params.Get("port", 0); | 68 | const int port = params.Get("port", 0); |
| 69 | |||
| 70 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); | ||
| 71 | |||
| 72 | // button is not an axis/stick button | ||
| 73 | if (button_id != PAD_STICK_ID) { | ||
| 74 | std::unique_ptr<GCButton> button = | ||
| 75 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); | ||
| 76 | return std::move(button); | ||
| 77 | } | ||
| 78 | |||
| 63 | // For Axis buttons, used by the binary sticks. | 79 | // For Axis buttons, used by the binary sticks. |
| 64 | if (params.Has("axis")) { | 80 | if (button_id == PAD_STICK_ID) { |
| 65 | const int axis = params.Get("axis", 0); | 81 | const int axis = params.Get("axis", 0); |
| 66 | const float threshold = params.Get("threshold", 0.5f); | 82 | const float threshold = params.Get("threshold", 0.25f); |
| 67 | const std::string direction_name = params.Get("direction", ""); | 83 | const std::string direction_name = params.Get("direction", ""); |
| 68 | bool trigger_if_greater; | 84 | bool trigger_if_greater; |
| 69 | if (direction_name == "+") { | 85 | if (direction_name == "+") { |
| @@ -77,10 +93,6 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 77 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, | 93 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 78 | adapter.get()); | 94 | adapter.get()); |
| 79 | } | 95 | } |
| 80 | |||
| 81 | std::unique_ptr<GCButton> button = | ||
| 82 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); | ||
| 83 | return std::move(button); | ||
| 84 | } | 96 | } |
| 85 | 97 | ||
| 86 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 98 | Common::ParamPackage GCButtonFactory::GetNextInput() { |
| @@ -106,10 +118,10 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { | |||
| 106 | params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); | 118 | params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); |
| 107 | if (pad.axis_value > 128) { | 119 | if (pad.axis_value > 128) { |
| 108 | params.Set("direction", "+"); | 120 | params.Set("direction", "+"); |
| 109 | params.Set("threshold", "0.5"); | 121 | params.Set("threshold", "0.25"); |
| 110 | } else { | 122 | } else { |
| 111 | params.Set("direction", "-"); | 123 | params.Set("direction", "-"); |
| 112 | params.Set("threshold", "-0.5"); | 124 | params.Set("threshold", "-0.25"); |
| 113 | } | 125 | } |
| 114 | break; | 126 | break; |
| 115 | } | 127 | } |
| @@ -232,7 +244,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 232 | continue; | 244 | continue; |
| 233 | } | 245 | } |
| 234 | // An analog device needs two axes, so we need to store the axis for later and wait for | 246 | // An analog device needs two axes, so we need to store the axis for later and wait for |
| 235 | // a second SDL event. The axes also must be from the same joystick. | 247 | // a second input event. The axes also must be from the same joystick. |
| 236 | const u8 axis = static_cast<u8>(pad.axis); | 248 | const u8 axis = static_cast<u8>(pad.axis); |
| 237 | if (analog_x_axis == -1) { | 249 | if (analog_x_axis == -1) { |
| 238 | analog_x_axis = axis; | 250 | analog_x_axis = axis; |