mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 15:10:35 +08:00
mavlink simple analyzer remove <limits> usage
- <limits> isn't available in the NuttX c++ standard library
This commit is contained in:
@@ -146,3 +146,29 @@ void SimpleAnalyzer::int_round(float &x) const
|
||||
x += 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
void convert_limit_safe(float in, uint16_t &out)
|
||||
{
|
||||
if (in > UINT16_MAX) {
|
||||
out = UINT16_MAX;
|
||||
|
||||
} else if (in < 0) {
|
||||
out = 0;
|
||||
|
||||
} else {
|
||||
out = static_cast<uint16_t>(in);
|
||||
}
|
||||
}
|
||||
|
||||
void convert_limit_safe(float in, int16_t &out)
|
||||
{
|
||||
if (in > INT16_MAX) {
|
||||
out = INT16_MAX;
|
||||
|
||||
} else if (in < INT16_MIN) {
|
||||
out = INT16_MIN;
|
||||
|
||||
} else {
|
||||
out = static_cast<int16_t>(in);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user