From daedebce2e67fbe0209cc3d9f2ea8028c0c54c1f Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 30 Oct 2021 12:15:47 +1100 Subject: [PATCH] AP_Baro: create and use HAL_SIM_BARO_ENABLED --- libraries/AP_Baro/AP_Baro.cpp | 29 ++++++++++++++++++++--------- libraries/AP_Baro/AP_Baro.h | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/libraries/AP_Baro/AP_Baro.cpp b/libraries/AP_Baro/AP_Baro.cpp index e2ce13be4d..0447cae0bd 100644 --- a/libraries/AP_Baro/AP_Baro.cpp +++ b/libraries/AP_Baro/AP_Baro.cpp @@ -535,7 +535,17 @@ void AP_Baro::init(void) sensors[i].bus_id.set(0); } -#if HAL_ENABLE_LIBUAVCAN_DRIVERS +#if AP_SIM_BARO_ENABLED + SITL::SIM *sitl = AP::sitl(); + if (sitl == nullptr) { + AP_HAL::panic("No SITL pointer"); + } + for(uint8_t i = 0; i < sitl->baro_count; i++) { + ADD_BACKEND(new AP_Baro_SITL(*this)); + } +#endif + +#if HAL_ENABLE_LIBUAVCAN_DRIVERS && !AP_SIM_BARO_ENABLED // Detect UAVCAN Modules, try as many times as there are driver slots for (uint8_t i = 0; i < BARO_MAX_DRIVERS; i++) { ADD_BACKEND(AP_Baro_UAVCAN::probe(*this)); @@ -552,6 +562,15 @@ void AP_Baro::init(void) // macro for use by HAL_INS_PROBE_LIST #define GET_I2C_DEVICE(bus, address) hal.i2c_mgr->get_device(bus, address) +#if AP_SIM_BARO_ENABLED +#if CONFIG_HAL_BOARD == HAL_BOARD_SITL + ADD_BACKEND(AP_Baro_MS56XX::probe(*this, + std::move(GET_I2C_DEVICE(_ext_bus, HAL_BARO_MS5611_I2C_ADDR)))); +#endif + // do not probe for other drivers when using simulation: + return; +#endif + #if defined(HAL_BARO_PROBE_LIST) // probe list from BARO lines in hwdef.dat HAL_BARO_PROBE_LIST; @@ -630,14 +649,6 @@ void AP_Baro::init(void) default: break; } -#elif AP_SIM_BARO_ENABLED - SITL::SIM *sitl = AP::sitl(); - if (sitl == nullptr) { - AP_HAL::panic("No SITL pointer"); - } - for(uint8_t i = 0; i < sitl->baro_count; i++) { - ADD_BACKEND(new AP_Baro_SITL(*this)); - } #elif HAL_BARO_DEFAULT == HAL_BARO_LPS25H_IMU_I2C ADD_BACKEND(AP_Baro_LPS2XH::probe_InvensenseIMU(*this, std::move(GET_I2C_DEVICE(HAL_BARO_LPS25H_I2C_BUS, HAL_BARO_LPS25H_I2C_ADDR)), diff --git a/libraries/AP_Baro/AP_Baro.h b/libraries/AP_Baro/AP_Baro.h index c4f3552028..68280969b8 100644 --- a/libraries/AP_Baro/AP_Baro.h +++ b/libraries/AP_Baro/AP_Baro.h @@ -7,7 +7,7 @@ #include #ifndef AP_SIM_BARO_ENABLED -#define AP_SIM_BARO_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#define AP_SIM_BARO_ENABLED AP_SIM_ENABLED #endif #ifndef HAL_MSP_BARO_ENABLED