summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input_common/helpers/joycon_driver.cpp16
-rw-r--r--src/input_common/helpers/joycon_driver.h5
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
408Common::Input::DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { 420Common::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
14namespace Common::Input { 15namespace 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;