summaryrefslogtreecommitdiffstats
path: root/src/input_common/gcadapter/gc_poller.cpp
diff options
context:
space:
mode:
authorAmeer <aj662@drexel.edu>2020-07-07 03:58:31 +0200
committerAmeer <aj662@drexel.edu>2020-07-07 03:58:31 +0200
commit7ad423923dddb5e037d54e70cb066b03f8346dec (patch)
tree5907a594637850d69e46fd26ae44da39264231d5 /src/input_common/gcadapter/gc_poller.cpp
parentMerge pull request #4194 from ReinUsesLisp/fix-shader-cache (diff)
downloadyuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.gz
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.bz2
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.lz
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.xz
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.zst
yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.zip
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:
explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_,
GCAdapter::Adapter* adapter)
: port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_),
- gcadapter(adapter) {
+ gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {
// L/R triggers range is only in positive direction beginning near 0
// 0.0 threshold equates to near half trigger press, but threshold accounts for variability.
if (axis > 3) {
@@ -43,7 +43,8 @@ public:
}
bool GetStatus() const override {
- const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
+ const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis);
+ const float axis_value = (current_axis_value - origin_value) / 128.0f;
if (trigger_if_greater) {
// TODO: Might be worthwile to set a slider for the trigger threshold. It is currently
// always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick
@@ -58,6 +59,7 @@ private:
float threshold;
bool trigger_if_greater;
GCAdapter::Adapter* gcadapter;
+ const float origin_value;
};
GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_)
@@ -144,14 +146,19 @@ void GCButtonFactory::EndConfiguration() {
class GCAnalog final : public Input::AnalogDevice {
public:
GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_, GCAdapter::Adapter* adapter)
- : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {}
+ : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter),
+ origin_value_x(adapter->GetOriginValue(port_, axis_x_)),
+ origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {}
float GetAxis(int axis) const {
std::lock_guard lock{mutex};
// division is not by a perfect 128 to account for some variance in center location
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
// [20-230]
- return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f;
+ if (axis % 2 == 0)
+ return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_x) / 95.0f;
+ else
+ return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value_y) / 95.0f;
}
std::pair<float, float> GetAnalog(int axis_x, int axis_y) const {
@@ -201,6 +208,8 @@ private:
const int axis_x;
const int axis_y;
const float deadzone;
+ const float origin_value_x;
+ const float origin_value_y;
mutable std::mutex mutex;
GCAdapter::Adapter* gcadapter;
};