AP_OpticalFlow: add singleton
This commit is contained in:
parent
ff77000d93
commit
ebf038eb57
@ -73,6 +73,8 @@ OpticalFlow::OpticalFlow(AP_AHRS_NavEKF &ahrs)
|
||||
: _ahrs(ahrs),
|
||||
_last_update_ms(0)
|
||||
{
|
||||
_singleton = this;
|
||||
|
||||
AP_Param::setup_object_defaults(this, var_info);
|
||||
}
|
||||
|
||||
@ -124,3 +126,14 @@ void OpticalFlow::update(void)
|
||||
_flags.healthy = (AP_HAL::millis() - _last_update_ms < 500);
|
||||
}
|
||||
|
||||
// singleton instance
|
||||
OpticalFlow *OpticalFlow::_singleton;
|
||||
|
||||
namespace AP {
|
||||
|
||||
OpticalFlow *opticalflow()
|
||||
{
|
||||
return OpticalFlow::get_singleton();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,11 @@ public:
|
||||
OpticalFlow(const OpticalFlow &other) = delete;
|
||||
OpticalFlow &operator=(const OpticalFlow&) = delete;
|
||||
|
||||
// get singleton instance
|
||||
static OpticalFlow *get_singleton() {
|
||||
return _singleton;
|
||||
}
|
||||
|
||||
// init - initialise sensor
|
||||
void init(void);
|
||||
|
||||
@ -79,6 +84,9 @@ public:
|
||||
static const struct AP_Param::GroupInfo var_info[];
|
||||
|
||||
private:
|
||||
|
||||
static OpticalFlow *_singleton;
|
||||
|
||||
AP_AHRS_NavEKF &_ahrs;
|
||||
OpticalFlow_backend *backend;
|
||||
|
||||
@ -100,4 +108,8 @@ private:
|
||||
uint32_t _last_update_ms; // millis() time of last update
|
||||
};
|
||||
|
||||
namespace AP {
|
||||
OpticalFlow *opticalflow();
|
||||
}
|
||||
|
||||
#include "OpticalFlow_backend.h"
|
||||
|
Loading…
Reference in New Issue
Block a user