From b471f9bfaced48e2a8b90c0f0523a81b314e12ab Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 24 Apr 2023 19:54:51 +1000 Subject: [PATCH] AP_ExternalAHRS: create and use backend defines for AP_ExternalAHRS --- libraries/AP_ExternalAHRS/AP_ExternalAHRS.cpp | 13 ++++++++++--- libraries/AP_ExternalAHRS/AP_ExternalAHRS.h | 4 ++++ .../AP_ExternalAHRS/AP_ExternalAHRS_LORD.cpp | 8 +++++--- libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.h | 16 ++++++---------- .../AP_ExternalAHRS_VectorNav.cpp | 9 +++++---- .../AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.h | 9 +++++---- .../AP_ExternalAHRS/AP_ExternalAHRS_config.h | 12 ++++++++++++ 7 files changed, 47 insertions(+), 24 deletions(-) diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS.cpp b/libraries/AP_ExternalAHRS/AP_ExternalAHRS.cpp index 061f983def..d0beac4a9a 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS.cpp +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS.cpp @@ -16,12 +16,15 @@ suppport for serial connected AHRS systems */ -#include "AP_ExternalAHRS.h" -#include "AP_ExternalAHRS_VectorNav.h" -#include "AP_ExternalAHRS_LORD.h" +#include "AP_ExternalAHRS_config.h" #if HAL_EXTERNAL_AHRS_ENABLED +#include "AP_ExternalAHRS.h" +#include "AP_ExternalAHRS_backend.h" +#include "AP_ExternalAHRS_VectorNav.h" +#include "AP_ExternalAHRS_LORD.h" + #include extern const AP_HAL::HAL &hal; @@ -90,13 +93,17 @@ void AP_ExternalAHRS::init(void) case DevType::None: // nothing to do break; +#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED case DevType::VecNav: backend = new AP_ExternalAHRS_VectorNav(this, state); break; +#endif +#if AP_EXTERNAL_AHRS_LORD_ENABLED case DevType::LORD: backend = new AP_ExternalAHRS_LORD(this, state); break; default: +#endif GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Unsupported ExternalAHRS type %u", unsigned(devtype)); break; } diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h b/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h index bef32381c6..5e69f54bb9 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS.h @@ -43,8 +43,12 @@ public: enum class DevType : uint8_t { None = 0, +#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED VecNav = 1, +#endif +#if AP_EXTERNAL_AHRS_LORD_ENABLED LORD = 2, +#endif }; static AP_ExternalAHRS *get_singleton(void) { diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.cpp b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.cpp index 8cd19ea4f3..9d04181a0a 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.cpp +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.cpp @@ -16,8 +16,11 @@ #define ALLOW_DOUBLE_MATH_FUNCTIONS +#include "AP_ExternalAHRS_config.h" + +#if AP_EXTERNAL_AHRS_LORD_ENABLED + #include "AP_ExternalAHRS_LORD.h" -#if HAL_EXTERNAL_AHRS_LORD_ENABLED #include #include #include @@ -582,5 +585,4 @@ double AP_ExternalAHRS_LORD::extract_double(const uint8_t *data, uint8_t offset) return *reinterpret_cast(&tmp); } -#endif // HAL_EXTERNAL_AHRS_ENABLED - +#endif // AP_EXTERNAL_AHRS_LORD_ENABLE diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.h b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.h index 846a15fd1c..495cda4170 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.h +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_LORD.h @@ -16,15 +16,12 @@ #pragma once +#include "AP_ExternalAHRS_config.h" + +#if AP_EXTERNAL_AHRS_LORD_ENABLED + #include "AP_ExternalAHRS_backend.h" - -#ifndef HAL_EXTERNAL_AHRS_LORD_ENABLED -#define HAL_EXTERNAL_AHRS_LORD_ENABLED HAL_EXTERNAL_AHRS_ENABLED -#endif - -#if HAL_EXTERNAL_AHRS_LORD_ENABLED - -#include +#include class AP_ExternalAHRS_LORD: public AP_ExternalAHRS_backend { @@ -153,5 +150,4 @@ private: }; -#endif // HAL_EXTERNAL_AHRS_ENABLED - +#endif // AP_EXTERNAL_AHRS_LORD_ENABLED diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.cpp b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.cpp index 74cd286afc..2e6c2b8fab 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.cpp +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.cpp @@ -18,6 +18,10 @@ #define ALLOW_DOUBLE_MATH_FUNCTIONS +#include "AP_ExternalAHRS_config.h" + +#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED + #include "AP_ExternalAHRS_VectorNav.h" #include #include @@ -31,8 +35,6 @@ #include #include -#if HAL_EXTERNAL_AHRS_ENABLED - extern const AP_HAL::HAL &hal; /* @@ -819,5 +821,4 @@ void AP_ExternalAHRS_VectorNav::send_status_report(GCS_MAVLINK &link) const mag_var, 0, 0); } -#endif // HAL_EXTERNAL_AHRS_ENABLED - +#endif // AP_EXTERNAL_AHRS_VECTORNAV_ENABLED diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.h b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.h index 80824896f4..183184bf24 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.h +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_VectorNav.h @@ -18,9 +18,11 @@ #pragma once -#include "AP_ExternalAHRS_backend.h" +#include "AP_ExternalAHRS_config.h" -#if HAL_EXTERNAL_AHRS_ENABLED +#if AP_EXTERNAL_AHRS_VECTORNAV_ENABLED + +#include "AP_ExternalAHRS_backend.h" class AP_ExternalAHRS_VectorNav : public AP_ExternalAHRS_backend { @@ -92,5 +94,4 @@ private: }; -#endif // HAL_EXTERNAL_AHRS_ENABLED - +#endif // AP_EXTERNAL_AHRS_VECTORNAV_ENABLED diff --git a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_config.h b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_config.h index 2131a1b625..0e167aad76 100644 --- a/libraries/AP_ExternalAHRS/AP_ExternalAHRS_config.h +++ b/libraries/AP_ExternalAHRS/AP_ExternalAHRS_config.h @@ -5,3 +5,15 @@ #ifndef HAL_EXTERNAL_AHRS_ENABLED #define HAL_EXTERNAL_AHRS_ENABLED BOARD_FLASH_SIZE > 1024 #endif + +#ifndef AP_EXTERNAL_AHRS_BACKEND_DEFAULT_ENABLED +#define AP_EXTERNAL_AHRS_BACKEND_DEFAULT_ENABLED HAL_EXTERNAL_AHRS_ENABLED +#endif + +#ifndef AP_EXTERNAL_AHRS_LORD_ENABLED +#define AP_EXTERNAL_AHRS_LORD_ENABLED AP_EXTERNAL_AHRS_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_EXTERNAL_AHRS_VECTORNAV_ENABLED +#define AP_EXTERNAL_AHRS_VECTORNAV_ENABLED AP_EXTERNAL_AHRS_BACKEND_DEFAULT_ENABLED +#endif