Fix 16-bit range check in TMenuItem::action_edit for 32-bit boards #14834
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.
This was previously checking against a 32-bit range. This allowed incrementing beyond the range of encoderPosition, causing unexpected wraparound behavior.
Description
This fixes the menu item range check for 32-bit processors. The comment in this function claims to range-check for
int16_t
, but it actually checked the range againstint
. This worked for AVR, but is incorrect for 32-bit boards.Benefits
On 32-bit boards, this prevents the value being editing from overflowing encoderPosition, before reaching the a min/max value. When editing the value, it now stops at the actual possible maximum, rather than wrapping back around to the minimum. This should make the behavior consistent with AVR boards.
The experience is still not good if the existing value falls outside the possible encoder range. In this situation the value will be coerced to the minimum value, effectively losing the user's setting. Additional code changes would be needed to prevent this, or to increase the range of the encoder.
Related Issues
This fixes the wrap-around symptom described in issue #14821.
I would not consider the issue resolved unless more work is done to allow the larger range, or at least prevent the loss of an existing value if it cannot be edited from the menu.