diff --git a/libraries/AP_Baro/AP_Baro.cpp b/libraries/AP_Baro/AP_Baro.cpp index 8872a64f5b..547cdb4a33 100644 --- a/libraries/AP_Baro/AP_Baro.cpp +++ b/libraries/AP_Baro/AP_Baro.cpp @@ -130,11 +130,16 @@ const AP_Param::GroupInfo AP_Baro::var_info[] = { AP_GROUPEND }; +// singleton instance +AP_Baro *AP_Baro::_instance; + /* AP_Baro constructor */ AP_Baro::AP_Baro() { + _instance = this; + AP_Param::setup_object_defaults(this, var_info); } diff --git a/libraries/AP_Baro/AP_Baro.h b/libraries/AP_Baro/AP_Baro.h index ac955baf8d..233d9a5a2d 100644 --- a/libraries/AP_Baro/AP_Baro.h +++ b/libraries/AP_Baro/AP_Baro.h @@ -27,6 +27,15 @@ public: // constructor AP_Baro(); + /* Do not allow copies */ + AP_Baro(const AP_Baro &other) = delete; + AP_Baro &operator=(const AP_Baro&) = delete; + + // get singleton + static AP_Baro *get_instance(void) { + return _instance; + } + // barometer types typedef enum { BARO_TYPE_AIR, @@ -161,6 +170,9 @@ public: void set_pressure_correction(uint8_t instance, float p_correction); private: + // singleton + static AP_Baro *_instance; + // how many drivers do we have? uint8_t _num_drivers; AP_Baro_Backend *drivers[BARO_MAX_DRIVERS];