mirror of https://github.com/ArduPilot/ardupilot
AP_Beacon: add singleton
This commit is contained in:
parent
8d90b09829
commit
8ce4f73550
|
@ -75,6 +75,12 @@ const AP_Param::GroupInfo AP_Beacon::var_info[] = {
|
||||||
AP_Beacon::AP_Beacon(AP_SerialManager &_serial_manager) :
|
AP_Beacon::AP_Beacon(AP_SerialManager &_serial_manager) :
|
||||||
serial_manager(_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);
|
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));
|
return ((_driver != nullptr) && (_type != AP_BeaconType_None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// singleton instance
|
||||||
|
AP_Beacon *AP_Beacon::_singleton;
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
|
||||||
|
AP_Beacon *beacon()
|
||||||
|
{
|
||||||
|
return AP_Beacon::get_singleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
|
|
||||||
AP_Beacon(AP_SerialManager &_serial_manager);
|
AP_Beacon(AP_SerialManager &_serial_manager);
|
||||||
|
|
||||||
|
// get singleton instance
|
||||||
|
static AP_Beacon *get_singleton() { return _singleton; }
|
||||||
|
|
||||||
// external position backend types (used by _TYPE parameter)
|
// external position backend types (used by _TYPE parameter)
|
||||||
enum AP_BeaconType {
|
enum AP_BeaconType {
|
||||||
AP_BeaconType_None = 0,
|
AP_BeaconType_None = 0,
|
||||||
|
@ -102,6 +105,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
static AP_Beacon *_singleton;
|
||||||
|
|
||||||
// check if device is ready
|
// check if device is ready
|
||||||
bool device_ready(void) const;
|
bool device_ready(void) const;
|
||||||
|
|
||||||
|
@ -138,3 +143,7 @@ private:
|
||||||
uint8_t boundary_num_points; // number of points in boundary
|
uint8_t boundary_num_points; // number of points in boundary
|
||||||
uint8_t boundary_num_beacons; // total number of beacon points consumed while building boundary
|
uint8_t boundary_num_beacons; // total number of beacon points consumed while building boundary
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
AP_Beacon *beacon();
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue