core/hid: Add output devices
This commit is contained in:
parent
e14ae06391
commit
06a5ef5874
20 changed files with 313 additions and 145 deletions
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -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<CemuhookUDP::UDPClient> udp_client;
|
||||
std::shared_ptr<InputFactory> udp_client_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<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
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue