mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AC_Sprayer: add singleton
This commit is contained in:
parent
4915c72f10
commit
4223d933d2
@ -50,6 +50,14 @@ const AP_Param::GroupInfo AC_Sprayer::var_info[] = {
|
|||||||
|
|
||||||
AC_Sprayer::AC_Sprayer()
|
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);
|
AP_Param::setup_object_defaults(this, var_info);
|
||||||
|
|
||||||
// check for silly parameter values
|
// 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
|
// 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)
|
void AC_Sprayer::run(const bool true_false)
|
||||||
{
|
{
|
||||||
// return immediately if no change
|
// return immediately if no change
|
||||||
@ -168,3 +185,12 @@ void AC_Sprayer::update()
|
|||||||
stop_spraying();
|
stop_spraying();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
|
||||||
|
AC_Sprayer *sprayer()
|
||||||
|
{
|
||||||
|
return AC_Sprayer::get_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -38,6 +38,9 @@ public:
|
|||||||
AC_Sprayer(const AC_Sprayer &other) = delete;
|
AC_Sprayer(const AC_Sprayer &other) = delete;
|
||||||
AC_Sprayer &operator=(const AC_Sprayer&) = 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
|
/// run - allow or disallow spraying to occur
|
||||||
void run(bool true_false);
|
void run(bool true_false);
|
||||||
|
|
||||||
@ -82,3 +85,7 @@ private:
|
|||||||
|
|
||||||
void stop_spraying();
|
void stop_spraying();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
AC_Sprayer *sprayer();
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user