AP_Mount: add singleton

This commit is contained in:
Peter Barker 2018-07-25 09:30:23 +10:00 committed by Peter Barker
parent 1e39c17908
commit 4ae6aeed7e
2 changed files with 32 additions and 0 deletions

View File

@ -397,6 +397,14 @@ AP_Mount::AP_Mount(const AP_AHRS_TYPE &ahrs, const struct Location &current_loc)
_ahrs(ahrs),
_current_loc(current_loc)
{
if (_singleton != nullptr) {
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
AP_HAL::panic("Mount must be singleton");
#endif
return;
}
_singleton = this;
AP_Param::setup_object_defaults(this, var_info);
}
@ -635,3 +643,16 @@ void AP_Mount::send_gimbal_report(mavlink_channel_t chan)
}
}
}
// singleton instance
AP_Mount *AP_Mount::_singleton;
namespace AP {
AP_Mount *mount()
{
return AP_Mount::get_singleton();
}
};

View File

@ -61,6 +61,10 @@ public:
AP_Mount(const AP_Mount &other) = delete;
AP_Mount &operator=(const AP_Mount&) = delete;
// get singleton instance
static AP_Mount *get_singleton() {
return _singleton;
}
// Enums
enum MountType {
@ -139,6 +143,9 @@ public:
static const struct AP_Param::GroupInfo var_info[];
protected:
static AP_Mount *_singleton;
// private members
const AP_AHRS_TYPE &_ahrs;
const struct Location &_current_loc; // reference to the vehicle's current location
@ -183,3 +190,7 @@ protected:
struct Location _roi_target; // roi target location
} state[AP_MOUNT_MAX_INSTANCES];
};
namespace AP {
AP_Mount *mount();
};