diff options
| author | 2023-10-29 11:25:02 -0400 | |
|---|---|---|
| committer | 2023-10-29 11:25:02 -0400 | |
| commit | 40c97c0549fa5f680f47a7f9d10c536d1cb1fd0d (patch) | |
| tree | a75821894c25e0de0f466e1ca3f78400e8a8a78a | |
| parent | Merge pull request #11843 from liamwhite/sync-process (diff) | |
| parent | input_common: joycon: Move vibrations to a queue (diff) | |
| download | yuzu-40c97c0549fa5f680f47a7f9d10c536d1cb1fd0d.tar.gz yuzu-40c97c0549fa5f680f47a7f9d10c536d1cb1fd0d.tar.xz yuzu-40c97c0549fa5f680f47a7f9d10c536d1cb1fd0d.zip | |
Merge pull request #11852 from german77/async_brr
input_common: joycon: Move vibrations to a queue
| -rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_driver.h | 5 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index cf51f3481..c9f903213 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -139,7 +139,7 @@ void JoyconDriver::InputThread(std::stop_token stop_token) { | |||
| 139 | input_thread_running = true; | 139 | input_thread_running = true; |
| 140 | 140 | ||
| 141 | // Max update rate is 5ms, ensure we are always able to read a bit faster | 141 | // Max update rate is 5ms, ensure we are always able to read a bit faster |
| 142 | constexpr int ThreadDelay = 2; | 142 | constexpr int ThreadDelay = 3; |
| 143 | std::vector<u8> buffer(MaxBufferSize); | 143 | std::vector<u8> buffer(MaxBufferSize); |
| 144 | 144 | ||
| 145 | while (!stop_token.stop_requested()) { | 145 | while (!stop_token.stop_requested()) { |
| @@ -163,6 +163,17 @@ void JoyconDriver::InputThread(std::stop_token stop_token) { | |||
| 163 | OnNewData(buffer); | 163 | OnNewData(buffer); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | if (!vibration_queue.Empty()) { | ||
| 167 | VibrationValue vibration_value; | ||
| 168 | vibration_queue.Pop(vibration_value); | ||
| 169 | last_vibration_result = rumble_protocol->SendVibration(vibration_value); | ||
| 170 | } | ||
| 171 | |||
| 172 | // We can't keep up with vibrations. Start skipping. | ||
| 173 | while (vibration_queue.Size() > 6) { | ||
| 174 | vibration_queue.Pop(); | ||
| 175 | } | ||
| 176 | |||
| 166 | std::this_thread::yield(); | 177 | std::this_thread::yield(); |
| 167 | } | 178 | } |
| 168 | 179 | ||
| @@ -402,7 +413,8 @@ Common::Input::DriverResult JoyconDriver::SetVibration(const VibrationValue& vib | |||
| 402 | if (disable_input_thread) { | 413 | if (disable_input_thread) { |
| 403 | return Common::Input::DriverResult::HandleInUse; | 414 | return Common::Input::DriverResult::HandleInUse; |
| 404 | } | 415 | } |
| 405 | return rumble_protocol->SendVibration(vibration); | 416 | vibration_queue.Push(vibration); |
| 417 | return last_vibration_result; | ||
| 406 | } | 418 | } |
| 407 | 419 | ||
| 408 | Common::Input::DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { | 420 | Common::Input::DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { |
diff --git a/src/input_common/helpers/joycon_driver.h b/src/input_common/helpers/joycon_driver.h index 335e12cc3..5355780fb 100644 --- a/src/input_common/helpers/joycon_driver.h +++ b/src/input_common/helpers/joycon_driver.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <span> | 9 | #include <span> |
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | 11 | ||
| 12 | #include "common/threadsafe_queue.h" | ||
| 12 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | 13 | #include "input_common/helpers/joycon_protocol/joycon_types.h" |
| 13 | 14 | ||
| 14 | namespace Common::Input { | 15 | namespace Common::Input { |
| @@ -152,6 +153,10 @@ private: | |||
| 152 | SerialNumber handle_serial_number{}; // Serial number type reported by hidapi | 153 | SerialNumber handle_serial_number{}; // Serial number type reported by hidapi |
| 153 | SupportedFeatures supported_features{}; | 154 | SupportedFeatures supported_features{}; |
| 154 | 155 | ||
| 156 | /// Queue of vibration request to controllers | ||
| 157 | Common::Input::DriverResult last_vibration_result{Common::Input::DriverResult::Success}; | ||
| 158 | Common::SPSCQueue<VibrationValue> vibration_queue; | ||
| 159 | |||
| 155 | // Thread related | 160 | // Thread related |
| 156 | mutable std::mutex mutex; | 161 | mutable std::mutex mutex; |
| 157 | std::jthread input_thread; | 162 | std::jthread input_thread; |