Closed muttering-oldman closed 7 months ago
In Betaflight I found a function with some comments explaining the "magic" numbers. Maybe it will be useful for someone. https://github.com/betaflight/betaflight/blob/master/src/main/rx/crsf.c
STATIC_UNIT_TESTED float crsfReadRawRC(const rxRuntimeState_t *rxRuntimeState, uint8_t chan)
{
UNUSED(rxRuntimeState);
if (channelScale == CRSF_RC_CHANNEL_SCALE_LEGACY) {
/* conversion from RC value to PWM
* for 0x16 RC frame
* RC PWM
* min 172 -> 988us
* mid 992 -> 1500us
* max 1811 -> 2012us
* scale factor = (2012-988) / (1811-172) = 0.62477120195241
* offset = 988 - 172 * 0.62477120195241 = 880.53935326418548
*/
return (channelScale * (float)crsfChannelData[chan]) + 881;
} else {
/* conversion from RC value to PWM
* for 0x17 Subset RC frame
*/
return (channelScale * (float)crsfChannelData[chan]) + 988;
}
}
Hi! Sorry for the confusion. I mapped those values this way because that's how betaflight does it. Now that I think about it, it might be better to return the raw values and leave the mapping to the user.
I think you can do two methods. One can return raw values, and the second can return the values as they are now.
I just released a new version with a better mapping system :))
Hi! Thanks for this library! After running through it with debug I have a better understanding of crsf. But I have a small question. In the
map_chan
function I see some "magic" numbers. Could you tell me a little about them? Or maybe you can give me links to articles about crsf parsing?