Set inputs to 0 upon controller disconnect#177
Open
charlielee206 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tl;dr: Set inputs to 0 upon controller disconnect.
I don't know if this was a bug or a feature, but I found out that if the joycons disconnected while in use, the last button states were kept until the controller was reconnected.
I found this quite annoying, especially since my switch is old, and the slack in the rails cause the controllers tend to disconnect for a short while. even a short disconnect creates a "phantom drift" state where the mouse pointer keeps drifting. I would have to wait until the controller reconnected to stop this movement.
Also, if the controller was receiving an input while it was disconnected, it took significantly longer to reconnect. I assume this is due to some kind of
packet loss assumption -> timeoutoperation on the kernel level. This additional reconnection delay combined with the previous issue and caused me a headache.I made some simple changes to the code so it resets every input to 0 when it detects a controller disconnect. This seemed to fix both the "phantom drift upon controller disconnect" problem and "Takes longer to reconnect" problems.
This "fix" still does not take care of everything. If the stick is not at (0,0) while being reconnected, the cursor will be whipped back in the opposite direction upon release of the stick. I assume this is due to a calibration process upon controller connection, and the process tries to make up for an massive imaginary stick drift. I'm sure someone smarter than me will be able to create some kind of stick state memory and compare it and sync it upon reconnection or something.
I do not know enough about linux driver programming or programming in general to know what problems this "fix" will cause, but it worked for me, and I am hoping it will work for someone else, or someone smarter than me will look at the code and make a better fix.