mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
Fix underflow in channel based RSSI calculations for out of range values
If the RSSI channel PWM values were outside the expected 1000-2000 range, the `scaleRange()` function does not work properly. In particular if the value was below the minimum the result would be negative. Then this would cause an underflow when applied as a `uint16` to `setRssiDirect()`. This fix constrains the input range from 1000 to 2000.
This commit is contained in:
parent
77ceda89c4
commit
cd4d756790
1 changed files with 1 additions and 1 deletions
|
@ -757,7 +757,7 @@ static void updateRSSIPWM(void)
|
|||
int16_t pwmRssi = rcData[rxConfig()->rssi_channel - 1];
|
||||
|
||||
// Range of rawPwmRssi is [1000;2000]. rssi should be in [0;1023];
|
||||
setRssiDirect(scaleRange(pwmRssi, PWM_RANGE_MIN, PWM_RANGE_MAX, 0, RSSI_MAX_VALUE), RSSI_SOURCE_RX_CHANNEL);
|
||||
setRssiDirect(scaleRange(constrain(pwmRssi, PWM_RANGE_MIN, PWM_RANGE_MAX), PWM_RANGE_MIN, PWM_RANGE_MAX, 0, RSSI_MAX_VALUE), RSSI_SOURCE_RX_CHANNEL);
|
||||
}
|
||||
|
||||
static void updateRSSIADC(timeUs_t currentTimeUs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue