AP_RangeFinder: fixed detection of multiple types

Pair-Programmed-With: Allyson Kreft
This commit is contained in:
Andrew Tridgell 2014-07-01 06:42:22 +10:00
parent 7ceb14bec0
commit f6d9bc5d7e

View File

@ -210,25 +210,32 @@ void RangeFinder::detect_instance(uint8_t instance)
if (AP_RangeFinder_PulsedLightLRF::detect(*this, instance)) { if (AP_RangeFinder_PulsedLightLRF::detect(*this, instance)) {
state[instance].instance = instance; state[instance].instance = instance;
drivers[instance] = new AP_RangeFinder_PulsedLightLRF(*this, instance, state[instance]); drivers[instance] = new AP_RangeFinder_PulsedLightLRF(*this, instance, state[instance]);
return;
} }
} else if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_MBI2C) { }
if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_MBI2C) {
if (AP_RangeFinder_MaxsonarI2CXL::detect(*this, instance)) { if (AP_RangeFinder_MaxsonarI2CXL::detect(*this, instance)) {
state[instance].instance = instance; state[instance].instance = instance;
drivers[instance] = new AP_RangeFinder_MaxsonarI2CXL(*this, instance, state[instance]); drivers[instance] = new AP_RangeFinder_MaxsonarI2CXL(*this, instance, state[instance]);
return;
} }
}
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 #if CONFIG_HAL_BOARD == HAL_BOARD_PX4
} else if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_PX4) { if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_PX4) {
if (AP_RangeFinder_PX4::detect(*this, instance)) { if (AP_RangeFinder_PX4::detect(*this, instance)) {
state[instance].instance = instance; state[instance].instance = instance;
drivers[instance] = new AP_RangeFinder_PX4(*this, instance, state[instance]); drivers[instance] = new AP_RangeFinder_PX4(*this, instance, state[instance]);
return;
} }
}
#endif #endif
} else if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_ANALOG) { if (_type[instance] == RangeFinder_TYPE_AUTO || _type[instance] == RangeFinder_TYPE_ANALOG) {
// note that analog must be the last to be checked, as it will // note that analog must be the last to be checked, as it will
// always come back as present if the pin is valid // always come back as present if the pin is valid
if (AP_RangeFinder_analog::detect(*this, instance)) { if (AP_RangeFinder_analog::detect(*this, instance)) {
state[instance].instance = instance; state[instance].instance = instance;
drivers[instance] = new AP_RangeFinder_analog(*this, instance, state[instance]); drivers[instance] = new AP_RangeFinder_analog(*this, instance, state[instance]);
return;
} }
} }
} }