AP_Mount: add singleton
This commit is contained in:
parent
1e39c17908
commit
4ae6aeed7e
@ -397,6 +397,14 @@ AP_Mount::AP_Mount(const AP_AHRS_TYPE &ahrs, const struct Location ¤t_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();
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -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();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user