From 30651dadcbdd717a6c0632d0ef5da8980134e740 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 25 Jun 2023 17:35:56 -0500 Subject: [PATCH 1/2] Implement extended controller button support --- src/input.cpp | 5 +++-- src/platform/common.h | 38 ++++++++++++++++++++-------------- src/platform/windows/input.cpp | 3 +++ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index fb862325d09..3de6c327dc6 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -254,7 +254,7 @@ namespace input { << "--begin controller packet--"sv << std::endl << "controllerNumber ["sv << packet->controllerNumber << ']' << std::endl << "activeGamepadMask ["sv << util::hex(packet->activeGamepadMask).to_string_view() << ']' << std::endl - << "buttonFlags ["sv << util::hex(packet->buttonFlags).to_string_view() << ']' << std::endl + << "buttonFlags ["sv << util::hex((uint32_t) packet->buttonFlags | (packet->buttonFlags2 << 16)).to_string_view() << ']' << std::endl << "leftTrigger ["sv << util::hex(packet->leftTrigger).to_string_view() << ']' << std::endl << "rightTrigger ["sv << util::hex(packet->rightTrigger).to_string_view() << ']' << std::endl << "leftStickX ["sv << packet->leftStickX << ']' << std::endl @@ -691,8 +691,9 @@ namespace input { } std::uint16_t bf = packet->buttonFlags; + std::uint32_t bf2 = packet->buttonFlags2; platf::gamepad_state_t gamepad_state { - bf, + bf | (bf2 << 16), packet->leftTrigger, packet->rightTrigger, packet->leftStickX, diff --git a/src/platform/common.h b/src/platform/common.h index cdb5785e076..07f4c9d3fc0 100644 --- a/src/platform/common.h +++ b/src/platform/common.h @@ -49,21 +49,27 @@ namespace video { namespace platf { constexpr auto MAX_GAMEPADS = 32; - constexpr std::uint16_t DPAD_UP = 0x0001; - constexpr std::uint16_t DPAD_DOWN = 0x0002; - constexpr std::uint16_t DPAD_LEFT = 0x0004; - constexpr std::uint16_t DPAD_RIGHT = 0x0008; - constexpr std::uint16_t START = 0x0010; - constexpr std::uint16_t BACK = 0x0020; - constexpr std::uint16_t LEFT_STICK = 0x0040; - constexpr std::uint16_t RIGHT_STICK = 0x0080; - constexpr std::uint16_t LEFT_BUTTON = 0x0100; - constexpr std::uint16_t RIGHT_BUTTON = 0x0200; - constexpr std::uint16_t HOME = 0x0400; - constexpr std::uint16_t A = 0x1000; - constexpr std::uint16_t B = 0x2000; - constexpr std::uint16_t X = 0x4000; - constexpr std::uint16_t Y = 0x8000; + constexpr std::uint32_t DPAD_UP = 0x0001; + constexpr std::uint32_t DPAD_DOWN = 0x0002; + constexpr std::uint32_t DPAD_LEFT = 0x0004; + constexpr std::uint32_t DPAD_RIGHT = 0x0008; + constexpr std::uint32_t START = 0x0010; + constexpr std::uint32_t BACK = 0x0020; + constexpr std::uint32_t LEFT_STICK = 0x0040; + constexpr std::uint32_t RIGHT_STICK = 0x0080; + constexpr std::uint32_t LEFT_BUTTON = 0x0100; + constexpr std::uint32_t RIGHT_BUTTON = 0x0200; + constexpr std::uint32_t HOME = 0x0400; + constexpr std::uint32_t A = 0x1000; + constexpr std::uint32_t B = 0x2000; + constexpr std::uint32_t X = 0x4000; + constexpr std::uint32_t Y = 0x8000; + constexpr std::uint32_t PADDLE1 = 0x010000; + constexpr std::uint32_t PADDLE2 = 0x020000; + constexpr std::uint32_t PADDLE3 = 0x040000; + constexpr std::uint32_t PADDLE4 = 0x080000; + constexpr std::uint32_t TOUCHPAD_BUTTON = 0x100000; + constexpr std::uint32_t MISC_BUTTON = 0x200000; struct rumble_t { KITTY_DEFAULT_CONSTR(rumble_t) @@ -154,7 +160,7 @@ namespace platf { }; struct gamepad_state_t { - std::uint16_t buttonFlags; + std::uint32_t buttonFlags; std::uint8_t lt; std::uint8_t rt; std::int16_t lsX; diff --git a/src/platform/windows/input.cpp b/src/platform/windows/input.cpp index c94904267b3..737fb9e3fbc 100644 --- a/src/platform/windows/input.cpp +++ b/src/platform/windows/input.cpp @@ -520,6 +520,9 @@ namespace platf { if (gamepad_state.buttonFlags & HOME) buttons |= DS4_SPECIAL_BUTTON_PS; + // Allow either PS4/PS5 clickpad button or Xbox Series X share button to activate DS4 clickpad + if (gamepad_state.buttonFlags & (TOUCHPAD_BUTTON | MISC_BUTTON)) buttons |= DS4_SPECIAL_BUTTON_TOUCHPAD; + return (DS4_SPECIAL_BUTTONS) buttons; } From 55b0d7acf72bb5f5cfca876eef3eb791b80af8d5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 25 Jun 2023 17:36:44 -0500 Subject: [PATCH 2/2] Fix max gamepad count to match protocol limitation --- src/platform/common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/common.h b/src/platform/common.h index 07f4c9d3fc0..d9af3b18647 100644 --- a/src/platform/common.h +++ b/src/platform/common.h @@ -47,7 +47,8 @@ namespace video { } // namespace video namespace platf { - constexpr auto MAX_GAMEPADS = 32; + // Limited by bits in activeGamepadMask + constexpr auto MAX_GAMEPADS = 16; constexpr std::uint32_t DPAD_UP = 0x0001; constexpr std::uint32_t DPAD_DOWN = 0x0002;