AP_Beacon: add singleton

This commit is contained in:
Peter Barker 2019-05-22 16:01:49 +10:00 committed by Tom Pittenger
parent 8d90b09829
commit 8ce4f73550
2 changed files with 28 additions and 0 deletions

View File

@ -75,6 +75,12 @@ const AP_Param::GroupInfo AP_Beacon::var_info[] = {
AP_Beacon::AP_Beacon(AP_SerialManager &_serial_manager) :
serial_manager(_serial_manager)
{
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
if (_singleton != nullptr) {
AP_HAL::panic("Fence must be singleton");
}
#endif
_singleton = this;
AP_Param::setup_object_defaults(this, var_info);
}
@ -376,3 +382,16 @@ bool AP_Beacon::device_ready(void) const
{
return ((_driver != nullptr) && (_type != AP_BeaconType_None));
}
// singleton instance
AP_Beacon *AP_Beacon::_singleton;
namespace AP {
AP_Beacon *beacon()
{
return AP_Beacon::get_singleton();
}
}

View File

@ -34,6 +34,9 @@ public:
AP_Beacon(AP_SerialManager &_serial_manager);
// get singleton instance
static AP_Beacon *get_singleton() { return _singleton; }
// external position backend types (used by _TYPE parameter)
enum AP_BeaconType {
AP_BeaconType_None = 0,
@ -102,6 +105,8 @@ public:
private:
static AP_Beacon *_singleton;
// check if device is ready
bool device_ready(void) const;
@ -138,3 +143,7 @@ private:
uint8_t boundary_num_points; // number of points in boundary
uint8_t boundary_num_beacons; // total number of beacon points consumed while building boundary
};
namespace AP {
AP_Beacon *beacon();
};