From 70a4f6c15440f98640839f5e5c4e0aa6cdc38139 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Tue, 8 Mar 2022 12:49:34 +1100 Subject: [PATCH] fix: Companion will set critical radio general settings to profile defaults if mismatched boards (#1575) * Do not import potentially conflicting radio settings * Revert "Do not import potentially conflicting radio settings" This reverts commit 06a19c04d6de341568362b87311264081aa3d38f. * Override critical general settings to defaults when board mismatch --- .../src/firmwares/edgetx/yaml_generalsettings.cpp | 14 ++++++++++++++ companion/src/firmwares/generalsettings.cpp | 10 +++++----- companion/src/firmwares/generalsettings.h | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 2cd2ef247..71e6f4503 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -264,6 +264,12 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // If conversion should rename file with _converted suffix as done for bin // Need to pass back messages and flags like converted so they can be handled in a more suitable section + // Note: This is part of an interim workaround to ensure critical settings are set to profile board defaults + // TODO: remove and let board conversion occur as for eeprom and profile + // this will require yaml import of general and model settings to be refactored to not use current firmware + bool needsConversion = false; + // + rhs.variant = Board::BOARD_UNKNOWN; std::string flavour; @@ -280,6 +286,7 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) return false; } flavour = fw->getFlavour().toStdString(); + needsConversion = true; } else if (fw->getFlavour().toStdString() != flavour) { auto msfw = Firmware::getFirmwareForFlavour(QString(flavour.c_str())); @@ -290,8 +297,10 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // TODO: this triggers an error in the calling code so we need a graceful way to handle return false; } + needsConversion = true; } + // TODO: do not override here rhs.variant = fw->getBoard(); YamlCalibData calib; @@ -399,6 +408,11 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // OneBit sampling (X9D only?) node["uartSampleMode"] >> rhs.uartSampleMode; + // override critical settings after import + // TODO: for consistency move up call stack to use existing eeprom and profile conversions + if (needsConversion) + rhs.init(); + return true; } } // namespace YAML diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index e9b12a8d6..2bc022355 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -70,12 +70,14 @@ bool GeneralSettings::isSliderAvailable(int index) const return sliderConfig[index] != Board::SLIDER_NONE; } -GeneralSettings::GeneralSettings() +void GeneralSettings::clear() { memset(reinterpret_cast(this), 0, sizeof(GeneralSettings)); + init(); +} - contrast = 25; - +void GeneralSettings::init() +{ for (int i = 0; i < CPN_MAX_ANALOGS; ++i) { calibMid[i] = 0x200; calibSpanNeg[i] = 0x180; @@ -247,8 +249,6 @@ GeneralSettings::GeneralSettings() internalModule = g.profile[g.sessionId()].defaultInternalModule(); - const char * themeName = IS_FLYSKY_NV14(board) ? "FlySky" : "EdgeTX"; - RadioTheme::init(themeName, themeData); } void GeneralSettings::setDefaultControlTypes(Board::Type board) diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index c871289fd..1729adbeb 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -141,7 +141,9 @@ class GeneralSettings { enum TelemetryBaudrate { }; - GeneralSettings(); + GeneralSettings() { clear(); } + void clear(); + void init(); void convert(RadioDataConversionState & cstate); void setDefaultControlTypes(Board::Type board);