summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_poller.cpp
diff options
context:
space:
mode:
authorGravatar Ameer2020-06-21 15:31:57 -0400
committerGravatar Ameer2020-06-21 15:31:57 -0400
commitc94583d867fd909d8731ba50e085352aae0e6885 (patch)
tree9c691c1382d3317f45ad09cb43a93f9223fe379b /src/input_common/gcadapter/gc_poller.cpp
parentCleanup after linter (diff)
downloadyuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.gz
yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.xz
yuzu-c94583d867fd909d8731ba50e085352aae0e6885.zip
Clang Formatting
Diffstat (limited to 'src/input_common/gcadapter/gc_poller.cpp')
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index 772bd8890..51b3362d6 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -1,10 +1,14 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
1#include <atomic> 5#include <atomic>
2#include <list> 6#include <list>
3#include <mutex> 7#include <mutex>
4#include <utility> 8#include <utility>
5#include "input_common/gcadapter/gc_poller.h"
6#include "input_common/gcadapter/gc_adapter.h"
7#include "common/threadsafe_queue.h" 9#include "common/threadsafe_queue.h"
10#include "input_common/gcadapter/gc_adapter.h"
11#include "input_common/gcadapter/gc_poller.h"
8 12
9// Using extern as to avoid multply defined symbols. 13// Using extern as to avoid multply defined symbols.
10extern Common::SPSCQueue<GCPadStatus> pad_queue[4]; 14extern Common::SPSCQueue<GCPadStatus> pad_queue[4];
@@ -14,9 +18,7 @@ namespace InputCommon {
14 18
15class GCButton final : public Input::ButtonDevice { 19class GCButton final : public Input::ButtonDevice {
16public: 20public:
17 explicit GCButton(int port_, int button_, int axis_) 21 explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {}
18 : port(port_), button(button_) {
19 }
20 22
21 ~GCButton() override; 23 ~GCButton() override;
22 24
@@ -31,17 +33,14 @@ private:
31 33
32class GCAxisButton final : public Input::ButtonDevice { 34class GCAxisButton final : public Input::ButtonDevice {
33public: 35public:
34 explicit GCAxisButton(int port_, int axis_, float threshold_, 36 explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_)
35 bool trigger_if_greater_) 37 : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) {
36 : port(port_), axis(axis_), threshold(threshold_),
37 trigger_if_greater(trigger_if_greater_) {
38 } 38 }
39 39
40
41 bool GetStatus() const override { 40 bool GetStatus() const override {
42 const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; 41 const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f;
43 if (trigger_if_greater) { 42 if (trigger_if_greater) {
44 return axis_value > 0.10f; //TODO(ameerj) : Fix threshold. 43 return axis_value > 0.10f; // TODO(ameerj) : Fix threshold.
45 } 44 }
46 return axis_value < -0.10f; 45 return axis_value < -0.10f;
47 } 46 }
@@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
164 163
165void GCButtonFactory::BeginConfiguration() { 164void GCButtonFactory::BeginConfiguration() {
166 polling = true; 165 polling = true;
167 for (int i = 0; i < 4; i++) 166 for (int i = 0; i < 4; i++) {
168 pad_queue[i].Clear(); 167 pad_queue[i].Clear();
168 }
169 GCAdapter::BeginConfiguration(); 169 GCAdapter::BeginConfiguration();
170} 170}
171 171
172void GCButtonFactory::EndConfiguration() { 172void GCButtonFactory::EndConfiguration() {
173 polling = false; 173 polling = false;
174 174 for (int i = 0; i < 4; i++) {
175 for (int i = 0; i < 4; i++)
176 pad_queue[i].Clear(); 175 pad_queue[i].Clear();
176 }
177 GCAdapter::EndConfiguration(); 177 GCAdapter::EndConfiguration();
178} 178}
179 179
180class GCAnalog final : public Input::AnalogDevice { 180class GCAnalog final : public Input::AnalogDevice {
181public: 181public:
182 GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) 182 GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_)
183 : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { 183 : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {}
184 }
185 184
186 float GetAxis(int axis) const { 185 float GetAxis(int axis) const {
187 std::lock_guard lock{mutex}; 186 std::lock_guard lock{mutex};
188 // division is not by a perfect 128 to account for some variance in center location 187 // division is not by a perfect 128 to account for some variance in center location
189 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230] 188 // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
189 // [20-230]
190 return (state[port].axes.at(axis) - 128.0f) / 95.0f; 190 return (state[port].axes.at(axis) - 128.0f) / 95.0f;
191 } 191 }
192 192
@@ -240,18 +240,16 @@ private:
240 mutable std::mutex mutex; 240 mutable std::mutex mutex;
241}; 241};
242 242
243
244/// An analog device factory that creates analog devices from GC Adapter 243/// An analog device factory that creates analog devices from GC Adapter
245GCAnalogFactory::GCAnalogFactory() {}; 244GCAnalogFactory::GCAnalogFactory(){};
246
247 245
248/** 246/**
249* Creates analog device from joystick axes 247 * Creates analog device from joystick axes
250* @param params contains parameters for creating the device: 248 * @param params contains parameters for creating the device:
251* - "port": the nth gcpad on the adapter 249 * - "port": the nth gcpad on the adapter
252* - "axis_x": the index of the axis to be bind as x-axis 250 * - "axis_x": the index of the axis to be bind as x-axis
253* - "axis_y": the index of the axis to be bind as y-axis 251 * - "axis_y": the index of the axis to be bind as y-axis
254*/ 252 */
255std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { 253std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) {
256 const std::string guid = params.Get("guid", "0"); 254 const std::string guid = params.Get("guid", "0");
257 const int port = params.Get("port", 0); 255 const int port = params.Get("port", 0);
@@ -264,15 +262,17 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param
264 262
265void GCAnalogFactory::BeginConfiguration() { 263void GCAnalogFactory::BeginConfiguration() {
266 polling = true; 264 polling = true;
267 for (int i = 0; i < 4; i++) 265 for (int i = 0; i < 4; i++) {
268 pad_queue[i].Clear(); 266 pad_queue[i].Clear();
267 }
269 GCAdapter::BeginConfiguration(); 268 GCAdapter::BeginConfiguration();
270} 269}
271 270
272void GCAnalogFactory::EndConfiguration() { 271void GCAnalogFactory::EndConfiguration() {
273 polling = false; 272 polling = false;
274 for (int i = 0; i < 4; i++) 273 for (int i = 0; i < 4; i++) {
275 pad_queue[i].Clear(); 274 pad_queue[i].Clear();
275 }
276 GCAdapter::EndConfiguration(); 276 GCAdapter::EndConfiguration();
277} 277}
278 278