Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_RangeFinder: Optimize statements #13403

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions libraries/AP_RangeFinder/AP_RangeFinder_TeraRangerI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,19 @@ bool AP_RangeFinder_TeraRangerI2C::collect_raw(uint16_t &raw_distance)
// Checks for error code and if correct converts to cm
bool AP_RangeFinder_TeraRangerI2C::process_raw_measure(uint16_t raw_distance, uint16_t &output_distance_cm)
{
// Check for error codes
if (raw_distance == 0xFFFF) {
// Too far away is unreliable so we dont enforce max range here
return false;
} else if (raw_distance == 0x0000) {
// Too close
return false;
} else if (raw_distance == 0x0001) {
// Unable to measure
return false;
} else {
output_distance_cm = raw_distance/10; // Conversion to centimeters
return true;
}
// Check for error codes
switch (raw_distance) {
case 0xFFFF:
// Too far away is unreliable so we dont enforce max range here
case 0x0000:
// Too close
case 0x0001:
// Unable to measure
return false;
default:
output_distance_cm = raw_distance/10; // Conversion to centimeters
return true;
}
}

/*
Expand Down