Skip to content

Joystick Invert Option#43

Merged
dmadison merged 8 commits intomasterfrom
development
Jan 10, 2021
Merged

Joystick Invert Option#43
dmadison merged 8 commits intomasterfrom
development

Conversation

@dmadison
Copy link
Copy Markdown
Owner

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 getButton function 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 send function has been modified so that both modes (serial and emulation) toggle the internal newData flag. This effectively restricts the send debug 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 the newData flag itself, and declutters the serial motor generally. If users prefer the old version with the constant status output they can call printDebug() wherever necessary.

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]
@dmadison dmadison merged commit ac8ead1 into master Jan 10, 2021
@dmadison dmadison deleted the development branch January 10, 2021 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant