From 854c933716f0f5e1dbf62157c5a76e65213b30b2 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 20 Sep 2021 16:41:15 -0500 Subject: input_common: Create input poller and mapping --- src/input_common/input_poller.h | 189 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/input_common/input_poller.h (limited to 'src/input_common/input_poller.h') diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h new file mode 100644 index 000000000..3c1e5b541 --- /dev/null +++ b/src/input_common/input_poller.h @@ -0,0 +1,189 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included + +#pragma once + +namespace Input { +class InputDevice; + +template +class Factory; +}; // namespace Input + +namespace InputCommon { +class InputEngine; +/** + * An Input factory. It receives input events and forward them to all input devices it created. + */ +class InputFactory final : public Input::Factory { +public: + explicit InputFactory(std::shared_ptr input_engine_); + + /** + * Creates a 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" + * - analog: Contains "axis" + * - trigger: Contains "button" and "axis" + * - stick: Contains "axis_x" and "axis_y" + * - motion: Contains "axis_x", "axis_y" and "axis_z" + * - motion: Contains "motion" + * - touch: Contains "button", "axis_x" and "axis_y" + * - battery: Contains "battery" + * @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 + * @param - "hat": similar as "button" but it's a group of hat buttons from SDL + * @param - "axis": the axis number of the axis to bind with the input + * @param - "motion": the motion number of the motion to bind with the input + * @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 + * @return an unique input device with the parameters specified + */ + std::unique_ptr Create(const Common::ParamPackage& params) override; + +private: + /** + * Creates a button device from the parameters given. + * @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 + * @param - "toggle": press once to enable, press again to disable + * @param - "inverted": inverts the output of the button + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateButtonDevice(const Common::ParamPackage& params); + + /** + * Creates a hat button device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "button": the controller hat id to bind with the input + * @param - "direction": the direction id to be detected + * @param - "toggle": press once to enable, press again to disable + * @param - "inverted": inverts the output of the button + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateHatButtonDevice(const Common::ParamPackage& params); + + /** + * Creates a stick device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "axis_x": the controller horizontal axis id to bind with the input + * @param - "axis_y": the controller vertical axis id to bind with the input + * @param - "deadzone": the mimimum required value to be detected + * @param - "range": the maximum value required to reach 100% + * @param - "threshold": the mimimum required value to considered pressed + * @param - "offset_x": the amount of offset in the x axis + * @param - "offset_y": the amount of offset in the y axis + * @param - "invert_x": inverts the sign of the horizontal axis + * @param - "invert_y": inverts the sign of the vertical axis + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateStickDevice(const Common::ParamPackage& params); + + /** + * Creates an analog device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "axis": the controller axis id to bind with the input + * @param - "deadzone": the mimimum required value to be detected + * @param - "range": the maximum value required to reach 100% + * @param - "threshold": the mimimum required value to considered pressed + * @param - "offset": the amount of offset in the axis + * @param - "invert": inverts the sign of the axis + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateAnalogDevice(const Common::ParamPackage& params); + + /** + * Creates a trigger device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "button": the controller hat id to bind with the input + * @param - "direction": the direction id to be detected + * @param - "toggle": press once to enable, press again to disable + * @param - "inverted": inverts the output of the button + * @param - "axis": the controller axis id to bind with the input + * @param - "deadzone": the mimimum required value to be detected + * @param - "range": the maximum value required to reach 100% + * @param - "threshold": the mimimum required value to considered pressed + * @param - "offset": the amount of offset in the axis + * @param - "invert": inverts the sign of the axis + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateTriggerDevice(const Common::ParamPackage& params); + + /** + * Creates a touch device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "button": the controller hat id to bind with the input + * @param - "direction": the direction id to be detected + * @param - "toggle": press once to enable, press again to disable + * @param - "inverted": inverts the output of the button + * @param - "axis_x": the controller horizontal axis id to bind with the input + * @param - "axis_y": the controller vertical axis id to bind with the input + * @param - "deadzone": the mimimum required value to be detected + * @param - "range": the maximum value required to reach 100% + * @param - "threshold": the mimimum required value to considered pressed + * @param - "offset_x": the amount of offset in the x axis + * @param - "offset_y": the amount of offset in the y axis + * @param - "invert_x": inverts the sign of the horizontal axis + * @param - "invert_y": inverts the sign of the vertical axis + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateTouchDevice(const Common::ParamPackage& params); + + /** + * Creates a battery 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 input device with the parameters specified + */ + std::unique_ptr CreateBatteryDevice(const Common::ParamPackage& params); + + /** + * Creates a motion device from the parameters given. + * @param params contains parameters for creating the device: + * @param - "axis_x": the controller horizontal axis id to bind with the input + * @param - "axis_y": the controller vertical axis id to bind with the input + * @param - "axis_z": the controller fordward axis id to bind with the input + * @param - "deadzone": the mimimum required value to be detected + * @param - "range": the maximum value required to reach 100% + * @param - "offset_x": the amount of offset in the x axis + * @param - "offset_y": the amount of offset in the y axis + * @param - "offset_z": the amount of offset in the z axis + * @param - "invert_x": inverts the sign of the horizontal axis + * @param - "invert_y": inverts the sign of the vertical axis + * @param - "invert_z": inverts the sign of the fordward axis + * @param - "guid": text string for identifing controllers + * @param - "port": port of the connected device + * @param - "pad": slot of the connected controller + * @return an unique input device with the parameters specified + */ + std::unique_ptr CreateMotionDevice(Common::ParamPackage params); + + std::shared_ptr input_engine; +}; +} // namespace InputCommon -- cgit v1.2.3 From 06a5ef5874144a70e30e577a83ba68d1dad79e78 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 11 Oct 2021 00:43:11 -0500 Subject: core/hid: Add output devices --- src/input_common/input_poller.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/input_common/input_poller.h') 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 { +public: + explicit OutputFactory(std::shared_ptr 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 Create( + const Common::ParamPackage& params) override; + +private: + std::shared_ptr input_engine; +}; + class InputFactory final : public Input::Factory { public: explicit InputFactory(std::shared_ptr 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 Create(const Common::ParamPackage& params) override; + std::unique_ptr Create( + const Common::ParamPackage& params) override; private: /** -- cgit v1.2.3 From e0da5c1bbcdf85676f968b63c8ae2587f0464193 Mon Sep 17 00:00:00 2001 From: german77 Date: Fri, 15 Oct 2021 19:07:47 -0500 Subject: kraken: Fix errors from rebase and format files --- src/input_common/input_poller.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/input_common/input_poller.h') diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h index 16cade5fa..1357e104b 100644 --- a/src/input_common/input_poller.h +++ b/src/input_common/input_poller.h @@ -29,8 +29,7 @@ public: * @param - "pad": slot of the connected controller * @return an unique ouput device with the parameters specified */ - std::unique_ptr Create( - const Common::ParamPackage& params) override; + std::unique_ptr Create(const Common::ParamPackage& params) override; private: std::shared_ptr input_engine; @@ -41,8 +40,8 @@ public: explicit InputFactory(std::shared_ptr input_engine_); /** - * Creates an input device from the parameters given. Identifies the type of input to be returned - * if it contains the following parameters: + * 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" * - analog: Contains "axis" @@ -65,8 +64,7 @@ public: * @param - "battery": Only used as a placeholder to set the input type * @return an unique input device with the parameters specified */ - std::unique_ptr Create( - const Common::ParamPackage& params) override; + std::unique_ptr Create(const Common::ParamPackage& params) override; private: /** -- cgit v1.2.3 From 2b1b0c2a30e242b08ec120e09803ec54d5445703 Mon Sep 17 00:00:00 2001 From: german77 Date: Sat, 30 Oct 2021 22:23:10 -0500 Subject: kraken: Address comments from review start lion review --- src/input_common/input_poller.h | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/input_common/input_poller.h') diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h index 1357e104b..573f09fde 100644 --- a/src/input_common/input_poller.h +++ b/src/input_common/input_poller.h @@ -17,7 +17,7 @@ class InputEngine; * An Input factory. It receives input events and forward them to all input devices it created. */ -class OutputFactory final : public Input::Factory { +class OutputFactory final : public Common::Input::Factory { public: explicit OutputFactory(std::shared_ptr input_engine_); @@ -29,13 +29,14 @@ public: * @param - "pad": slot of the connected controller * @return an unique ouput device with the parameters specified */ - std::unique_ptr Create(const Common::ParamPackage& params) override; + std::unique_ptr Create( + const Common::ParamPackage& params) override; private: std::shared_ptr input_engine; }; -class InputFactory final : public Input::Factory { +class InputFactory final : public Common::Input::Factory { public: explicit InputFactory(std::shared_ptr input_engine_); @@ -64,7 +65,7 @@ public: * @param - "battery": Only used as a placeholder to set the input type * @return an unique input device with the parameters specified */ - std::unique_ptr Create(const Common::ParamPackage& params) override; + std::unique_ptr Create(const Common::ParamPackage& params) override; private: /** @@ -79,7 +80,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateButtonDevice(const Common::ParamPackage& params); + std::unique_ptr CreateButtonDevice( + const Common::ParamPackage& params); /** * Creates a hat button device from the parameters given. @@ -93,7 +95,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateHatButtonDevice(const Common::ParamPackage& params); + std::unique_ptr CreateHatButtonDevice( + const Common::ParamPackage& params); /** * Creates a stick device from the parameters given. @@ -112,7 +115,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateStickDevice(const Common::ParamPackage& params); + std::unique_ptr CreateStickDevice( + const Common::ParamPackage& params); /** * Creates an analog device from the parameters given. @@ -128,7 +132,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateAnalogDevice(const Common::ParamPackage& params); + std::unique_ptr CreateAnalogDevice( + const Common::ParamPackage& params); /** * Creates a trigger device from the parameters given. @@ -148,7 +153,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateTriggerDevice(const Common::ParamPackage& params); + std::unique_ptr CreateTriggerDevice( + const Common::ParamPackage& params); /** * Creates a touch device from the parameters given. @@ -171,7 +177,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateTouchDevice(const Common::ParamPackage& params); + std::unique_ptr CreateTouchDevice( + const Common::ParamPackage& params); /** * Creates a battery device from the parameters given. @@ -181,7 +188,8 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateBatteryDevice(const Common::ParamPackage& params); + std::unique_ptr CreateBatteryDevice( + const Common::ParamPackage& params); /** * Creates a motion device from the parameters given. @@ -202,7 +210,7 @@ private: * @param - "pad": slot of the connected controller * @return an unique input device with the parameters specified */ - std::unique_ptr CreateMotionDevice(Common::ParamPackage params); + std::unique_ptr CreateMotionDevice(Common::ParamPackage params); std::shared_ptr input_engine; }; -- cgit v1.2.3