diff options
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 96e22d3ad..92e9e8e89 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -15,7 +15,7 @@ namespace InputCommon { | |||
| 15 | 15 | ||
| 16 | class GCButton final : public Input::ButtonDevice { | 16 | class GCButton final : public Input::ButtonDevice { |
| 17 | public: | 17 | public: |
| 18 | explicit GCButton(int port_, int button_, GCAdapter::Adapter* adapter) | 18 | explicit GCButton(int port_, int button_, const GCAdapter::Adapter* adapter) |
| 19 | : port(port_), button(button_), gcadapter(adapter) {} | 19 | : port(port_), button(button_), gcadapter(adapter) {} |
| 20 | 20 | ||
| 21 | ~GCButton() override; | 21 | ~GCButton() override; |
| @@ -30,15 +30,16 @@ public: | |||
| 30 | private: | 30 | private: |
| 31 | const int port; | 31 | const int port; |
| 32 | const int button; | 32 | const int button; |
| 33 | GCAdapter::Adapter* gcadapter; | 33 | const GCAdapter::Adapter* gcadapter; |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | class GCAxisButton final : public Input::ButtonDevice { | 36 | class GCAxisButton final : public Input::ButtonDevice { |
| 37 | public: | 37 | public: |
| 38 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 38 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, |
| 39 | GCAdapter::Adapter* adapter) | 39 | const GCAdapter::Adapter* adapter) |
| 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 40 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 41 | gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {} | 41 | gcadapter(adapter), |
| 42 | origin_value(static_cast<float>(adapter->GetOriginValue(port_, axis_))) {} | ||
| 42 | 43 | ||
| 43 | bool GetStatus() const override { | 44 | bool GetStatus() const override { |
| 44 | if (gcadapter->DeviceConnected(port)) { | 45 | if (gcadapter->DeviceConnected(port)) { |
| @@ -59,7 +60,7 @@ private: | |||
| 59 | const int axis; | 60 | const int axis; |
| 60 | float threshold; | 61 | float threshold; |
| 61 | bool trigger_if_greater; | 62 | bool trigger_if_greater; |
| 62 | GCAdapter::Adapter* gcadapter; | 63 | const GCAdapter::Adapter* gcadapter; |
| 63 | const float origin_value; | 64 | const float origin_value; |
| 64 | }; | 65 | }; |
| 65 | 66 | ||
| @@ -76,8 +77,7 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 76 | 77 | ||
| 77 | // button is not an axis/stick button | 78 | // button is not an axis/stick button |
| 78 | if (button_id != PAD_STICK_ID) { | 79 | if (button_id != PAD_STICK_ID) { |
| 79 | auto button = std::make_unique<GCButton>(port, button_id, adapter.get()); | 80 | return std::make_unique<GCButton>(port, button_id, adapter.get()); |
| 80 | return std::move(button); | ||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | // For Axis buttons, used by the binary sticks. | 83 | // For Axis buttons, used by the binary sticks. |
| @@ -149,19 +149,18 @@ void GCButtonFactory::EndConfiguration() { | |||
| 149 | 149 | ||
| 150 | class GCAnalog final : public Input::AnalogDevice { | 150 | class GCAnalog final : public Input::AnalogDevice { |
| 151 | public: | 151 | public: |
| 152 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) | 152 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, |
| 153 | const GCAdapter::Adapter* adapter, float range_) | ||
| 153 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), | 154 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter), |
| 154 | origin_value_x(adapter->GetOriginValue(port_, axis_x_)), | 155 | origin_value_x(static_cast<float>(adapter->GetOriginValue(port_, axis_x_))), |
| 155 | origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {} | 156 | origin_value_y(static_cast<float>(adapter->GetOriginValue(port_, axis_y_))), |
| 157 | range(range_) {} | ||
| 156 | 158 | ||
| 157 | float GetAxis(int axis) const { | 159 | float GetAxis(int axis) const { |
| 158 | if (gcadapter->DeviceConnected(port)) { | 160 | if (gcadapter->DeviceConnected(port)) { |
| 159 | std::lock_guard lock{mutex}; | 161 | std::lock_guard lock{mutex}; |
| 160 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; | 162 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; |
| 161 | // division is not by a perfect 128 to account for some variance in center location | 163 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / (100.0f * range); |
| 162 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range | ||
| 163 | // [20-230] | ||
| 164 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f; | ||
| 165 | } | 164 | } |
| 166 | return 0.0f; | 165 | return 0.0f; |
| 167 | } | 166 | } |
| @@ -194,7 +193,7 @@ public: | |||
| 194 | 193 | ||
| 195 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 194 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
| 196 | const auto [x, y] = GetStatus(); | 195 | const auto [x, y] = GetStatus(); |
| 197 | const float directional_deadzone = 0.4f; | 196 | const float directional_deadzone = 0.5f; |
| 198 | switch (direction) { | 197 | switch (direction) { |
| 199 | case Input::AnalogDirection::RIGHT: | 198 | case Input::AnalogDirection::RIGHT: |
| 200 | return x > directional_deadzone; | 199 | return x > directional_deadzone; |
| @@ -213,9 +212,10 @@ private: | |||
| 213 | const int axis_x; | 212 | const int axis_x; |
| 214 | const int axis_y; | 213 | const int axis_y; |
| 215 | const float deadzone; | 214 | const float deadzone; |
| 216 | GCAdapter::Adapter* gcadapter; | 215 | const GCAdapter::Adapter* gcadapter; |
| 217 | const float origin_value_x; | 216 | const float origin_value_x; |
| 218 | const float origin_value_y; | 217 | const float origin_value_y; |
| 218 | const float range; | ||
| 219 | mutable std::mutex mutex; | 219 | mutable std::mutex mutex; |
| 220 | }; | 220 | }; |
| 221 | 221 | ||
| @@ -234,9 +234,10 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param | |||
| 234 | const int port = params.Get("port", 0); | 234 | const int port = params.Get("port", 0); |
| 235 | const int axis_x = params.Get("axis_x", 0); | 235 | const int axis_x = params.Get("axis_x", 0); |
| 236 | const int axis_y = params.Get("axis_y", 1); | 236 | const int axis_y = params.Get("axis_y", 1); |
| 237 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); | 237 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); |
| 238 | const float range = std::clamp(params.Get("range", 1.0f), 0.50f, 1.50f); | ||
| 238 | 239 | ||
| 239 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get()); | 240 | return std::make_unique<GCAnalog>(port, axis_x, axis_y, deadzone, adapter.get(), range); |
| 240 | } | 241 | } |
| 241 | 242 | ||
| 242 | void GCAnalogFactory::BeginConfiguration() { | 243 | void GCAnalogFactory::BeginConfiguration() { |
| @@ -264,7 +265,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 264 | if (analog_x_axis == -1) { | 265 | if (analog_x_axis == -1) { |
| 265 | analog_x_axis = axis; | 266 | analog_x_axis = axis; |
| 266 | controller_number = static_cast<int>(port); | 267 | controller_number = static_cast<int>(port); |
| 267 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { | 268 | } else if (analog_y_axis == -1 && analog_x_axis != axis && |
| 269 | controller_number == static_cast<int>(port)) { | ||
| 268 | analog_y_axis = axis; | 270 | analog_y_axis = axis; |
| 269 | } | 271 | } |
| 270 | } | 272 | } |