input_poller.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. namespace Input {
  5. class InputDevice;
  6. template <typename InputDevice>
  7. class Factory;
  8. }; // namespace Input
  9. namespace InputCommon {
  10. class InputEngine;
  11. class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> {
  12. public:
  13. explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_);
  14. /**
  15. * Creates an output device from the parameters given.
  16. * @param params contains parameters for creating the device:
  17. * - "guid" text string for identifying controllers
  18. * - "port": port of the connected device
  19. * - "pad": slot of the connected controller
  20. * @returns a unique output device with the parameters specified
  21. */
  22. std::unique_ptr<Common::Input::OutputDevice> Create(
  23. const Common::ParamPackage& params) override;
  24. private:
  25. std::shared_ptr<InputEngine> input_engine;
  26. };
  27. /**
  28. * An Input factory. It receives input events and forward them to all input devices it created.
  29. */
  30. class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> {
  31. public:
  32. explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
  33. /**
  34. * Creates an input device from the parameters given. Identifies the type of input to be
  35. * returned if it contains the following parameters:
  36. * - button: Contains "button" or "code"
  37. * - hat_button: Contains "hat"
  38. * - analog: Contains "axis"
  39. * - trigger: Contains "button" and "axis"
  40. * - stick: Contains "axis_x" and "axis_y"
  41. * - motion: Contains "axis_x", "axis_y" and "axis_z"
  42. * - motion: Contains "motion"
  43. * - touch: Contains "button", "axis_x" and "axis_y"
  44. * - battery: Contains "battery"
  45. * - output: Contains "output"
  46. * @param params contains parameters for creating the device:
  47. * - "code": the code of the keyboard key to bind with the input
  48. * - "button": same as "code" but for controller buttons
  49. * - "hat": similar as "button" but it's a group of hat buttons from SDL
  50. * - "axis": the axis number of the axis to bind with the input
  51. * - "motion": the motion number of the motion to bind with the input
  52. * - "axis_x": same as axis but specifying horizontal direction
  53. * - "axis_y": same as axis but specifying vertical direction
  54. * - "axis_z": same as axis but specifying forward direction
  55. * - "battery": Only used as a placeholder to set the input type
  56. * @returns a unique input device with the parameters specified
  57. */
  58. std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
  59. private:
  60. /**
  61. * Creates a button device from the parameters given.
  62. * @param params contains parameters for creating the device:
  63. * - "code": the code of the keyboard key to bind with the input
  64. * - "button": same as "code" but for controller buttons
  65. * - "toggle": press once to enable, press again to disable
  66. * - "inverted": inverts the output of the button
  67. * - "guid": text string for identifying controllers
  68. * - "port": port of the connected device
  69. * - "pad": slot of the connected controller
  70. * @returns a unique input device with the parameters specified
  71. */
  72. std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice(
  73. const Common::ParamPackage& params);
  74. /**
  75. * Creates a hat button device from the parameters given.
  76. * @param params contains parameters for creating the device:
  77. * - "button": the controller hat id to bind with the input
  78. * - "direction": the direction id to be detected
  79. * - "toggle": press once to enable, press again to disable
  80. * - "inverted": inverts the output of the button
  81. * - "guid": text string for identifying controllers
  82. * - "port": port of the connected device
  83. * - "pad": slot of the connected controller
  84. * @returns a unique input device with the parameters specified
  85. */
  86. std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice(
  87. const Common::ParamPackage& params);
  88. /**
  89. * Creates a stick device from the parameters given.
  90. * @param params contains parameters for creating the device:
  91. * - "axis_x": the controller horizontal axis id to bind with the input
  92. * - "axis_y": the controller vertical axis id to bind with the input
  93. * - "deadzone": the minimum required value to be detected
  94. * - "range": the maximum value required to reach 100%
  95. * - "threshold": the minimum required value to considered pressed
  96. * - "offset_x": the amount of offset in the x axis
  97. * - "offset_y": the amount of offset in the y axis
  98. * - "invert_x": inverts the sign of the horizontal axis
  99. * - "invert_y": inverts the sign of the vertical axis
  100. * - "guid": text string for identifying controllers
  101. * - "port": port of the connected device
  102. * - "pad": slot of the connected controller
  103. * @returns a unique input device with the parameters specified
  104. */
  105. std::unique_ptr<Common::Input::InputDevice> CreateStickDevice(
  106. const Common::ParamPackage& params);
  107. /**
  108. * Creates an analog device from the parameters given.
  109. * @param params contains parameters for creating the device:
  110. * - "axis": the controller axis id to bind with the input
  111. * - "deadzone": the minimum required value to be detected
  112. * - "range": the maximum value required to reach 100%
  113. * - "threshold": the minimum required value to considered pressed
  114. * - "offset": the amount of offset in the axis
  115. * - "invert": inverts the sign of the axis
  116. * - "guid": text string for identifying controllers
  117. * - "port": port of the connected device
  118. * - "pad": slot of the connected controller
  119. * @returns a unique input device with the parameters specified
  120. */
  121. std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice(
  122. const Common::ParamPackage& params);
  123. /**
  124. * Creates a trigger device from the parameters given.
  125. * @param params contains parameters for creating the device:
  126. * - "button": the controller hat id to bind with the input
  127. * - "direction": the direction id to be detected
  128. * - "toggle": press once to enable, press again to disable
  129. * - "inverted": inverts the output of the button
  130. * - "axis": the controller axis id to bind with the input
  131. * - "deadzone": the minimum required value to be detected
  132. * - "range": the maximum value required to reach 100%
  133. * - "threshold": the minimum required value to considered pressed
  134. * - "offset": the amount of offset in the axis
  135. * - "invert": inverts the sign of the axis
  136. * - "guid": text string for identifying controllers
  137. * - "port": port of the connected device
  138. * - "pad": slot of the connected controller
  139. * @returns a unique input device with the parameters specified
  140. */
  141. std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice(
  142. const Common::ParamPackage& params);
  143. /**
  144. * Creates a touch device from the parameters given.
  145. * @param params contains parameters for creating the device:
  146. * - "button": the controller hat id to bind with the input
  147. * - "direction": the direction id to be detected
  148. * - "toggle": press once to enable, press again to disable
  149. * - "inverted": inverts the output of the button
  150. * - "axis_x": the controller horizontal axis id to bind with the input
  151. * - "axis_y": the controller vertical axis id to bind with the input
  152. * - "deadzone": the minimum required value to be detected
  153. * - "range": the maximum value required to reach 100%
  154. * - "threshold": the minimum required value to considered pressed
  155. * - "offset_x": the amount of offset in the x axis
  156. * - "offset_y": the amount of offset in the y axis
  157. * - "invert_x": inverts the sign of the horizontal axis
  158. * - "invert_y": inverts the sign of the vertical axis
  159. * - "guid": text string for identifying controllers
  160. * - "port": port of the connected device
  161. * - "pad": slot of the connected controller
  162. * @returns a unique input device with the parameters specified
  163. */
  164. std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice(
  165. const Common::ParamPackage& params);
  166. /**
  167. * Creates a battery device from the parameters given.
  168. * @param params contains parameters for creating the device:
  169. * - "guid": text string for identifying controllers
  170. * - "port": port of the connected device
  171. * - "pad": slot of the connected controller
  172. * @returns a unique input device with the parameters specified
  173. */
  174. std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice(
  175. const Common::ParamPackage& params);
  176. /**
  177. * Creates a color device from the parameters given.
  178. * @param params contains parameters for creating the device:
  179. * - "guid": text string for identifying controllers
  180. * - "port": port of the connected device
  181. * - "pad": slot of the connected controller
  182. * @returns a unique input device with the parameters specified
  183. */
  184. std::unique_ptr<Common::Input::InputDevice> CreateColorDevice(
  185. const Common::ParamPackage& params);
  186. /**
  187. * Creates a motion device from the parameters given.
  188. * @param params contains parameters for creating the device:
  189. * - "axis_x": the controller horizontal axis id to bind with the input
  190. * - "axis_y": the controller vertical axis id to bind with the input
  191. * - "axis_z": the controller forward axis id to bind with the input
  192. * - "deadzone": the minimum required value to be detected
  193. * - "range": the maximum value required to reach 100%
  194. * - "offset_x": the amount of offset in the x axis
  195. * - "offset_y": the amount of offset in the y axis
  196. * - "offset_z": the amount of offset in the z axis
  197. * - "invert_x": inverts the sign of the horizontal axis
  198. * - "invert_y": inverts the sign of the vertical axis
  199. * - "invert_z": inverts the sign of the forward axis
  200. * - "guid": text string for identifying controllers
  201. * - "port": port of the connected device
  202. * - "pad": slot of the connected controller
  203. * @returns a unique input device with the parameters specified
  204. */
  205. std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
  206. /**
  207. * Creates a camera device from the parameters given.
  208. * @param params contains parameters for creating the device:
  209. * - "guid": text string for identifying controllers
  210. * - "port": port of the connected device
  211. * - "pad": slot of the connected controller
  212. * @returns a unique input device with the parameters specified
  213. */
  214. std::unique_ptr<Common::Input::InputDevice> CreateCameraDevice(
  215. const Common::ParamPackage& params);
  216. /**
  217. * Creates a nfc device from the parameters given.
  218. * @param params contains parameters for creating the device:
  219. * - "guid": text string for identifying controllers
  220. * - "port": port of the connected device
  221. * - "pad": slot of the connected controller
  222. * @returns a unique input device with the parameters specified
  223. */
  224. std::unique_ptr<Common::Input::InputDevice> CreateNfcDevice(const Common::ParamPackage& params);
  225. std::shared_ptr<InputEngine> input_engine;
  226. };
  227. } // namespace InputCommon