diff options
| author | 2020-07-14 13:04:02 -0400 | |
|---|---|---|
| committer | 2020-07-14 13:04:02 -0400 | |
| commit | 93fe982a0c3a5bfb7fa5df97ebced0a7692ccaf3 (patch) | |
| tree | c4ab9e3acff296733b00effd85371bf04db6491f /src/input_common/gcadapter/gc_poller.cpp | |
| parent | Break out of scan loop if can't find adapter on first run (diff) | |
| parent | Merge pull request #4294 from MerryMage/cpu-opt-settings (diff) | |
| download | yuzu-93fe982a0c3a5bfb7fa5df97ebced0a7692ccaf3.tar.gz yuzu-93fe982a0c3a5bfb7fa5df97ebced0a7692ccaf3.tar.xz yuzu-93fe982a0c3a5bfb7fa5df97ebced0a7692ccaf3.zip | |
Rebase to master
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ad321e933..96e22d3ad 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <list> | 6 | #include <list> |
| 7 | #include <mutex> | 7 | #include <mutex> |
| 8 | #include <utility> | 8 | #include <utility> |
| 9 | #include "common/assert.h" | ||
| 9 | #include "common/threadsafe_queue.h" | 10 | #include "common/threadsafe_queue.h" |
| 10 | #include "input_common/gcadapter/gc_adapter.h" | 11 | #include "input_common/gcadapter/gc_adapter.h" |
| 11 | #include "input_common/gcadapter/gc_poller.h" | 12 | #include "input_common/gcadapter/gc_poller.h" |
| @@ -20,7 +21,10 @@ public: | |||
| 20 | ~GCButton() override; | 21 | ~GCButton() override; |
| 21 | 22 | ||
| 22 | bool GetStatus() const override { | 23 | bool GetStatus() const override { |
| 23 | return gcadapter->GetPadState()[port].buttons.at(button); | 24 | if (gcadapter->DeviceConnected(port)) { |
| 25 | return gcadapter->GetPadState()[port].buttons.at(button); | ||
| 26 | } | ||
| 27 | return false; | ||
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | private: | 30 | private: |
| @@ -37,14 +41,17 @@ public: | |||
| 37 | gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {} | 41 | gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {} |
| 38 | 42 | ||
| 39 | bool GetStatus() const override { | 43 | bool GetStatus() const override { |
| 40 | const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis); | 44 | if (gcadapter->DeviceConnected(port)) { |
| 41 | const float axis_value = (current_axis_value - origin_value) / 128.0f; | 45 | const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis); |
| 42 | if (trigger_if_greater) { | 46 | const float axis_value = (current_axis_value - origin_value) / 128.0f; |
| 43 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently | 47 | if (trigger_if_greater) { |
| 44 | // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick | 48 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is |
| 45 | return axis_value > threshold; | 49 | // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick |
| 50 | return axis_value > threshold; | ||
| 51 | } | ||
| 52 | return axis_value < -threshold; | ||
| 46 | } | 53 | } |
| 47 | return axis_value < -threshold; | 54 | return false; |
| 48 | } | 55 | } |
| 49 | 56 | ||
| 50 | private: | 57 | private: |
| @@ -90,9 +97,12 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 90 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, | 97 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 91 | adapter.get()); | 98 | adapter.get()); |
| 92 | } | 99 | } |
| 100 | |||
| 101 | UNREACHABLE(); | ||
| 102 | return nullptr; | ||
| 93 | } | 103 | } |
| 94 | 104 | ||
| 95 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 105 | Common::ParamPackage GCButtonFactory::GetNextInput() const { |
| 96 | Common::ParamPackage params; | 106 | Common::ParamPackage params; |
| 97 | GCAdapter::GCPadStatus pad; | 107 | GCAdapter::GCPadStatus pad; |
| 98 | auto& queue = adapter->GetPadQueue(); | 108 | auto& queue = adapter->GetPadQueue(); |
| @@ -145,12 +155,15 @@ public: | |||
| 145 | origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {} | 155 | origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {} |
| 146 | 156 | ||
| 147 | float GetAxis(int axis) const { | 157 | float GetAxis(int axis) const { |
| 148 | std::lock_guard lock{mutex}; | 158 | if (gcadapter->DeviceConnected(port)) { |
| 149 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; | 159 | std::lock_guard lock{mutex}; |
| 150 | // division is not by a perfect 128 to account for some variance in center location | 160 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; |
| 151 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range | 161 | // division is not by a perfect 128 to account for some variance in center location |
| 152 | // [20-230] | 162 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range |
| 153 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f; | 163 | // [20-230] |
| 164 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f; | ||
| 165 | } | ||
| 166 | return 0.0f; | ||
| 154 | } | 167 | } |
| 155 | 168 | ||
| 156 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { | 169 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { |
| @@ -250,7 +263,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 250 | const u8 axis = static_cast<u8>(pad.axis); | 263 | const u8 axis = static_cast<u8>(pad.axis); |
| 251 | if (analog_x_axis == -1) { | 264 | if (analog_x_axis == -1) { |
| 252 | analog_x_axis = axis; | 265 | analog_x_axis = axis; |
| 253 | controller_number = port; | 266 | controller_number = static_cast<int>(port); |
| 254 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { | 267 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { |
| 255 | analog_y_axis = axis; | 268 | analog_y_axis = axis; |
| 256 | } | 269 | } |