summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/gcadapter/gc_adapter.h6
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp34
2 files changed, 25 insertions, 15 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h
index 120ce4c02..e2cdd6255 100644
--- a/src/input_common/gcadapter/gc_adapter.h
+++ b/src/input_common/gcadapter/gc_adapter.h
@@ -100,6 +100,9 @@ public:
100 void BeginConfiguration(); 100 void BeginConfiguration();
101 void EndConfiguration(); 101 void EndConfiguration();
102 102
103 /// Returns true if there is a device connected to port
104 bool DeviceConnected(std::size_t port);
105
103 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue(); 106 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
104 const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const; 107 const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
105 108
@@ -119,9 +122,6 @@ private:
119 /// Stop scanning for the adapter 122 /// Stop scanning for the adapter
120 void StopScanThread(); 123 void StopScanThread();
121 124
122 /// Returns true if there is a device connected to port
123 bool DeviceConnected(std::size_t port);
124
125 /// Resets status of device connected to port 125 /// Resets status of device connected to port
126 void ResetDeviceType(std::size_t port); 126 void ResetDeviceType(std::size_t port);
127 127
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index bddfa102f..b20419ec3 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -21,7 +21,10 @@ public:
21 ~GCButton() override; 21 ~GCButton() override;
22 22
23 bool GetStatus() const override { 23 bool GetStatus() const override {
24 return gcadapter->GetPadState()[port].buttons.at(button); 24 if (gcadapter->DeviceConnected(port)) {
25 return gcadapter->GetPadState()[port].buttons.at(button);
26 }
27 return false;
25 } 28 }
26 29
27private: 30private:
@@ -44,13 +47,17 @@ public:
44 } 47 }
45 48
46 bool GetStatus() const override { 49 bool GetStatus() const override {
47 const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; 50 if (gcadapter->DeviceConnected(port)) {
48 if (trigger_if_greater) { 51 const float axis_value =
49 // 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;
50 // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick 53 if (trigger_if_greater) {
51 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;
52 } 59 }
53 return axis_value < -threshold; 60 return false;
54 } 61 }
55 62
56private: 63private:
@@ -151,11 +158,14 @@ public:
151 : 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) {}
152 159
153 float GetAxis(int axis) const { 160 float GetAxis(int axis) const {
154 std::lock_guard lock{mutex}; 161 if (gcadapter->DeviceConnected(port)) {
155 // division is not by a perfect 128 to account for some variance in center location 162 std::lock_guard lock{mutex};
156 // 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
157 // [20-230] 164 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
158 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;
159 } 169 }
160 170
161 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 {