Merged
Conversation
Minor change, but prevents rewriting both axes if only one changes
Makes the function static and changes both Range arguments to pass by const reference rather than copy, as the function does not need to (and shouldn't!) modify the input ranges.
Note that the 'invert' helper function returns int16_t instead of int32_t because it's used *after* the long value rescaling, and the max value used by the output data is int16
These can already be treated as digital by the 'set' function, so we should be able to treat them as digital with the 'get' function as well. Any input greater than 0 is considered 'pressed' - other thresholds can be done by the user with the analog function.
This makes it easier to follow changes to the debug data stream and helps debug the changing state of 'newData' itself.
In place of calculating this "manually" with the ADC value
Oops. In 1bc0123 I accidentally reordered these while git adding a patch. Changing back to keep the axes-specific functions separate from the "joystick as a whole" functions. [skip ci]
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.
The main change in this PR is the option to invert joysticks. When setting a joystick using the axis-specific function (e.g.
setJoystickY) the user can pass an optional third boolean argument which inverts the output.While I was at it I also adjusted the
getButtonfunction to return a boolean interpretation of the trigger values (!= 0 ? 1 : 0). This allows the 'get' function to match the 'set' function in treating the analog triggers as digital. I debated about what to set the threshold at, but eventually settled on "any input" because it covers the most ground. If the user needs a higher threshold they can do it themselves with the output from the analog trigger function.This PR also includes minor improvements to the internal joystick setting function (
setJoystickDirect) and the input rescaling function, neither of which should affect the public API.Lastly the serial version of the
sendfunction has been modified so that both modes (serial and emulation) toggle the internalnewDataflag. This effectively restricts thesenddebug output to only print values on change, same as the library in emulation mode. This change should make it easier to see atomic changes (e.g. single button presses), debug thenewDataflag itself, and declutters the serial motor generally. If users prefer the old version with the constant status output they can callprintDebug()wherever necessary.