From b9ae30bbf9099683d2b8de875f1d5b702dbcdc51 Mon Sep 17 00:00:00 2001 From: Harsh Mittal Date: Thu, 9 Jan 2025 13:42:39 +0530 Subject: [PATCH] Fix Unique Flight Modes Only --- src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h | 2 +- src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h | 2 +- src/FirmwarePlugin/APM/ArduRoverFirmwarePlugin.h | 2 +- src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h | 2 +- src/FirmwarePlugin/FirmwarePlugin.cc | 13 ++++++++++++- src/FirmwarePlugin/FirmwarePlugin.h | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h index 34de7a716aa..75970a9b159 100644 --- a/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduCopterFirmwarePlugin.h @@ -74,7 +74,7 @@ class ArduCopterFirmwarePlugin : public APMFirmwarePlugin QString autoDisarmParameter (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral("DISARM_DELAY"); } bool supportsSmartRTL (void) const override { return true; } - void updateAvailableFlightModes (FlightModeList modeList) final; + void updateAvailableFlightModes (FlightModeList modeList) override; protected: uint32_t _convertToCustomFlightModeEnum(uint32_t val) const override; diff --git a/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h index 918fca157d2..a27e969e1ac 100644 --- a/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduPlaneFirmwarePlugin.h @@ -61,7 +61,7 @@ class ArduPlaneFirmwarePlugin : public APMFirmwarePlugin const FirmwarePlugin::remapParamNameMajorVersionMap_t& paramNameRemapMajorVersionMap(void) const final { return _remapParamName; } QString stabilizedFlightMode (void) const override; - void updateAvailableFlightModes (FlightModeList modeList) final; + void updateAvailableFlightModes (FlightModeList modeList) override; protected: uint32_t _convertToCustomFlightModeEnum(uint32_t val) const override; diff --git a/src/FirmwarePlugin/APM/ArduRoverFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduRoverFirmwarePlugin.h index 0e8f0cc1587..d8f10c89e3d 100644 --- a/src/FirmwarePlugin/APM/ArduRoverFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduRoverFirmwarePlugin.h @@ -54,7 +54,7 @@ class ArduRoverFirmwarePlugin : public APMFirmwarePlugin QString offlineEditingParamFile (Vehicle* vehicle) override { Q_UNUSED(vehicle); return QStringLiteral(":/FirmwarePlugin/APM/Rover.OfflineEditing.params"); } QString stabilizedFlightMode (void) const override; - void updateAvailableFlightModes (FlightModeList modeList) final; + void updateAvailableFlightModes (FlightModeList modeList) override; protected: uint32_t _convertToCustomFlightModeEnum(uint32_t val) const override; diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h index 52530af81dc..625fd8bcd95 100644 --- a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h @@ -154,7 +154,7 @@ class ArduSubFirmwarePlugin : public APMFirmwarePlugin QString stabilizedFlightMode (void) const override; QString motorDetectionFlightMode (void) const override; - void updateAvailableFlightModes (FlightModeList modeList) final; + void updateAvailableFlightModes (FlightModeList modeList) override; protected: uint32_t _convertToCustomFlightModeEnum(uint32_t val) const override; diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index eaaec8e477f..7ff67bad34c 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -594,6 +594,17 @@ void FirmwarePlugin::_updateModeMappings(FlightModeList &modeList){ _modeEnumToString[mode.custom_mode] = nModeName; } mode.mode_name = nModeName; - _availableFlightModeList += mode; + _addNewFlightMode(mode); } } + +void FirmwarePlugin::_addNewFlightMode(FirmwareFlightMode &mode) +{ + for(auto &m:_availableFlightModeList){ + if(m.custom_mode == mode.custom_mode){ + // Already Exist + return; + } + } + _availableFlightModeList += mode; +} diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index 53b9ce7579d..bc3ee6ca798 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -438,6 +438,7 @@ class FirmwarePlugin : public QObject // Update internal mappings for a list of flight modes void _updateModeMappings(FlightModeList &modeList); + void _addNewFlightMode (FirmwareFlightMode &mode); FlightModeList _availableFlightModeList; FlightModeCustomModeMap _modeEnumToString;