AP_Terrain: Add singleton

This commit is contained in:
Michael du Breuil 2019-04-23 20:19:53 -07:00 committed by Andrew Tridgell
parent 50b76a27aa
commit fc9b102b28
2 changed files with 13 additions and 0 deletions

View File

@ -35,6 +35,8 @@
extern const AP_HAL::HAL& hal; extern const AP_HAL::HAL& hal;
AP_Terrain *AP_Terrain::singleton;
// table of user settable parameters // table of user settable parameters
const AP_Param::GroupInfo AP_Terrain::var_info[] = { const AP_Param::GroupInfo AP_Terrain::var_info[] = {
// @Param: ENABLE // @Param: ENABLE
@ -62,6 +64,13 @@ AP_Terrain::AP_Terrain(const AP_Mission &_mission) :
fd(-1) fd(-1)
{ {
AP_Param::setup_object_defaults(this, var_info); AP_Param::setup_object_defaults(this, var_info);
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
if (singleton != nullptr) {
AP_HAL::panic("Terrain must be singleton");
}
#endif
singleton = this;
} }
/* /*

View File

@ -82,6 +82,8 @@ public:
AP_Terrain(const AP_Terrain &other) = delete; AP_Terrain(const AP_Terrain &other) = delete;
AP_Terrain &operator=(const AP_Terrain&) = delete; AP_Terrain &operator=(const AP_Terrain&) = delete;
static AP_Terrain *get_singleton(void) { return singleton; }
enum TerrainStatus { enum TerrainStatus {
TerrainStatusDisabled = 0, // not enabled TerrainStatusDisabled = 0, // not enabled
TerrainStatusUnhealthy = 1, // no terrain data for current location TerrainStatusUnhealthy = 1, // no terrain data for current location
@ -413,5 +415,7 @@ private:
// status // status
enum TerrainStatus system_status = TerrainStatusDisabled; enum TerrainStatus system_status = TerrainStatusDisabled;
static AP_Terrain *singleton;
}; };
#endif // AP_TERRAIN_AVAILABLE #endif // AP_TERRAIN_AVAILABLE