From ed608d37f62102491bc3f42ffbb88be6150cde21 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 30 Oct 2021 12:15:48 +1100 Subject: [PATCH] AP_Compass: add and use AP_SIM_COMPASS_ENABLED --- libraries/AP_Compass/AP_Compass.cpp | 2 +- libraries/AP_Compass/AP_Compass.h | 4 ++++ libraries/AP_Compass/AP_Compass_SITL.cpp | 5 +++-- libraries/AP_Compass/AP_Compass_SITL.h | 8 +++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Compass/AP_Compass.cpp b/libraries/AP_Compass/AP_Compass.cpp index c0288fd955..cb6e9b7319 100644 --- a/libraries/AP_Compass/AP_Compass.cpp +++ b/libraries/AP_Compass/AP_Compass.cpp @@ -1227,7 +1227,7 @@ void Compass::_detect_backends(void) } #endif -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL +#if AP_SIM_COMPASS_ENABLED ADD_BACKEND(DRIVER_SITL, new AP_Compass_SITL()); #endif diff --git a/libraries/AP_Compass/AP_Compass.h b/libraries/AP_Compass/AP_Compass.h index 5efe23adb7..994ea71832 100644 --- a/libraries/AP_Compass/AP_Compass.h +++ b/libraries/AP_Compass/AP_Compass.h @@ -70,6 +70,10 @@ #define MAX_CONNECTED_MAGS (COMPASS_MAX_UNREG_DEV+COMPASS_MAX_INSTANCES) +#ifndef AP_SIM_COMPASS_ENABLED +#define AP_SIM_COMPASS_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + #include "CompassCalibrator.h" class CompassLearn; diff --git a/libraries/AP_Compass/AP_Compass_SITL.cpp b/libraries/AP_Compass/AP_Compass_SITL.cpp index a4134f4690..2740163720 100644 --- a/libraries/AP_Compass/AP_Compass_SITL.cpp +++ b/libraries/AP_Compass/AP_Compass_SITL.cpp @@ -1,8 +1,9 @@ #include "AP_Compass_SITL.h" +#if AP_SIM_COMPASS_ENABLED + #include -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL extern const AP_HAL::HAL& hal; AP_Compass_SITL::AP_Compass_SITL() @@ -158,4 +159,4 @@ void AP_Compass_SITL::read() drain_accumulated_samples(_compass_instance[i], nullptr); } } -#endif +#endif // AP_SIM_COMPASS_ENABLED diff --git a/libraries/AP_Compass/AP_Compass_SITL.h b/libraries/AP_Compass/AP_Compass_SITL.h index 8fb4595f05..4beba3416f 100644 --- a/libraries/AP_Compass/AP_Compass_SITL.h +++ b/libraries/AP_Compass/AP_Compass_SITL.h @@ -1,13 +1,15 @@ #pragma once #include "AP_Compass.h" + +#if AP_SIM_COMPASS_ENABLED + #include "AP_Compass_Backend.h" -#if CONFIG_HAL_BOARD == HAL_BOARD_SITL -#include #include #include #include +#include #define MAX_SITL_COMPASSES 3 @@ -42,4 +44,4 @@ private: Vector3f _last_odi; Vector3f _last_data[MAX_SITL_COMPASSES]; }; -#endif // CONFIG_HAL_BOARD +#endif // AP_SIM_COMPASS_ENABLED