From 0248614add99c1df1bc7c9ff97091f678ff75aca Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 12:36:28 -0400 Subject: GC Adapter Implementation --- src/input_common/gcadapter/gc_adapter.h | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/input_common/gcadapter/gc_adapter.h (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h new file mode 100644 index 000000000..9b02d1382 --- /dev/null +++ b/src/input_common/gcadapter/gc_adapter.h @@ -0,0 +1,116 @@ +#pragma once +#include +#include +#include +#include +#include "common/common_types.h" + + +enum { + PAD_USE_ORIGIN = 0x0080, + PAD_GET_ORIGIN = 0x2000, + PAD_ERR_STATUS = 0x8000, +}; + +enum PadButton { + PAD_BUTTON_LEFT = 0x0001, + PAD_BUTTON_RIGHT = 0x0002, + PAD_BUTTON_DOWN = 0x0004, + PAD_BUTTON_UP = 0x0008, + PAD_TRIGGER_Z = 0x0010, + PAD_TRIGGER_R = 0x0020, + PAD_TRIGGER_L = 0x0040, + PAD_BUTTON_A = 0x0100, + PAD_BUTTON_B = 0x0200, + PAD_BUTTON_X = 0x0400, + PAD_BUTTON_Y = 0x0800, + PAD_BUTTON_START = 0x1000, + // Below is for compatibility with "AxisButton" type + PAD_STICK = 0x2000, + +}; + +enum PadAxes { STICK_X, STICK_Y, SUBSTICK_X, SUBSTICK_Y, TRIGGER_LEFT, TRIGGER_RIGHT }; + +struct GCPadStatus { + u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits + u8 stickX; // 0 <= stickX <= 255 + u8 stickY; // 0 <= stickY <= 255 + u8 substickX; // 0 <= substickX <= 255 + u8 substickY; // 0 <= substickY <= 255 + u8 triggerLeft; // 0 <= triggerLeft <= 255 + u8 triggerRight; // 0 <= triggerRight <= 255 + bool isConnected{true}; + + static const u8 MAIN_STICK_CENTER_X = 0x80; + static const u8 MAIN_STICK_CENTER_Y = 0x80; + static const u8 MAIN_STICK_RADIUS = 0x7f; + static const u8 C_STICK_CENTER_X = 0x80; + static const u8 C_STICK_CENTER_Y = 0x80; + static const u8 C_STICK_RADIUS = 0x7f; + + static const u8 TRIGGER_CENTER = 20; + static const u8 THRESHOLD = 10; + u8 port; + u8 axis_which = 255; + u8 axis_value = 255; +}; + +struct GCState { + std::unordered_map buttons; + std::unordered_map axes; +}; + + +namespace GCAdapter { +enum ControllerTypes { + CONTROLLER_NONE = 0, + CONTROLLER_WIRED = 1, + CONTROLLER_WIRELESS = 2 +}; + +enum { + NO_ADAPTER_DETECTED = 0, + ADAPTER_DETECTED = 1, +}; + +// Current adapter status: detected/not detected/in error (holds the error code) +static int current_status = NO_ADAPTER_DETECTED; + +GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); +/// Initialize the GC Adapter capture and read sequence +void Init(); + +/// Close the adapter read thread and release the adapter +void Shutdown(); + +/// Begin scanning for the GC Adapter. +void StartScanThread(); + +/// Stop scanning for the adapter +void StopScanThread(); + +/// Returns true if there is a device connected to port +bool DeviceConnected(int port); + +/// Resets status of device connected to port +void ResetDeviceType(int port); + +/// Returns true if we successfully gain access to GC Adapter +bool CheckDeviceAccess(libusb_device* device); + +/// Captures GC Adapter endpoint address, +void GetGCEndpoint(libusb_device* device); + +/// For shutting down, clear all data, join all threads, release usb +void Reset(); + +/// For use in initialization, querying devices to find the adapter +void Setup(); + +/// Used for polling +void BeginConfiguration(); + +void EndConfiguration(); + +} // end of namespace GCAdapter -- cgit v1.2.3 From c94583d867fd909d8731ba50e085352aae0e6885 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 15:31:57 -0400 Subject: Clang Formatting --- src/input_common/gcadapter/gc_adapter.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 9b02d1382..05ee73c65 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -1,11 +1,14 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + #pragma once #include -#include -#include #include +#include +#include #include "common/common_types.h" - enum { PAD_USE_ORIGIN = 0x0080, PAD_GET_ORIGIN = 0x2000, @@ -61,13 +64,8 @@ struct GCState { std::unordered_map axes; }; - namespace GCAdapter { -enum ControllerTypes { - CONTROLLER_NONE = 0, - CONTROLLER_WIRED = 1, - CONTROLLER_WIRELESS = 2 -}; +enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; enum { NO_ADAPTER_DETECTED = 0, -- cgit v1.2.3 From 121af3646dad0f80453d2ffffa688dd4435d3acc Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 18:43:01 -0400 Subject: Singleton GC Adapter class, remove globals, fix naming convention Fix clang formatting Manual fix for configure_input_player formatting Add missing lib usb cmake command --- src/input_common/gcadapter/gc_adapter.h | 145 +++++++++++++++++++++----------- 1 file changed, 97 insertions(+), 48 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 05ee73c65..3d5c41f9a 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -8,6 +8,9 @@ #include #include #include "common/common_types.h" +#include "common/threadsafe_queue.h" + +namespace GCAdapter { enum { PAD_USE_ORIGIN = 0x0080, @@ -33,29 +36,38 @@ enum PadButton { }; -enum PadAxes { STICK_X, STICK_Y, SUBSTICK_X, SUBSTICK_Y, TRIGGER_LEFT, TRIGGER_RIGHT }; +enum class PadAxes : u8 { + StickX, + StickY, + SubstickX, + SubstickY, + TriggerLeft, + TriggerRight, + Undefined, +}; +const struct GCPadConstants { + const u8 MAIN_STICK_CENTER_X = 0x80; + const u8 MAIN_STICK_CENTER_Y = 0x80; + const u8 MAIN_STICK_RADIUS = 0x7f; + const u8 C_STICK_CENTER_X = 0x80; + const u8 C_STICK_CENTER_Y = 0x80; + const u8 C_STICK_RADIUS = 0x7f; + + const u8 TRIGGER_CENTER = 20; + const u8 THRESHOLD = 10; +} pad_constants; struct GCPadStatus { - u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits - u8 stickX; // 0 <= stickX <= 255 - u8 stickY; // 0 <= stickY <= 255 - u8 substickX; // 0 <= substickX <= 255 - u8 substickY; // 0 <= substickY <= 255 - u8 triggerLeft; // 0 <= triggerLeft <= 255 - u8 triggerRight; // 0 <= triggerRight <= 255 - bool isConnected{true}; - - static const u8 MAIN_STICK_CENTER_X = 0x80; - static const u8 MAIN_STICK_CENTER_Y = 0x80; - static const u8 MAIN_STICK_RADIUS = 0x7f; - static const u8 C_STICK_CENTER_X = 0x80; - static const u8 C_STICK_CENTER_Y = 0x80; - static const u8 C_STICK_RADIUS = 0x7f; - - static const u8 TRIGGER_CENTER = 20; - static const u8 THRESHOLD = 10; + u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits + u8 stick_x; // 0 <= stick_x <= 255 + u8 stick_y; // 0 <= stick_y <= 255 + u8 substick_x; // 0 <= substick_x <= 255 + u8 substick_y; // 0 <= substick_y <= 255 + u8 trigger_left; // 0 <= trigger_left <= 255 + u8 trigger_right; // 0 <= trigger_right <= 255 + u8 port; - u8 axis_which = 255; + PadAxes axis = PadAxes::Undefined; u8 axis_value = 255; }; @@ -64,51 +76,88 @@ struct GCState { std::unordered_map axes; }; -namespace GCAdapter { -enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; +enum class ControllerTypes { None, Wired, Wireless }; enum { NO_ADAPTER_DETECTED = 0, ADAPTER_DETECTED = 1, }; -// Current adapter status: detected/not detected/in error (holds the error code) -static int current_status = NO_ADAPTER_DETECTED; +/// Singleton Adapter class +class Adapter { +public: + /// For retreiving the singleton instance + static Adapter* GetInstance(); + + /// Used for polling + void BeginConfiguration(); + void EndConfiguration(); + + std::array, 4>& GetPadQueue(); + std::array& GetPadState(); + +private: + /// Singleton instance. + static Adapter* adapter_instance; + + /// Initialize the GC Adapter capture and read sequence + Adapter(); -GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); -/// Initialize the GC Adapter capture and read sequence -void Init(); + /// Close the adapter read thread and release the adapter + ~Adapter(); -/// Close the adapter read thread and release the adapter -void Shutdown(); + GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); -/// Begin scanning for the GC Adapter. -void StartScanThread(); + void PadToState(GCPadStatus pad, GCState& state); -/// Stop scanning for the adapter -void StopScanThread(); + void Read(); + void ScanThreadFunc(); + /// Begin scanning for the GC Adapter. + void StartScanThread(); -/// Returns true if there is a device connected to port -bool DeviceConnected(int port); + /// Stop scanning for the adapter + void StopScanThread(); -/// Resets status of device connected to port -void ResetDeviceType(int port); + /// Returns true if there is a device connected to port + bool DeviceConnected(int port); -/// Returns true if we successfully gain access to GC Adapter -bool CheckDeviceAccess(libusb_device* device); + /// Resets status of device connected to port + void ResetDeviceType(int port); -/// Captures GC Adapter endpoint address, -void GetGCEndpoint(libusb_device* device); + /// Returns true if we successfully gain access to GC Adapter + bool CheckDeviceAccess(libusb_device* device); -/// For shutting down, clear all data, join all threads, release usb -void Reset(); + /// Captures GC Adapter endpoint address, + void GetGCEndpoint(libusb_device* device); -/// For use in initialization, querying devices to find the adapter -void Setup(); + /// For shutting down, clear all data, join all threads, release usb + void Reset(); -/// Used for polling -void BeginConfiguration(); + /// For use in initialization, querying devices to find the adapter + void Setup(); -void EndConfiguration(); + int current_status = NO_ADAPTER_DETECTED; + libusb_device_handle* usb_adapter_handle = nullptr; + ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None, + ControllerTypes::None, ControllerTypes::None}; + + std::mutex s_mutex; + + std::thread adapter_input_thread; + bool adapter_thread_running; + + std::mutex initialization_mutex; + std::thread detect_thread; + bool detect_thread_running = false; + + libusb_context* libusb_ctx; + + u8 input_endpoint = 0; + + bool configuring = false; + + std::array, 4> pad_queue; + std::array state; +}; } // end of namespace GCAdapter -- cgit v1.2.3 From 5f0fa4cb8283d61ad2993273fa48b2fd3868a680 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 20:32:43 -0400 Subject: fix include thread --- src/input_common/gcadapter/gc_adapter.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 3d5c41f9a..a32ca0464 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "common/common_types.h" #include "common/threadsafe_queue.h" -- cgit v1.2.3 From 968d631aa59a0a4e51e219eaa143d2b95593c3e7 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 21:15:58 -0400 Subject: std::arrays where appropriate, clear q in adapter class, other touch ups --- src/input_common/gcadapter/gc_adapter.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index a32ca0464..cb0dd0ab1 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -96,6 +96,8 @@ public: std::array, 4>& GetPadQueue(); std::array& GetPadState(); + std::array, 4>& GetPadQueue() const; + std::array& GetPadState() const; private: /// Singleton instance. @@ -139,8 +141,7 @@ private: int current_status = NO_ADAPTER_DETECTED; libusb_device_handle* usb_adapter_handle = nullptr; - ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None, - ControllerTypes::None, ControllerTypes::None}; + std::array adapter_controllers_status{}; std::mutex s_mutex; -- cgit v1.2.3 From 46b4461fbb0514dd50c096ef896b1752d81079d0 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sun, 21 Jun 2020 21:50:58 -0400 Subject: shared_ptr for the GC adapter class, constexpr constants --- src/input_common/gcadapter/gc_adapter.h | 40 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index cb0dd0ab1..d7a57e7b7 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -46,17 +46,6 @@ enum class PadAxes : u8 { TriggerRight, Undefined, }; -const struct GCPadConstants { - const u8 MAIN_STICK_CENTER_X = 0x80; - const u8 MAIN_STICK_CENTER_Y = 0x80; - const u8 MAIN_STICK_RADIUS = 0x7f; - const u8 C_STICK_CENTER_X = 0x80; - const u8 C_STICK_CENTER_Y = 0x80; - const u8 C_STICK_RADIUS = 0x7f; - - const u8 TRIGGER_CENTER = 20; - const u8 THRESHOLD = 10; -} pad_constants; struct GCPadStatus { u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits @@ -67,6 +56,15 @@ struct GCPadStatus { u8 trigger_left; // 0 <= trigger_left <= 255 u8 trigger_right; // 0 <= trigger_right <= 255 + static constexpr u8 MAIN_STICK_CENTER_X = 0x80; + static constexpr u8 MAIN_STICK_CENTER_Y = 0x80; + static constexpr u8 MAIN_STICK_RADIUS = 0x7f; + static constexpr u8 C_STICK_CENTER_X = 0x80; + static constexpr u8 C_STICK_CENTER_Y = 0x80; + static constexpr u8 C_STICK_RADIUS = 0x7f; + static constexpr u8 TRIGGER_CENTER = 20; + static constexpr u8 THRESHOLD = 10; + u8 port; PadAxes axis = PadAxes::Undefined; u8 axis_value = 255; @@ -87,28 +85,22 @@ enum { /// Singleton Adapter class class Adapter { public: - /// For retreiving the singleton instance - static Adapter* GetInstance(); + /// Initialize the GC Adapter capture and read sequence + Adapter(); + /// Close the adapter read thread and release the adapter + ~Adapter(); /// Used for polling void BeginConfiguration(); void EndConfiguration(); std::array, 4>& GetPadQueue(); + const std::array, 4>& GetPadQueue() const; + std::array& GetPadState(); - std::array, 4>& GetPadQueue() const; - std::array& GetPadState() const; + const std::array& GetPadState() const; private: - /// Singleton instance. - static Adapter* adapter_instance; - - /// Initialize the GC Adapter capture and read sequence - Adapter(); - - /// Close the adapter read thread and release the adapter - ~Adapter(); - GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); void PadToState(GCPadStatus pad, GCState& state); -- cgit v1.2.3 From fcc23139f622963c86e7f53c8b96f6f214294032 Mon Sep 17 00:00:00 2001 From: Ameer Date: Mon, 22 Jun 2020 18:11:59 -0400 Subject: std::array and const reference passing of non-trivial objects --- src/input_common/gcadapter/gc_adapter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index d7a57e7b7..ff0202e3b 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -101,9 +101,9 @@ public: const std::array& GetPadState() const; private: - GCPadStatus CheckStatus(int port, u8 adapter_payload[37]); + GCPadStatus CheckStatus(int port, const std::array& adapter_payload); - void PadToState(GCPadStatus pad, GCState& state); + void PadToState(const GCPadStatus& pad, GCState& state); void Read(); void ScanThreadFunc(); @@ -154,4 +154,4 @@ private: std::array state; }; -} // end of namespace GCAdapter +} // namespace GCAdapter -- cgit v1.2.3 From d4e07fd95e999e34562428c628985a6eb1fb532d Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 23 Jun 2020 12:47:58 -0400 Subject: Fix deallocation of GC Adapter --- src/input_common/gcadapter/gc_adapter.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index ff0202e3b..7aed0b480 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -82,7 +82,6 @@ enum { ADAPTER_DETECTED = 1, }; -/// Singleton Adapter class class Adapter { public: /// Initialize the GC Adapter capture and read sequence -- cgit v1.2.3 From 743e1f02a06187164d55f4208b8e85742abd4498 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 23 Jun 2020 17:37:15 -0400 Subject: cleanup check access, read, and factory GetNextInput funcs. Use size rather than magic number --- src/input_common/gcadapter/gc_adapter.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 7aed0b480..abfe0d7b3 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -37,6 +37,12 @@ enum PadButton { }; +/// Used to loop through the and assign button in poller +static constexpr std::array PadButtonArray{ + PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP, + PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L, PAD_BUTTON_A, + PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_BUTTON_START}; + enum class PadAxes : u8 { StickX, StickY, @@ -100,7 +106,7 @@ public: const std::array& GetPadState() const; private: - GCPadStatus CheckStatus(int port, const std::array& adapter_payload); + GCPadStatus GetPadStatus(int port, const std::array& adapter_payload); void PadToState(const GCPadStatus& pad, GCState& state); -- cgit v1.2.3 From c18dc9c707235d7ba6fe230cb3045f2c13d04e62 Mon Sep 17 00:00:00 2001 From: Ameer Date: Wed, 24 Jun 2020 11:39:30 -0400 Subject: padbutton enum class and struct initiailization --- src/input_common/gcadapter/gc_adapter.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index abfe0d7b3..91aa9622b 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -19,7 +19,7 @@ enum { PAD_ERR_STATUS = 0x8000, }; -enum PadButton { +enum class PadButton { PAD_BUTTON_LEFT = 0x0001, PAD_BUTTON_RIGHT = 0x0002, PAD_BUTTON_DOWN = 0x0004, @@ -34,14 +34,14 @@ enum PadButton { PAD_BUTTON_START = 0x1000, // Below is for compatibility with "AxisButton" type PAD_STICK = 0x2000, - }; /// Used to loop through the and assign button in poller static constexpr std::array PadButtonArray{ - PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP, - PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L, PAD_BUTTON_A, - PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_BUTTON_START}; + PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, + PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, + PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, + PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START}; enum class PadAxes : u8 { StickX, @@ -54,13 +54,13 @@ enum class PadAxes : u8 { }; struct GCPadStatus { - u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits - u8 stick_x; // 0 <= stick_x <= 255 - u8 stick_y; // 0 <= stick_y <= 255 - u8 substick_x; // 0 <= substick_x <= 255 - u8 substick_y; // 0 <= substick_y <= 255 - u8 trigger_left; // 0 <= trigger_left <= 255 - u8 trigger_right; // 0 <= trigger_right <= 255 + u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits + u8 stick_x{}; // 0 <= stick_x <= 255 + u8 stick_y{}; // 0 <= stick_y <= 255 + u8 substick_x{}; // 0 <= substick_x <= 255 + u8 substick_y{}; // 0 <= substick_y <= 255 + u8 trigger_left{}; // 0 <= trigger_left <= 255 + u8 trigger_right{}; // 0 <= trigger_right <= 255 static constexpr u8 MAIN_STICK_CENTER_X = 0x80; static constexpr u8 MAIN_STICK_CENTER_Y = 0x80; @@ -71,9 +71,9 @@ struct GCPadStatus { static constexpr u8 TRIGGER_CENTER = 20; static constexpr u8 THRESHOLD = 10; - u8 port; - PadAxes axis = PadAxes::Undefined; - u8 axis_value = 255; + u8 port{}; + PadAxes axis{PadAxes::Undefined}; + u8 axis_value{255}; }; struct GCState { -- cgit v1.2.3 From 34a590e50966341cec5f1874410931decbce284f Mon Sep 17 00:00:00 2001 From: Ameer Date: Wed, 1 Jul 2020 12:52:50 -0400 Subject: Reset adapter state on init, fixes errors relating driver hang from unexpected unplug --- src/input_common/gcadapter/gc_adapter.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 91aa9622b..4a8e2644c 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -152,6 +152,7 @@ private: libusb_context* libusb_ctx; u8 input_endpoint = 0; + u8 output_endpoint = 0; bool configuring = false; -- cgit v1.2.3 From e69d715e3d42aaa5e99ebe8e578e64242d049a8c Mon Sep 17 00:00:00 2001 From: Ameer Date: Fri, 3 Jul 2020 11:52:07 -0400 Subject: Address lioncash feedback: Log formatting, extern const PadButtonArray, little touch ups --- src/input_common/gcadapter/gc_adapter.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 4a8e2644c..161d522ac 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -36,12 +36,7 @@ enum class PadButton { PAD_STICK = 0x2000, }; -/// Used to loop through the and assign button in poller -static constexpr std::array PadButtonArray{ - PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, - PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, - PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, - PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START}; +extern const std::array PadButtonArray; enum class PadAxes : u8 { StickX, -- cgit v1.2.3 From d00972fce1fe5f2eb13c7e5d7e4e56036cb6bc91 Mon Sep 17 00:00:00 2001 From: Ameer Date: Sat, 4 Jul 2020 00:40:48 -0400 Subject: Fix for always firing triggers on some controllers, trigger threshold more universal --- src/input_common/gcadapter/gc_adapter.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/input_common/gcadapter/gc_adapter.h') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 161d522ac..0ea6263eb 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -63,9 +63,11 @@ struct GCPadStatus { static constexpr u8 C_STICK_CENTER_X = 0x80; static constexpr u8 C_STICK_CENTER_Y = 0x80; static constexpr u8 C_STICK_RADIUS = 0x7f; - static constexpr u8 TRIGGER_CENTER = 20; static constexpr u8 THRESHOLD = 10; + // 256/4, at least a quarter press to count as a press. For polling mostly + static constexpr u8 TRIGGER_THRESHOLD = 64; + u8 port{}; PadAxes axis{PadAxes::Undefined}; u8 axis_value{255}; -- cgit v1.2.3