From a4c56fcb821b1b21028e85f568de5f4cb1b521eb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Dec 2017 12:06:11 +1100 Subject: [PATCH] AP_BattMonitor: removed create() method for objects See discussion here: https://github.com/ArduPilot/ardupilot/issues/7331 we were getting some uninitialised variables. While it only showed up in AP_SbusOut, it means we can't be sure it won't happen on other objects, so safest to remove the approach Thanks to assistance from Lucas, Peter and Francisco --- libraries/AP_BattMonitor/AP_BattMonitor.h | 6 +----- .../examples/AP_BattMonitor_test/AP_BattMonitor_test.cpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.h b/libraries/AP_BattMonitor/AP_BattMonitor.h index 4f58264d85..7a1b79e8bd 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor.h @@ -37,9 +37,7 @@ class AP_BattMonitor friend class AP_BattMonitor_SMBus_Maxell; public: - static AP_BattMonitor create() { return AP_BattMonitor{}; } - - constexpr AP_BattMonitor(AP_BattMonitor &&other) = default; + AP_BattMonitor(); /* Do not allow copies */ AP_BattMonitor(const AP_BattMonitor &other) = delete; @@ -179,8 +177,6 @@ protected: AP_Int8 _low_voltage_source; /// voltage type used for detection of low voltage event private: - AP_BattMonitor(); - BattMonitor_State state[AP_BATT_MONITOR_MAX_INSTANCES]; AP_BattMonitor_Backend *drivers[AP_BATT_MONITOR_MAX_INSTANCES]; uint8_t _num_instances; /// number of monitors diff --git a/libraries/AP_BattMonitor/examples/AP_BattMonitor_test/AP_BattMonitor_test.cpp b/libraries/AP_BattMonitor/examples/AP_BattMonitor_test/AP_BattMonitor_test.cpp index ee3920acff..c35c8ebca7 100644 --- a/libraries/AP_BattMonitor/examples/AP_BattMonitor_test/AP_BattMonitor_test.cpp +++ b/libraries/AP_BattMonitor/examples/AP_BattMonitor_test/AP_BattMonitor_test.cpp @@ -11,7 +11,7 @@ void loop(); const AP_HAL::HAL& hal = AP_HAL::get_HAL(); -static AP_BattMonitor battery_mon = AP_BattMonitor::create(); +static AP_BattMonitor battery_mon; uint32_t timer; void setup() {