From f9a94fd7dd57cdb9717488c763ce88066e5e7b3a Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 8 Nov 2023 09:23:40 +1100 Subject: [PATCH] AP_RangeFinder: make AP_RANGEFINDER_ENABLED remove more code --- libraries/AP_RangeFinder/AP_RangeFinder.cpp | 6 ++++-- libraries/AP_RangeFinder/AP_RangeFinder.h | 4 ++++ .../AP_RangeFinder/AP_RangeFinder_Backend.cpp | 5 +++++ libraries/AP_RangeFinder/AP_RangeFinder_Backend.h | 6 ++++++ .../AP_RangeFinder_Backend_Serial.cpp | 6 ++++++ .../AP_RangeFinder/AP_RangeFinder_Backend_Serial.h | 6 ++++++ libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp | 6 ++++++ libraries/AP_RangeFinder/AP_RangeFinder_Params.h | 6 ++++++ libraries/AP_RangeFinder/AP_RangeFinder_config.h | 14 ++++++++------ 9 files changed, 51 insertions(+), 8 deletions(-) diff --git a/libraries/AP_RangeFinder/AP_RangeFinder.cpp b/libraries/AP_RangeFinder/AP_RangeFinder.cpp index 6f1f4a6c26..2134162eab 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder.cpp @@ -14,6 +14,9 @@ */ #include "AP_RangeFinder.h" + +#if AP_RANGEFINDER_ENABLED + #include "AP_RangeFinder_analog.h" #include "AP_RangeFinder_PulsedLightLRF.h" #include "AP_RangeFinder_MaxsonarI2CXL.h" @@ -273,7 +276,6 @@ bool RangeFinder::_add_backend(AP_RangeFinder_Backend *backend, uint8_t instance */ void RangeFinder::detect_instance(uint8_t instance, uint8_t& serial_instance) { -#if AP_RANGEFINDER_ENABLED AP_RangeFinder_Backend_Serial *(*serial_create_fn)(RangeFinder::RangeFinder_State&, AP_RangeFinder_Params&) = nullptr; const Type _type = (Type)params[instance].type.get(); @@ -618,7 +620,6 @@ void RangeFinder::detect_instance(uint8_t instance, uint8_t& serial_instance) // param count could have changed AP_Param::invalidate_count(); } -#endif //AP_RANGEFINDER_ENABLED } AP_RangeFinder_Backend *RangeFinder::get_backend(uint8_t id) const { @@ -925,3 +926,4 @@ RangeFinder *rangefinder() } +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder.h b/libraries/AP_RangeFinder/AP_RangeFinder.h index f94b0205ef..c67ad5cce7 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder.h @@ -16,6 +16,8 @@ #include "AP_RangeFinder_config.h" +#if AP_RANGEFINDER_ENABLED + #include #include #include @@ -319,3 +321,5 @@ private: namespace AP { RangeFinder *rangefinder(); }; + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Backend.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_Backend.cpp index bd0e9be294..3ae267a928 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Backend.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Backend.cpp @@ -13,6 +13,10 @@ along with this program. If not, see . */ +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include #include #include "AP_RangeFinder.h" @@ -89,3 +93,4 @@ void AP_RangeFinder_Backend::get_state(RangeFinder::RangeFinder_State &state_arg } #endif +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Backend.h b/libraries/AP_RangeFinder/AP_RangeFinder_Backend.h index ca2decd044..e1ae5b5012 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Backend.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Backend.h @@ -14,6 +14,10 @@ */ #pragma once +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include #include #include @@ -100,3 +104,5 @@ protected: virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const = 0; }; + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.cpp index af27aaf5a7..0dacdca94d 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.cpp @@ -13,6 +13,10 @@ along with this program. If not, see . */ +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include #include "AP_RangeFinder_Backend_Serial.h" #include @@ -61,3 +65,5 @@ void AP_RangeFinder_Backend_Serial::update(void) set_status(RangeFinder::Status::NoData); } } + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.h b/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.h index e4349d75b8..35f3f8dca4 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Backend_Serial.h @@ -1,5 +1,9 @@ #pragma once +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include "AP_RangeFinder_Backend.h" class AP_RangeFinder_Backend_Serial : public AP_RangeFinder_Backend @@ -38,3 +42,5 @@ protected: // maximum time between readings before we change state to NoData: virtual uint16_t read_timeout_ms() const { return 200; } }; + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp index 83816dd865..860b4d9949 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Params.cpp @@ -1,3 +1,7 @@ +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include "AP_RangeFinder_Params.h" #include "AP_RangeFinder.h" @@ -139,3 +143,5 @@ const AP_Param::GroupInfo AP_RangeFinder_Params::var_info[] = { AP_RangeFinder_Params::AP_RangeFinder_Params(void) { AP_Param::setup_object_defaults(this, var_info); } + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_Params.h b/libraries/AP_RangeFinder/AP_RangeFinder_Params.h index 23e4406d07..17893c3e68 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_Params.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_Params.h @@ -1,5 +1,9 @@ #pragma once +#include "AP_RangeFinder_config.h" + +#if AP_RANGEFINDER_ENABLED + #include #include @@ -27,3 +31,5 @@ public: AP_Int8 address; AP_Int8 orientation; }; + +#endif // AP_RANGEFINDER_ENABLED diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_config.h b/libraries/AP_RangeFinder/AP_RangeFinder_config.h index 71e1d01217..69d1f6e537 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_config.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_config.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -19,10 +20,7 @@ #endif #ifndef AP_RANGEFINDER_BBB_PRU_ENABLED -#define AP_RANGEFINDER_BBB_PRU_ENABLED ( \ - AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED && \ - CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI \ - ) +#define AP_RANGEFINDER_BBB_PRU_ENABLED (AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI) #endif #ifndef AP_RANGEFINDER_BENEWAKE_ENABLED @@ -94,7 +92,7 @@ #endif #ifndef AP_RANGEFINDER_LUA_ENABLED -#define AP_RANGEFINDER_LUA_ENABLED AP_SCRIPTING_ENABLED +#define AP_RANGEFINDER_LUA_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED && AP_SCRIPTING_ENABLED #endif #ifndef AP_RANGEFINDER_MAVLINK_ENABLED @@ -110,7 +108,7 @@ #endif #ifndef HAL_MSP_RANGEFINDER_ENABLED -#define HAL_MSP_RANGEFINDER_ENABLED HAL_MSP_ENABLED +#define HAL_MSP_RANGEFINDER_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED && HAL_MSP_ENABLED #endif #ifndef AP_RANGEFINDER_NMEA_ENABLED @@ -141,6 +139,10 @@ #define AP_RANGEFINDER_SIM_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL && AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED) #endif +#ifndef HAL_MSP_RANGEFINDER_ENABLED +#define HAL_MSP_RANGEFINDER_ENABLED (AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED && HAL_MSP_ENABLED) +#endif + #ifndef AP_RANGEFINDER_TERARANGER_SERIAL_ENABLED #define AP_RANGEFINDER_TERARANGER_SERIAL_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED #endif