AP_RCMapper: add singleton

This commit is contained in:
Andy Piper 2019-12-01 15:32:14 +00:00 committed by Andrew Tridgell
parent a09c18386e
commit e166e90c1d
2 changed files with 23 additions and 0 deletions

View File

@ -61,8 +61,19 @@ const AP_Param::GroupInfo RCMapper::var_info[] = {
AP_GROUPEND
};
// singleton instance
RCMapper *RCMapper::_singleton;
// object constructor.
RCMapper::RCMapper(void)
{
if (_singleton != nullptr) {
AP_HAL::panic("RCMapper must be singleton");
}
AP_Param::setup_object_defaults(this, var_info);
_singleton = this;
}
RCMapper *AP::rcmap() {
return RCMapper::get_singleton();
}

View File

@ -12,6 +12,12 @@ public:
RCMapper(const RCMapper &other) = delete;
RCMapper &operator=(const RCMapper&) = delete;
// get singleton instance
static RCMapper *get_singleton()
{
return _singleton;
}
/// roll - return input channel number for roll / aileron input
uint8_t roll() const { return _ch_roll; }
@ -40,4 +46,10 @@ private:
AP_Int8 _ch_throttle;
AP_Int8 _ch_forward;
AP_Int8 _ch_lateral;
static RCMapper *_singleton;
};
namespace AP
{
RCMapper *rcmap();
};