Constraining PPMHandset ppm value within the CRSF limits #3303
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.
Bug
The
fmapimplementation incrsf_protocol.his at risk of underflow errors when thexis fed less thanin_min.For example, calling
fmap(5, 10, 20, 100, 200)will be result in:(5-10)*(200-100)*2 ...However, as the variables are defined as unsigned types, 5-10 = -5 will be wrapped into
65535-5=65530, which gives an erroneously large value.With some old PPM handset, the values could be go outside the defined range.
Fix
Straightforward, constrain the x within in_min -- in_max range.
Story
The bug was discovered when testing an old PPM radio with an ELRS TX; the control surfaces are flipped all the way to the other side when the stick was deflected to its minimum position.
Close investigation revealed that the PPM signal from the radio was outside the hard-coded range of (988, 2012) in PPMHandset.cpp, causing the underflow.
PS. ELRS module installation on an old Futaba radio which discovered this defect:


