AP_Arming: add singleton

This commit is contained in:
Peter Barker 2019-05-06 13:33:15 +10:00 committed by Randy Mackay
parent 48ac028cd0
commit d384827291
2 changed files with 32 additions and 0 deletions

View File

@ -115,6 +115,11 @@ extern AP_IOMCU iomcu;
AP_Arming::AP_Arming()
{
if (_singleton) {
AP_HAL::panic("Too many AP_Arming instances");
}
_singleton = this;
AP_Param::setup_object_defaults(this, var_info);
}
@ -894,3 +899,22 @@ bool AP_Arming::rc_checks_copter_sub(const bool display_failure, const RC_Channe
}
return ret;
}
AP_Arming *AP_Arming::_singleton = nullptr;
/*
* Get the AP_InertialSensor singleton
*/
AP_Arming *AP_Arming::get_singleton()
{
return AP_Arming::_singleton;
}
namespace AP {
AP_Arming &arming()
{
return *AP_Arming::get_singleton();
}
};

View File

@ -14,6 +14,8 @@ public:
AP_Arming(const AP_Arming &other) = delete;
AP_Arming &operator=(const AP_Arming&) = delete;
static AP_Arming *get_singleton();
enum ArmingChecks {
ARMING_CHECK_NONE = 0x0000,
ARMING_CHECK_ALL = 0x0001,
@ -133,6 +135,8 @@ protected:
private:
static AP_Arming *_singleton;
bool ins_accels_consistent(const AP_InertialSensor &ins);
bool ins_gyros_consistent(const AP_InertialSensor &ins);
@ -146,3 +150,7 @@ private:
MIS_ITEM_CHECK_MAX
};
};
namespace AP {
AP_Arming &arming();
};