From c283bb968b3698890b727ab2c873928aada63dbc Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 5 Jan 2019 21:44:40 +1100 Subject: [PATCH] AP_Baro: support 0 detected simulated baros --- libraries/AP_Baro/AP_Baro.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/AP_Baro/AP_Baro.cpp b/libraries/AP_Baro/AP_Baro.cpp index aaf790b08a..bf6b9c7433 100644 --- a/libraries/AP_Baro/AP_Baro.cpp +++ b/libraries/AP_Baro/AP_Baro.cpp @@ -452,11 +452,6 @@ void AP_Baro::init(void) return; } -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL - ADD_BACKEND(new AP_Baro_SITL(*this)); - return; -#endif - #if HAL_WITH_UAVCAN // Detect UAVCAN Modules, try as many times as there are driver slots for (uint8_t i = 0; i < BARO_MAX_DRIVERS; i++) { @@ -542,6 +537,17 @@ void AP_Baro::init(void) default: break; } +#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL + SITL::SITL *sitl = AP::sitl(); + if (sitl == nullptr) { + AP_HAL::panic("No SITL pointer"); + } + if (sitl->baro_count > 1) { + ::fprintf(stderr, "More than one baro not supported. Sorry."); + } + if (sitl->baro_count == 1) { + ADD_BACKEND(new AP_Baro_SITL(*this)); + } #elif HAL_BARO_DEFAULT == HAL_BARO_HIL drivers[0] = new AP_Baro_HIL(*this); _num_drivers = 1;