AP_OpticalFlow: add singleton

This commit is contained in:
Peter Barker 2018-09-02 16:32:12 +10:00 committed by Andrew Tridgell
parent ff77000d93
commit ebf038eb57
2 changed files with 25 additions and 0 deletions

View File

@ -73,6 +73,8 @@ OpticalFlow::OpticalFlow(AP_AHRS_NavEKF &ahrs)
: _ahrs(ahrs), : _ahrs(ahrs),
_last_update_ms(0) _last_update_ms(0)
{ {
_singleton = this;
AP_Param::setup_object_defaults(this, var_info); 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); _flags.healthy = (AP_HAL::millis() - _last_update_ms < 500);
} }
// singleton instance
OpticalFlow *OpticalFlow::_singleton;
namespace AP {
OpticalFlow *opticalflow()
{
return OpticalFlow::get_singleton();
}
}

View File

@ -36,6 +36,11 @@ public:
OpticalFlow(const OpticalFlow &other) = delete; OpticalFlow(const OpticalFlow &other) = delete;
OpticalFlow &operator=(const OpticalFlow&) = delete; OpticalFlow &operator=(const OpticalFlow&) = delete;
// get singleton instance
static OpticalFlow *get_singleton() {
return _singleton;
}
// init - initialise sensor // init - initialise sensor
void init(void); void init(void);
@ -79,6 +84,9 @@ public:
static const struct AP_Param::GroupInfo var_info[]; static const struct AP_Param::GroupInfo var_info[];
private: private:
static OpticalFlow *_singleton;
AP_AHRS_NavEKF &_ahrs; AP_AHRS_NavEKF &_ahrs;
OpticalFlow_backend *backend; OpticalFlow_backend *backend;
@ -100,4 +108,8 @@ private:
uint32_t _last_update_ms; // millis() time of last update uint32_t _last_update_ms; // millis() time of last update
}; };
namespace AP {
OpticalFlow *opticalflow();
}
#include "OpticalFlow_backend.h" #include "OpticalFlow_backend.h"