From 35be68348d550ef5d57d080e014693ae17cc18d9 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Thu, 8 Nov 2018 21:34:35 +0900 Subject: [PATCH] AP_RangeFinder: benewake logic reordering this should be a non-functional change --- .../AP_RangeFinder_Benewake.cpp | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Benewake.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_Benewake.cpp index 1260ff458a..cfc3693e3c 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Benewake.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Benewake.cpp @@ -109,31 +109,29 @@ bool AP_RangeFinder_Benewake::get_reading(uint16_t &reading_cm) } // if checksum matches extract contents if ((uint8_t)(checksum & 0xFF) == linebuf[BENEWAKE_FRAME_LENGTH-1]) { - // calculate distance and add to sum + // calculate distance uint16_t dist = ((uint16_t)linebuf[3] << 8) | linebuf[2]; - if (dist < BENEWAKE_DIST_MAX_CM) { + if (dist >= BENEWAKE_DIST_MAX_CM) { + // this reading is out of range + count_out_of_range++; + } else if (model_type == BENEWAKE_TFmini) { // TFmini has short distance mode (mm) - if (model_type == BENEWAKE_TFmini) { - if (linebuf[6] == 0x02) { - dist *= 0.1f; - } - // no signal byte from TFmini so add distance to sum + if (linebuf[6] == 0x02) { + dist *= 0.1f; + } + // no signal byte from TFmini so add distance to sum + sum_cm += dist; + count++; + } else { + // TF02 provides signal reliability (good = 7 or 8) + if (linebuf[6] >= 7) { + // add distance to sum sum_cm += dist; count++; } else { - // TF02 provides signal reliability (good = 7 or 8) - if (linebuf[6] >= 7) { - // add distance to sum - sum_cm += dist; - count++; - } else { - // this reading is out of range - count_out_of_range++; - } + // this reading is out of range + count_out_of_range++; } - } else { - // this reading is out of range - count_out_of_range++; } } // clear buffer