AP_Baro: make AP_Baro a singleton

for AP_Airspeed
This commit is contained in:
rde-mato 2017-11-03 15:43:44 +11:00 committed by Andrew Tridgell
parent e120e912f1
commit 787420931e
2 changed files with 13 additions and 0 deletions

View File

@ -141,11 +141,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);
}

View File

@ -30,6 +30,11 @@ public:
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,
@ -164,6 +169,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];