summaryrefslogtreecommitdiff
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/gc_adapter.cpp8
-rw-r--r--src/input_common/drivers/gc_adapter.h2
-rw-r--r--src/input_common/drivers/sdl_driver.cpp8
-rw-r--r--src/input_common/drivers/sdl_driver.h2
-rw-r--r--src/input_common/helpers/stick_from_buttons.cpp3
-rw-r--r--src/input_common/helpers/stick_from_buttons.h3
-rw-r--r--src/input_common/helpers/touch_from_buttons.cpp4
-rw-r--r--src/input_common/input_engine.h18
-rw-r--r--src/input_common/input_poller.cpp40
-rw-r--r--src/input_common/input_poller.h28
-rw-r--r--src/input_common/main.cpp30
11 files changed, 117 insertions, 29 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp
index 6721ba4f7..2aa5a16a6 100644
--- a/src/input_common/drivers/gc_adapter.cpp
+++ b/src/input_common/drivers/gc_adapter.cpp
@@ -322,13 +322,17 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
322 return true; 322 return true;
323} 323}
324 324
325bool GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) { 325Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
326 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f; 326 const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
327 const auto processed_amplitude = 327 const auto processed_amplitude =
328 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); 328 static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
329 329
330 pads[identifier.port].rumble_amplitude = processed_amplitude; 330 pads[identifier.port].rumble_amplitude = processed_amplitude;
331 return rumble_enabled; 331
332 if (!rumble_enabled) {
333 return Input::VibrationError::Disabled;
334 }
335 return Input::VibrationError::None;
332} 336}
333 337
334void GCAdapter::UpdateVibrations() { 338void GCAdapter::UpdateVibrations() {
diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h
index c0bf1ed7a..dd23dd9f3 100644
--- a/src/input_common/drivers/gc_adapter.h
+++ b/src/input_common/drivers/gc_adapter.h
@@ -24,7 +24,7 @@ public:
24 explicit GCAdapter(const std::string input_engine_); 24 explicit GCAdapter(const std::string input_engine_);
25 ~GCAdapter(); 25 ~GCAdapter();
26 26
27 bool SetRumble(const PadIdentifier& identifier, 27 Input::VibrationError SetRumble(const PadIdentifier& identifier,
28 const Input::VibrationStatus vibration) override; 28 const Input::VibrationStatus vibration) override;
29 29
30 /// Used for automapping features 30 /// Used for automapping features
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index efb4a2106..f7f03c5f2 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -506,7 +506,8 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
506 } 506 }
507 return devices; 507 return devices;
508} 508}
509bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) { 509Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
510 const Input::VibrationStatus vibration) {
510 const auto joystick = 511 const auto joystick =
511 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); 512 GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port));
512 const auto process_amplitude = [](f32 amplitude) { 513 const auto process_amplitude = [](f32 amplitude) {
@@ -519,7 +520,10 @@ bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::Vibratio
519 .high_frequency = vibration.high_frequency, 520 .high_frequency = vibration.high_frequency,
520 }; 521 };
521 522
522 return joystick->RumblePlay(new_vibration); 523 if (!joystick->RumblePlay(new_vibration)) {
524 return Input::VibrationError::Unknown;
525 }
526 return Input::VibrationError::None;
523} 527}
524Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, 528Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
525 s32 axis, float value) const { 529 s32 axis, float value) const {
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index d8d350184..f66b33c77 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -58,7 +58,7 @@ 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 SetRumble(const PadIdentifier& identifier, 61 Input::VibrationError SetRumble(const PadIdentifier& identifier,
62 const Input::VibrationStatus vibration) override; 62 const Input::VibrationStatus vibration) override;
63 63
64private: 64private:
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp
index 38f150746..89ba4aeb1 100644
--- a/src/input_common/helpers/stick_from_buttons.cpp
+++ b/src/input_common/helpers/stick_from_buttons.cpp
@@ -251,7 +251,8 @@ private:
251 std::chrono::time_point<std::chrono::steady_clock> last_update; 251 std::chrono::time_point<std::chrono::steady_clock> last_update;
252}; 252};
253 253
254std::unique_ptr<Input::InputDevice> StickFromButton::Create(const Common::ParamPackage& params) { 254std::unique_ptr<Input::InputDevice> StickFromButton::Create(
255 const Common::ParamPackage& params) {
255 const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); 256 const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
256 auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine)); 257 auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine));
257 auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine)); 258 auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine));
diff --git a/src/input_common/helpers/stick_from_buttons.h b/src/input_common/helpers/stick_from_buttons.h
index 1d6e24c98..87165e022 100644
--- a/src/input_common/helpers/stick_from_buttons.h
+++ b/src/input_common/helpers/stick_from_buttons.h
@@ -25,7 +25,8 @@ public:
25 * - "modifier": a serialized ParamPackage for creating a button device as the modifier 25 * - "modifier": a serialized ParamPackage for creating a button device as the modifier
26 * - "modifier_scale": a float for the multiplier the modifier gives to the position 26 * - "modifier_scale": a float for the multiplier the modifier gives to the position
27 */ 27 */
28 std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; 28 std::unique_ptr<Input::InputDevice> Create(
29 const Common::ParamPackage& params) override;
29}; 30};
30 31
31} // namespace InputCommon 32} // namespace InputCommon
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp
index 2abfaf841..6c9046ffb 100644
--- a/src/input_common/helpers/touch_from_buttons.cpp
+++ b/src/input_common/helpers/touch_from_buttons.cpp
@@ -57,7 +57,9 @@ private:
57 const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; 57 const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
58}; 58};
59 59
60std::unique_ptr<Input::InputDevice> TouchFromButton::Create(const Common::ParamPackage& params) { 60
61std::unique_ptr<Input::InputDevice> TouchFromButton::Create(
62 const Common::ParamPackage& params) {
61 const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); 63 const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
62 auto button = 64 auto button =
63 Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine)); 65 Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine));
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h
index 86a8e00d8..8a953c382 100644
--- a/src/input_common/input_engine.h
+++ b/src/input_common/input_engine.h
@@ -114,18 +114,24 @@ public:
114 // Disable configuring mode for mapping 114 // Disable configuring mode for mapping
115 void EndConfiguration(); 115 void EndConfiguration();
116 116
117 // Sets rumble to a controller
118 virtual bool SetRumble([[maybe_unused]] const PadIdentifier& identifier,
119 [[maybe_unused]] const Input::VibrationStatus vibration) {
120 return false;
121 }
122
123 // Sets a led pattern for a controller 117 // Sets a led pattern for a controller
124 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier, 118 virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
125 [[maybe_unused]] const Input::LedStatus led_status) { 119 [[maybe_unused]] const Input::LedStatus led_status) {
126 return; 120 return;
127 } 121 }
128 122
123 // Sets rumble to a controller
124 virtual Input::VibrationError SetRumble([[maybe_unused]] const PadIdentifier& identifier,
125 [[maybe_unused]] const Input::VibrationStatus vibration) {
126 return Input::VibrationError::NotSupported;
127 }
128
129 // Sets polling mode to a controller
130 virtual Input::PollingError SetPollingMode([[maybe_unused]] const PadIdentifier& identifier,
131 [[maybe_unused]] const Input::PollingMode vibration) {
132 return Input::PollingError::NotSupported;
133 }
134
129 // Returns the engine name 135 // Returns the engine name
130 [[nodiscard]] const std::string& GetEngineName() const; 136 [[nodiscard]] const std::string& GetEngineName() const;
131 137
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index 46a7dd276..781012886 100644
--- a/src/input_common/input_poller.cpp
+++ b/src/input_common/input_poller.cpp
@@ -592,6 +592,28 @@ private:
592 InputEngine* input_engine; 592 InputEngine* input_engine;
593}; 593};
594 594
595class OutputFromIdentifier final : public Input::OutputDevice {
596public:
597 explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
598 : identifier(identifier_), input_engine(input_engine_) {}
599
600 virtual void SetLED( Input::LedStatus led_status) {
601 input_engine->SetLeds(identifier, led_status);
602 }
603
604 virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) {
605 return input_engine->SetRumble(identifier, vibration_status);
606 }
607
608 virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) {
609 return input_engine->SetPollingMode(identifier, polling_mode);
610 }
611
612private:
613 const PadIdentifier identifier;
614 InputEngine* input_engine;
615};
616
595std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice( 617std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice(
596 const Common::ParamPackage& params) { 618 const Common::ParamPackage& params) {
597 const PadIdentifier identifier = { 619 const PadIdentifier identifier = {
@@ -825,7 +847,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
825InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) 847InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_)
826 : input_engine(std::move(input_engine_)) {} 848 : input_engine(std::move(input_engine_)) {}
827 849
828std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPackage& params) { 850std::unique_ptr<Input::InputDevice> InputFactory::Create(
851 const Common::ParamPackage& params) {
829 if (params.Has("button") && params.Has("axis")) { 852 if (params.Has("button") && params.Has("axis")) {
830 return CreateTriggerDevice(params); 853 return CreateTriggerDevice(params);
831 } 854 }
@@ -857,4 +880,19 @@ std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPack
857 return std::make_unique<DummyInput>(); 880 return std::make_unique<DummyInput>();
858} 881}
859 882
883OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_)
884 : input_engine(std::move(input_engine_)) {}
885
886std::unique_ptr<Input::OutputDevice> OutputFactory::Create(
887 const Common::ParamPackage& params) {
888 const PadIdentifier identifier = {
889 .guid = Common::UUID{params.Get("guid", "")},
890 .port = static_cast<std::size_t>(params.Get("port", 0)),
891 .pad = static_cast<std::size_t>(params.Get("pad", 0)),
892 };
893
894 input_engine->PreSetController(identifier);
895 return std::make_unique<OutputFromIdentifier>(identifier, input_engine.get());
896}
897
860} // namespace InputCommon 898} // namespace InputCommon
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h
index 3c1e5b541..16cade5fa 100644
--- a/src/input_common/input_poller.h
+++ b/src/input_common/input_poller.h
@@ -16,12 +16,32 @@ class InputEngine;
16/** 16/**
17 * An Input factory. It receives input events and forward them to all input devices it created. 17 * An Input factory. It receives input events and forward them to all input devices it created.
18 */ 18 */
19
20class OutputFactory final : public Input::Factory<Input::OutputDevice> {
21public:
22 explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_);
23
24 /**
25 * Creates an output device from the parameters given.
26 * @param params contains parameters for creating the device:
27 * @param - "guid": text string for identifing controllers
28 * @param - "port": port of the connected device
29 * @param - "pad": slot of the connected controller
30 * @return an unique ouput device with the parameters specified
31 */
32 std::unique_ptr<Input::OutputDevice> Create(
33 const Common::ParamPackage& params) override;
34
35private:
36 std::shared_ptr<InputEngine> input_engine;
37};
38
19class InputFactory final : public Input::Factory<Input::InputDevice> { 39class InputFactory final : public Input::Factory<Input::InputDevice> {
20public: 40public:
21 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); 41 explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
22 42
23 /** 43 /**
24 * Creates a input device from the parameters given. Identifies the type of input to be returned 44 * Creates an input device from the parameters given. Identifies the type of input to be returned
25 * if it contains the following parameters: 45 * if it contains the following parameters:
26 * - button: Contains "button" or "code" 46 * - button: Contains "button" or "code"
27 * - hat_button: Contains "hat" 47 * - hat_button: Contains "hat"
@@ -32,6 +52,7 @@ public:
32 * - motion: Contains "motion" 52 * - motion: Contains "motion"
33 * - touch: Contains "button", "axis_x" and "axis_y" 53 * - touch: Contains "button", "axis_x" and "axis_y"
34 * - battery: Contains "battery" 54 * - battery: Contains "battery"
55 * - output: Contains "output"
35 * @param params contains parameters for creating the device: 56 * @param params contains parameters for creating the device:
36 * @param - "code": the code of the keyboard key to bind with the input 57 * @param - "code": the code of the keyboard key to bind with the input
37 * @param - "button": same as "code" but for controller buttons 58 * @param - "button": same as "code" but for controller buttons
@@ -41,10 +62,11 @@ public:
41 * @param - "axis_x": same as axis but specifing horizontal direction 62 * @param - "axis_x": same as axis but specifing horizontal direction
42 * @param - "axis_y": same as axis but specifing vertical direction 63 * @param - "axis_y": same as axis but specifing vertical direction
43 * @param - "axis_z": same as axis but specifing forward direction 64 * @param - "axis_z": same as axis but specifing forward direction
44 * @param - "battery": Only used as a placeholder to set the input type 65 * @param - "battery": Only used as a placeholder to set the input type
45 * @return an unique input device with the parameters specified 66 * @return an unique input device with the parameters specified
46 */ 67 */
47 std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; 68 std::unique_ptr<Input::InputDevice> Create(
69 const Common::ParamPackage& params) override;
48 70
49private: 71private:
50 /** 72 /**
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 46ca6b76c..b7fe9cb37 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -46,8 +46,10 @@ struct InputSubsystem::Impl {
46 46
47 gcadapter = std::make_shared<GCAdapter>("gcpad"); 47 gcadapter = std::make_shared<GCAdapter>("gcpad");
48 gcadapter->SetMappingCallback(mapping_callback); 48 gcadapter->SetMappingCallback(mapping_callback);
49 gcadapter_factory = std::make_shared<InputFactory>(gcadapter); 49 gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter);
50 Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), gcadapter_factory); 50 gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter);
51 Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), gcadapter_input_factory);
52 Input::RegisterFactory<Input::OutputDevice>(gcadapter->GetEngineName(), gcadapter_output_factory);
51 53
52 udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); 54 udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp");
53 udp_client->SetMappingCallback(mapping_callback); 55 udp_client->SetMappingCallback(mapping_callback);
@@ -62,8 +64,10 @@ struct InputSubsystem::Impl {
62#ifdef HAVE_SDL2 64#ifdef HAVE_SDL2
63 sdl = std::make_shared<SDLDriver>("sdl"); 65 sdl = std::make_shared<SDLDriver>("sdl");
64 sdl->SetMappingCallback(mapping_callback); 66 sdl->SetMappingCallback(mapping_callback);
65 sdl_factory = std::make_shared<InputFactory>(sdl); 67 sdl_input_factory = std::make_shared<InputFactory>(sdl);
66 Input::RegisterFactory<Input::InputDevice>(sdl->GetEngineName(), sdl_factory); 68 sdl_output_factory = std::make_shared<OutputFactory>(sdl);
69 Input::RegisterFactory<Input::InputDevice>(sdl->GetEngineName(), sdl_input_factory);
70 Input::RegisterFactory<Input::OutputDevice>(sdl->GetEngineName(), sdl_output_factory);
67#endif 71#endif
68 72
69 Input::RegisterFactory<Input::InputDevice>("touch_from_button", 73 Input::RegisterFactory<Input::InputDevice>("touch_from_button",
@@ -247,21 +251,27 @@ struct InputSubsystem::Impl {
247 } 251 }
248 252
249 std::shared_ptr<MappingFactory> mapping_factory; 253 std::shared_ptr<MappingFactory> mapping_factory;
254
250 std::shared_ptr<Keyboard> keyboard; 255 std::shared_ptr<Keyboard> keyboard;
251 std::shared_ptr<InputFactory> keyboard_factory;
252 std::shared_ptr<Mouse> mouse; 256 std::shared_ptr<Mouse> mouse;
253 std::shared_ptr<InputFactory> mouse_factory;
254 std::shared_ptr<GCAdapter> gcadapter; 257 std::shared_ptr<GCAdapter> gcadapter;
255 std::shared_ptr<InputFactory> gcadapter_factory;
256 std::shared_ptr<TouchScreen> touch_screen; 258 std::shared_ptr<TouchScreen> touch_screen;
257 std::shared_ptr<InputFactory> touch_screen_factory; 259 std::shared_ptr<TasInput::Tas> tas_input;
258 std::shared_ptr<CemuhookUDP::UDPClient> udp_client; 260 std::shared_ptr<CemuhookUDP::UDPClient> udp_client;
261
262 std::shared_ptr<InputFactory> keyboard_factory;
263 std::shared_ptr<InputFactory> mouse_factory;
264 std::shared_ptr<InputFactory> gcadapter_input_factory;
265 std::shared_ptr<InputFactory> touch_screen_factory;
259 std::shared_ptr<InputFactory> udp_client_factory; 266 std::shared_ptr<InputFactory> udp_client_factory;
260 std::shared_ptr<TasInput::Tas> tas_input;
261 std::shared_ptr<InputFactory> tas_input_factory; 267 std::shared_ptr<InputFactory> tas_input_factory;
268
269 std::shared_ptr<OutputFactory> gcadapter_output_factory;
270
262#ifdef HAVE_SDL2 271#ifdef HAVE_SDL2
263 std::shared_ptr<SDLDriver> sdl; 272 std::shared_ptr<SDLDriver> sdl;
264 std::shared_ptr<InputFactory> sdl_factory; 273 std::shared_ptr<InputFactory> sdl_input_factory;
274 std::shared_ptr<OutputFactory> sdl_output_factory;
265#endif 275#endif
266}; 276};
267 277