diff options
Diffstat (limited to 'src/input_common/drivers')
| -rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/drivers/gc_adapter.h | 3 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 45 | ||||
| -rw-r--r-- | src/input_common/drivers/sdl_driver.h | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 2 |
6 files changed, 77 insertions, 7 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 155caae42..8abd41726 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -524,4 +524,20 @@ Common::Input::ButtonNames GCAdapter::GetUIName(const Common::ParamPackage& para | |||
| 524 | return Common::Input::ButtonNames::Invalid; | 524 | return Common::Input::ButtonNames::Invalid; |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | bool GCAdapter::IsStickInverted(const Common::ParamPackage& params) { | ||
| 528 | if (!params.Has("port")) { | ||
| 529 | return false; | ||
| 530 | } | ||
| 531 | |||
| 532 | const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0)); | ||
| 533 | const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0)); | ||
| 534 | if (x_axis != PadAxes::StickY && x_axis != PadAxes::SubstickY) { | ||
| 535 | return false; | ||
| 536 | } | ||
| 537 | if (y_axis != PadAxes::StickX && y_axis != PadAxes::SubstickX) { | ||
| 538 | return false; | ||
| 539 | } | ||
| 540 | return true; | ||
| 541 | } | ||
| 542 | |||
| 527 | } // namespace InputCommon | 543 | } // namespace InputCommon |
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h index 7ce1912a3..894ab65a4 100644 --- a/src/input_common/drivers/gc_adapter.h +++ b/src/input_common/drivers/gc_adapter.h | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <mutex> | ||
| 10 | #include <stop_token> | 9 | #include <stop_token> |
| 11 | #include <string> | 10 | #include <string> |
| 12 | #include <thread> | 11 | #include <thread> |
| @@ -36,6 +35,8 @@ public: | |||
| 36 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; | 35 | AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; |
| 37 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; | 36 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; |
| 38 | 37 | ||
| 38 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 39 | |||
| 39 | private: | 40 | private: |
| 40 | enum class PadButton { | 41 | enum class PadButton { |
| 41 | Undefined = 0x0000, | 42 | Undefined = 0x0000, |
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index c17ea305e..a5c63e74a 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -62,7 +62,7 @@ public: | |||
| 62 | 62 | ||
| 63 | bool UpdateMotion(SDL_ControllerSensorEvent event) { | 63 | bool UpdateMotion(SDL_ControllerSensorEvent event) { |
| 64 | constexpr float gravity_constant = 9.80665f; | 64 | constexpr float gravity_constant = 9.80665f; |
| 65 | std::lock_guard lock{mutex}; | 65 | std::scoped_lock lock{mutex}; |
| 66 | const u64 time_difference = event.timestamp - last_motion_update; | 66 | const u64 time_difference = event.timestamp - last_motion_update; |
| 67 | last_motion_update = event.timestamp; | 67 | last_motion_update = event.timestamp; |
| 68 | switch (event.sensor) { | 68 | switch (event.sensor) { |
| @@ -241,7 +241,7 @@ private: | |||
| 241 | }; | 241 | }; |
| 242 | 242 | ||
| 243 | std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) { | 243 | std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickByGUID(const std::string& guid, int port) { |
| 244 | std::lock_guard lock{joystick_map_mutex}; | 244 | std::scoped_lock lock{joystick_map_mutex}; |
| 245 | const auto it = joystick_map.find(guid); | 245 | const auto it = joystick_map.find(guid); |
| 246 | 246 | ||
| 247 | if (it != joystick_map.end()) { | 247 | if (it != joystick_map.end()) { |
| @@ -263,7 +263,7 @@ std::shared_ptr<SDLJoystick> SDLDriver::GetSDLJoystickBySDLID(SDL_JoystickID sdl | |||
| 263 | auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); | 263 | auto sdl_joystick = SDL_JoystickFromInstanceID(sdl_id); |
| 264 | const std::string guid = GetGUID(sdl_joystick); | 264 | const std::string guid = GetGUID(sdl_joystick); |
| 265 | 265 | ||
| 266 | std::lock_guard lock{joystick_map_mutex}; | 266 | std::scoped_lock lock{joystick_map_mutex}; |
| 267 | const auto map_it = joystick_map.find(guid); | 267 | const auto map_it = joystick_map.find(guid); |
| 268 | 268 | ||
| 269 | if (map_it == joystick_map.end()) { | 269 | if (map_it == joystick_map.end()) { |
| @@ -297,7 +297,7 @@ void SDLDriver::InitJoystick(int joystick_index) { | |||
| 297 | 297 | ||
| 298 | const std::string guid = GetGUID(sdl_joystick); | 298 | const std::string guid = GetGUID(sdl_joystick); |
| 299 | 299 | ||
| 300 | std::lock_guard lock{joystick_map_mutex}; | 300 | std::scoped_lock lock{joystick_map_mutex}; |
| 301 | if (joystick_map.find(guid) == joystick_map.end()) { | 301 | if (joystick_map.find(guid) == joystick_map.end()) { |
| 302 | auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller); | 302 | auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller); |
| 303 | PreSetController(joystick->GetPadIdentifier()); | 303 | PreSetController(joystick->GetPadIdentifier()); |
| @@ -326,7 +326,7 @@ void SDLDriver::InitJoystick(int joystick_index) { | |||
| 326 | void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { | 326 | void SDLDriver::CloseJoystick(SDL_Joystick* sdl_joystick) { |
| 327 | const std::string guid = GetGUID(sdl_joystick); | 327 | const std::string guid = GetGUID(sdl_joystick); |
| 328 | 328 | ||
| 329 | std::lock_guard lock{joystick_map_mutex}; | 329 | std::scoped_lock lock{joystick_map_mutex}; |
| 330 | // This call to guid is safe since the joystick is guaranteed to be in the map | 330 | // This call to guid is safe since the joystick is guaranteed to be in the map |
| 331 | const auto& joystick_guid_list = joystick_map[guid]; | 331 | const auto& joystick_guid_list = joystick_map[guid]; |
| 332 | const auto joystick_it = std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(), | 332 | const auto joystick_it = std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(), |
| @@ -392,7 +392,7 @@ void SDLDriver::HandleGameControllerEvent(const SDL_Event& event) { | |||
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | void SDLDriver::CloseJoysticks() { | 394 | void SDLDriver::CloseJoysticks() { |
| 395 | std::lock_guard lock{joystick_map_mutex}; | 395 | std::scoped_lock lock{joystick_map_mutex}; |
| 396 | joystick_map.clear(); | 396 | joystick_map.clear(); |
| 397 | } | 397 | } |
| 398 | 398 | ||
| @@ -934,4 +934,37 @@ u8 SDLDriver::GetHatButtonId(const std::string& direction_name) const { | |||
| 934 | return direction; | 934 | return direction; |
| 935 | } | 935 | } |
| 936 | 936 | ||
| 937 | bool SDLDriver::IsStickInverted(const Common::ParamPackage& params) { | ||
| 938 | if (!params.Has("guid") || !params.Has("port")) { | ||
| 939 | return false; | ||
| 940 | } | ||
| 941 | const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0)); | ||
| 942 | if (joystick == nullptr) { | ||
| 943 | return false; | ||
| 944 | } | ||
| 945 | auto* controller = joystick->GetSDLGameController(); | ||
| 946 | if (controller == nullptr) { | ||
| 947 | return false; | ||
| 948 | } | ||
| 949 | |||
| 950 | const auto& axis_x = params.Get("axis_x", 0); | ||
| 951 | const auto& axis_y = params.Get("axis_y", 0); | ||
| 952 | const auto& binding_left_x = | ||
| 953 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX); | ||
| 954 | const auto& binding_right_x = | ||
| 955 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX); | ||
| 956 | const auto& binding_left_y = | ||
| 957 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY); | ||
| 958 | const auto& binding_right_y = | ||
| 959 | SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY); | ||
| 960 | |||
| 961 | if (axis_x != binding_left_y.value.axis && axis_x != binding_right_y.value.axis) { | ||
| 962 | return false; | ||
| 963 | } | ||
| 964 | if (axis_y != binding_left_x.value.axis && axis_y != binding_right_x.value.axis) { | ||
| 965 | return false; | ||
| 966 | } | ||
| 967 | return true; | ||
| 968 | } | ||
| 969 | |||
| 937 | } // namespace InputCommon | 970 | } // namespace InputCommon |
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index 4cde3606f..dcd0d1e64 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h | |||
| @@ -58,6 +58,8 @@ public: | |||
| 58 | std::string GetHatButtonName(u8 direction_value) const override; | 58 | std::string GetHatButtonName(u8 direction_value) const override; |
| 59 | u8 GetHatButtonId(const std::string& direction_name) const override; | 59 | u8 GetHatButtonId(const std::string& direction_name) const override; |
| 60 | 60 | ||
| 61 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 62 | |||
| 61 | Common::Input::VibrationError SetRumble( | 63 | Common::Input::VibrationError SetRumble( |
| 62 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; | 64 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; |
| 63 | 65 | ||
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 9780ead10..825262a07 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -547,6 +547,22 @@ Common::Input::ButtonNames UDPClient::GetUIName(const Common::ParamPackage& para | |||
| 547 | return Common::Input::ButtonNames::Invalid; | 547 | return Common::Input::ButtonNames::Invalid; |
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | bool UDPClient::IsStickInverted(const Common::ParamPackage& params) { | ||
| 551 | if (!params.Has("guid") || !params.Has("port") || !params.Has("pad")) { | ||
| 552 | return false; | ||
| 553 | } | ||
| 554 | |||
| 555 | const auto x_axis = static_cast<PadAxes>(params.Get("axis_x", 0)); | ||
| 556 | const auto y_axis = static_cast<PadAxes>(params.Get("axis_y", 0)); | ||
| 557 | if (x_axis != PadAxes::LeftStickY && x_axis != PadAxes::RightStickY) { | ||
| 558 | return false; | ||
| 559 | } | ||
| 560 | if (y_axis != PadAxes::LeftStickX && y_axis != PadAxes::RightStickX) { | ||
| 561 | return false; | ||
| 562 | } | ||
| 563 | return true; | ||
| 564 | } | ||
| 565 | |||
| 550 | void TestCommunication(const std::string& host, u16 port, | 566 | void TestCommunication(const std::string& host, u16 port, |
| 551 | const std::function<void()>& success_callback, | 567 | const std::function<void()>& success_callback, |
| 552 | const std::function<void()>& failure_callback) { | 568 | const std::function<void()>& failure_callback) { |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index c7cc7d846..dece2a45b 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -64,6 +64,8 @@ public: | |||
| 64 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; | 64 | MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; |
| 65 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; | 65 | Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; |
| 66 | 66 | ||
| 67 | bool IsStickInverted(const Common::ParamPackage& params) override; | ||
| 68 | |||
| 67 | private: | 69 | private: |
| 68 | enum class PadButton { | 70 | enum class PadButton { |
| 69 | Undefined = 0x0000, | 71 | Undefined = 0x0000, |