From 5a085b161097d4c49b8a941661dbc54d09dab424 Mon Sep 17 00:00:00 2001 From: Aaron Wang Shi Date: Sat, 28 Nov 2015 17:37:40 +0800 Subject: [PATCH] AP_Compass: add support to BH hat --- libraries/AP_Compass/Compass.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/AP_Compass/Compass.cpp b/libraries/AP_Compass/Compass.cpp index 30181a221f..5f04abbadc 100644 --- a/libraries/AP_Compass/Compass.cpp +++ b/libraries/AP_Compass/Compass.cpp @@ -427,9 +427,15 @@ void Compass::_detect_backends(void) #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT _add_backend(AP_Compass_HMC5843::detect_i2c(*this, hal.i2c)); _add_backend(AP_Compass_LSM303D::detect_spi(*this)); -#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && \ - CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE && \ - CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_BEBOP && \ +#elif HAL_COMPASS_DEFAULT == HAL_COMPASS_BH + // detect_mpu9250() failed will cause panic if no actual mpu9250 backend, + // in BH, only one compass should be detected + AP_Compass_Backend *backend = AP_Compass_HMC5843::detect_i2c(*this, hal.i2c); + backend ? _add_backend(backend) + : _add_backend(AP_Compass_AK8963::detect_mpu9250(*this, 0)); +#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && \ + CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE && \ + CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_BEBOP && \ CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_MINLURE _add_backend(AP_Compass_HMC5843::detect_i2c(*this, hal.i2c)); _add_backend(AP_Compass_AK8963::detect_mpu9250(*this, 0));