summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_poller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index 385ce8430..c9bb7e571 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -34,7 +34,7 @@ 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), origin_value(adapter->GetOriginValue(port_, axis_)) {
38 // L/R triggers range is only in positive direction beginning near 0 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. 39 // 0.0 threshold equates to near half trigger press, but threshold accounts for variability.
40 if (axis > 3) { 40 if (axis > 3) {
@@ -43,7 +43,8 @@ public:
43 } 43 }
44 44
45 bool GetStatus() const override { 45 bool GetStatus() const override {
46 const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; 46 const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis);
47 const float axis_value = (current_axis_value - origin_value) / 128.0f;
47 if (trigger_if_greater) { 48 if (trigger_if_greater) {
48 // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently 49 // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently
49 // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick 50 // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick
@@ -58,6 +59,7 @@ private:
58 float threshold; 59 float threshold;
59 bool trigger_if_greater; 60 bool trigger_if_greater;
60 GCAdapter::Adapter* gcadapter; 61 GCAdapter::Adapter* gcadapter;
62 const float origin_value;
61}; 63};
62 64
63GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) 65GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_)
@@ -144,14 +146,19 @@ void GCButtonFactory::EndConfiguration() {
144class GCAnalog final : public Input::AnalogDevice { 146class GCAnalog final : public Input::AnalogDevice {
145public: 147public:
146 GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter) 148 GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter)
147 : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} 149 : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter),
150 origin_value_x(adapter->GetOriginValue(port_, axis_x_)),
151 origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {}
148 152
149 float GetAxis(int axis) const { 153 float GetAxis(int axis) const {
150 std::lock_guard lock{mutex}; 154 std::lock_guard lock{mutex};
151 // division is not by a perfect 128 to account for some variance in center location 155 // division is not by a perfect 128 to account for some variance in center location
152 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range 156 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
153 // [20-230] 157 // [20-230]
154 return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; 158 if (axis % 2 == 0)
159 return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_x) / 95.0f;
160 else
161 return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_y) / 95.0f;
155 } 162 }
156 163
157 std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { 164 std::pair<float, float> GetAnalog(int axis_x, int axis_y) const {
@@ -201,6 +208,8 @@ private:
201 const int axis_x; 208 const int axis_x;
202 const int axis_y; 209 const int axis_y;
203 const float deadzone; 210 const float deadzone;
211 const float origin_value_x;
212 const float origin_value_y;
204 mutable std::mutex mutex; 213 mutable std::mutex mutex;
205 GCAdapter::Adapter* gcadapter; 214 GCAdapter::Adapter* gcadapter;
206}; 215};