diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 5 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.cpp | 8 | ||||
| -rw-r--r-- | src/input_common/drivers/udp_client.h | 4 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 4 | ||||
| -rw-r--r-- | src/input_common/input_mapping.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/input_mapping.h | 8 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 13 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 6 | ||||
| -rw-r--r-- | src/input_common/main.h | 2 |
9 files changed, 36 insertions, 25 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index ed6281772..577bf5c31 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -109,8 +109,9 @@ public: | |||
| 109 | 109 | ||
| 110 | bool HasHDRumble() const { | 110 | bool HasHDRumble() const { |
| 111 | if (sdl_controller) { | 111 | if (sdl_controller) { |
| 112 | return (SDL_GameControllerGetType(sdl_controller.get()) == | 112 | const auto type = SDL_GameControllerGetType(sdl_controller.get()); |
| 113 | SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO); | 113 | return (type == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO) || |
| 114 | (type == SDL_CONTROLLER_TYPE_PS5); | ||
| 114 | } | 115 | } |
| 115 | return false; | 116 | return false; |
| 116 | } | 117 | } |
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 9aaeb91be..d1cdb1ab2 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -339,7 +339,7 @@ void UDPClient::StartCommunication(std::size_t client, const std::string& host, | |||
| 339 | } | 339 | } |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { | 342 | PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { |
| 343 | const std::size_t client = pad_index / PADS_PER_CLIENT; | 343 | const std::size_t client = pad_index / PADS_PER_CLIENT; |
| 344 | return { | 344 | return { |
| 345 | .guid = clients[client].uuid, | 345 | .guid = clients[client].uuid, |
| @@ -348,9 +348,9 @@ const PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { | |||
| 348 | }; | 348 | }; |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | const Common::UUID UDPClient::GetHostUUID(const std::string host) const { | 351 | Common::UUID UDPClient::GetHostUUID(const std::string& host) const { |
| 352 | const auto ip = boost::asio::ip::address_v4::from_string(host); | 352 | const auto ip = boost::asio::ip::make_address_v4(host); |
| 353 | const auto hex_host = fmt::format("{:06x}", ip.to_ulong()); | 353 | const auto hex_host = fmt::format("{:06x}", ip.to_uint()); |
| 354 | return Common::UUID{hex_host}; | 354 | return Common::UUID{hex_host}; |
| 355 | } | 355 | } |
| 356 | 356 | ||
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index 61a1fff37..30d7c2682 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -145,8 +145,8 @@ private: | |||
| 145 | void OnPortInfo(Response::PortInfo); | 145 | void OnPortInfo(Response::PortInfo); |
| 146 | void OnPadData(Response::PadData, std::size_t client); | 146 | void OnPadData(Response::PadData, std::size_t client); |
| 147 | void StartCommunication(std::size_t client, const std::string& host, u16 port); | 147 | void StartCommunication(std::size_t client, const std::string& host, u16 port); |
| 148 | const PadIdentifier GetPadIdentifier(std::size_t pad_index) const; | 148 | PadIdentifier GetPadIdentifier(std::size_t pad_index) const; |
| 149 | const Common::UUID GetHostUUID(const std::string host) const; | 149 | Common::UUID GetHostUUID(const std::string& host) const; |
| 150 | 150 | ||
| 151 | Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; | 151 | Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; |
| 152 | 152 | ||
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 390581c94..fe2faee5a 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | // Pad Identifier of data source | 17 | // Pad Identifier of data source |
| 18 | struct PadIdentifier { | 18 | struct PadIdentifier { |
| 19 | Common::UUID guid{}; | 19 | Common::UUID guid{Common::INVALID_UUID}; |
| 20 | std::size_t port{}; | 20 | std::size_t port{}; |
| 21 | std::size_t pad{}; | 21 | std::size_t pad{}; |
| 22 | 22 | ||
| @@ -89,7 +89,7 @@ struct UpdateCallback { | |||
| 89 | 89 | ||
| 90 | // Triggered if data changed on the controller and the engine is on configuring mode | 90 | // Triggered if data changed on the controller and the engine is on configuring mode |
| 91 | struct MappingCallback { | 91 | struct MappingCallback { |
| 92 | std::function<void(MappingData)> on_data; | 92 | std::function<void(const MappingData&)> on_data; |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | // Input Identifier of data source | 95 | // Input Identifier of data source |
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 475257f42..a7a6ad8c2 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -2,14 +2,13 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/settings.h" | 5 | #include "common/settings.h" |
| 7 | #include "input_common/input_engine.h" | 6 | #include "input_common/input_engine.h" |
| 8 | #include "input_common/input_mapping.h" | 7 | #include "input_common/input_mapping.h" |
| 9 | 8 | ||
| 10 | namespace InputCommon { | 9 | namespace InputCommon { |
| 11 | 10 | ||
| 12 | MappingFactory::MappingFactory() {} | 11 | MappingFactory::MappingFactory() = default; |
| 13 | 12 | ||
| 14 | void MappingFactory::BeginMapping(Polling::InputType type) { | 13 | void MappingFactory::BeginMapping(Polling::InputType type) { |
| 15 | is_enabled = true; | 14 | is_enabled = true; |
| @@ -19,7 +18,7 @@ void MappingFactory::BeginMapping(Polling::InputType type) { | |||
| 19 | second_axis = -1; | 18 | second_axis = -1; |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | [[nodiscard]] const Common::ParamPackage MappingFactory::GetNextInput() { | 21 | Common::ParamPackage MappingFactory::GetNextInput() { |
| 23 | Common::ParamPackage input; | 22 | Common::ParamPackage input; |
| 24 | input_queue.Pop(input); | 23 | input_queue.Pop(input); |
| 25 | return input; | 24 | return input; |
| @@ -57,7 +56,7 @@ void MappingFactory::StopMapping() { | |||
| 57 | void MappingFactory::RegisterButton(const MappingData& data) { | 56 | void MappingFactory::RegisterButton(const MappingData& data) { |
| 58 | Common::ParamPackage new_input; | 57 | Common::ParamPackage new_input; |
| 59 | new_input.Set("engine", data.engine); | 58 | new_input.Set("engine", data.engine); |
| 60 | if (data.pad.guid != Common::UUID{}) { | 59 | if (data.pad.guid.IsValid()) { |
| 61 | new_input.Set("guid", data.pad.guid.Format()); | 60 | new_input.Set("guid", data.pad.guid.Format()); |
| 62 | } | 61 | } |
| 63 | new_input.Set("port", static_cast<int>(data.pad.port)); | 62 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| @@ -93,7 +92,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { | |||
| 93 | void MappingFactory::RegisterStick(const MappingData& data) { | 92 | void MappingFactory::RegisterStick(const MappingData& data) { |
| 94 | Common::ParamPackage new_input; | 93 | Common::ParamPackage new_input; |
| 95 | new_input.Set("engine", data.engine); | 94 | new_input.Set("engine", data.engine); |
| 96 | if (data.pad.guid != Common::UUID{}) { | 95 | if (data.pad.guid.IsValid()) { |
| 97 | new_input.Set("guid", data.pad.guid.Format()); | 96 | new_input.Set("guid", data.pad.guid.Format()); |
| 98 | } | 97 | } |
| 99 | new_input.Set("port", static_cast<int>(data.pad.port)); | 98 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| @@ -138,7 +137,7 @@ void MappingFactory::RegisterStick(const MappingData& data) { | |||
| 138 | void MappingFactory::RegisterMotion(const MappingData& data) { | 137 | void MappingFactory::RegisterMotion(const MappingData& data) { |
| 139 | Common::ParamPackage new_input; | 138 | Common::ParamPackage new_input; |
| 140 | new_input.Set("engine", data.engine); | 139 | new_input.Set("engine", data.engine); |
| 141 | if (data.pad.guid != Common::UUID{}) { | 140 | if (data.pad.guid.IsValid()) { |
| 142 | new_input.Set("guid", data.pad.guid.Format()); | 141 | new_input.Set("guid", data.pad.guid.Format()); |
| 143 | } | 142 | } |
| 144 | new_input.Set("port", static_cast<int>(data.pad.port)); | 143 | new_input.Set("port", static_cast<int>(data.pad.port)); |
diff --git a/src/input_common/input_mapping.h b/src/input_common/input_mapping.h index 93564b5f8..e0dfbc7ad 100644 --- a/src/input_common/input_mapping.h +++ b/src/input_common/input_mapping.h | |||
| @@ -3,8 +3,14 @@ | |||
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | |||
| 7 | #include "common/param_package.h" | ||
| 6 | #include "common/threadsafe_queue.h" | 8 | #include "common/threadsafe_queue.h" |
| 7 | 9 | ||
| 10 | namespace InputCommon::Polling { | ||
| 11 | enum class InputType; | ||
| 12 | } | ||
| 13 | |||
| 8 | namespace InputCommon { | 14 | namespace InputCommon { |
| 9 | class InputEngine; | 15 | class InputEngine; |
| 10 | struct MappingData; | 16 | struct MappingData; |
| @@ -20,7 +26,7 @@ public: | |||
| 20 | void BeginMapping(Polling::InputType type); | 26 | void BeginMapping(Polling::InputType type); |
| 21 | 27 | ||
| 22 | /// Returns an input event with mapping information from the input_queue | 28 | /// Returns an input event with mapping information from the input_queue |
| 23 | [[nodiscard]] const Common::ParamPackage GetNextInput(); | 29 | [[nodiscard]] Common::ParamPackage GetNextInput(); |
| 24 | 30 | ||
| 25 | /** | 31 | /** |
| 26 | * Registers mapping input data from the driver | 32 | * Registers mapping input data from the driver |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 7b370335f..2f3c0735a 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -504,9 +504,10 @@ private: | |||
| 504 | 504 | ||
| 505 | class InputFromMotion final : public Common::Input::InputDevice { | 505 | class InputFromMotion final : public Common::Input::InputDevice { |
| 506 | public: | 506 | public: |
| 507 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, | 507 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| 508 | InputEngine* input_engine_) | 508 | InputEngine* input_engine_) |
| 509 | : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) { | 509 | : identifier(identifier_), motion_sensor(motion_sensor_), gyro_threshold(gyro_threshold_), |
| 510 | input_engine(input_engine_) { | ||
| 510 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 511 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| 511 | const InputIdentifier input_identifier{ | 512 | const InputIdentifier input_identifier{ |
| 512 | .identifier = identifier, | 513 | .identifier = identifier, |
| @@ -525,8 +526,9 @@ public: | |||
| 525 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); | 526 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); |
| 526 | Common::Input::MotionStatus status{}; | 527 | Common::Input::MotionStatus status{}; |
| 527 | const Common::Input::AnalogProperties properties = { | 528 | const Common::Input::AnalogProperties properties = { |
| 528 | .deadzone = 0.001f, | 529 | .deadzone = 0.0f, |
| 529 | .range = 1.0f, | 530 | .range = 1.0f, |
| 531 | .threshold = gyro_threshold, | ||
| 530 | .offset = 0.0f, | 532 | .offset = 0.0f, |
| 531 | }; | 533 | }; |
| 532 | status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties}; | 534 | status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties}; |
| @@ -551,6 +553,7 @@ public: | |||
| 551 | private: | 553 | private: |
| 552 | const PadIdentifier identifier; | 554 | const PadIdentifier identifier; |
| 553 | const int motion_sensor; | 555 | const int motion_sensor; |
| 556 | const float gyro_threshold; | ||
| 554 | int callback_key; | 557 | int callback_key; |
| 555 | InputEngine* input_engine; | 558 | InputEngine* input_engine; |
| 556 | }; | 559 | }; |
| @@ -873,9 +876,11 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | |||
| 873 | 876 | ||
| 874 | if (params.Has("motion")) { | 877 | if (params.Has("motion")) { |
| 875 | const auto motion_sensor = params.Get("motion", 0); | 878 | const auto motion_sensor = params.Get("motion", 0); |
| 879 | const auto gyro_threshold = params.Get("threshold", 0.007f); | ||
| 876 | input_engine->PreSetController(identifier); | 880 | input_engine->PreSetController(identifier); |
| 877 | input_engine->PreSetMotion(identifier, motion_sensor); | 881 | input_engine->PreSetMotion(identifier, motion_sensor); |
| 878 | return std::make_unique<InputFromMotion>(identifier, motion_sensor, input_engine.get()); | 882 | return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold, |
| 883 | input_engine.get()); | ||
| 879 | } | 884 | } |
| 880 | 885 | ||
| 881 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); | 886 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 940744c5f..a4d7ed645 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -27,7 +27,7 @@ namespace InputCommon { | |||
| 27 | struct InputSubsystem::Impl { | 27 | struct InputSubsystem::Impl { |
| 28 | void Initialize() { | 28 | void Initialize() { |
| 29 | mapping_factory = std::make_shared<MappingFactory>(); | 29 | mapping_factory = std::make_shared<MappingFactory>(); |
| 30 | MappingCallback mapping_callback{[this](MappingData data) { RegisterInput(data); }}; | 30 | MappingCallback mapping_callback{[this](const MappingData& data) { RegisterInput(data); }}; |
| 31 | 31 | ||
| 32 | keyboard = std::make_shared<Keyboard>("keyboard"); | 32 | keyboard = std::make_shared<Keyboard>("keyboard"); |
| 33 | keyboard->SetMappingCallback(mapping_callback); | 33 | keyboard->SetMappingCallback(mapping_callback); |
| @@ -284,7 +284,7 @@ struct InputSubsystem::Impl { | |||
| 284 | #endif | 284 | #endif |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | void RegisterInput(MappingData data) { | 287 | void RegisterInput(const MappingData& data) { |
| 288 | mapping_factory->RegisterInput(data); | 288 | mapping_factory->RegisterInput(data); |
| 289 | } | 289 | } |
| 290 | 290 | ||
| @@ -394,7 +394,7 @@ void InputSubsystem::BeginMapping(Polling::InputType type) { | |||
| 394 | impl->mapping_factory->BeginMapping(type); | 394 | impl->mapping_factory->BeginMapping(type); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | const Common::ParamPackage InputSubsystem::GetNextInput() const { | 397 | Common::ParamPackage InputSubsystem::GetNextInput() const { |
| 398 | return impl->mapping_factory->GetNextInput(); | 398 | return impl->mapping_factory->GetNextInput(); |
| 399 | } | 399 | } |
| 400 | 400 | ||
diff --git a/src/input_common/main.h b/src/input_common/main.h index c6f97f691..baf107e0f 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -126,7 +126,7 @@ public: | |||
| 126 | void BeginMapping(Polling::InputType type); | 126 | void BeginMapping(Polling::InputType type); |
| 127 | 127 | ||
| 128 | /// Returns an input event with mapping information. | 128 | /// Returns an input event with mapping information. |
| 129 | [[nodiscard]] const Common::ParamPackage GetNextInput() const; | 129 | [[nodiscard]] Common::ParamPackage GetNextInput() const; |
| 130 | 130 | ||
| 131 | /// Stop polling from all backends. | 131 | /// Stop polling from all backends. |
| 132 | void StopMapping() const; | 132 | void StopMapping() const; |