mirror of https://github.com/ArduPilot/ardupilot
AP_RangeFinder: Make singleton
This commit is contained in:
parent
5393337dfa
commit
7d6c3ec683
|
@ -540,6 +540,13 @@ RangeFinder::RangeFinder(AP_SerialManager &_serial_manager, enum Rotation orient
|
||||||
for (uint8_t i=0; i<RANGEFINDER_MAX_INSTANCES; i++) {
|
for (uint8_t i=0; i<RANGEFINDER_MAX_INSTANCES; i++) {
|
||||||
state[i].orientation.set_default(orientation_default);
|
state[i].orientation.set_default(orientation_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
||||||
|
if (_singleton != nullptr) {
|
||||||
|
AP_HAL::panic("Rangefinder must be singleton");
|
||||||
|
}
|
||||||
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
||||||
|
_singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -864,3 +871,5 @@ MAV_DISTANCE_SENSOR RangeFinder::get_mav_distance_sensor_type_orient(enum Rotati
|
||||||
}
|
}
|
||||||
return backend->get_mav_distance_sensor_type();
|
return backend->get_mav_distance_sensor_type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RangeFinder *RangeFinder::_singleton;
|
||||||
|
|
|
@ -157,8 +157,12 @@ public:
|
||||||
*/
|
*/
|
||||||
bool pre_arm_check() const;
|
bool pre_arm_check() const;
|
||||||
|
|
||||||
|
static RangeFinder *get_singleton(void) { return _singleton; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static RangeFinder *_singleton;
|
||||||
|
|
||||||
RangeFinder_State state[RANGEFINDER_MAX_INSTANCES];
|
RangeFinder_State state[RANGEFINDER_MAX_INSTANCES];
|
||||||
AP_RangeFinder_Backend *drivers[RANGEFINDER_MAX_INSTANCES];
|
AP_RangeFinder_Backend *drivers[RANGEFINDER_MAX_INSTANCES];
|
||||||
uint8_t num_instances:3;
|
uint8_t num_instances:3;
|
||||||
|
|
Loading…
Reference in New Issue