diff --git a/libraries/AC_Sprayer/AC_Sprayer.cpp b/libraries/AC_Sprayer/AC_Sprayer.cpp index afd2677bb4..c472462a3e 100644 --- a/libraries/AC_Sprayer/AC_Sprayer.cpp +++ b/libraries/AC_Sprayer/AC_Sprayer.cpp @@ -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(); +} + +}; diff --git a/libraries/AC_Sprayer/AC_Sprayer.h b/libraries/AC_Sprayer/AC_Sprayer.h index c8e77516bd..6f606e548f 100644 --- a/libraries/AC_Sprayer/AC_Sprayer.h +++ b/libraries/AC_Sprayer/AC_Sprayer.h @@ -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(); +};