summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_poller.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-07-16 11:40:09 -0400
committerGravatar GitHub2020-07-16 11:40:09 -0400
commita89dfc9183347be638f49f8d9ca4d0f38ca9de76 (patch)
tree3c01f62ddd0b416ced79f288736e0d1fa9b6a586 /src/input_common/gcadapter/gc_poller.cpp
parentMerge pull request #4337 from lat9nq/fix-per-game-async (diff)
parentRebase to master (diff)
downloadyuzu-a89dfc9183347be638f49f8d9ca4d0f38ca9de76.tar.gz
yuzu-a89dfc9183347be638f49f8d9ca4d0f38ca9de76.tar.xz
yuzu-a89dfc9183347be638f49f8d9ca4d0f38ca9de76.zip
Merge pull request #4261 from ameerj/gc-calibration
input_common: GC Controller save and compare against analog origin state
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index b20419ec3..96e22d3ad 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -38,18 +38,12 @@ 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 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) { 41 gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {}
42 // L/R triggers range is only in positive direction beginning near 0
43 // 0.0 threshold equates to near half trigger press, but threshold accounts for variability.
44 if (axis > 3) {
45 threshold *= -0.5;
46 }
47 }
48 42
49 bool GetStatus() const override { 43 bool GetStatus() const override {
50 if (gcadapter->DeviceConnected(port)) { 44 if (gcadapter->DeviceConnected(port)) {
51 const float axis_value = 45 const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis);
52 (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; 46 const float axis_value = (current_axis_value - origin_value) / 128.0f;
53 if (trigger_if_greater) { 47 if (trigger_if_greater) {
54 // TODO: Might be worthwile to set a slider for the trigger threshold. It is 48 // 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 49 // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick
@@ -66,6 +60,7 @@ private:
66 float threshold; 60 float threshold;
67 bool trigger_if_greater; 61 bool trigger_if_greater;
68 GCAdapter::Adapter* gcadapter; 62 GCAdapter::Adapter* gcadapter;
63 const float origin_value;
69}; 64};
70 65
71GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) 66GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_)
@@ -155,15 +150,18 @@ void GCButtonFactory::EndConfiguration() {
155class GCAnalog final : public Input::AnalogDevice { 150class GCAnalog final : public Input::AnalogDevice {
156public: 151public:
157 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_, GCAdapter::Adapter* adapter)
158 : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} 153 : 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_y(adapter->GetOriginValue(port_, axis_y_)) {}
159 156
160 float GetAxis(int axis) const { 157 float GetAxis(int axis) const {
161 if (gcadapter->DeviceConnected(port)) { 158 if (gcadapter->DeviceConnected(port)) {
162 std::lock_guard lock{mutex}; 159 std::lock_guard lock{mutex};
160 const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y;
163 // division is not by a perfect 128 to account for some variance in center location 161 // division is not by a perfect 128 to account for some variance in center location
164 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range 162 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
165 // [20-230] 163 // [20-230]
166 return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; 164 return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f;
167 } 165 }
168 return 0.0f; 166 return 0.0f;
169 } 167 }
@@ -215,8 +213,10 @@ private:
215 const int axis_x; 213 const int axis_x;
216 const int axis_y; 214 const int axis_y;
217 const float deadzone; 215 const float deadzone;
218 mutable std::mutex mutex;
219 GCAdapter::Adapter* gcadapter; 216 GCAdapter::Adapter* gcadapter;
217 const float origin_value_x;
218 const float origin_value_y;
219 mutable std::mutex mutex;
220}; 220};
221 221
222/// An analog device factory that creates analog devices from GC Adapter 222/// An analog device factory that creates analog devices from GC Adapter