summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/sdl_driver.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers/sdl_driver.h')
-rw-r--r--src/input_common/drivers/sdl_driver.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index dcd0d1e64..0846fbb50 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -12,6 +12,7 @@
12#include <SDL.h> 12#include <SDL.h>
13 13
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/threadsafe_queue.h"
15#include "input_common/input_engine.h" 16#include "input_common/input_engine.h"
16 17
17union SDL_Event; 18union SDL_Event;
@@ -46,6 +47,7 @@ public:
46 * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so 47 * Check how many identical joysticks (by guid) were connected before the one with sdl_id and so
47 * tie it to a SDLJoystick with the same guid and that port 48 * tie it to a SDLJoystick with the same guid and that port
48 */ 49 */
50 std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const Common::UUID& guid, int port);
49 std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); 51 std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port);
50 52
51 std::vector<Common::ParamPackage> GetInputDevices() const override; 53 std::vector<Common::ParamPackage> GetInputDevices() const override;
@@ -64,24 +66,32 @@ public:
64 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override; 66 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
65 67
66private: 68private:
69 struct VibrationRequest {
70 PadIdentifier identifier;
71 Common::Input::VibrationStatus vibration;
72 };
73
67 void InitJoystick(int joystick_index); 74 void InitJoystick(int joystick_index);
68 void CloseJoystick(SDL_Joystick* sdl_joystick); 75 void CloseJoystick(SDL_Joystick* sdl_joystick);
69 76
70 /// Needs to be called before SDL_QuitSubSystem. 77 /// Needs to be called before SDL_QuitSubSystem.
71 void CloseJoysticks(); 78 void CloseJoysticks();
72 79
73 Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis, 80 /// Takes all vibrations from the queue and sends the command to the controller
74 float value = 0.1f) const; 81 void SendVibrations();
75 Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid, 82
83 Common::ParamPackage BuildAnalogParamPackageForButton(int port, const Common::UUID& guid,
84 s32 axis, float value = 0.1f) const;
85 Common::ParamPackage BuildButtonParamPackageForButton(int port, const Common::UUID& guid,
76 s32 button) const; 86 s32 button) const;
77 87
78 Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, s32 hat, 88 Common::ParamPackage BuildHatParamPackageForButton(int port, const Common::UUID& guid, s32 hat,
79 u8 value) const; 89 u8 value) const;
80 90
81 Common::ParamPackage BuildMotionParam(int port, std::string guid) const; 91 Common::ParamPackage BuildMotionParam(int port, const Common::UUID& guid) const;
82 92
83 Common::ParamPackage BuildParamPackageForBinding( 93 Common::ParamPackage BuildParamPackageForBinding(
84 int port, const std::string& guid, const SDL_GameControllerButtonBind& binding) const; 94 int port, const Common::UUID& guid, const SDL_GameControllerButtonBind& binding) const;
85 95
86 Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x, 96 Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x,
87 int axis_y, float offset_x, 97 int axis_y, float offset_x,
@@ -107,8 +117,11 @@ private:
107 /// Returns true if the button is on the left joycon 117 /// Returns true if the button is on the left joycon
108 bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const; 118 bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const;
109 119
120 /// Queue of vibration request to controllers
121 Common::SPSCQueue<VibrationRequest> vibration_queue;
122
110 /// Map of GUID of a list of corresponding virtual Joysticks 123 /// Map of GUID of a list of corresponding virtual Joysticks
111 std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; 124 std::unordered_map<Common::UUID, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
112 std::mutex joystick_map_mutex; 125 std::mutex joystick_map_mutex;
113 126
114 bool start_thread = false; 127 bool start_thread = false;