Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
e4dfd513
There was an error fetching the commit references. Please try again later.
Commit
e4dfd513
authored
1 year ago
by
german77
Browse files
Options
Downloads
Patches
Plain Diff
input_common: joycon: Move vibrations to a queue
parent
db37e583
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/input_common/helpers/joycon_driver.cpp
+14
-2
14 additions, 2 deletions
src/input_common/helpers/joycon_driver.cpp
src/input_common/helpers/joycon_driver.h
+5
-0
5 additions, 0 deletions
src/input_common/helpers/joycon_driver.h
with
19 additions
and
2 deletions
src/input_common/helpers/joycon_driver.cpp
+
14
−
2
View file @
e4dfd513
...
...
@@ -139,7 +139,7 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
input_thread_running
=
true
;
// Max update rate is 5ms, ensure we are always able to read a bit faster
constexpr
int
ThreadDelay
=
2
;
constexpr
int
ThreadDelay
=
3
;
std
::
vector
<
u8
>
buffer
(
MaxBufferSize
);
while
(
!
stop_token
.
stop_requested
())
{
...
...
@@ -163,6 +163,17 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
OnNewData
(
buffer
);
}
if
(
!
vibration_queue
.
Empty
())
{
VibrationValue
vibration_value
;
vibration_queue
.
Pop
(
vibration_value
);
last_vibration_result
=
rumble_protocol
->
SendVibration
(
vibration_value
);
}
// We can't keep up with vibrations. Start skipping.
while
(
vibration_queue
.
Size
()
>
6
)
{
vibration_queue
.
Pop
();
}
std
::
this_thread
::
yield
();
}
...
...
@@ -402,7 +413,8 @@ Common::Input::DriverResult JoyconDriver::SetVibration(const VibrationValue& vib
if
(
disable_input_thread
)
{
return
Common
::
Input
::
DriverResult
::
HandleInUse
;
}
return
rumble_protocol
->
SendVibration
(
vibration
);
vibration_queue
.
Push
(
vibration
);
return
last_vibration_result
;
}
Common
::
Input
::
DriverResult
JoyconDriver
::
SetLedConfig
(
u8
led_pattern
)
{
...
...
This diff is collapsed.
Click to expand it.
src/input_common/helpers/joycon_driver.h
+
5
−
0
View file @
e4dfd513
...
...
@@ -9,6 +9,7 @@
#include
<span>
#include
<thread>
#include
"common/threadsafe_queue.h"
#include
"input_common/helpers/joycon_protocol/joycon_types.h"
namespace
Common
::
Input
{
...
...
@@ -152,6 +153,10 @@ private:
SerialNumber
handle_serial_number
{};
// Serial number type reported by hidapi
SupportedFeatures
supported_features
{};
/// Queue of vibration request to controllers
Common
::
Input
::
DriverResult
last_vibration_result
{
Common
::
Input
::
DriverResult
::
Success
};
Common
::
SPSCQueue
<
VibrationValue
>
vibration_queue
;
// Thread related
mutable
std
::
mutex
mutex
;
std
::
jthread
input_thread
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment