summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_adapter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.h')
-rw-r--r--src/input_common/gcadapter/gc_adapter.h51
1 files changed, 12 insertions, 39 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h
index 3586c8bda..75bf9fe74 100644
--- a/src/input_common/gcadapter/gc_adapter.h
+++ b/src/input_common/gcadapter/gc_adapter.h
@@ -10,6 +10,7 @@
10#include <unordered_map> 10#include <unordered_map>
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/threadsafe_queue.h" 12#include "common/threadsafe_queue.h"
13#include "input_common/main.h"
13 14
14struct libusb_context; 15struct libusb_context;
15struct libusb_device; 16struct libusb_device;
@@ -47,24 +48,10 @@ enum class PadAxes : u8 {
47}; 48};
48 49
49struct GCPadStatus { 50struct GCPadStatus {
50 u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits 51 u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits
51 u8 stick_x{}; // 0 <= stick_x <= 255 52
52 u8 stick_y{}; // 0 <= stick_y <= 255 53 std::array<u8, 6> axis_values{}; // Triggers and sticks, following indices defined in PadAxes
53 u8 substick_x{}; // 0 <= substick_x <= 255 54 static constexpr u8 THRESHOLD = 50; // Threshold for axis press for polling
54 u8 substick_y{}; // 0 <= substick_y <= 255
55 u8 trigger_left{}; // 0 <= trigger_left <= 255
56 u8 trigger_right{}; // 0 <= trigger_right <= 255
57
58 static constexpr u8 MAIN_STICK_CENTER_X = 0x80;
59 static constexpr u8 MAIN_STICK_CENTER_Y = 0x80;
60 static constexpr u8 MAIN_STICK_RADIUS = 0x7f;
61 static constexpr u8 C_STICK_CENTER_X = 0x80;
62 static constexpr u8 C_STICK_CENTER_Y = 0x80;
63 static constexpr u8 C_STICK_RADIUS = 0x7f;
64 static constexpr u8 THRESHOLD = 10;
65
66 // 256/4, at least a quarter press to count as a press. For polling mostly
67 static constexpr u8 TRIGGER_THRESHOLD = 64;
68 55
69 u8 port{}; 56 u8 port{};
70 PadAxes axis{PadAxes::Undefined}; 57 PadAxes axis{PadAxes::Undefined};
@@ -78,11 +65,6 @@ struct GCState {
78 65
79enum class ControllerTypes { None, Wired, Wireless }; 66enum class ControllerTypes { None, Wired, Wireless };
80 67
81enum {
82 NO_ADAPTER_DETECTED = 0,
83 ADAPTER_DETECTED = 1,
84};
85
86class Adapter { 68class Adapter {
87public: 69public:
88 /// Initialize the GC Adapter capture and read sequence 70 /// Initialize the GC Adapter capture and read sequence
@@ -94,8 +76,12 @@ public:
94 void BeginConfiguration(); 76 void BeginConfiguration();
95 void EndConfiguration(); 77 void EndConfiguration();
96 78
79 std::vector<Common::ParamPackage> GetInputDevices() const;
80 InputCommon::ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) const;
81 InputCommon::AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) const;
82
97 /// Returns true if there is a device connected to port 83 /// Returns true if there is a device connected to port
98 bool DeviceConnected(std::size_t port); 84 bool DeviceConnected(std::size_t port) const;
99 85
100 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue(); 86 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
101 const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const; 87 const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
@@ -111,12 +97,6 @@ private:
111 void PadToState(const GCPadStatus& pad, GCState& state); 97 void PadToState(const GCPadStatus& pad, GCState& state);
112 98
113 void Read(); 99 void Read();
114 void ScanThreadFunc();
115 /// Begin scanning for the GC Adapter.
116 void StartScanThread();
117
118 /// Stop scanning for the adapter
119 void StopScanThread();
120 100
121 /// Resets status of device connected to port 101 /// Resets status of device connected to port
122 void ResetDeviceType(std::size_t port); 102 void ResetDeviceType(std::size_t port);
@@ -133,19 +113,11 @@ private:
133 /// For use in initialization, querying devices to find the adapter 113 /// For use in initialization, querying devices to find the adapter
134 void Setup(); 114 void Setup();
135 115
136 int current_status = NO_ADAPTER_DETECTED;
137 libusb_device_handle* usb_adapter_handle = nullptr; 116 libusb_device_handle* usb_adapter_handle = nullptr;
138 std::array<ControllerTypes, 4> adapter_controllers_status{};
139
140 std::mutex s_mutex;
141 117
142 std::thread adapter_input_thread; 118 std::thread adapter_input_thread;
143 bool adapter_thread_running; 119 bool adapter_thread_running;
144 120
145 std::mutex initialization_mutex;
146 std::thread detect_thread;
147 bool detect_thread_running = false;
148
149 libusb_context* libusb_ctx; 121 libusb_context* libusb_ctx;
150 122
151 u8 input_endpoint = 0; 123 u8 input_endpoint = 0;
@@ -153,10 +125,11 @@ private:
153 125
154 bool configuring = false; 126 bool configuring = false;
155 127
156 std::array<Common::SPSCQueue<GCPadStatus>, 4> pad_queue;
157 std::array<GCState, 4> state; 128 std::array<GCState, 4> state;
158 std::array<bool, 4> get_origin; 129 std::array<bool, 4> get_origin;
159 std::array<GCPadStatus, 4> origin_status; 130 std::array<GCPadStatus, 4> origin_status;
131 std::array<Common::SPSCQueue<GCPadStatus>, 4> pad_queue;
132 std::array<ControllerTypes, 4> adapter_controllers_status{};
160}; 133};
161 134
162} // namespace GCAdapter 135} // namespace GCAdapter