summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-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) {
return true;
}
-bool GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
+Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
const auto processed_amplitude =
static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
pads[identifier.port].rumble_amplitude = processed_amplitude;
- return rumble_enabled;
+
+ if (!rumble_enabled) {
+ return Input::VibrationError::Disabled;
+ }
+ return Input::VibrationError::None;
}
void 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:
explicit GCAdapter(const std::string input_engine_);
~GCAdapter();
- bool SetRumble(const PadIdentifier& identifier,
+ Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override;
/// 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 {
}
return devices;
}
-bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::VibrationStatus vibration) {
+Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
+ const Input::VibrationStatus vibration) {
const auto joystick =
GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port));
const auto process_amplitude = [](f32 amplitude) {
@@ -519,7 +520,10 @@ bool SDLDriver::SetRumble(const PadIdentifier& identifier, const Input::Vibratio
.high_frequency = vibration.high_frequency,
};
- return joystick->RumblePlay(new_vibration);
+ if (!joystick->RumblePlay(new_vibration)) {
+ return Input::VibrationError::Unknown;
+ }
+ return Input::VibrationError::None;
}
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
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:
std::string GetHatButtonName(u8 direction_value) const override;
u8 GetHatButtonId(const std::string direction_name) const override;
- bool SetRumble(const PadIdentifier& identifier,
+ Input::VibrationError SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) override;
private:
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:
std::chrono::time_point<std::chrono::steady_clock> last_update;
};
-std::unique_ptr<Input::InputDevice> StickFromButton::Create(const Common::ParamPackage& params) {
+std::unique_ptr<Input::InputDevice> StickFromButton::Create(
+ const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine));
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:
* - "modifier": a serialized ParamPackage for creating a button device as the modifier
* - "modifier_scale": a float for the multiplier the modifier gives to the position
*/
- std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override;
+ std::unique_ptr<Input::InputDevice> Create(
+ const Common::ParamPackage& params) override;
};
} // 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:
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
};
-std::unique_ptr<Input::InputDevice> TouchFromButton::Create(const Common::ParamPackage& params) {
+
+std::unique_ptr<Input::InputDevice> TouchFromButton::Create(
+ const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button =
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:
// Disable configuring mode for mapping
void EndConfiguration();
- // Sets rumble to a controller
- virtual bool SetRumble([[maybe_unused]] const PadIdentifier& identifier,
- [[maybe_unused]] const Input::VibrationStatus vibration) {
- return false;
- }
-
// Sets a led pattern for a controller
virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::LedStatus led_status) {
return;
}
+ // Sets rumble to a controller
+ virtual Input::VibrationError SetRumble([[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::VibrationStatus vibration) {
+ return Input::VibrationError::NotSupported;
+ }
+
+ // Sets polling mode to a controller
+ virtual Input::PollingError SetPollingMode([[maybe_unused]] const PadIdentifier& identifier,
+ [[maybe_unused]] const Input::PollingMode vibration) {
+ return Input::PollingError::NotSupported;
+ }
+
// Returns the engine name
[[nodiscard]] const std::string& GetEngineName() const;
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:
InputEngine* input_engine;
};
+class OutputFromIdentifier final : public Input::OutputDevice {
+public:
+ explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
+ : identifier(identifier_), input_engine(input_engine_) {}
+
+ virtual void SetLED( Input::LedStatus led_status) {
+ input_engine->SetLeds(identifier, led_status);
+ }
+
+ virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) {
+ return input_engine->SetRumble(identifier, vibration_status);
+ }
+
+ virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) {
+ return input_engine->SetPollingMode(identifier, polling_mode);
+ }
+
+private:
+ const PadIdentifier identifier;
+ InputEngine* input_engine;
+};
+
std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice(
const Common::ParamPackage& params) {
const PadIdentifier identifier = {
@@ -825,7 +847,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_)
: input_engine(std::move(input_engine_)) {}
-std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPackage& params) {
+std::unique_ptr<Input::InputDevice> InputFactory::Create(
+ const Common::ParamPackage& params) {
if (params.Has("button") && params.Has("axis")) {
return CreateTriggerDevice(params);
}
@@ -857,4 +880,19 @@ std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPack
return std::make_unique<DummyInput>();
}
+OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_)
+ : input_engine(std::move(input_engine_)) {}
+
+std::unique_ptr<Input::OutputDevice> OutputFactory::Create(
+ const Common::ParamPackage& params) {
+ const PadIdentifier identifier = {
+ .guid = Common::UUID{params.Get("guid", "")},
+ .port = static_cast<std::size_t>(params.Get("port", 0)),
+ .pad = static_cast<std::size_t>(params.Get("pad", 0)),
+ };
+
+ input_engine->PreSetController(identifier);
+ return std::make_unique<OutputFromIdentifier>(identifier, input_engine.get());
+}
+
} // 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;
/**
* An Input factory. It receives input events and forward them to all input devices it created.
*/
+
+class OutputFactory final : public Input::Factory<Input::OutputDevice> {
+public:
+ explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_);
+
+ /**
+ * Creates an output device from the parameters given.
+ * @param params contains parameters for creating the device:
+ * @param - "guid": text string for identifing controllers
+ * @param - "port": port of the connected device
+ * @param - "pad": slot of the connected controller
+ * @return an unique ouput device with the parameters specified
+ */
+ std::unique_ptr<Input::OutputDevice> Create(
+ const Common::ParamPackage& params) override;
+
+private:
+ std::shared_ptr<InputEngine> input_engine;
+};
+
class InputFactory final : public Input::Factory<Input::InputDevice> {
public:
explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
/**
- * Creates a input device from the parameters given. Identifies the type of input to be returned
+ * Creates an input device from the parameters given. Identifies the type of input to be returned
* if it contains the following parameters:
* - button: Contains "button" or "code"
* - hat_button: Contains "hat"
@@ -32,6 +52,7 @@ public:
* - motion: Contains "motion"
* - touch: Contains "button", "axis_x" and "axis_y"
* - battery: Contains "battery"
+ * - output: Contains "output"
* @param params contains parameters for creating the device:
* @param - "code": the code of the keyboard key to bind with the input
* @param - "button": same as "code" but for controller buttons
@@ -41,10 +62,11 @@ public:
* @param - "axis_x": same as axis but specifing horizontal direction
* @param - "axis_y": same as axis but specifing vertical direction
* @param - "axis_z": same as axis but specifing forward direction
- * @param - "battery": Only used as a placeholder to set the input type
+ * @param - "battery": Only used as a placeholder to set the input type
* @return an unique input device with the parameters specified
*/
- std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override;
+ std::unique_ptr<Input::InputDevice> Create(
+ const Common::ParamPackage& params) override;
private:
/**
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 {
gcadapter = std::make_shared<GCAdapter>("gcpad");
gcadapter->SetMappingCallback(mapping_callback);
- gcadapter_factory = std::make_shared<InputFactory>(gcadapter);
- Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), gcadapter_factory);
+ gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter);
+ gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter);
+ Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), gcadapter_input_factory);
+ Input::RegisterFactory<Input::OutputDevice>(gcadapter->GetEngineName(), gcadapter_output_factory);
udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp");
udp_client->SetMappingCallback(mapping_callback);
@@ -62,8 +64,10 @@ struct InputSubsystem::Impl {
#ifdef HAVE_SDL2
sdl = std::make_shared<SDLDriver>("sdl");
sdl->SetMappingCallback(mapping_callback);
- sdl_factory = std::make_shared<InputFactory>(sdl);
- Input::RegisterFactory<Input::InputDevice>(sdl->GetEngineName(), sdl_factory);
+ sdl_input_factory = std::make_shared<InputFactory>(sdl);
+ sdl_output_factory = std::make_shared<OutputFactory>(sdl);
+ Input::RegisterFactory<Input::InputDevice>(sdl->GetEngineName(), sdl_input_factory);
+ Input::RegisterFactory<Input::OutputDevice>(sdl->GetEngineName(), sdl_output_factory);
#endif
Input::RegisterFactory<Input::InputDevice>("touch_from_button",
@@ -247,21 +251,27 @@ struct InputSubsystem::Impl {
}
std::shared_ptr<MappingFactory> mapping_factory;
+
std::shared_ptr<Keyboard> keyboard;
- std::shared_ptr<InputFactory> keyboard_factory;
std::shared_ptr<Mouse> mouse;
- std::shared_ptr<InputFactory> mouse_factory;
std::shared_ptr<GCAdapter> gcadapter;
- std::shared_ptr<InputFactory> gcadapter_factory;
std::shared_ptr<TouchScreen> touch_screen;
- std::shared_ptr<InputFactory> touch_screen_factory;
+ std::shared_ptr<TasInput::Tas> tas_input;
std::shared_ptr<CemuhookUDP::UDPClient> udp_client;
+
+ std::shared_ptr<InputFactory> keyboard_factory;
+ std::shared_ptr<InputFactory> mouse_factory;
+ std::shared_ptr<InputFactory> gcadapter_input_factory;
+ std::shared_ptr<InputFactory> touch_screen_factory;
std::shared_ptr<InputFactory> udp_client_factory;
- std::shared_ptr<TasInput::Tas> tas_input;
std::shared_ptr<InputFactory> tas_input_factory;
+
+ std::shared_ptr<OutputFactory> gcadapter_output_factory;
+
#ifdef HAVE_SDL2
std::shared_ptr<SDLDriver> sdl;
- std::shared_ptr<InputFactory> sdl_factory;
+ std::shared_ptr<InputFactory> sdl_input_factory;
+ std::shared_ptr<OutputFactory> sdl_output_factory;
#endif
};