Skip to content

Commit

Permalink
sys_status.cpp: fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
amilcarlucas committed Feb 18, 2022
1 parent d8265ac commit ab11040
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions mavros/src/plugins/sys_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,29 @@ class BatteryStatusDiag : public diagnostic_updater::DiagnosticTask
min_voltage(6.0f)
{ }

// Move constructor, required to dynamically create an array of instances of this class
// because it contains an unique mutex object
BatteryStatusDiag(BatteryStatusDiag&& other) noexcept :
diagnostic_updater::DiagnosticTask(""),
added(false),
voltage(-1.0f),
current(0.0f),
remaining(0.0f),
min_voltage(6.0f)
{
*this = std::move(other);
}

// Move assignment operator, required to dynamically create an array of instances of this class
// because it contains an unique mutex object
BatteryStatusDiag& operator=(BatteryStatusDiag&& other) noexcept {
if (this != &other)
{
*this = std::move(other);
}
return *this;
}

void set_min_voltage(float volt) {
std::lock_guard<std::mutex> lock(mutex);
min_voltage = volt;
Expand Down Expand Up @@ -452,9 +475,9 @@ class SystemStatusPlugin : public plugin::PluginBase
has_battery_status0(false)
{
batt_diag.reserve(MAX_NR_BATTERY_STATUS);
batt_diag.emplace_back(std::move(BatteryStatusDiag("Battery")));
batt_diag.emplace_back("Battery");
for (int i = 2; i <= MAX_NR_BATTERY_STATUS ; ++i) {
batt_diag.emplace_back(std::move(BatteryStatusDiag(utils::format("Battery %u", i))));
batt_diag.emplace_back(utils::format("Battery %u", i));
}
}

Expand Down

0 comments on commit ab11040

Please sign in to comment.