diff options
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 385ce8430..b20419ec3 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: |
| @@ -43,13 +47,17 @@ public: | |||
| 43 | } | 47 | } |
| 44 | 48 | ||
| 45 | bool GetStatus() const override { | 49 | bool GetStatus() const override { |
| 46 | const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; | 50 | if (gcadapter->DeviceConnected(port)) { |
| 47 | if (trigger_if_greater) { | 51 | const float axis_value = |
| 48 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently | 52 | (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; |
| 49 | // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick | 53 | if (trigger_if_greater) { |
| 50 | return axis_value > threshold; | 54 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is |
| 55 | // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick | ||
| 56 | return axis_value > threshold; | ||
| 57 | } | ||
| 58 | return axis_value < -threshold; | ||
| 51 | } | 59 | } |
| 52 | return axis_value < -threshold; | 60 | return false; |
| 53 | } | 61 | } |
| 54 | 62 | ||
| 55 | private: | 63 | private: |
| @@ -94,9 +102,12 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 94 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, | 102 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 95 | adapter.get()); | 103 | adapter.get()); |
| 96 | } | 104 | } |
| 105 | |||
| 106 | UNREACHABLE(); | ||
| 107 | return nullptr; | ||
| 97 | } | 108 | } |
| 98 | 109 | ||
| 99 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 110 | Common::ParamPackage GCButtonFactory::GetNextInput() const { |
| 100 | Common::ParamPackage params; | 111 | Common::ParamPackage params; |
| 101 | GCAdapter::GCPadStatus pad; | 112 | GCAdapter::GCPadStatus pad; |
| 102 | auto& queue = adapter->GetPadQueue(); | 113 | auto& queue = adapter->GetPadQueue(); |
| @@ -147,11 +158,14 @@ public: | |||
| 147 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} | 158 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} |
| 148 | 159 | ||
| 149 | float GetAxis(int axis) const { | 160 | float GetAxis(int axis) const { |
| 150 | std::lock_guard lock{mutex}; | 161 | if (gcadapter->DeviceConnected(port)) { |
| 151 | // division is not by a perfect 128 to account for some variance in center location | 162 | std::lock_guard lock{mutex}; |
| 152 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range | 163 | // division is not by a perfect 128 to account for some variance in center location |
| 153 | // [20-230] | 164 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range |
| 154 | return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; | 165 | // [20-230] |
| 166 | return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; | ||
| 167 | } | ||
| 168 | return 0.0f; | ||
| 155 | } | 169 | } |
| 156 | 170 | ||
| 157 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { | 171 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { |
| @@ -249,7 +263,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 249 | const u8 axis = static_cast<u8>(pad.axis); | 263 | const u8 axis = static_cast<u8>(pad.axis); |
| 250 | if (analog_x_axis == -1) { | 264 | if (analog_x_axis == -1) { |
| 251 | analog_x_axis = axis; | 265 | analog_x_axis = axis; |
| 252 | controller_number = port; | 266 | controller_number = static_cast<int>(port); |
| 253 | } 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) { |
| 254 | analog_y_axis = axis; | 268 | analog_y_axis = axis; |
| 255 | } | 269 | } |