From 2e80b2e1d074d0dd08a16d59e1678199c69ae5bc Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 25 Aug 2017 10:20:18 -0700 Subject: [PATCH] AP_RangeFinder: add static create method --- libraries/AP_RangeFinder/RangeFinder.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libraries/AP_RangeFinder/RangeFinder.h b/libraries/AP_RangeFinder/RangeFinder.h index 8ec128a344..f4e1520fe6 100644 --- a/libraries/AP_RangeFinder/RangeFinder.h +++ b/libraries/AP_RangeFinder/RangeFinder.h @@ -26,14 +26,24 @@ #define RANGEFINDER_PREARM_ALT_MAX_CM 200 #define RANGEFINDER_PREARM_REQUIRED_CHANGE_CM 50 -class AP_RangeFinder_Backend; - +class AP_RangeFinder_Backend; + class RangeFinder { -public: friend class AP_RangeFinder_Backend; - RangeFinder(AP_SerialManager &_serial_manager, enum Rotation orientation_default); +public: + static RangeFinder create(AP_SerialManager &_serial_manager, + enum Rotation orientation_default) + { + return RangeFinder(_serial_manager, orientation_default); + } + + constexpr RangeFinder(RangeFinder &&other) = default; + + /* Do not allow copies */ + RangeFinder(const RangeFinder &other) = delete; + RangeFinder &operator=(const RangeFinder&) = delete; // RangeFinder driver types enum RangeFinder_Type { @@ -156,6 +166,8 @@ public: private: + RangeFinder(AP_SerialManager &_serial_manager, enum Rotation orientation_default); + RangeFinder_State state[RANGEFINDER_MAX_INSTANCES]; AP_RangeFinder_Backend *drivers[RANGEFINDER_MAX_INSTANCES]; uint8_t num_instances:3;