From f667c098a2d028f56d66d8bb16bdc8712f45b239 Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Wed, 22 Sep 2021 20:49:58 +0100 Subject: [PATCH] AP_RangeFinder: analog: check for valid pin --- libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp index ee8920652a..980bfe7c54 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_analog.cpp @@ -63,12 +63,11 @@ bool AP_RangeFinder_analog::detect(AP_RangeFinder_Params &_params) */ void AP_RangeFinder_analog::update_voltage(void) { - if (source == nullptr) { + if (source == nullptr || !source->set_pin(params.pin)) { state.voltage_mv = 0; + set_status(RangeFinder::Status::NotConnected); return; } - // cope with changed settings - source->set_pin(params.pin); if (params.ratiometric) { state.voltage_mv = source->voltage_average_ratiometric() * 1000U; } else {