mavlink simple analyzer remove <limits> usage

- <limits> isn't available in the NuttX c++ standard library
This commit is contained in:
Daniel Agar
2019-01-20 16:16:54 -05:00
parent 572d1cefe8
commit ce5fbc7751
3 changed files with 46 additions and 27 deletions
@@ -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);
}
}