AC_Sprayer: add singleton

This commit is contained in:
Peter Barker 2018-06-08 13:36:19 +10:00 committed by Randy Mackay
parent 4915c72f10
commit 4223d933d2
2 changed files with 33 additions and 0 deletions

View File

@ -50,6 +50,14 @@ const AP_Param::GroupInfo AC_Sprayer::var_info[] = {
AC_Sprayer::AC_Sprayer()
{
if (_s_instance) {
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
AP_HAL::panic("Too many sprayers");
#endif
return;
}
_s_instance = this;
AP_Param::setup_object_defaults(this, var_info);
// check for silly parameter values
@ -63,6 +71,15 @@ AC_Sprayer::AC_Sprayer()
// To-Do: ensure that the pump and spinner servo channels are enabled
}
/*
* Get the AP_Sprayer singleton
*/
AC_Sprayer *AC_Sprayer::_s_instance = nullptr;
AC_Sprayer *AC_Sprayer::get_instance()
{
return _s_instance;
}
void AC_Sprayer::run(const bool true_false)
{
// return immediately if no change
@ -168,3 +185,12 @@ void AC_Sprayer::update()
stop_spraying();
}
}
namespace AP {
AC_Sprayer *sprayer()
{
return AC_Sprayer::get_instance();
}
};

View File

@ -38,6 +38,9 @@ public:
AC_Sprayer(const AC_Sprayer &other) = delete;
AC_Sprayer &operator=(const AC_Sprayer&) = delete;
static AC_Sprayer *get_instance();
static AC_Sprayer *_s_instance;
/// run - allow or disallow spraying to occur
void run(bool true_false);
@ -82,3 +85,7 @@ private:
void stop_spraying();
};
namespace AP {
AC_Sprayer *sprayer();
};