From 89517d8bd8fdb40b3d03f868dba7add60c39abc6 Mon Sep 17 00:00:00 2001 From: rotorman Date: Sat, 13 Nov 2021 16:30:37 +0100 Subject: [PATCH 001/180] Use ETX instead of OTX (also as a file extension). --- companion/src/constants.h | 3 +- companion/src/mainwindow.cpp | 4 +- companion/src/mdichild.cpp | 6 +-- companion/src/mdichild.h | 2 +- .../src/simulation/simulatorstartupdialog.cpp | 2 +- companion/src/simulation/simulatorwidget.cpp | 10 ++--- companion/src/simulator.cpp | 2 +- companion/src/storage/CMakeLists.txt | 2 +- companion/src/storage/{otx.cpp => etx.cpp} | 20 ++++----- companion/src/storage/{otx.h => etx.h} | 14 +++--- companion/src/storage/firmwareinterface.cpp | 14 +++--- companion/src/storage/storage.cpp | 6 ++- companion/src/storage/storage.h | 3 +- companion/src/tests/conversions.cpp | 22 +++++----- radio/src/lua/api_general.cpp | 2 +- radio/src/lua/api_model.cpp | 6 +-- radio/src/pulses/multi.cpp | 8 ++-- radio/src/pulses/multi.h | 4 +- radio/src/sdcard.h | 40 +++++++++--------- .../yaml/yaml_datastructs_funcs.cpp | 2 +- radio/src/storage/eeprom_raw.cpp | 4 +- radio/src/storage/eeprom_rlc.cpp | 4 +- radio/src/storage/sdcard_raw.cpp | 4 +- .../storage/yaml/yaml_datastructs_funcs.cpp | 4 +- radio/src/targets/simu/opentxsimulator.cpp | 10 ++--- radio/src/tests/CMakeLists.txt | 4 +- .../{model_23_x10.otx => model_23_x10.etx} | Bin .../{model_23_x12s.otx => model_23_x12s.etx} | Bin ...{model_25_tx16s.otx => model_25_tx16s.etx} | Bin 29 files changed, 103 insertions(+), 99 deletions(-) rename companion/src/storage/{otx.cpp => etx.cpp} (84%) rename companion/src/storage/{otx.h => etx.h} (84%) rename radio/src/tests/{model_23_x10.otx => model_23_x10.etx} (100%) rename radio/src/tests/{model_23_x12s.otx => model_23_x12s.etx} (100%) rename radio/src/tests/{model_25_tx16s.otx => model_25_tx16s.etx} (100%) diff --git a/companion/src/constants.h b/companion/src/constants.h index b06792a91..5a6511168 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -60,8 +60,9 @@ #define DFU_FILES_FILTER "DFU " % CPN_STR_FILES % " (*.dfu);;" #define EEPE_FILES_FILTER "EEPE " % CPN_STR_FILES % " (*.eepe);;" #define OTX_FILES_FILTER "OpenTX " % CPN_STR_FILES % " (*.otx);;" +#define ETX_FILES_FILTER "EdgeTX " % CPN_STR_FILES % " (*.etx);;" #define YML_FILES_FILTER "YAML " % CPN_STR_FILES % " (*.yml);;" -#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.otx *.yml *.eepe *.bin *.hex);;" % OTX_FILES_FILTER % YML_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER +#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.otx *.yml *.eepe *.bin *.hex);;" % ETX_FILES_FILTER % OTX_FILES_FILTER % YML_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER #define FLASH_FILES_FILTER "FLASH " % CPN_STR_FILES % " (*.bin *.hex *.dfu);;" % BIN_FILES_FILTER % HEX_FILES_FILTER % DFU_FILES_FILTER #define EXTERNAL_EEPROM_FILES_FILTER "EEPROM " % CPN_STR_FILES % " (*.bin *.hex);;" % BIN_FILES_FILTER % HEX_FILES_FILTER #define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE" diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 54d06c071..e1465f9f3 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -157,7 +157,7 @@ MainWindow::MainWindow(): if (!str.isEmpty()) { int fileType = getStorageType(str); - if (fileType==STORAGE_TYPE_EEPE || fileType==STORAGE_TYPE_EEPM || fileType==STORAGE_TYPE_BIN || fileType==STORAGE_TYPE_OTX) { + if (fileType==STORAGE_TYPE_EEPE || fileType==STORAGE_TYPE_EEPM || fileType==STORAGE_TYPE_BIN || fileType==STORAGE_TYPE_ETX) { MdiChild * child = createMdiChild(); if (child->loadFile(str)) { if (!(printing && model >= 0 && (getCurrentFirmware()->getCapability(Models) == 0 || modelgetCapability(Models)) && !printfilename.isEmpty())) { @@ -908,7 +908,7 @@ void MainWindow::readEeprom() Board::Type board = getCurrentBoard(); QString tempFile; if (IS_FAMILY_HORUS_OR_T16(board)) - tempFile = generateProcessUniqueTempFileName("temp.otx"); + tempFile = generateProcessUniqueTempFileName("temp.etx"); else tempFile = generateProcessUniqueTempFileName("temp.bin"); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 600f44851..14a4266b1 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1320,7 +1320,7 @@ void MdiChild::newFile(bool createDefaults) { static int sequenceNumber = 1; isUntitled = true; - curFile = QString("document%1.otx").arg(sequenceNumber++); + curFile = QString("document%1.etx").arg(sequenceNumber++); updateTitle(); if (createDefaults && firmware->getCapability(Capability::HasModelCategories)) { @@ -1375,7 +1375,7 @@ bool MdiChild::saveAs(bool isNew) #ifdef __APPLE__ QString filter; #else - QString filter(OTX_FILES_FILTER % YML_FILES_FILTER); + QString filter(ETX_FILES_FILTER % YML_FILES_FILTER); #endif QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" + fi.fileName(), filter); @@ -1455,7 +1455,7 @@ void MdiChild::setCurrentFile(const QString & fileName) void MdiChild::forceNewFilename(const QString & suffix, const QString & ext) { - curFile.replace(QRegExp("\\.(eepe|bin|hex|otx)$"), suffix + "." + ext); + curFile.replace(QRegExp("\\.(eepe|bin|hex|etx)$"), suffix + "." + ext); } bool MdiChild::convertStorage(Board::Type from, Board::Type to, bool newFile) diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 079205cc1..b44047aba 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -179,7 +179,7 @@ class MdiChild : public QWidget bool maybeSave(); void setCurrentFile(const QString & fileName); - void forceNewFilename(const QString & suffix = "", const QString & ext = "otx"); + void forceNewFilename(const QString & suffix = "", const QString & ext = "etx"); bool convertStorage(Board::Type from, Board::Type to, bool newFile = false); void showWarning(const QString & msg); int askQuestion(const QString & msg, QMessageBox::StandardButtons buttons = (QMessageBox::Yes | QMessageBox::No), QMessageBox::StandardButton defaultButton = QMessageBox::No); diff --git a/companion/src/simulation/simulatorstartupdialog.cpp b/companion/src/simulation/simulatorstartupdialog.cpp index e48a32afe..8d70a2b50 100644 --- a/companion/src/simulation/simulatorstartupdialog.cpp +++ b/companion/src/simulation/simulatorstartupdialog.cpp @@ -120,7 +120,7 @@ QString SimulatorStartupDialog::radioEepromFileName(const QString & firmwareId, if (pos > 0) radioId = radioId.mid(pos+1); if (usesCategorizedStorage(radioId)) - ext = "otx"; + ext = "etx"; eepromFileName = QString("eeprom-%1.%2").arg(radioId, ext); eepromFileName = QDir(folder).filePath(eepromFileName.toLatin1()); diff --git a/companion/src/simulation/simulatorwidget.cpp b/companion/src/simulation/simulatorwidget.cpp index 8f3ef08c2..365cb57d4 100644 --- a/companion/src/simulation/simulatorwidget.cpp +++ b/companion/src/simulation/simulatorwidget.cpp @@ -249,9 +249,9 @@ bool SimulatorWidget::setStartupData(const QByteArray & dataSource, bool fromFil error = store.error(); } else { - if (fileName.endsWith(".otx", Qt::CaseInsensitive)) { - // no radios can work with .otx files directly, so we load contents into either - // a temporary folder (Horus) or local data array (other radios) which we'll save back to .otx upon exit + if (fileName.endsWith(".etx", Qt::CaseInsensitive)) { + // no radios can work with .etx files directly, so we load contents into either + // a temporary folder (Horus) or local data array (other radios) which we'll save back to .etx upon exit if ((ret = setRadioData(&simuData))) { startupFromFile = false; return true; @@ -365,7 +365,7 @@ bool SimulatorWidget::useTempDataPath(bool deleteOnClose) if (deleteTempRadioData) deleteTempData(); - QTemporaryDir tmpDir(QDir::tempPath() + "/otx-XXXXXX"); + QTemporaryDir tmpDir(QDir::tempPath() + "/etx-XXXXXX"); if (tmpDir.isValid()) { setDataPath(tmpDir.path()); tmpDir.setAutoRemove(false); @@ -379,7 +379,7 @@ bool SimulatorWidget::useTempDataPath(bool deleteOnClose) } } -// This will save radio data from temporary folder structure back into an .otx file, eg. for Horus. +// This will save radio data from temporary folder structure back into an .etx file, eg. for Horus. bool SimulatorWidget::saveTempData() { bool ret = false; diff --git a/companion/src/simulator.cpp b/companion/src/simulator.cpp index 283248496..7caca8e97 100644 --- a/companion/src/simulator.cpp +++ b/companion/src/simulator.cpp @@ -127,7 +127,7 @@ CommandLineParseResult cliOptions(SimulatorOptions * simOptions, int * profileId QApplication::translate("SimulatorMain", "type")); cliOptions.addPositionalArgument(QApplication::translate("SimulatorMain", "data-source"), - QApplication::translate("SimulatorMain", "Radio data (.bin/.eeprom/.otx) image file to use OR data folder path (for Horus-style radios).\n" + QApplication::translate("SimulatorMain", "Radio data (.bin/.eeprom/.etx) image file to use OR data folder path (for Horus-style radios).\n" "NOTE: any existing EEPROM data incompatible with the selected radio type may be overwritten!"), QApplication::translate("SimulatorMain", "[data-source]")); diff --git a/companion/src/storage/CMakeLists.txt b/companion/src/storage/CMakeLists.txt index 8df237238..2781b50b9 100644 --- a/companion/src/storage/CMakeLists.txt +++ b/companion/src/storage/CMakeLists.txt @@ -12,7 +12,7 @@ set(storage_NAMES hexeeprom categorized sdcard - otx + etx yaml ) diff --git a/companion/src/storage/otx.cpp b/companion/src/storage/etx.cpp similarity index 84% rename from companion/src/storage/otx.cpp rename to companion/src/storage/etx.cpp index 90ea2bbf8..e79d9d477 100644 --- a/companion/src/storage/otx.cpp +++ b/companion/src/storage/etx.cpp @@ -18,13 +18,13 @@ * GNU General Public License for more details. */ -#include "otx.h" +#include "etx.h" #include "miniz.c" #include #define MZ_ALLOCATION_SIZE (32*1024) -bool OtxFormat::load(RadioData & radioData) +bool EtxFormat::load(RadioData & radioData) { QFile file(filename); @@ -40,7 +40,7 @@ bool OtxFormat::load(RadioData & radioData) // open zip file memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_reader_init_mem(&zip_archive, archiveContents.data(), archiveContents.size(), 0)) { - qDebug() << tr("Error opening OTX archive %1").arg(filename); + qDebug() << tr("Error opening ETX archive %1").arg(filename); return false; } @@ -49,13 +49,13 @@ bool OtxFormat::load(RadioData & radioData) return result; } -bool OtxFormat::write(const RadioData & radioData) +bool EtxFormat::write(const RadioData & radioData) { qDebug() << "Saving to archive" << filename; memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_writer_init_heap(&zip_archive, 0, MZ_ALLOCATION_SIZE)) { - setError(tr("Error initializing OTX archive writer")); + setError(tr("Error initializing ETX archive writer")); return false; } @@ -76,12 +76,12 @@ bool OtxFormat::write(const RadioData & radioData) } } else { - setError(tr("Error creating OTX file %1:\n%2.").arg(filename).arg(file.errorString())); + setError(tr("Error creating ETX file %1:\n%2.").arg(filename).arg(file.errorString())); result = false; } } else { - setError(tr("Error creating OTX archive")); + setError(tr("Error creating ETX archive")); result = false; } } @@ -90,7 +90,7 @@ bool OtxFormat::write(const RadioData & radioData) return result; } -bool OtxFormat::loadFile(QByteArray & filedata, const QString & filename) +bool EtxFormat::loadFile(QByteArray & filedata, const QString & filename) { size_t size; void * data = mz_zip_reader_extract_file_to_heap(&zip_archive, qPrintable(filename), &size, 0); @@ -105,10 +105,10 @@ bool OtxFormat::loadFile(QByteArray & filedata, const QString & filename) return true; } -bool OtxFormat::writeFile(const QByteArray & filedata, const QString & filename) +bool EtxFormat::writeFile(const QByteArray & filedata, const QString & filename) { if (!mz_zip_writer_add_mem(&zip_archive, filename.toStdString().c_str(), filedata.data(), filedata.size(), MZ_DEFAULT_LEVEL)) { - setError(tr("Error adding %1 to OTX archive").arg(filename)); + setError(tr("Error adding %1 to ETX archive").arg(filename)); return false; } diff --git a/companion/src/storage/otx.h b/companion/src/storage/etx.h similarity index 84% rename from companion/src/storage/otx.h rename to companion/src/storage/etx.h index da4923488..8c7002ed2 100644 --- a/companion/src/storage/otx.h +++ b/companion/src/storage/etx.h @@ -18,8 +18,8 @@ * GNU General Public License for more details. */ -#ifndef _OTX_H_ -#define _OTX_H_ +#ifndef _ETX_H_ +#define _ETX_H_ #include "categorized.h" @@ -29,17 +29,17 @@ #include "miniz.c" #undef MINIZ_HEADER_FILE_ONLY -class OtxFormat : public CategorizedStorageFormat +class EtxFormat : public CategorizedStorageFormat { - Q_DECLARE_TR_FUNCTIONS(OtxFormat) + Q_DECLARE_TR_FUNCTIONS(EtxFormat) public: - OtxFormat(const QString & filename): + EtxFormat(const QString & filename): CategorizedStorageFormat(filename) { } - virtual QString name() { return "otx"; } + virtual QString name() { return "etx"; } virtual bool load(RadioData & radioData); virtual bool write(const RadioData & radioData); @@ -50,4 +50,4 @@ class OtxFormat : public CategorizedStorageFormat mz_zip_archive zip_archive; }; -#endif // _OTX_H_ +#endif // _ETX_H_ diff --git a/companion/src/storage/firmwareinterface.cpp b/companion/src/storage/firmwareinterface.cpp index 4357928d1..79ca4a2fe 100644 --- a/companion/src/storage/firmwareinterface.cpp +++ b/companion/src/storage/firmwareinterface.cpp @@ -305,11 +305,11 @@ bool FirmwareInterface::seekSplash(QByteArray sps, QByteArray spe, int size) return false; } -#define OTX_SPS_9X "SPS\0\200\100" -#define OTX_SPS_TARANIS "SPS\0\324\100" -#define OTX_SPS_SIZE 6 -#define OTX_SPE "SPE" -#define OTX_SPE_SIZE 4 +#define ETX_SPS_9X "SPS\0\200\100" +#define ETX_SPS_TARANIS "SPS\0\324\100" +#define ETX_SPS_SIZE 6 +#define ETX_SPE "SPE" +#define ETX_SPE_SIZE 4 void FirmwareInterface::seekSplash() { @@ -342,11 +342,11 @@ void FirmwareInterface::seekSplash() return; } - if (seekSplash(QByteArray(OTX_SPS_9X, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), 1024)) { + if (seekSplash(QByteArray(ETX_SPS_9X, ETX_SPS_SIZE), QByteArray(ETX_SPE, ETX_SPE_SIZE), 1024)) { return; } - if (seekSplash(QByteArray(OTX_SPS_TARANIS, OTX_SPS_SIZE), QByteArray(OTX_SPE, OTX_SPE_SIZE), RLE_SPLASH_MAX_SIZE)) { + if (seekSplash(QByteArray(ETX_SPS_TARANIS, ETX_SPS_SIZE), QByteArray(ETX_SPE, ETX_SPE_SIZE), RLE_SPLASH_MAX_SIZE)) { splashWidth = SPLASHX9D_WIDTH; splashHeight = SPLASHX9D_HEIGHT; splash_format = QImage::Format_Indexed8; diff --git a/companion/src/storage/storage.cpp b/companion/src/storage/storage.cpp index 63a5f429e..8ec511769 100644 --- a/companion/src/storage/storage.cpp +++ b/companion/src/storage/storage.cpp @@ -20,7 +20,7 @@ #include "bineeprom.h" #include "eepe.h" -#include "otx.h" +#include "etx.h" #include "sdcard.h" #include "yaml.h" #include "firmwareinterface.h" @@ -42,6 +42,8 @@ StorageType getStorageType(const QString & filename) return STORAGE_TYPE_XML; else if (suffix == "OTX") return STORAGE_TYPE_OTX; + else if (suffix == "ETX") + return STORAGE_TYPE_ETX; else if (suffix == "YML") return STORAGE_TYPE_YML; else @@ -63,7 +65,7 @@ void registerStorageFactories() registerStorageFactory(new DefaultStorageFactory("bin")); registerStorageFactory(new DefaultStorageFactory("eepe")); registerStorageFactory(new DefaultStorageFactory("hex")); - registerStorageFactory(new DefaultStorageFactory("otx")); + registerStorageFactory(new DefaultStorageFactory("etx")); registerStorageFactory(new DefaultStorageFactory("yml")); registerStorageFactory(new SdcardStorageFactory()); } diff --git a/companion/src/storage/storage.h b/companion/src/storage/storage.h index f9843650e..1e112158a 100644 --- a/companion/src/storage/storage.h +++ b/companion/src/storage/storage.h @@ -37,7 +37,8 @@ enum StorageType STORAGE_TYPE_XML, STORAGE_TYPE_SDCARD, STORAGE_TYPE_OTX, - STORAGE_TYPE_YML + STORAGE_TYPE_YML, + STORAGE_TYPE_ETX }; StorageType getStorageType(const QString & filename); diff --git a/companion/src/tests/conversions.cpp b/companion/src/tests/conversions.cpp index 8317d6ef3..b68fc0969 100644 --- a/companion/src/tests/conversions.cpp +++ b/companion/src/tests/conversions.cpp @@ -1,6 +1,6 @@ #include "gtests.h" #include "location.h" -#include "storage/otx.h" +#include "storage/etx.h" #include "storage/storage.h" #include "firmwares/opentx/opentxinterface.h" #include "firmwares/customfunctiondata.h" @@ -210,12 +210,12 @@ TEST(Conversions, ConversionX10From22) { QByteArray byteBuffer; -#define USE_OTX +#define USE_ETX -#if defined(USE_OTX) - OtxFormat otx(RADIO_TESTS_PATH "/model_22_x10.otx"); +#if defined(USE_ETX) + EtxFormat etx(RADIO_TESTS_PATH "/model_22_x10.etx"); RadioData radio; - EXPECT_EQ(true, otx.load(radio)); + EXPECT_EQ(true, etx.load(radio)); const GeneralSettings& settings = radio.generalSettings; const ModelData& model = radio.models[0]; @@ -253,7 +253,7 @@ TEST(Conversions, ConversionX10From22) EXPECT_STREQ("BT_X10", settings.bluetoothName); EXPECT_STREQ("EdgeTX", settings.themeData.themeName); -#if !defined(USE_OTX) +#if !defined(USE_ETX) byteBuffer.clear(); ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x10/MODELS/model1.bin")); @@ -295,12 +295,12 @@ TEST(Conversions, ConversionX12SFrom22) { QByteArray byteBuffer; -#define USE_OTX +#define USE_ETX -#if defined(USE_OTX) - OtxFormat otx(RADIO_TESTS_PATH "/model_22_x12s.otx"); +#if defined(USE_ETX) + EtxFormat etx(RADIO_TESTS_PATH "/model_22_x12s.etx"); RadioData radio; - EXPECT_EQ(true, otx.load(radio)); + EXPECT_EQ(true, etx.load(radio)); const GeneralSettings& settings = radio.generalSettings; const ModelData& model = radio.models[0]; @@ -330,7 +330,7 @@ TEST(Conversions, ConversionX12SFrom22) EXPECT_STREQ("BT", settings.bluetoothName); EXPECT_STREQ("EdgeTX", settings.themeData.themeName); -#if !defined(USE_OTX) +#if !defined(USE_ETX) byteBuffer.clear(); ASSERT_EQ(true, loadFile(byteBuffer, RADIO_TESTS_PATH "/model_22_x10/MODELS/model1.bin")); diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 354cdd1c8..c4b006b3e 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -1507,7 +1507,7 @@ then the loaded script (or "chunk") is returned as a function. Otherwise, return as part of the file name and the .lua/.luac will be appended to that. @param mode (string) (optional) Controls whether to force loading the text (.lua) or pre-compiled binary (.luac) - version of the script. By default OTx will load the newest version and compile a new binary if necessary (overwriting any + version of the script. By default ETX will load the newest version and compile a new binary if necessary (overwriting any existing .luac version of the same script, and stripping some debug info like line numbers). You can use `mode` to control the loading behavior more specifically. Possible values are: * `b` only binary. diff --git a/radio/src/lua/api_model.cpp b/radio/src/lua/api_model.cpp index e9dc36eb3..07f9f6832 100644 --- a/radio/src/lua/api_model.cpp +++ b/radio/src/lua/api_model.cpp @@ -158,7 +158,7 @@ static int luaModelGetModule(lua_State *L) if (module.type == MODULE_TYPE_MULTIMODULE) { int protocol = g_model.moduleData[idx].getMultiProtocol() + 1; int subprotocol = g_model.moduleData[idx].subType; - convertOtxProtocolToMulti(&protocol, &subprotocol); // Special treatment for the FrSky entry... + convertEtxProtocolToMulti(&protocol, &subprotocol); // Special treatment for the FrSky entry... lua_pushtableinteger(L, "protocol", protocol); lua_pushtableinteger(L, "subProtocol", subprotocol); if (getMultiModuleStatus(idx).isValid()) { @@ -231,8 +231,8 @@ static int luaModelSetModule(lua_State *L) #endif } #if defined(MULTIMODULE) - if (protocol > 0 && subprotocol >= 0) { // Both are needed to compute otx protocol - convertMultiProtocolToOtx(&protocol, &subprotocol); + if (protocol > 0 && subprotocol >= 0) { // Both are needed to compute etx protocol + convertMultiProtocolToEtx(&protocol, &subprotocol); g_model.moduleData[idx].setMultiProtocol(protocol - 1); g_model.moduleData[idx].subType = subprotocol; } diff --git a/radio/src/pulses/multi.cpp b/radio/src/pulses/multi.cpp index 93a2a2dfa..cb2bfdd9d 100644 --- a/radio/src/pulses/multi.cpp +++ b/radio/src/pulses/multi.cpp @@ -53,7 +53,7 @@ static void sendDSM(uint8_t moduleIdx); void multiPatchCustom(uint8_t moduleIdx) { if (g_model.moduleData[moduleIdx].multi.customProto) { - uint8_t type = g_model.moduleData[moduleIdx].getMultiProtocol() - 1; // custom where starting at 1, otx list at 0 + uint8_t type = g_model.moduleData[moduleIdx].getMultiProtocol() - 1; // custom where starting at 1, etx list at 0 int subtype = g_model.moduleData[moduleIdx].subType; g_model.moduleData[moduleIdx].multi.customProto = 0; @@ -268,7 +268,7 @@ void sendChannels(uint8_t moduleIdx) } } -void convertMultiProtocolToOtx(int *protocol, int *subprotocol) +void convertMultiProtocolToEtx(int *protocol, int *subprotocol) { if (*protocol == 3 && *subprotocol == 0) { *protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1; @@ -312,7 +312,7 @@ void convertMultiProtocolToOtx(int *protocol, int *subprotocol) *protocol -= 1; } -void convertOtxProtocolToMulti(int *protocol, int *subprotocol) +void convertEtxProtocolToMulti(int *protocol, int *subprotocol) { // Special treatment for the FrSky entry... if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY + 1) { @@ -407,7 +407,7 @@ void sendFrameProtocolHeader(uint8_t moduleIdx, bool failsafe) } // Special treatment for the FrSky entry... - convertOtxProtocolToMulti(&type, &subtype); + convertEtxProtocolToMulti(&type, &subtype); // Set the highest bit of option byte in AFHDS2A protocol to instruct MULTI to passthrough telemetry bytes instead // of sending Frsky D telemetry diff --git a/radio/src/pulses/multi.h b/radio/src/pulses/multi.h index d9a50d318..756fcf28a 100644 --- a/radio/src/pulses/multi.h +++ b/radio/src/pulses/multi.h @@ -25,8 +25,8 @@ #include "pulses_common.h" void multiPatchCustom(uint8_t moduleIdx); -void convertOtxProtocolToMulti(int *protocol, int *subprotocol); -void convertMultiProtocolToOtx(int *protocol, int *subprotocol); +void convertEtxProtocolToMulti(int *protocol, int *subprotocol); +void convertMultiProtocolToEtx(int *protocol, int *subprotocol); class UartMultiPulses: public DataBuffer { diff --git a/radio/src/sdcard.h b/radio/src/sdcard.h index 43896b690..51873d4b8 100644 --- a/radio/src/sdcard.h +++ b/radio/src/sdcard.h @@ -133,45 +133,45 @@ inline const char * SDCARD_ERROR(FRESULT result) const char * getBasename(const char * path); #if defined(PCBX12S) - #define OTX_FOURCC 0x3478746F // otx for X12S + #define ETX_FOURCC 0x3478746F // etx for X12S #elif defined(RADIO_T16) - #define OTX_FOURCC 0x3F78746F // otx for Jumper T16 + #define ETX_FOURCC 0x3F78746F // etx for Jumper T16 #elif defined(RADIO_T18) - #define OTX_FOURCC 0x4078746F // otx for Jumper T18 + #define ETX_FOURCC 0x4078746F // etx for Jumper T18 #elif defined(RADIO_TX16S) - #define OTX_FOURCC 0x3878746F // otx for Radiomaster TX16S + #define ETX_FOURCC 0x3878746F // etx for Radiomaster TX16S #elif defined(PCBX10) - #define OTX_FOURCC 0x3778746F // otx for X10 + #define ETX_FOURCC 0x3778746F // etx for X10 #elif defined(PCBX9E) - #define OTX_FOURCC 0x3578746F // otx for Taranis X9E + #define ETX_FOURCC 0x3578746F // etx for Taranis X9E #elif defined(PCBXLITES) - #define OTX_FOURCC 0x3B78746F // otx for Taranis X-Lite S + #define ETX_FOURCC 0x3B78746F // etx for Taranis X-Lite S #elif defined(PCBXLITE) - #define OTX_FOURCC 0x3978746F // otx for Taranis X-Lite + #define ETX_FOURCC 0x3978746F // etx for Taranis X-Lite #elif defined(RADIO_T12) - #define OTX_FOURCC 0x3D78746F // otx for Jumper T12 + #define ETX_FOURCC 0x3D78746F // etx for Jumper T12 #elif defined(RADIO_TLITE) - #define OTX_FOURCC 0x4278746F // otx for Jumper TLite + #define ETX_FOURCC 0x4278746F // etx for Jumper TLite #elif defined(RADIO_TPRO) - #define OTX_FOURCC 0x4678746F // otx for Jumper TPro + #define ETX_FOURCC 0x4678746F // etx for Jumper TPro #elif defined(RADIO_TX12) - #define OTX_FOURCC 0x4178746F // otx for Radiomaster TX12 + #define ETX_FOURCC 0x4178746F // etx for Radiomaster TX12 #elif defined(RADIO_ZORRO) - #define OTX_FOURCC 0x4778746F // otx for Radiomaster Zorro + #define ETX_FOURCC 0x4778746F // otx for Radiomaster Zorro #elif defined(RADIO_T8) - #define OTX_FOURCC 0x4378746F // otx for Radiomaster T8 + #define ETX_FOURCC 0x4378746F // etx for Radiomaster T8 #elif defined(PCBX7) - #define OTX_FOURCC 0x3678746F // otx for Taranis X7 / X7S / X7 Express / X7S Express + #define ETX_FOURCC 0x3678746F // etx for Taranis X7 / X7S / X7 Express / X7S Express #elif defined(PCBX9LITES) - #define OTX_FOURCC 0x3E78746F // otx for Taranis X9-Lite S + #define ETX_FOURCC 0x3E78746F // etx for Taranis X9-Lite S #elif defined(PCBX9LITE) - #define OTX_FOURCC 0x3C78746F // otx for Taranis X9-Lite + #define ETX_FOURCC 0x3C78746F // etx for Taranis X9-Lite #elif defined(PCBX9D) || defined(PCBX9DP) - #define OTX_FOURCC 0x3378746F // otx for Taranis X9D + #define ETX_FOURCC 0x3378746F // etx for Taranis X9D #elif defined(PCBNV14) - #define OTX_FOURCC 0x3A78746F // otx for NV14 + #define ETX_FOURCC 0x3A78746F // etx for NV14 #elif defined(PCBSKY9X) - #define OTX_FOURCC 0x3278746F // otx for sky9x + #define ETX_FOURCC 0x3278746F // etx for sky9x #endif bool isFileAvailable(const char * filename, bool exclDir = false); diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index 0894b995e..cb1104166 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -1132,7 +1132,7 @@ bool w_modSubtype(void* user, uint8_t* data, uint32_t bitoffs, // data as-is (no FrSky special casing) int type = md->getMultiProtocol() + 1; int subtype = val; - convertOtxProtocolToMulti(&type, &subtype); + convertEtxProtocolToMulti(&type, &subtype); // output "[type],[subtype]" str = yaml_unsigned2str(type); diff --git a/radio/src/storage/eeprom_raw.cpp b/radio/src/storage/eeprom_raw.cpp index a7381319d..f3acf4ecb 100644 --- a/radio/src/storage/eeprom_raw.cpp +++ b/radio/src/storage/eeprom_raw.cpp @@ -473,7 +473,7 @@ const char * eeBackupModel(uint8_t i_fileSrc) uint16_t size = eeModelSize(i_fileSrc); - *(uint32_t*)&buf[0] = OTX_FOURCC; + *(uint32_t*)&buf[0] = ETX_FOURCC; buf[4] = g_eeGeneral.version; buf[5] = 'M'; *(uint16_t*)&buf[6] = size; @@ -540,7 +540,7 @@ const char * eeRestoreModel(uint8_t i_fileDst, char *model_name) } uint8_t version = (uint8_t)buf[4]; - if (*(uint32_t*)&buf[0] != OTX_FOURCC || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') { + if (*(uint32_t*)&buf[0] != ETX_FOURCC || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') { f_close(&restoreFile); return STR_INCOMPATIBLE; } diff --git a/radio/src/storage/eeprom_rlc.cpp b/radio/src/storage/eeprom_rlc.cpp index 8f18c72a1..0c8d80315 100644 --- a/radio/src/storage/eeprom_rlc.cpp +++ b/radio/src/storage/eeprom_rlc.cpp @@ -508,7 +508,7 @@ const char * eeBackupModel(uint8_t i_fileSrc) EFile theFile2; theFile2.openRd(FILE_MODEL(i_fileSrc)); - *(uint32_t*)&buf[0] = OTX_FOURCC; + *(uint32_t*)&buf[0] = ETX_FOURCC; buf[4] = g_eeGeneral.version; buf[5] = 'M'; *(uint16_t*)&buf[6] = eeModelSize(i_fileSrc); @@ -561,7 +561,7 @@ const char * eeRestoreModel(uint8_t i_fileDst, char *model_name) } uint8_t version = (uint8_t)buf[4]; - if (*(uint32_t*)&buf[0] != OTX_FOURCC || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') { + if (*(uint32_t*)&buf[0] != ETX_FOURCC || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') { f_close(&g_oLogFile); return STR_INCOMPATIBLE; } diff --git a/radio/src/storage/sdcard_raw.cpp b/radio/src/storage/sdcard_raw.cpp index 34bc56be4..b84c75554 100644 --- a/radio/src/storage/sdcard_raw.cpp +++ b/radio/src/storage/sdcard_raw.cpp @@ -37,7 +37,7 @@ const char *writeFileBin(const char *filename, const uint8_t *data, return SDCARD_ERROR(result); } - *(uint32_t*)&buf[0] = OTX_FOURCC; + *(uint32_t*)&buf[0] = ETX_FOURCC; buf[4] = version; buf[5] = 'M'; *(uint16_t*)&buf[6] = size; @@ -99,7 +99,7 @@ const char* openFileBin(const char * fullpath, FIL * file, uint16_t * size, uint } *version = (uint8_t)buf[4]; - if (*(uint32_t *)&buf[0] != OTX_FOURCC || *version < FIRST_CONV_EEPROM_VER || + if (*(uint32_t *)&buf[0] != ETX_FOURCC || *version < FIRST_CONV_EEPROM_VER || *version > EEPROM_VER || buf[5] != 'M') { f_close(file); return STR_INCOMPATIBLE; diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 5af9c9299..4774f437e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -1646,8 +1646,8 @@ static void r_modSubtype(void* user, uint8_t* data, uint32_t bitoffs, val++; val_len--; int subtype = yaml_str2uint(val, val_len); - // convert to OTX format and write to vars - convertMultiProtocolToOtx(&type, &subtype); + // convert to ETX format and write to vars + convertMultiProtocolToEtx(&type, &subtype); if (type > 0) { md->setMultiProtocol(type - 1); md->subType = subtype; diff --git a/radio/src/targets/simu/opentxsimulator.cpp b/radio/src/targets/simu/opentxsimulator.cpp index a07be6d5c..51408d2eb 100644 --- a/radio/src/targets/simu/opentxsimulator.cpp +++ b/radio/src/targets/simu/opentxsimulator.cpp @@ -32,7 +32,7 @@ #define GET_SWITCH_BOOL(sw__) getSwitch((sw__), 0); -#define OTXS_DBG qDebug() << "(" << simuTimerMicros() << "us)" +#define ETXS_DBG qDebug() << "(" << simuTimerMicros() << "us)" int16_t g_anas[Analogs::NUM_ANALOGS]; QVector OpenTxSimulator::tracebackDevices; @@ -106,7 +106,7 @@ void OpenTxSimulator::init() if (isRunning()) return; - OTXS_DBG; + ETXS_DBG; if (!m_timer10ms) { // make sure we create & control the timer from current thread @@ -134,7 +134,7 @@ void OpenTxSimulator::start(const char * filename, bool tests) { if (isRunning()) return; - OTXS_DBG << "file:" << filename << "tests:" << tests; + ETXS_DBG << "file:" << filename << "tests:" << tests; QMutexLocker lckr(&m_mtxSimuMain); QMutexLocker slckr(&m_mtxSettings); @@ -150,7 +150,7 @@ void OpenTxSimulator::stop() { if (!isRunning()) return; - OTXS_DBG; + ETXS_DBG; setStopRequested(true); @@ -380,7 +380,7 @@ void OpenTxSimulator::setTrainerTimeout(uint16_t ms) void OpenTxSimulator::sendTelemetry(const QByteArray data) { - //OTXS_DBG << data; + //ETXS_DBG << data; sportProcessTelemetryPacket((uint8_t *)data.constData()); } diff --git a/radio/src/tests/CMakeLists.txt b/radio/src/tests/CMakeLists.txt index 4417696c3..7d07d6ff1 100644 --- a/radio/src/tests/CMakeLists.txt +++ b/radio/src/tests/CMakeLists.txt @@ -19,9 +19,9 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND) foreach(model_file ${EXTRACT_MODEL_FILES}) add_custom_command( - DEPENDS ${TESTS_PATH}/${model_file}.otx + DEPENDS ${TESTS_PATH}/${model_file}.etx OUTPUT ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin - COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.otx >/dev/null + COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.etx >/dev/null WORKING_DIRECTORY ${TESTS_BUILD_PATH} ) add_custom_target(${model_file}_files diff --git a/radio/src/tests/model_23_x10.otx b/radio/src/tests/model_23_x10.etx similarity index 100% rename from radio/src/tests/model_23_x10.otx rename to radio/src/tests/model_23_x10.etx diff --git a/radio/src/tests/model_23_x12s.otx b/radio/src/tests/model_23_x12s.etx similarity index 100% rename from radio/src/tests/model_23_x12s.otx rename to radio/src/tests/model_23_x12s.etx diff --git a/radio/src/tests/model_25_tx16s.otx b/radio/src/tests/model_25_tx16s.etx similarity index 100% rename from radio/src/tests/model_25_tx16s.otx rename to radio/src/tests/model_25_tx16s.etx From a7948f736b22c4006858f0e371633646c3b45249 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 16:17:36 +1100 Subject: [PATCH 002/180] Add back otx format --- companion/src/storage/CMakeLists.txt | 1 + companion/src/storage/otx.cpp | 116 +++++++++++++++++++++++++++ companion/src/storage/otx.h | 53 ++++++++++++ companion/src/storage/storage.cpp | 25 +++--- 4 files changed, 185 insertions(+), 10 deletions(-) create mode 100644 companion/src/storage/otx.cpp create mode 100644 companion/src/storage/otx.h diff --git a/companion/src/storage/CMakeLists.txt b/companion/src/storage/CMakeLists.txt index 2781b50b9..31dd86e9f 100644 --- a/companion/src/storage/CMakeLists.txt +++ b/companion/src/storage/CMakeLists.txt @@ -13,6 +13,7 @@ set(storage_NAMES categorized sdcard etx + otx yaml ) diff --git a/companion/src/storage/otx.cpp b/companion/src/storage/otx.cpp new file mode 100644 index 000000000..90ea2bbf8 --- /dev/null +++ b/companion/src/storage/otx.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "otx.h" +#include "miniz.c" +#include + +#define MZ_ALLOCATION_SIZE (32*1024) + +bool OtxFormat::load(RadioData & radioData) +{ + QFile file(filename); + + if (!file.open(QFile::ReadOnly)) { + setError(tr("Error opening file %1:\n%2.").arg(filename).arg(file.errorString())); + return false; + } + + QByteArray archiveContents = file.readAll(); + + qDebug() << "File" << filename << "read, size:" << archiveContents.size(); + + // open zip file + memset(&zip_archive, 0, sizeof(zip_archive)); + if (!mz_zip_reader_init_mem(&zip_archive, archiveContents.data(), archiveContents.size(), 0)) { + qDebug() << tr("Error opening OTX archive %1").arg(filename); + return false; + } + + bool result = CategorizedStorageFormat::load(radioData); + mz_zip_reader_end(&zip_archive); + return result; +} + +bool OtxFormat::write(const RadioData & radioData) +{ + qDebug() << "Saving to archive" << filename; + + memset(&zip_archive, 0, sizeof(zip_archive)); + if (!mz_zip_writer_init_heap(&zip_archive, 0, MZ_ALLOCATION_SIZE)) { + setError(tr("Error initializing OTX archive writer")); + return false; + } + + bool result = CategorizedStorageFormat::write(radioData); + if (result) { + // finalize archive and get contents + char * archiveContents; + size_t archiveSize; + if (mz_zip_writer_finalize_heap_archive(&zip_archive, (void **)&archiveContents, &archiveSize)) { + qDebug() << "Archive size" << archiveSize; + // write contents to file + QFile file(filename); + if (file.open(QIODevice::WriteOnly)) { + qint64 len = file.write(archiveContents, archiveSize); + if (len != (qint64)archiveSize) { + setError(tr("Error writing file %1:\n%2.").arg(filename).arg(file.errorString())); + result = false; + } + } + else { + setError(tr("Error creating OTX file %1:\n%2.").arg(filename).arg(file.errorString())); + result = false; + } + } + else { + setError(tr("Error creating OTX archive")); + result = false; + } + } + + mz_zip_writer_end(&zip_archive); + return result; +} + +bool OtxFormat::loadFile(QByteArray & filedata, const QString & filename) +{ + size_t size; + void * data = mz_zip_reader_extract_file_to_heap(&zip_archive, qPrintable(filename), &size, 0); + if (!data) { + return false; + } + + qDebug() << QString("Extracted file %1, size=%2").arg(filename).arg(size); + filedata.clear(); + filedata.append((char *)data, size); + mz_free(data); + return true; +} + +bool OtxFormat::writeFile(const QByteArray & filedata, const QString & filename) +{ + if (!mz_zip_writer_add_mem(&zip_archive, filename.toStdString().c_str(), filedata.data(), filedata.size(), MZ_DEFAULT_LEVEL)) { + setError(tr("Error adding %1 to OTX archive").arg(filename)); + return false; + } + + return true; +} diff --git a/companion/src/storage/otx.h b/companion/src/storage/otx.h new file mode 100644 index 000000000..da4923488 --- /dev/null +++ b/companion/src/storage/otx.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _OTX_H_ +#define _OTX_H_ + +#include "categorized.h" + +#include + +#define MINIZ_HEADER_FILE_ONLY +#include "miniz.c" +#undef MINIZ_HEADER_FILE_ONLY + +class OtxFormat : public CategorizedStorageFormat +{ + Q_DECLARE_TR_FUNCTIONS(OtxFormat) + + public: + OtxFormat(const QString & filename): + CategorizedStorageFormat(filename) + { + } + + virtual QString name() { return "otx"; } + virtual bool load(RadioData & radioData); + virtual bool write(const RadioData & radioData); + + protected: + virtual bool loadFile(QByteArray & fileData, const QString & fileName); + virtual bool writeFile(const QByteArray & fileData, const QString & fileName); + + mz_zip_archive zip_archive; +}; + +#endif // _OTX_H_ diff --git a/companion/src/storage/storage.cpp b/companion/src/storage/storage.cpp index 8ec511769..ad7a7eabd 100644 --- a/companion/src/storage/storage.cpp +++ b/companion/src/storage/storage.cpp @@ -20,6 +20,7 @@ #include "bineeprom.h" #include "eepe.h" +#include "otx.h" #include "etx.h" #include "sdcard.h" #include "yaml.h" @@ -65,6 +66,7 @@ void registerStorageFactories() registerStorageFactory(new DefaultStorageFactory("bin")); registerStorageFactory(new DefaultStorageFactory("eepe")); registerStorageFactory(new DefaultStorageFactory("hex")); + registerStorageFactory(new DefaultStorageFactory("otx")); registerStorageFactory(new DefaultStorageFactory("etx")); registerStorageFactory(new DefaultStorageFactory("yml")); registerStorageFactory(new SdcardStorageFactory()); @@ -86,17 +88,20 @@ bool Storage::load(RadioData & radioData) bool ret = false; foreach(StorageFactory * factory, registeredStorageFactories) { - StorageFormat * format = factory->instance(filename); - if (format->load(radioData)) { - board = format->getBoard(); - setWarning(format->warning()); - ret = true; - break; + if (factory->probe(filename)) { + StorageFormat * format = factory->instance(filename); + if (format->load(radioData)) { + board = format->getBoard(); + setWarning(format->warning()); + ret = true; + delete format; + break; + } + else { + setError(format->error()); + } + delete format; } - else { - setError(format->error()); - } - delete format; } return ret; From 0db9363df9312cf5ab26b846bda4a8a194e364d7 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 16:28:59 +1100 Subject: [PATCH 003/180] Fix miniz linker --- companion/src/storage/etx.cpp | 2 +- companion/src/storage/otx.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/storage/etx.cpp b/companion/src/storage/etx.cpp index e79d9d477..a3aac58da 100644 --- a/companion/src/storage/etx.cpp +++ b/companion/src/storage/etx.cpp @@ -19,7 +19,7 @@ */ #include "etx.h" -#include "miniz.c" +#include "miniz.c" // Can only be included once! #include #define MZ_ALLOCATION_SIZE (32*1024) diff --git a/companion/src/storage/otx.cpp b/companion/src/storage/otx.cpp index 90ea2bbf8..d7509be34 100644 --- a/companion/src/storage/otx.cpp +++ b/companion/src/storage/otx.cpp @@ -19,7 +19,7 @@ */ #include "otx.h" -#include "miniz.c" +//#include "miniz.c" Can only be included once refer etx.cpp #include #define MZ_ALLOCATION_SIZE (32*1024) From 76c3dd82407939a9bd33bce0ae4e66a60d775dad Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 16:34:15 +1100 Subject: [PATCH 004/180] Use full project names --- companion/src/storage/etx.cpp | 10 +++++----- companion/src/storage/otx.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/companion/src/storage/etx.cpp b/companion/src/storage/etx.cpp index a3aac58da..a20365fcf 100644 --- a/companion/src/storage/etx.cpp +++ b/companion/src/storage/etx.cpp @@ -40,7 +40,7 @@ bool EtxFormat::load(RadioData & radioData) // open zip file memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_reader_init_mem(&zip_archive, archiveContents.data(), archiveContents.size(), 0)) { - qDebug() << tr("Error opening ETX archive %1").arg(filename); + qDebug() << tr("Error opening EdgeTX archive %1").arg(filename); return false; } @@ -55,7 +55,7 @@ bool EtxFormat::write(const RadioData & radioData) memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_writer_init_heap(&zip_archive, 0, MZ_ALLOCATION_SIZE)) { - setError(tr("Error initializing ETX archive writer")); + setError(tr("Error initializing EdgeTX archive writer")); return false; } @@ -76,12 +76,12 @@ bool EtxFormat::write(const RadioData & radioData) } } else { - setError(tr("Error creating ETX file %1:\n%2.").arg(filename).arg(file.errorString())); + setError(tr("Error creating EdgeTX file %1:\n%2.").arg(filename).arg(file.errorString())); result = false; } } else { - setError(tr("Error creating ETX archive")); + setError(tr("Error creating EdgeTX archive")); result = false; } } @@ -108,7 +108,7 @@ bool EtxFormat::loadFile(QByteArray & filedata, const QString & filename) bool EtxFormat::writeFile(const QByteArray & filedata, const QString & filename) { if (!mz_zip_writer_add_mem(&zip_archive, filename.toStdString().c_str(), filedata.data(), filedata.size(), MZ_DEFAULT_LEVEL)) { - setError(tr("Error adding %1 to ETX archive").arg(filename)); + setError(tr("Error adding %1 to EdgeTX archive").arg(filename)); return false; } diff --git a/companion/src/storage/otx.cpp b/companion/src/storage/otx.cpp index d7509be34..caf87c22a 100644 --- a/companion/src/storage/otx.cpp +++ b/companion/src/storage/otx.cpp @@ -40,7 +40,7 @@ bool OtxFormat::load(RadioData & radioData) // open zip file memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_reader_init_mem(&zip_archive, archiveContents.data(), archiveContents.size(), 0)) { - qDebug() << tr("Error opening OTX archive %1").arg(filename); + qDebug() << tr("Error opening OpenTX archive %1").arg(filename); return false; } @@ -55,7 +55,7 @@ bool OtxFormat::write(const RadioData & radioData) memset(&zip_archive, 0, sizeof(zip_archive)); if (!mz_zip_writer_init_heap(&zip_archive, 0, MZ_ALLOCATION_SIZE)) { - setError(tr("Error initializing OTX archive writer")); + setError(tr("Error initializing OpenTX archive writer")); return false; } @@ -76,12 +76,12 @@ bool OtxFormat::write(const RadioData & radioData) } } else { - setError(tr("Error creating OTX file %1:\n%2.").arg(filename).arg(file.errorString())); + setError(tr("Error creating OpenTX file %1:\n%2.").arg(filename).arg(file.errorString())); result = false; } } else { - setError(tr("Error creating OTX archive")); + setError(tr("Error creating OpenTX archive")); result = false; } } @@ -108,7 +108,7 @@ bool OtxFormat::loadFile(QByteArray & filedata, const QString & filename) bool OtxFormat::writeFile(const QByteArray & filedata, const QString & filename) { if (!mz_zip_writer_add_mem(&zip_archive, filename.toStdString().c_str(), filedata.data(), filedata.size(), MZ_DEFAULT_LEVEL)) { - setError(tr("Error adding %1 to OTX archive").arg(filename)); + setError(tr("Error adding %1 to OpenTX archive").arg(filename)); return false; } From 2e7f20def978e927d1c8eb356b9c8fb4cca105a8 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 17:04:02 +1100 Subject: [PATCH 005/180] Force ETX file extn on save --- companion/src/mdichild.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 14a4266b1..dbde4aa3f 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1360,7 +1360,7 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile) bool MdiChild::save() { QFileInfo fi(curFile); - if (isUntitled || !fi.isWritable()) { + if (isUntitled || !fi.isWritable() || (fi.suffix().toLower() != "etx" && fi.suffix().toLower() != "yml")) { return saveAs(true); } else { @@ -1455,7 +1455,7 @@ void MdiChild::setCurrentFile(const QString & fileName) void MdiChild::forceNewFilename(const QString & suffix, const QString & ext) { - curFile.replace(QRegExp("\\.(eepe|bin|hex|etx)$"), suffix + "." + ext); + curFile.replace(QRegExp("\\.(eepe|bin|hex|otx|etx)$"), suffix + "." + ext); } bool MdiChild::convertStorage(Board::Type from, Board::Type to, bool newFile) From 73539a10a97cfe1c4c7de1f6f443448fa5b54f3f Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 22:51:48 +1100 Subject: [PATCH 006/180] Rename libsims --- companion/src/CMakeLists.txt | 6 +++--- radio/src/targets/simu/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 9c98e519d..7f6ef9263 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -313,7 +313,7 @@ add_subdirectory(tests) ############# Install #################### # Generate list of simulator plugins, used by all platforms -file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/*opentx-*simulator${CMAKE_SHARED_LIBRARY_SUFFIX}") +file(GLOB simulator_plugins "${CMAKE_BINARY_DIR}/*edgetx-*simulator${CMAKE_SHARED_LIBRARY_SUFFIX}") # the current flavour is not automatically added if build in the current cmake iteration, so always # add its library name to be sure @@ -349,7 +349,7 @@ if(POLICY CMP0026) endif() if(SIMU_TARGET) - get_property(current_plugin TARGET opentx-${FLAVOUR}-simulator PROPERTY LOCATION) + get_property(current_plugin TARGET edgetx-${FLAVOUR}-simulator PROPERTY LOCATION) list(APPEND simulator_plugins "${current_plugin}") endif() @@ -545,7 +545,7 @@ if(APPLE) set(CPACK_DMG_DS_STORE ${PROJECT_SOURCE_DIR}/companion/targets/mac/DS_Store) set(CPACK_PACKAGE_FILE_NAME "opentx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}") endif(APPLE) - + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") get_filename_component(_qt_bin_dir "${QT_QMAKE_EXECUTABLE}" DIRECTORY) find_program(LINUXDEPLOY_EXECUTABLE linuxdeployqt HINTS "${_qt_bin_dir}") diff --git a/radio/src/targets/simu/CMakeLists.txt b/radio/src/targets/simu/CMakeLists.txt index 60f9a69b2..8f45df562 100644 --- a/radio/src/targets/simu/CMakeLists.txt +++ b/radio/src/targets/simu/CMakeLists.txt @@ -34,7 +34,7 @@ if(SIMU_LUA_COMPILER) endif() if(Qt5Widgets_FOUND) - set(SIMULATOR_FLAVOUR opentx-${FLAVOUR}) + set(SIMULATOR_FLAVOUR edgetx-${FLAVOUR}) set(SIMULATOR_TARGET ${SIMULATOR_FLAVOUR}-simulator) add_definitions(-DSIMULATOR_FLAVOUR="${SIMULATOR_FLAVOUR}") include_directories(${COMPANION_SRC_DIRECTORY} ${COMPANION_SRC_DIRECTORY}/simulation) @@ -52,7 +52,7 @@ if(Qt5Widgets_FOUND) COMMAND ${CMAKE_STRIP} $) endif() endif() - + # Introduced at 2.5 - TODO replace with a code change # When compiled shared simulators using libopenui and Companion have classes named MainWindow From 8ad4aa04ab7b3e98d5bea4a3d69e662ec64da822 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 14 Nov 2021 22:57:15 +1100 Subject: [PATCH 007/180] Rename firmwares --- .../src/firmwares/opentx/opentxinterface.cpp | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 940d57456..1afb13482 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -1275,20 +1275,20 @@ void registerOpenTxFirmwares() OpenTxFirmware * firmware; /* FrSky Taranis X9D+ board */ - firmware = new OpenTxFirmware("opentx-x9d+", Firmware::tr("FrSky Taranis X9D+"), BOARD_TARANIS_X9DP); + firmware = new OpenTxFirmware("edgetx-x9d+", Firmware::tr("FrSky Taranis X9D+"), BOARD_TARANIS_X9DP); firmware->addOption("noras", Firmware::tr("Disable RAS (SWR)")); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX + AFHDS3); /* FrSky Taranis X9D+ 2019 board */ - firmware = new OpenTxFirmware("opentx-x9d+2019", Firmware::tr("FrSky Taranis X9D+ 2019"), BOARD_TARANIS_X9DP_2019); + firmware = new OpenTxFirmware("edgetx-x9d+2019", Firmware::tr("FrSky Taranis X9D+ 2019"), BOARD_TARANIS_X9DP_2019); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky Taranis X9D board */ - firmware = new OpenTxFirmware("opentx-x9d", Firmware::tr("FrSky Taranis X9D"), BOARD_TARANIS_X9D); + firmware = new OpenTxFirmware("edgetx-x9d", Firmware::tr("FrSky Taranis X9D"), BOARD_TARANIS_X9D); firmware->addOption("noras", Firmware::tr("Disable RAS (SWR)")); firmware->addOption("haptic", Firmware::tr("Haptic module installed")); addOpenTxTaranisOptions(firmware); @@ -1296,7 +1296,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX + AFHDS3); /* FrSky Taranis X9E board */ - firmware = new OpenTxFirmware("opentx-x9e", Firmware::tr("FrSky Taranis X9E"), BOARD_TARANIS_X9E); + firmware = new OpenTxFirmware("edgetx-x9e", Firmware::tr("FrSky Taranis X9E"), BOARD_TARANIS_X9E); firmware->addOption("shutdownconfirm", Firmware::tr("Confirmation before radio shutdown")); firmware->addOption("horussticks", Firmware::tr("Horus gimbals installed (Hall sensors)")); addOpenTxTaranisOptions(firmware); @@ -1304,44 +1304,44 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X9-Lite board */ - firmware = new OpenTxFirmware("opentx-x9lite", Firmware::tr("FrSky Taranis X9-Lite"), BOARD_TARANIS_X9LITE); + firmware = new OpenTxFirmware("edgetx-x9lite", Firmware::tr("FrSky Taranis X9-Lite"), BOARD_TARANIS_X9LITE); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X9-LiteS board */ - firmware = new OpenTxFirmware("opentx-x9lites", Firmware::tr("FrSky Taranis X9-Lite S"), BOARD_TARANIS_X9LITES); + firmware = new OpenTxFirmware("edgetx-x9lites", Firmware::tr("FrSky Taranis X9-Lite S"), BOARD_TARANIS_X9LITES); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X7 board */ - firmware = new OpenTxFirmware("opentx-x7", Firmware::tr("FrSky Taranis X7 / X7S"), BOARD_TARANIS_X7); + firmware = new OpenTxFirmware("edgetx-x7", Firmware::tr("FrSky Taranis X7 / X7S"), BOARD_TARANIS_X7); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X7 Access board */ - firmware = new OpenTxFirmware("opentx-x7access", Firmware::tr("FrSky Taranis X7 / X7S Access"), BOARD_TARANIS_X7_ACCESS); + firmware = new OpenTxFirmware("edgetx-x7access", Firmware::tr("FrSky Taranis X7 / X7S Access"), BOARD_TARANIS_X7_ACCESS); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X-Lite S/PRO board */ - firmware = new OpenTxFirmware("opentx-xlites", Firmware::tr("FrSky Taranis X-Lite S/PRO"), BOARD_TARANIS_XLITES); + firmware = new OpenTxFirmware("edgetx-xlites", Firmware::tr("FrSky Taranis X-Lite S/PRO"), BOARD_TARANIS_XLITES); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X-Lite board */ - firmware = new OpenTxFirmware("opentx-xlite", Firmware::tr("FrSky Taranis X-Lite"), BOARD_TARANIS_XLITE); + firmware = new OpenTxFirmware("edgetx-xlite", Firmware::tr("FrSky Taranis X-Lite"), BOARD_TARANIS_XLITE); // firmware->addOption("stdr9m", Firmware::tr("Use JR-sized R9M module")); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X10 board */ - firmware = new OpenTxFirmware("opentx-x10", Firmware::tr("FrSky Horus X10 / X10S"), BOARD_X10); + firmware = new OpenTxFirmware("edgetx-x10", Firmware::tr("FrSky Horus X10 / X10S"), BOARD_X10); addOpenTxFrskyOptions(firmware); firmware->addOption("internalaccess", Firmware::tr("Support for ACCESS internal module replacement")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1349,13 +1349,13 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X10 Express board */ - firmware = new OpenTxFirmware("opentx-x10express", Firmware::tr("FrSky Horus X10 Express / X10S Express"), BOARD_X10_EXPRESS); + firmware = new OpenTxFirmware("edgetx-x10express", Firmware::tr("FrSky Horus X10 Express / X10S Express"), BOARD_X10_EXPRESS); addOpenTxFrskyOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X12 (Horus) board */ - firmware = new OpenTxFirmware("opentx-x12s", Firmware::tr("FrSky Horus X12S"), BOARD_HORUS_X12S); + firmware = new OpenTxFirmware("edgetx-x12s", Firmware::tr("FrSky Horus X12S"), BOARD_HORUS_X12S); addOpenTxFrskyOptions(firmware); firmware->addOption("internalaccess", Firmware::tr("Support for ACCESS internal module replacement")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1364,7 +1364,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* Jumper T12 board */ - firmware = new OpenTxFirmware("opentx-t12", QCoreApplication::translate("Firmware", "Jumper T12 / T12 Pro"), BOARD_JUMPER_T12); + firmware = new OpenTxFirmware("edgetx-t12", QCoreApplication::translate("Firmware", "Jumper T12 / T12 Pro"), BOARD_JUMPER_T12); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1375,7 +1375,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T-Lite board */ - firmware = new OpenTxFirmware("opentx-tlite", QCoreApplication::translate("Firmware", "Jumper T-Lite"), BOARD_JUMPER_TLITE); + firmware = new OpenTxFirmware("edgetx-tlite", QCoreApplication::translate("Firmware", "Jumper T-Lite"), BOARD_JUMPER_TLITE); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1395,7 +1395,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T16 board */ - firmware = new OpenTxFirmware("opentx-t16", Firmware::tr("Jumper T16 / T16+ / T16 Pro"), BOARD_JUMPER_T16); + firmware = new OpenTxFirmware("edgetx-t16", Firmware::tr("Jumper T16 / T16+ / T16 Pro"), BOARD_JUMPER_T16); addOpenTxFrskyOptions(firmware); firmware->addOption("internalmulti", Firmware::tr("Support for MULTI internal module")); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); @@ -1404,7 +1404,7 @@ void registerOpenTxFirmwares() registerOpenTxFirmware(firmware); /* Radiomaster TX12 board */ - firmware = new OpenTxFirmware("opentx-tx12", QCoreApplication::translate("Firmware", "Radiomaster TX12"), BOARD_RADIOMASTER_TX12); + firmware = new OpenTxFirmware("edgetx-tx12", QCoreApplication::translate("Firmware", "Radiomaster TX12"), BOARD_RADIOMASTER_TX12); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1425,7 +1425,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX + AFHDS3); /* Radiomaster T8 board */ - firmware = new OpenTxFirmware("opentx-t8", QCoreApplication::translate("Firmware", "Radiomaster T8"), BOARD_RADIOMASTER_T8); + firmware = new OpenTxFirmware("edgetx-t8", QCoreApplication::translate("Firmware", "Radiomaster T8"), BOARD_RADIOMASTER_T8); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1436,7 +1436,7 @@ void registerOpenTxFirmwares() firmware->addOption("bindkey", Firmware::tr("Allow bind using bind key")); /* Radiomaster TX16S board */ - firmware = new OpenTxFirmware("opentx-tx16s", Firmware::tr("Radiomaster TX16S / SE / Hall / Masterfire"), BOARD_RADIOMASTER_TX16S); + firmware = new OpenTxFirmware("edgetx-tx16s", Firmware::tr("Radiomaster TX16S / SE / Hall / Masterfire"), BOARD_RADIOMASTER_TX16S); addOpenTxFrskyOptions(firmware); addOpenTxRfOptions(firmware, FLEX); static const Firmware::Option opt_bt("bluetooth", Firmware::tr("Support for bluetooth module")); @@ -1446,7 +1446,7 @@ void registerOpenTxFirmwares() registerOpenTxFirmware(firmware); /* Jumper T18 board */ - firmware = new OpenTxFirmware("opentx-t18", Firmware::tr("Jumper T18"), BOARD_JUMPER_T18); + firmware = new OpenTxFirmware("edgetx-t18", Firmware::tr("Jumper T18"), BOARD_JUMPER_T18); addOpenTxFrskyOptions(firmware); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1454,30 +1454,30 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* FlySky NV14 board */ - firmware = new OpenTxFirmware("opentx-nv14", QCoreApplication::translate("Firmware", "FlySky NV14"), BOARD_FLYSKY_NV14); + firmware = new OpenTxFirmware("edgetx-nv14", QCoreApplication::translate("Firmware", "FlySky NV14"), BOARD_FLYSKY_NV14); addOpenTxFrskyOptions(firmware); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); addOpenTxRfOptions(firmware, FLEX + AFHDS3); registerOpenTxFirmware(firmware); /* 9XR-Pro */ - firmware = new OpenTxFirmware("opentx-9xrpro", Firmware::tr("Turnigy 9XR-PRO"), BOARD_9XRPRO); + firmware = new OpenTxFirmware("edgetx-9xrpro", Firmware::tr("Turnigy 9XR-PRO"), BOARD_9XRPRO); addOpenTxArm9xOptions(firmware, false); registerOpenTxFirmware(firmware, true); /* ar9x board */ - firmware = new OpenTxFirmware("opentx-ar9x", Firmware::tr("9X with AR9X board"), BOARD_AR9X); + firmware = new OpenTxFirmware("edgetx-ar9x", Firmware::tr("9X with AR9X board"), BOARD_AR9X); addOpenTxArm9xOptions(firmware, true); //firmware->addOption("rtc", Firmware::tr("Optional RTC added")); //firmware->addOption("volume", Firmware::tr("i2c volume control added")); registerOpenTxFirmware(firmware, true); /* Sky9x board */ - firmware = new OpenTxFirmware("opentx-sky9x", Firmware::tr("9X with Sky9x board"), BOARD_SKY9X); + firmware = new OpenTxFirmware("edgetx-sky9x", Firmware::tr("9X with Sky9x board"), BOARD_SKY9X); addOpenTxArm9xOptions(firmware); registerOpenTxFirmware(firmware, true); - Firmware::setDefaultVariant(Firmware::getFirmwareForId("opentx-tx16s")); + Firmware::setDefaultVariant(Firmware::getFirmwareForId("edgetx-tx16s")); Firmware::setCurrentVariant(Firmware::getDefaultVariant()); } From 9db320577aa38a173cfb8bd634eb83e27d0f1aeb Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 15 Nov 2021 06:27:56 +1100 Subject: [PATCH 008/180] Move miniz include to categorized storage --- companion/src/storage/categorized.cpp | 1 + companion/src/storage/etx.cpp | 1 - companion/src/storage/otx.cpp | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index d659ae81f..5786b3127 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -20,6 +20,7 @@ #include "categorized.h" #include "firmwares/opentx/opentxinterface.h" +#include "miniz.c" // Can only be included once! bool CategorizedStorageFormat::load(RadioData & radioData) { diff --git a/companion/src/storage/etx.cpp b/companion/src/storage/etx.cpp index a20365fcf..051bf8391 100644 --- a/companion/src/storage/etx.cpp +++ b/companion/src/storage/etx.cpp @@ -19,7 +19,6 @@ */ #include "etx.h" -#include "miniz.c" // Can only be included once! #include #define MZ_ALLOCATION_SIZE (32*1024) diff --git a/companion/src/storage/otx.cpp b/companion/src/storage/otx.cpp index caf87c22a..44dbd9ef2 100644 --- a/companion/src/storage/otx.cpp +++ b/companion/src/storage/otx.cpp @@ -19,7 +19,6 @@ */ #include "otx.h" -//#include "miniz.c" Can only be included once refer etx.cpp #include #define MZ_ALLOCATION_SIZE (32*1024) From 06fef816f0f2be3dd30c919f6cba52bd716042d2 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 15 Nov 2021 08:44:52 +1100 Subject: [PATCH 009/180] Convert profile firmware types and remove some old code --- companion/src/storage/appdata.cpp | 58 +++++++------------------------ companion/src/storage/appdata.h | 4 +-- 2 files changed, 14 insertions(+), 48 deletions(-) diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index 5e64ad8fc..805953306 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -409,12 +409,6 @@ QMap AppData::getActiveProfiles() const void AppData::convertSettings(QSettings & settings) { quint32 savedVer = settings.value(SETTINGS_VERSION_KEY, 0).toUInt(); -#if (VERSION_NUMBER < QT_VERSION_CHECK(2, 3, 0)) - // convert old 2.2.x version marker; TODO: remove once v2.3 is established (because we'll always convert and clean 2.2.x settings anyway) - if (savedVer == 220) - savedVer = 0x2020000; -#endif - if (savedVer == CPN_SETTINGS_VERSION) return; if (savedVer > CPN_SETTINGS_VERSION) { @@ -432,29 +426,16 @@ void AppData::convertSettings(QSettings & settings) << " from v" << fmtHex(savedVer) << " (" << fmtHex(savedMajMin) << ") to v" << fmtHex(CPN_SETTINGS_VERSION) << " (" << fmtHex(currMajMin) << "). Removing unused: " << removeUnused; - if (settings.contains("useWizard")) { - if (!settings.contains(newModelAction_key())) - settings.setValue(newModelAction_key(), (settings.value("useWizard").toBool() ? MODEL_ACT_WIZARD : MODEL_ACT_EDITOR)); - if (removeUnused) - settings.remove("useWizard"); - } - - // meaning of warningId changed during v2.2 development but value of "7" indicates old setting, removing it will restore defaults - if (savedMajMin < 0x203 && settings.contains("warningId") && settings.value("warningId").toInt() == 7) - settings.remove("warningId"); - - // Convert joystick settings to new style of key names - static const QString jsCalBasePath = QStringLiteral("JsCalibration/%1"); - if (settings.contains(jsCalBasePath.arg("stick0_axe"))) { - const QStringList vars({"axe", "inv", "max", "med", "min"}); - for (int i=0; i < MAX_JOYSTICKS; ++i) { - for (const QString & var : vars) { - const QString oldPath = jsCalBasePath.arg(QString("stick%1_%2").arg(i).arg(var)); // old format "/stick#_var" - const QVariant val = settings.value(oldPath); - if (val.isValid()) - settings.setValue(jsCalBasePath.arg(QString("%1/stick_%2").arg(i).arg(var)), val); // new format "/#/stick_var" - if (removeUnused) - settings.remove(oldPath); + // firmwares renamed from opentx-* to edgetx-* at 2.6 + if (savedMajMin < 0x206) { + static const QString profileFwTypePath = QStringLiteral("Profiles/profile%1/fwType"); + for (int i = 0; i < MAX_PROFILES; i++) { + if (settings.contains(profileFwTypePath.arg(i))) { + const QVariant oldValue = settings.value(profileFwTypePath.arg(i)); + if (oldValue.isValid()) { + QString val = settings.value(profileFwTypePath.arg(i)).toString(); + settings.setValue(profileFwTypePath.arg(i), val.replace("opentx-", "edgetx-")); + } } } } @@ -481,7 +462,8 @@ void AppData::clearUnusedSettings(QSettings & settings) bool AppData::findPreviousVersionSettings(QString * version) const { - static const QStringList versList({QStringLiteral("2.2"), QStringLiteral("2.1"), QStringLiteral("2.0")}); + // TODO need a more dynamic method since ETX moves so quickly + static const QStringList versList({QStringLiteral("2.5"), QStringLiteral("2.4")}); for (const QString &ver : versList) { const QString prod("Companion " % ver); @@ -498,15 +480,6 @@ bool AppData::findPreviousVersionSettings(QString * version) const } } - QSettings settings(COMPANY, "OpenTX Companion"); - if (settings.contains(SETTINGS_VERSION_KEY)) { - *version = QStringLiteral("1.x"); - return true; - } - else { - settings.clear(); - } - return false; } @@ -515,13 +488,6 @@ bool AppData::importSettings(const QString & fromVersion) QString fromProduct; upgradeFromVersion.clear(); - if (fromVersion.startsWith("2.")) - fromProduct = "Companion " % fromVersion; - else if (fromVersion == "1.x") - fromProduct = "OpenTX Companion"; - else - return false; - upgradeFromVersion = fromVersion; QSettings fromSettings(COMPANY, fromProduct); diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 49d8f0658..f0ad887aa 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -38,7 +38,7 @@ #include #include -//! CPN_SETTINGS_REVISION is used to track settings changes independently of OpenTX version. It should be reset to zero whenever settings are migrated to new COMPANY or PRODUCT. +//! CPN_SETTINGS_REVISION is used to track settings changes independently of EdgeTX version. It should be reset to zero whenever settings are migrated to new COMPANY or PRODUCT. //! \note !! Increment this value if properties are removed or refactored. It will trigger a conversion/cleanup of any stored settings. \sa AppData::convertSettings() #define CPN_SETTINGS_REVISION 0 @@ -51,7 +51,7 @@ #define APP_COMPANION QStringLiteral("EdgeTX Companion") #define APP_SIMULATOR QStringLiteral("EdgeTX Simulator") -//! Default location for OpenTX-related user documents (settigns, logs, etc) +//! Default location for EdgeTX-related user documents (settigns, logs, etc) #define CPN_DOCUMENTS_LOCATION QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) % "/" % COMPANY //! Location for settings backup files. TODO: make option or remember last location. #define CPN_SETTINGS_BACKUP_DIR CPN_DOCUMENTS_LOCATION % "/backup" From e3231f04969a5067d654ac4b554c451d6254aac7 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 16 Nov 2021 06:12:26 +1100 Subject: [PATCH 010/180] Remove yaml from file filters --- companion/src/constants.h | 2 +- companion/src/mdichild.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 5a6511168..1c6a3a5c5 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -62,7 +62,7 @@ #define OTX_FILES_FILTER "OpenTX " % CPN_STR_FILES % " (*.otx);;" #define ETX_FILES_FILTER "EdgeTX " % CPN_STR_FILES % " (*.etx);;" #define YML_FILES_FILTER "YAML " % CPN_STR_FILES % " (*.yml);;" -#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.otx *.yml *.eepe *.bin *.hex);;" % ETX_FILES_FILTER % OTX_FILES_FILTER % YML_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER +#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.otx *.eepe *.bin *.hex);;" % ETX_FILES_FILTER % OTX_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER #define FLASH_FILES_FILTER "FLASH " % CPN_STR_FILES % " (*.bin *.hex *.dfu);;" % BIN_FILES_FILTER % HEX_FILES_FILTER % DFU_FILES_FILTER #define EXTERNAL_EEPROM_FILES_FILTER "EEPROM " % CPN_STR_FILES % " (*.bin *.hex);;" % BIN_FILES_FILTER % HEX_FILES_FILTER #define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE" diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index dbde4aa3f..dde2f4da7 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1360,7 +1360,7 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile) bool MdiChild::save() { QFileInfo fi(curFile); - if (isUntitled || !fi.isWritable() || (fi.suffix().toLower() != "etx" && fi.suffix().toLower() != "yml")) { + if (isUntitled || !fi.isWritable() || fi.suffix().toLower() != "etx") { return saveAs(true); } else { @@ -1375,7 +1375,7 @@ bool MdiChild::saveAs(bool isNew) #ifdef __APPLE__ QString filter; #else - QString filter(ETX_FILES_FILTER % YML_FILES_FILTER); + QString filter(ETX_FILES_FILTER); #endif QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" + fi.fileName(), filter); From cf43d3ed405e09b4060e05001586073a5d859f4b Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 18 Nov 2021 07:12:40 +1100 Subject: [PATCH 011/180] Fix settings conversion --- companion/src/storage/appdata.cpp | 21 ++++++++++++++++----- companion/src/storage/appdata.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index 805953306..cd5c129e4 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -412,7 +412,7 @@ void AppData::convertSettings(QSettings & settings) if (savedVer == CPN_SETTINGS_VERSION) return; if (savedVer > CPN_SETTINGS_VERSION) { - qWarning().noquote() << "Saved settings version is newer than current, skippig conversions. Saved:" << fmtHex(savedVer) << "Current:" << fmtHex(CPN_SETTINGS_VERSION); + qWarning().noquote() << "Saved settings version is newer than current, skipping conversions. Saved:" << fmtHex(savedVer) << "Current:" << fmtHex(CPN_SETTINGS_VERSION); return; } @@ -428,13 +428,21 @@ void AppData::convertSettings(QSettings & settings) // firmwares renamed from opentx-* to edgetx-* at 2.6 if (savedMajMin < 0x206) { + qInfo().noquote() << "Converting profiles"; static const QString profileFwTypePath = QStringLiteral("Profiles/profile%1/fwType"); for (int i = 0; i < MAX_PROFILES; i++) { if (settings.contains(profileFwTypePath.arg(i))) { const QVariant oldValue = settings.value(profileFwTypePath.arg(i)); if (oldValue.isValid()) { - QString val = settings.value(profileFwTypePath.arg(i)).toString(); - settings.setValue(profileFwTypePath.arg(i), val.replace("opentx-", "edgetx-")); + const QString oldval = settings.value(profileFwTypePath.arg(i)).toString(); + QString newval = oldval; + newval.replace("opentx-", "edgetx-"); + if (oldval != newval) { + settings.setValue(profileFwTypePath.arg(i), newval); + qInfo().noquote().nospace() << "Converted entry " << profileFwTypePath.arg(i) + << " from (" << oldval << ")" + << " to (" << newval << ")"; + } } } } @@ -485,7 +493,8 @@ bool AppData::findPreviousVersionSettings(QString * version) const bool AppData::importSettings(const QString & fromVersion) { - QString fromProduct; + QString fromProduct = PRODUCT_NO_VERS % " " % fromVersion; + //qDebug() << "From Product:" << fromProduct; upgradeFromVersion.clear(); upgradeFromVersion = fromVersion; @@ -501,8 +510,10 @@ bool AppData::importSettings(QSettings * fromSettings) // Create temporary settings because we may modify them before import. QSettings tempSettings(COMPANY, PRODUCT % "_import"); - for (const QString & key : fromSettings->allKeys()) + for (const QString & key : fromSettings->allKeys()) { tempSettings.setValue(key, fromSettings->value(key)); + //qInfo().noquote() << "Import key(" << key << ") value(" << fromSettings->value(key) << ")"; + } // convert settings first to simplify import process convertSettings(tempSettings); diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index f0ad887aa..3afa1dc77 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -47,6 +47,7 @@ #define COMPANY QStringLiteral("EdgeTX") #define COMPANY_DOMAIN QStringLiteral("edgetx.org") +#define PRODUCT_NO_VERS QStringLiteral("Companion") #define PRODUCT QStringLiteral("Companion " QT_STRINGIFY(VERSION_MAJOR) "." QT_STRINGIFY(VERSION_MINOR)) #define APP_COMPANION QStringLiteral("EdgeTX Companion") #define APP_SIMULATOR QStringLiteral("EdgeTX Simulator") From 4f284bc79cb13bb5ae760d099310ddd8dbf0e596 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 18 Nov 2021 07:15:07 +1100 Subject: [PATCH 012/180] Change more installer refs to edgetx and etx file extension --- companion/src/CMakeLists.txt | 4 ++-- companion/targets/windows/companion.nsi.in | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 7f6ef9263..d160ff674 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -529,7 +529,7 @@ IF(APPLE) # technically a hack (that is already is in the Bundle library ...) install(CODE " include(BundleUtilities) - file(GLOB bundle_simulator_libs \"\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/libopentx-*${CMAKE_SHARED_LIBRARY_SUFFIX}\") + file(GLOB bundle_simulator_libs \"\${CMAKE_INSTALL_PREFIX}/${companion_res_dir}/libedgetx-*${CMAKE_SHARED_LIBRARY_SUFFIX}\") set(BU_CHMOD_BUNDLE_ITEMS on) fixup_bundle(\"${APPS}\" \"\${bundle_simulator_libs};${bundle_qt_libs};${bundle_tools_path}\" \"${QT_LIB_DIR}\") file(RENAME \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_NAME}.app\" \"\${CMAKE_INSTALL_PREFIX}/${COMPANION_OSX_APP_BUNDLE_NAME}.app\") @@ -543,7 +543,7 @@ if(APPLE) set(CPACK_DMG_BACKGROUND_IMAGE ${COMPANION_SRC_DIRECTORY}/images/splash_dmg.png) set(CPACK_DMG_VOLUME_NAME "EdgeTX Companion") set(CPACK_DMG_DS_STORE ${PROJECT_SOURCE_DIR}/companion/targets/mac/DS_Store) - set(CPACK_PACKAGE_FILE_NAME "opentx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}") + set(CPACK_PACKAGE_FILE_NAME "edgetx-${CPACK_PACKAGE_NAME_LOWERCASE}-${VERSION}") endif(APPLE) if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") diff --git a/companion/targets/windows/companion.nsi.in b/companion/targets/windows/companion.nsi.in index 4db7bc587..81c04314e 100644 --- a/companion/targets/windows/companion.nsi.in +++ b/companion/targets/windows/companion.nsi.in @@ -104,7 +104,7 @@ Section "EdgeTX Companion @VERSION_FAMILY@" SecDummy - Delete "$INSTDIR\opentx-*-simulator.dll" + Delete "$INSTDIR\edgetx-*-simulator.dll" RMDir /r "$INSTDIR\lang" RMDir /r "$INSTDIR\phonon_backend" @@ -116,8 +116,8 @@ Section "EdgeTX Companion @VERSION_FAMILY@" SecDummy ;Store installation folder WriteRegStr HKCU "Software\EdgeTX\Companion @VERSION_FAMILY@" "" $INSTDIR - ;Associate with extentions .otx - ${registerExtension} "$INSTDIR\companion.exe" ".otx" "EdgeTX Settings File" + ;Associate with extentions .etx + ${registerExtension} "$INSTDIR\companion.exe" ".etx" "EdgeTX Settings File" ;Create uninstaller WriteUninstaller "$INSTDIR\Uninstall.exe" @@ -177,7 +177,7 @@ Section "un.EdgeTX Companion @VERSION_FAMILY@" Delete "$INSTDIR\license.txt" Delete "$INSTDIR\companion.exe" Delete "$INSTDIR\simulator.exe" - Delete "$INSTDIR\*opentx-*-simulator.dll" + Delete "$INSTDIR\*edgetx-*-simulator.dll" Delete "$INSTDIR\SDL.dll" ; MSVC-specific libs Delete "$INSTDIR\msvcp140.dll" @@ -218,10 +218,7 @@ Section "un.EdgeTX Companion @VERSION_FAMILY@" RMDir "$INSTDIR" - ${unregisterExtension} ".bin" "BIN File" - ${unregisterExtension} ".hex" "HEX File" - ${unregisterExtension} ".eepm" "EEPE File" - ${unregisterExtension} ".otx" "EdgeTX Settings File" + ${unregisterExtension} ".etx" "EdgeTX Settings File" !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder @@ -275,7 +272,7 @@ Function StartMenuLocationCreator ${NSD_CreateLabel} 0u 0u 100% 12u $(SML_MainLabel) Pop $R0 - ${NSD_CreateRadioButton} 8u 20u 100% 12u $(SML_RadioCurrent) + ${NSD_CreateRadioButton} 8u 20u 100% 12u $(SML_RadioCurrent) Pop $StartMenuLocationRadioCurrent ${NSD_AddStyle} $StartMenuLocationRadioCurrent ${WS_GROUP} @@ -284,7 +281,7 @@ Function StartMenuLocationCreator ${If} $StartMenuLocationValue == "all_users" ${NSD_SetState} $StartMenuLocationRadioAll ${BST_CHECKED} - ${Else} + ${Else} ${NSD_SetState} $StartMenuLocationRadioCurrent ${BST_CHECKED} ${EndIf} From 0f6db9c5cb0c307be273583acf14d0d483ead81b Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 28 Nov 2021 17:55:17 +1100 Subject: [PATCH 013/180] Detect sdcard format and split processing of otx and etx --- companion/src/constants.h | 4 +- companion/src/mdichild.cpp | 2 +- companion/src/storage/categorized.cpp | 212 +++++++++++++++++++++++++- companion/src/storage/categorized.h | 7 + companion/src/storage/sdcard.cpp | 1 - companion/src/storage/storage.h | 4 +- 6 files changed, 223 insertions(+), 7 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 1c6a3a5c5..4e66ff214 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -61,8 +61,8 @@ #define EEPE_FILES_FILTER "EEPE " % CPN_STR_FILES % " (*.eepe);;" #define OTX_FILES_FILTER "OpenTX " % CPN_STR_FILES % " (*.otx);;" #define ETX_FILES_FILTER "EdgeTX " % CPN_STR_FILES % " (*.etx);;" -#define YML_FILES_FILTER "YAML " % CPN_STR_FILES % " (*.yml);;" -#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.otx *.eepe *.bin *.hex);;" % ETX_FILES_FILTER % OTX_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER +#define YML_FILES_FILTER "EdgeTX YAML " % CPN_STR_FILES % " (*.yml);;" +#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.yml *.otx *.eepe *.bin *.hex);;" % ETX_FILES_FILTER % YML_FILES_FILTER % OTX_FILES_FILTER % EEPE_FILES_FILTER % BIN_FILES_FILTER % HEX_FILES_FILTER #define FLASH_FILES_FILTER "FLASH " % CPN_STR_FILES % " (*.bin *.hex *.dfu);;" % BIN_FILES_FILTER % HEX_FILES_FILTER % DFU_FILES_FILTER #define EXTERNAL_EEPROM_FILES_FILTER "EEPROM " % CPN_STR_FILES % " (*.bin *.hex);;" % BIN_FILES_FILTER % HEX_FILES_FILTER #define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE" diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index dde2f4da7..2c8732b4e 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1375,7 +1375,7 @@ bool MdiChild::saveAs(bool isNew) #ifdef __APPLE__ QString filter; #else - QString filter(ETX_FILES_FILTER); + QString filter(ETX_FILES_FILTER % YML_FILES_FILTER); #endif QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" + fi.fileName(), filter); diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 5786b3127..78ffd9c95 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -23,6 +23,34 @@ #include "miniz.c" // Can only be included once! bool CategorizedStorageFormat::load(RadioData & radioData) +{ + if (getStorageType(filename) == STORAGE_TYPE_ETX || + (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX)) + return loadYaml(radioData); + else + return loadBin(radioData); +} + +bool CategorizedStorageFormat::write(const RadioData & radioData) +{ + if (getStorageType(filename) == STORAGE_TYPE_ETX || + (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX)) + return writeYaml(radioData); + else + return writeBin(radioData); +} + +StorageType CategorizedStorageFormat::probeFormat() +{ + if (QFile(filename + "/RADIO/radio.yml").exists()) // converted + return getStorageType("radio.yml"); + else if (QFile(filename + "/RADIO/radio.bin").exists()) // unconverted + return getStorageType("radio.bin"); + else + return getStorageType(filename); +} + +bool CategorizedStorageFormat::loadBin(RadioData & radioData) { QByteArray radioSettingsBuffer; if (!loadFile(radioSettingsBuffer, "RADIO/radio.bin")) { @@ -114,7 +142,7 @@ bool CategorizedStorageFormat::load(RadioData & radioData) return true; } -bool CategorizedStorageFormat::write(const RadioData & radioData) +bool CategorizedStorageFormat::writeBin(const RadioData & radioData) { QByteArray modelsList; // models.txt QByteArray radioSettingsData; // radio.bin @@ -168,3 +196,185 @@ bool CategorizedStorageFormat::write(const RadioData & radioData) return true; } + +bool CategorizedStorageFormat::loadYaml(RadioData & radioData) +{ + if (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX) { + if (!QFile(filename + "/" + "RADIO/radio.yml").exists()) + qDebug() << tr("Can't find %1/RADIO/radio.yml").arg(filename); + else + qDebug() << tr("Found %1/RADIO/radio.yml").arg(filename); + + if (!QFile(filename + "/" + "MODELS/models.yml").exists()) + qDebug() << tr("Can't find %1/MODELS/models.yml").arg(filename); + else + qDebug() << tr("Found %1/MODELS/models.yml").arg(filename); + } + else { + if (!QFile(filename).exists()) + qDebug() << tr("Can't find %1").arg(filename); + else + qDebug() << tr("Found %1").arg(filename); + } + + setError(tr("Error: Yaml format ignored - under development")); + return false; // force failure until fully developed + + /* + This code a copy of loadBin with yaml file extensions ONLY + */ + + QByteArray radioSettingsBuffer; + if (!loadFile(radioSettingsBuffer, "RADIO/radio.yml")) { + setError(tr("Can't extract RADIO/radio.yml")); + return false; + } + + OpenTxEepromInterface * loadInterface = loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer); + if (!loadInterface) { + return false; + } + + board = loadInterface->getBoard(); + + QByteArray modelsListBuffer; + if (!loadFile(modelsListBuffer, "MODELS/models.yml")) { + setError(tr("Can't extract MODELS/models.yml")); + return false; + } + + QList lines = modelsListBuffer.split('\n'); + int modelIndex = 0; + int categoryIndex = -1; + foreach (const QByteArray & lineArray, lines) { + QString line = QString(lineArray).trimmed(); + if (line.isEmpty()) continue; + // qDebug() << "parsing line" << line; + + if (line.startsWith('[') && line.endsWith(']')) { + // ignore categories for boards that do not support them + if (getCurrentFirmware()->getCapability(HasModelCategories)) { + QString name = line.mid(1, line.size() - 2); + CategoryData category(qPrintable(name)); + radioData.categories.push_back(category); + categoryIndex++; + qDebug() << "added category" << name; + } + continue; + } + + // determine if we have a model number + QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts); + if (parts.size() == 2) { + // parse model number + int modelNumber = parts[0].toInt(); + if (modelNumber > 0 && modelNumber > modelIndex && modelNumber < getCurrentFirmware()->getCapability(Models)) { + modelIndex = modelNumber; + qDebug() << "advanced model number to" << modelIndex; + } + else { + if (modelNumber != modelIndex) qDebug() << "Invalid model number" << parts[0]; + } + parts.removeFirst(); + } + if (parts.size() == 1) { + // parse model file name and load + QString fileName = parts[0]; + qDebug() << "Loading model from file" << fileName << "into slot" << modelIndex; + QByteArray modelBuffer; + if (!loadFile(modelBuffer, QString("MODELS/%1").arg(fileName))) { + setError(tr("Can't extract %1").arg(fileName)); + return false; + } + if ((int)radioData.models.size() <= modelIndex) { + radioData.models.resize(modelIndex + 1); + } + if (!loadModelFromByteArray(radioData.models[modelIndex], modelBuffer)) { + setError(tr("Error loading models")); + return false; + } + strncpy(radioData.models[modelIndex].filename, qPrintable(fileName), sizeof(radioData.models[modelIndex].filename)); + if (IS_FAMILY_HORUS_OR_T16(board) && !strcmp(radioData.generalSettings.currModelFilename, qPrintable(fileName))) { + radioData.generalSettings.currModelIndex = modelIndex; + qDebug() << "currModelIndex =" << modelIndex; + } + if (getCurrentFirmware()->getCapability(HasModelCategories)) { + radioData.models[modelIndex].category = categoryIndex; + } + radioData.models[modelIndex].used = true; + modelIndex++; + continue; + } + + // invalid line + // TODO add to parsing report + qDebug() << "Invalid line" <> sortedModels(numCategories); + + writeRadioSettingsToByteArray(radioData.generalSettings, radioSettingsData); + if (!writeFile(radioSettingsData, "RADIO/radio.yml")) { + return false; + } + + for (size_t m=0; mgetCapability(HasModelCategories)) { + // Use format with model number and file name. This is needed because + // radios without category support can have unused model slots + modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename)); + } else { + sortedModels[model.category].push_back(QString("%1\n").arg(model.filename)); + } + } + + if (getCurrentFirmware()->getCapability(HasModelCategories)) { + for (size_t c=0; c Date: Sun, 28 Nov 2021 09:13:19 +0100 Subject: [PATCH 014/180] WiP: start parsing YaML --- .gitmodules | 3 + companion/src/CMakeLists.txt | 1 + companion/src/firmwares/CMakeLists.txt | 6 + .../src/firmwares/edgetx/edgetxinterface.cpp | 67 ++++++++ .../src/firmwares/edgetx/edgetxinterface.h | 30 ++++ .../firmwares/edgetx/yaml_generalsettings.h | 123 +++++++++++++++ companion/src/firmwares/edgetx/yaml_ops.h | 41 +++++ .../src/firmwares/edgetx/yaml_trainerdata.h | 71 +++++++++ companion/src/storage/categorized.cpp | 147 +----------------- companion/src/thirdparty/yaml-cpp | 1 + 10 files changed, 351 insertions(+), 139 deletions(-) create mode 100644 companion/src/firmwares/edgetx/edgetxinterface.cpp create mode 100644 companion/src/firmwares/edgetx/edgetxinterface.h create mode 100644 companion/src/firmwares/edgetx/yaml_generalsettings.h create mode 100644 companion/src/firmwares/edgetx/yaml_ops.h create mode 100644 companion/src/firmwares/edgetx/yaml_trainerdata.h create mode 160000 companion/src/thirdparty/yaml-cpp diff --git a/.gitmodules b/.gitmodules index 1da1a8370..ec08cff60 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ [submodule "radio/src/thirdparty/AccessDenied"] path = radio/src/thirdparty/AccessDenied url = https://github.com/raphaelcoeffic/AccessDenied.git +[submodule "companion/src/thirdparty/yaml-cpp"] + path = companion/src/thirdparty/yaml-cpp + url = https://github.com/jbeder/yaml-cpp.git diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index d160ff674..c3e2928f1 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -197,6 +197,7 @@ add_subdirectory(simulation) add_subdirectory(storage) add_subdirectory(thirdparty/qcustomplot) add_subdirectory(thirdparty/maxlibqt/src/widgets) +add_subdirectory(thirdparty/yaml-cpp) ############# Companion ############### diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 9a8593b99..2185e3676 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -29,6 +29,7 @@ set(firmwares_SRCS ersky9x/ersky9xinterface.cpp opentx/opentxeeprom.cpp opentx/opentxinterface.cpp + edgetx/edgetxinterface.cpp datahelpers.cpp customisation_data.cpp ) @@ -48,14 +49,19 @@ set(firmwares_QT qt5_wrap_cpp(firmwares_SRCS ${firmwares_QT}) add_library(firmwares ${firmwares_SRCS} ${firmwares_HDRS}) + target_link_libraries(firmwares ${CPN_COMMON_LIB} datamodels Qt5::Core Qt5::Xml Qt5::Widgets) +target_link_libraries(firmwares yaml-cpp) + target_include_directories(firmwares PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} + ${COMPANION_SRC_DIRECTORY}/thirdparty/yaml-cpp/include PUBLIC "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/er9x" "${CMAKE_CURRENT_LIST_DIR}/ersky9x" "${CMAKE_CURRENT_LIST_DIR}/opentx" + "${CMAKE_CURRENT_LIST_DIR}/edgetx" ) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp new file mode 100644 index 000000000..b38f0fbc0 --- /dev/null +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "edgetxinterface.h" + +#include "yaml_ops.h" +#include "yaml_generalsettings.h" + +static YAML::Node loadYamlFromByteArray(const QByteArray& data) +{ + // TODO: use real streaming to avoid memory copies + std::istringstream data_istream(data.toStdString()); + return YAML::Load(data_istream); +} + +bool loadModelFromYaml(ModelData& model, const QByteArray& data) +{ + try { + YAML::Node node = loadYamlFromByteArray(data); + //model << node; + } catch (const std::runtime_error& e) { + qDebug() << "YAML::ParserException: " << e.what(); + return false; + } + + return true; +} + +bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data) +{ + try { + YAML::Node node = loadYamlFromByteArray(data); + node >> settings; + } catch (const std::runtime_error& e) { + qDebug() << "YAML::ParserException: " << e.what(); + return false; + } + + return true; +} + +bool writeModelToYaml(const ModelData& model, QByteArray& data) +{ + return false; +} + +bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) +{ + return false; +} diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h new file mode 100644 index 000000000..bdfe01bf7 --- /dev/null +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include "radiodata.h" +#include + +bool loadModelFromYaml(ModelData& model, const QByteArray& data); +bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data); + +bool writeModelToByteArray(const ModelData& model, QByteArray& data); +bool writeRadioSettingsToByteArray(const GeneralSettings& settings, QByteArray& data); diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h new file mode 100644 index 000000000..1cda57076 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -0,0 +1,123 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "generalsettings.h" +#include "yaml_trainerdata.h" + +namespace YAML { + + template<> + struct convert { + + // static YAML::Node encode(const GeneralSettings& rhs) { + // Node node; + // // TODO: convert struct into Node + // return node; + // } + + static bool decode(const YAML::Node& node, GeneralSettings& rhs) { + + node["version"] >> rhs.version; + node["versionBla"] >> rhs.version; + // // calib + node["currModel"] >> rhs.currModelIndex; + // // filename + node["contrast"] >> rhs.contrast; + node["vBatWarn"] >> rhs.vBatWarn; + node["txVoltageCalibration"] >> rhs.txVoltageCalibration; + node["vBatMin"] >> rhs.vBatMin; + node["vBatMax"] >> rhs.vBatMax; + + // TODO: lookup table + //rhs.backlightMode = node["backlightMode"].as(); // backlight_mode_all + + node["trainer"] >> rhs.trainer; + node["view"] >> rhs.view; + node["fai"] >> rhs.fai; + node["disableMemoryWarning"] >> rhs.disableMemoryWarning; + //node["beepMode"] >> rhs.beeperMode; // TODO: string mapping + node["disableAlarmWarning"] >> rhs.disableAlarmWarning; + node["disableRssiPoweroffAlarm"] >> rhs.disableRssiPoweroffAlarm; + node["USBMode"] >> rhs.usbMode; + node["jackMode"] >> rhs.jackMode; + //node["hapticMode"] >> rhs.hapticMode; // TODO: strin mapping + node["stickMode"] >> rhs.stickMode; + node["timezone"] >> rhs.timezone; + node["adjustRTC"] >> rhs.adjustRTC; + node["inactivityTimer"] >> rhs.inactivityTimer; + node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? + node["splashMode"] >> rhs.splashMode; // TODO: B&W only + node["templateSetup"] >> rhs.templateSetup; + node["hapticLength"] >> rhs.hapticLength; // TODO: conversion??? + node["speakerPitch"] >> rhs.speakerPitch; // TODO: conversion??? + node["hapticStrength"] >> rhs.hapticStrength; // TODO: conversion??? + node["beepLength"] >> rhs.beeperLength; // TODO: conversion??? + node["gpsFormat"] >> rhs.gpsFormat; + node["speakerVolume"] >> rhs.speakerVolume; // TODO: conversion??? + node["backlightBright"] >> rhs.backlightBright; + node["switchesDelay"] >> rhs.switchesDelay; + node["globalTimer"] >> rhs.globalTimer; + node["bluetoothName"] >> rhs.bluetoothName; + node["bluetoothBaudrate"] >> rhs.bluetoothBaudrate; + node["bluetoothMode"] >> rhs.bluetoothMode; + node["countryCode"] >> rhs.countryCode; + node["jitterFilter"] >> rhs.jitterFilter; + node["disableRtcWarning"] >> rhs.rtcCheckDisable; // TODO: verify + node["keysBacklight"] >> rhs.keysBacklight; + node["imperial"] >> rhs.imperial; + node["ttsLanguage"] >> rhs.ttsLanguage; + node["beepVolume"] >> rhs.beepVolume; // TODO: conversion??? + node["wavVolume"] >> rhs.wavVolume; + node["varioVolume"] >> rhs.varioVolume; + node["varioPitch"] >> rhs.varioPitch; + node["varioRange"] >> rhs.varioRange; + node["varioRepeat"] >> rhs.varioRepeat; + node["backgroundVolume"] >> rhs.backgroundVolume; + //node["auxSerialMode"] >> rhs.auxSerialMode; + //node["aux2SerialMode"] >> rhs.aux2SerialMode; + //node["antennaMode"] >> rhs.antennaMode; + node["backlightColor"] >> rhs.backlightColor; + + // if (node["customFn"]) { + // const YAML::Node& cfn = node["customFn"]; + // for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { + // cfn[i] >> rhs.customFn[i]; + // } + // } + + // TODO: + // char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; + // unsigned int switchConfig[CPN_MAX_SWITCHES]; + // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; + // char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; + // unsigned int potConfig[CPN_MAX_KNOBS]; + // char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; + // unsigned int sliderConfig[CPN_MAX_SLIDERS]; + // RadioTheme::ThemeData themeData; + + node["ownerRegistrationID"] >> rhs.registrationId; + + return true; + } + }; +} + + diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h new file mode 100644 index 000000000..4dc4d6608 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include + +template +void operator>>(const YAML::Node& node, T& value) +{ + if (node) { + value = node.as(); + } +} + +template +void operator>>(const YAML::Node& node, char (&value)[N]) +{ + if (node) { + auto str = node.as(); + str.copy(value, N-1); + value[std::min(str.size(), N-1)] = '\0'; + } +} diff --git a/companion/src/firmwares/edgetx/yaml_trainerdata.h b/companion/src/firmwares/edgetx/yaml_trainerdata.h new file mode 100644 index 000000000..766c0930b --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_trainerdata.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "generalsettings.h" + +namespace YAML { + + template<> + struct convert { + + // static YAML::Node encode(const TrainerMix& rhs) { + // Node node; + // // TODO: convert struct into Node + // return node; + // } + + static bool decode(const YAML::Node& node, TrainerMix& rhs) + { + node["srcChn"] >> rhs.src; + //node["mode"] >> rhs.mode; // TODO: string mapping + node["studWeight"] >> rhs.weight; + return true; + } + }; + + template<> + struct convert { + + // static YAML::Node encode(const TrainerData& rhs) { + // Node node; + // // TODO: convert struct into Node + // return node; + // } + + static bool decode(const YAML::Node& node, TrainerData& rhs) + { + if (node["calib"]) { + const YAML::Node& calib = node["calib"]; + for (int i = 0; i < 4; i++) { + calib[i] >> rhs.calib[i]; + } + } + + if (node["mix"]) { + const YAML::Node& mix = node["mix"]; + for (int i = 0; i < 4; i++) { + mix[i] >> rhs.mix[i]; + } + } + return true; + } + }; +} diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 78ffd9c95..984c01842 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -20,6 +20,7 @@ #include "categorized.h" #include "firmwares/opentx/opentxinterface.h" +#include "firmwares/edgetx/edgetxinterface.h" #include "miniz.c" // Can only be included once! bool CategorizedStorageFormat::load(RadioData & radioData) @@ -217,8 +218,8 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) qDebug() << tr("Found %1").arg(filename); } - setError(tr("Error: Yaml format ignored - under development")); - return false; // force failure until fully developed + // setError(tr("Error: Yaml format ignored - under development")); + // return false; // force failure until fully developed /* This code a copy of loadBin with yaml file extensions ONLY @@ -229,88 +230,15 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) setError(tr("Can't extract RADIO/radio.yml")); return false; } - - OpenTxEepromInterface * loadInterface = loadRadioSettingsFromByteArray(radioData.generalSettings, radioSettingsBuffer); - if (!loadInterface) { + + if (!loadRadioSettingsFromYaml(radioData.generalSettings, radioSettingsBuffer)) { + setError(tr("Can't load RADIO/radio.yml")); return false; } - board = loadInterface->getBoard(); + // TODO: provide a simple text mapping + board = Board::BOARD_RADIOMASTER_TX16S; - QByteArray modelsListBuffer; - if (!loadFile(modelsListBuffer, "MODELS/models.yml")) { - setError(tr("Can't extract MODELS/models.yml")); - return false; - } - - QList lines = modelsListBuffer.split('\n'); - int modelIndex = 0; - int categoryIndex = -1; - foreach (const QByteArray & lineArray, lines) { - QString line = QString(lineArray).trimmed(); - if (line.isEmpty()) continue; - // qDebug() << "parsing line" << line; - - if (line.startsWith('[') && line.endsWith(']')) { - // ignore categories for boards that do not support them - if (getCurrentFirmware()->getCapability(HasModelCategories)) { - QString name = line.mid(1, line.size() - 2); - CategoryData category(qPrintable(name)); - radioData.categories.push_back(category); - categoryIndex++; - qDebug() << "added category" << name; - } - continue; - } - - // determine if we have a model number - QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts); - if (parts.size() == 2) { - // parse model number - int modelNumber = parts[0].toInt(); - if (modelNumber > 0 && modelNumber > modelIndex && modelNumber < getCurrentFirmware()->getCapability(Models)) { - modelIndex = modelNumber; - qDebug() << "advanced model number to" << modelIndex; - } - else { - if (modelNumber != modelIndex) qDebug() << "Invalid model number" << parts[0]; - } - parts.removeFirst(); - } - if (parts.size() == 1) { - // parse model file name and load - QString fileName = parts[0]; - qDebug() << "Loading model from file" << fileName << "into slot" << modelIndex; - QByteArray modelBuffer; - if (!loadFile(modelBuffer, QString("MODELS/%1").arg(fileName))) { - setError(tr("Can't extract %1").arg(fileName)); - return false; - } - if ((int)radioData.models.size() <= modelIndex) { - radioData.models.resize(modelIndex + 1); - } - if (!loadModelFromByteArray(radioData.models[modelIndex], modelBuffer)) { - setError(tr("Error loading models")); - return false; - } - strncpy(radioData.models[modelIndex].filename, qPrintable(fileName), sizeof(radioData.models[modelIndex].filename)); - if (IS_FAMILY_HORUS_OR_T16(board) && !strcmp(radioData.generalSettings.currModelFilename, qPrintable(fileName))) { - radioData.generalSettings.currModelIndex = modelIndex; - qDebug() << "currModelIndex =" << modelIndex; - } - if (getCurrentFirmware()->getCapability(HasModelCategories)) { - radioData.models[modelIndex].category = categoryIndex; - } - radioData.models[modelIndex].used = true; - modelIndex++; - continue; - } - - // invalid line - // TODO add to parsing report - qDebug() << "Invalid line" <> sortedModels(numCategories); - - writeRadioSettingsToByteArray(radioData.generalSettings, radioSettingsData); - if (!writeFile(radioSettingsData, "RADIO/radio.yml")) { - return false; - } - - for (size_t m=0; mgetCapability(HasModelCategories)) { - // Use format with model number and file name. This is needed because - // radios without category support can have unused model slots - modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename)); - } else { - sortedModels[model.category].push_back(QString("%1\n").arg(model.filename)); - } - } - - if (getCurrentFirmware()->getCapability(HasModelCategories)) { - for (size_t c=0; c Date: Sun, 28 Nov 2021 19:39:32 +1100 Subject: [PATCH 015/180] Add capability test for models list file --- companion/src/firmwares/eeprominterface.h | 3 ++- companion/src/firmwares/opentx/opentxinterface.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 099501c9d..d8e3fff1f 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -163,7 +163,8 @@ enum Capability { HasADCJitterFilter, HasTelemetryBaudrate, TopBarZones, - FunctionSwitches + FunctionSwitches, + HasModelList }; class EEPROMInterface diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 1afb13482..2ca769f35 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -752,14 +752,15 @@ int OpenTxFirmware::getCapability(::Capability capability) case HasAntennaChoice: return ((IS_FAMILY_HORUS_OR_T16(board) && board != Board::BOARD_X10_EXPRESS) || (IS_TARANIS_XLITE(board) && !IS_TARANIS_XLITES(board))) ? true : false; case HasADCJitterFilter: - return IS_HORUS_OR_TARANIS(board) ? true : false; + return IS_HORUS_OR_TARANIS(board); case HasTelemetryBaudrate: - return IS_HORUS_OR_TARANIS(board) ? true : false; + return IS_HORUS_OR_TARANIS(board); case TopBarZones: return getCapability(LcdWidth) > getCapability(LcdHeight) ? 4 : 2; case FunctionSwitches: return IS_JUMPER_TPRO(board) ? 6 : 0; - + case HasModelsList: + return IS_FAMILY_HORUS_OR_T16(board); default: return 0; } From cade5c352915c3c93e88b0eb50178bce3276809e Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 28 Nov 2021 20:45:38 +1100 Subject: [PATCH 016/180] Support reading and writing yaml settings from/to radio --- companion/src/firmwares/boards.cpp | 3 + companion/src/firmwares/boards.h | 3 +- companion/src/firmwares/eeprominterface.h | 3 +- companion/src/flasheepromdialog.cpp | 4 +- companion/src/flashfirmwaredialog.cpp | 6 +- companion/src/mainwindow.cpp | 28 ++-- companion/src/mainwindow.h | 8 +- companion/src/mdichild.cpp | 10 +- companion/src/mdichild.h | 2 +- companion/src/radiointerface.cpp | 195 +++++++++------------- companion/src/radiointerface.h | 6 +- 11 files changed, 116 insertions(+), 152 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index af164355c..344b3119e 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -486,6 +486,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) case NumFunctionSwitches: return IS_JUMPER_TPRO(board) ? 6 : 0; + case HasSDCard: + return IS_STM32(board); + default: return 0; } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index ea0476bda..050cf87e3 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -145,7 +145,8 @@ namespace Board { NumTrimSwitches, HasRTC, HasColorLcd, - NumFunctionSwitches + NumFunctionSwitches, + HasSDCard }; struct SwitchInfo diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index d8e3fff1f..df7c6d9f4 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -164,7 +164,8 @@ enum Capability { HasTelemetryBaudrate, TopBarZones, FunctionSwitches, - HasModelList + Has, + HasModelsList }; class EEPROMInterface diff --git a/companion/src/flasheepromdialog.cpp b/companion/src/flasheepromdialog.cpp index 6c210f940..87cb08fb7 100644 --- a/companion/src/flasheepromdialog.cpp +++ b/companion/src/flasheepromdialog.cpp @@ -266,7 +266,7 @@ void FlashEEpromDialog::on_burnButton_clicked() backupFilename = generateProcessUniqueTempFileName("eeprom.bin"); } if (!backupFilename.isEmpty()) { - if (!readEeprom(backupFilename, progressDialog.progress())) { + if (!readSettings(backupFilename, progressDialog.progress())) { return; } } @@ -297,7 +297,7 @@ void FlashEEpromDialog::on_burnButton_clicked() } // and write... - bool result = writeEeprom(filename, progressDialog.progress()); + bool result = writeSettings(filename, progressDialog.progress()); if (!result && !progressDialog.isEmpty()) { progressDialog.exec(); } diff --git a/companion/src/flashfirmwaredialog.cpp b/companion/src/flashfirmwaredialog.cpp index fc45a89ff..97f37f15a 100644 --- a/companion/src/flashfirmwaredialog.cpp +++ b/companion/src/flashfirmwaredialog.cpp @@ -307,7 +307,7 @@ void FlashFirmwareDialog::startFlash(const QString &filename) backupPath=g.backupDir(); } backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin"; - result = readEeprom(backupFilename, progressDialog.progress()); + result = readSettings(backupFilename, progressDialog.progress()); sleep(2); } @@ -322,14 +322,14 @@ void FlashFirmwareDialog::startFlash(const QString &filename) QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used")); restoreFilename = backupFilename; } - if (!writeEeprom(restoreFilename, progressDialog.progress())) { + if (!writeSettings(restoreFilename, progressDialog.progress())) { QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFilename)); } } progressDialog.progress()->setInfo(tr("Flashing done")); } - + progressDialog.exec(); if (isTempFileName(filename)) { diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index e1465f9f3..c76351781 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -897,13 +897,13 @@ void MainWindow::customizeSplash() dialog->deleteLater(); } -void MainWindow::writeEeprom() +void MainWindow::writeSettings() { if (activeMdiChild()) - activeMdiChild()->writeEeprom(); + activeMdiChild()->writeSettings(); } -void MainWindow::readEeprom() +void MainWindow::readSettings() { Board::Type board = getCurrentBoard(); QString tempFile; @@ -936,7 +936,7 @@ bool MainWindow::readFirmwareFromRadio(const QString & filename) bool MainWindow::readEepromFromRadio(const QString & filename) { ProgressDialog progressDialog(this, tr("Read Models and Settings from Radio"), CompanionIcon("read_eeprom.png")); - bool result = ::readEeprom(filename, progressDialog.progress()); + bool result = ::readSettings(filename, progressDialog.progress()); if (!result) { if (!progressDialog.isEmpty()) { progressDialog.exec(); @@ -1045,8 +1045,8 @@ void MainWindow::updateMenus() saveAsAct->setEnabled(activeChild); closeAct->setEnabled(activeChild); compareAct->setEnabled(activeChild); - writeEepromAct->setEnabled(activeChild); - readEepromAct->setEnabled(true); + writeSettingsAct->setEnabled(activeChild); + readSettingsAct->setEnabled(true); if (IS_FAMILY_HORUS_OR_T16(getCurrentBoard())) { writeBUToRadioAct->setEnabled(false); readBUToFileAct->setEnabled(false); @@ -1199,8 +1199,8 @@ void MainWindow::retranslateUi(bool showMsg) trAct(sdsyncAct, tr("Synchronize SD"), tr("SD card synchronization")); trAct(openDocURLAct, tr("Manuals and other Documents"), tr("Open the EdgeTX document page in a web browser")); - trAct(writeEepromAct, tr("Write Models and Settings To Radio"), tr("Write Models and Settings to Radio")); - trAct(readEepromAct, tr("Read Models and Settings From Radio"), tr("Read Models and Settings from Radio")); + trAct(writeSettingsAct, tr("Write Models and Settings To Radio"), tr("Write Models and Settings to Radio")); + trAct(readSettingsAct, tr("Read Models and Settings From Radio"), tr("Read Models and Settings from Radio")); trAct(burnConfigAct, tr("Configure Communications..."), tr("Configure software for communicating with the Radio")); trAct(writeBUToRadioAct, tr("Write Backup to Radio"), tr("Write Backup from file to Radio")); trAct(readBUToFileAct, tr("Backup Radio to File"), tr("Save a complete backup file of all settings and model data in the Radio")); @@ -1256,8 +1256,8 @@ void MainWindow::createActions() burnListAct = addAct("list.png", SLOT(burnList())); readFlashAct = addAct("read_flash.png", SLOT(readFlash())); writeFlashAct = addAct("write_flash.png", SLOT(writeFlash())); - writeEepromAct = addAct("write_eeprom.png", SLOT(writeEeprom())); - readEepromAct = addAct("read_eeprom.png", SLOT(readEeprom())); + writeSettingsAct = addAct("write_eeprom.png", SLOT(writeSettings())); + readSettingsAct = addAct("read_eeprom.png", SLOT(readSettings())); burnConfigAct = addAct("configure.png", SLOT(burnConfig())); writeBUToRadioAct = addAct("write_eeprom_file.png", SLOT(writeBackup())); @@ -1347,8 +1347,8 @@ void MainWindow::createMenus() settingsMenu->addAction(importSettingsAct); burnMenu = menuBar()->addMenu(""); - burnMenu->addAction(writeEepromAct); - burnMenu->addAction(readEepromAct); + burnMenu->addAction(writeSettingsAct); + burnMenu->addAction(readSettingsAct); burnMenu->addSeparator(); burnMenu->addAction(writeBUToRadioAct); burnMenu->addAction(readBUToFileAct); @@ -1435,8 +1435,8 @@ void MainWindow::createToolBars() burnToolBar = new QToolBar(this); addToolBar( Qt::LeftToolBarArea, burnToolBar ); burnToolBar->setObjectName("Write"); - burnToolBar->addAction(writeEepromAct); - burnToolBar->addAction(readEepromAct); + burnToolBar->addAction(writeSettingsAct); + burnToolBar->addAction(readSettingsAct); burnToolBar->addSeparator(); burnToolBar->addAction(writeBUToRadioAct); burnToolBar->addAction(readBUToFileAct); diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 78178d7f8..87202acf2 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -103,8 +103,8 @@ class MainWindow : public QMainWindow bool loadProfileId(const unsigned pid); void loadProfile(); void logFile(); - void writeEeprom(); - void readEeprom(); + void writeSettings(); + void readSettings(); void writeFlash(QString fileToFlash=""); void readFlash(); void writeBackup(); @@ -203,8 +203,8 @@ class MainWindow : public QMainWindow QAction *changelogAct; QAction *compareAct; QAction *editSplashAct; - QAction *writeEepromAct; - QAction *readEepromAct; + QAction *writeSettingsAct; + QAction *readSettingsAct; QAction *burnConfigAct; QAction *burnListAct; QAction *writeFlashAct; diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 2c8732b4e..e1d59e041 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1528,7 +1528,7 @@ int MdiChild::askQuestion(const QString & msg, QMessageBox::StandardButtons butt return QMessageBox::question(this, CPN_STR_APP_NAME, msg, buttons, defaultButton); } -void MdiChild::writeEeprom() // write to Tx +void MdiChild::writeSettings() // write to Tx { if (g.confirmWriteModelsAndSettings()) { QMessageBox msgbox; @@ -1547,19 +1547,21 @@ void MdiChild::writeEeprom() // write to Tx } Board::Type board = getCurrentBoard(); - if (IS_FAMILY_HORUS_OR_T16(board)) { + + if (Boards::getCapability(board, Board::HasSDCard)) { QString radioPath = findMassstoragePath("RADIO", true); qDebug() << "Searching for SD card, found" << radioPath; if (radioPath.isEmpty()) { - qDebug() << "MdiChild::writeEeprom(): Horus radio not found"; + qDebug() << "Radio SD card not found"; QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Unable to find radio SD card!")); return; } if (saveFile(radioPath, false)) { - emit newStatusMessage(tr("Models and Settings written"), 2000); + QMessageBox::information(this, CPN_STR_TTL_INFO, tr("Saved models and settings to radio")); } else { qDebug() << "MdiChild::writeEeprom(): saveFile error"; + QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Error saving models and settings to radio!")); } } else { diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index b44047aba..af5aa49e8 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -87,7 +87,7 @@ class MdiChild : public QWidget bool saveAs(bool isNew=false); bool saveFile(const QString & fileName, bool setCurrent=true); void closeFile(bool force = false); - void writeEeprom(); + void writeSettings(); void print(int model=-1, const QString & filename=""); void onFirmwareChanged(); diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index 2d9524521..21fd4af5c 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -175,7 +175,7 @@ bool writeFirmware(const QString & filename, ProgressWidget * progress) return flashProcess.run(); } -bool readEeprom(const QString & filename, ProgressWidget * progress) +bool readSettings(const QString & filename, ProgressWidget * progress) { Board::Type board = getCurrentBoard(); @@ -186,64 +186,84 @@ bool readEeprom(const QString & filename, ProgressWidget * progress) return false; } - if (IS_FAMILY_HORUS_OR_T16(board)) { - QString radioPath = findMassstoragePath("RADIO", true); - qDebug() << "Searching for SD card, found" << radioPath; - if (radioPath.isEmpty()) { - QMessageBox::critical(progress, CPN_STR_TTL_ERROR, - QCoreApplication::translate("RadioInterface", "Unable to find radio SD card!")); - return false; - } - RadioData radioData; - Storage inputStorage(radioPath); - if (!inputStorage.load(radioData)) { - QMessageBox::critical(progress, CPN_STR_TTL_ERROR, inputStorage.error()); - return false; - } - Storage outputStorage(filename); - if (!outputStorage.write(radioData)) { - QMessageBox::critical(progress, CPN_STR_TTL_ERROR, outputStorage.error()); - return false; - } + if (Boards::getCapability(board, Board::HasSDCard)) + readSettingsSDCard(filename, progress); + else + readSettingsEeprom(filename, progress); +} - if (getCurrentBoard() == Board::BOARD_JUMPER_T16 && inputStorage.getBoard() == Board::BOARD_X10) { - if (displayT16ImportWarning() == false) - return false; - } +bool readSettingsSDCard(const QString & filename, ProgressWidget * progress) +{ + QString radioPath = findMassstoragePath("RADIO", true); + qDebug() << "Searching for SD card, found" << radioPath; + if (radioPath.isEmpty()) { + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, + QCoreApplication::translate("RadioInterface", "Unable to find radio SD card!")); + return false; } - else { - QString path = findMassstoragePath("EEPROM.BIN"); - if (path.isEmpty()) { - // On previous OpenTX we called the EEPROM file "TARANIS.BIN" :( - path = findMassstoragePath("TARANIS.BIN"); - } - if (path.isEmpty()) { - // Mike's bootloader calls the EEPROM file "ERSKY9X.BIN" :( - path = findMassstoragePath("ERSKY9X.BIN"); - } - if (path.isEmpty()) { - RadioNotFoundDialog dialog(progress); - dialog.exec(); + + // if radio.yml it is a converted radio + // if radio.bin unconverted pre 2.6 + // if neither then unconverted eeprom or empty + if (!QFile::exists(radioPath % "/RADIO/radio.yml") && !QFile::exists(radioPath % "/RADIO/radio.bin")) + return readSettingsEeprom(filename, progress); + + RadioData radioData; + Storage inputStorage(radioPath); + if (!inputStorage.load(radioData)) { + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, inputStorage.error()); + return false; + } + Storage outputStorage(filename); + if (!outputStorage.write(radioData)) { + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, outputStorage.error()); + return false; + } + + if (getCurrentBoard() == Board::BOARD_JUMPER_T16 && inputStorage.getBoard() == Board::BOARD_X10) { + if (displayT16ImportWarning() == false) return false; - } - CopyProcess copyProcess(path, filename, progress); - if (!copyProcess.run()) { - return false; - } + } + + return QFileInfo(filename).exists(); +} - if (!IS_STM32(board)) { - FlashProcess flashProcess(getRadioInterfaceCmd(), getReadEEpromCmd(filename), progress); - if (!flashProcess.run()) { - return false; - } +bool readSettingsEeprom(const QString & filename, ProgressWidget * progress) +{ + Board::Type board = getCurrentBoard(); + + QString path = findMassstoragePath("EEPROM.BIN"); + if (path.isEmpty()) { + // On previous OpenTX we called the EEPROM file "TARANIS.BIN" :( + path = findMassstoragePath("TARANIS.BIN"); + } + if (path.isEmpty()) { + // Mike's bootloader calls the EEPROM file "ERSKY9X.BIN" :( + path = findMassstoragePath("ERSKY9X.BIN"); + } + if (path.isEmpty()) { + RadioNotFoundDialog dialog(progress); + dialog.exec(); + return false; + } + CopyProcess copyProcess(path, filename, progress); + if (!copyProcess.run()) { + return false; + } + + + if (!IS_STM32(board)) { + FlashProcess flashProcess(getRadioInterfaceCmd(), getReadEEpromCmd(filename), progress); + if (!flashProcess.run()) { + return false; } } return QFileInfo(filename).exists(); } -bool writeEeprom(const QString & filename, ProgressWidget * progress) +bool writeSettings(const QString & filename, ProgressWidget * progress) { Board::Type board = getCurrentBoard(); @@ -272,94 +292,29 @@ bool writeEeprom(const QString & filename, ProgressWidget * progress) return false; } -#if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) -#if defined WIN32 || !defined __GNUC__ -#include -bool isRemovableMedia(const QString & vol) -{ - char szDosDeviceName[MAX_PATH]; - QString volume = vol; - UINT driveType = GetDriveType(volume.replace("/", "\\").toLatin1()); - if (driveType != DRIVE_REMOVABLE) - return false; - QueryDosDevice(volume.replace("/", "").toLatin1(), szDosDeviceName, MAX_PATH); - if (strstr(szDosDeviceName, "\\Floppy") != NULL) { // it's a floppy - return false; - } - return true; -} -#else - #include "mountlist.h" -#endif // defined WIN32 || !defined __GNUC__ -#endif // (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) - QString findMassstoragePath(const QString & filename, bool onlyPath) { QString temppath; - QString eepromfile; + QString probefile; bool found = false; + QRegularExpression fstypeRe("^(v?fat|msdos)", QRegularExpression::CaseInsensitiveOption); // Linux: "vfat"; macOS: "msdos"; Win: "FAT32" -#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) + foreach(const QStorageInfo & si, QStorageInfo::mountedVolumes()) { //qDebug() << si.rootPath() << si.name() << si.device() << si.displayName() << si.fileSystemType() << si.isReady(); if (!si.isReady() || !QString(si.fileSystemType()).contains(fstypeRe)) continue; temppath = si.rootPath(); - eepromfile = temppath % "/" % filename; - qDebug() << "Searching for" << eepromfile; - if (QFile::exists(eepromfile)) { + probefile = temppath % "/" % filename; + qDebug() << "Searching for" << probefile; + if (QFile::exists(probefile)) { found = true; break; } } -#elif defined WIN32 || !defined __GNUC__ - static QStringList blacklist; - foreach(const QFileInfo & drive, QDir::drives()) { - temppath = drive.absolutePath(); - if (blacklist.contains(temppath)) - continue; - if (!isRemovableMedia(temppath)) { - blacklist.append(temppath); - continue; - } - WCHAR szVolumeName[256] ; - WCHAR szFileSystemName[256]; - DWORD dwSerialNumber = 0; - DWORD dwMaxFileNameLength=256; - DWORD dwFileSystemFlags=0; - if (!GetVolumeInformationW( (WCHAR *) drive.absolutePath().utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256)) - continue; - eepromfile = temppath % "/" % filename; - qDebug() << "Searching for" << eepromfile; - if (QFile::exists(eepromfile)) { - found = true; - break; - } - } -#else - const static QStringList blacklist = QStringList() << "/" << "/net" << "/proc" << "/run"; - QStringList drives; - struct mount_entry *entry; - struct mount_entry *firstEntry; - firstEntry = entry = read_file_system_list(true); - while (entry != NULL) { - temppath = entry->me_mountdir; - if (!drives.contains(entry->me_devname) && !blacklist.contains(temppath) && QString(entry->me_type).contains(fstypeRe)) { - drives.append(entry->me_devname); - eepromfile = temppath % "/" % filename; - qDebug() << "Searching for" << eepromfile; - if (QFile::exists(eepromfile)) { - found = true; - break; - } - } - entry = entry->me_next; - } - free_file_system_list(firstEntry); -#endif if (found) - return onlyPath ? temppath : eepromfile; + return onlyPath ? temppath : probefile; else return QString(); } diff --git a/companion/src/radiointerface.h b/companion/src/radiointerface.h index 37053fac5..76c635e83 100644 --- a/companion/src/radiointerface.h +++ b/companion/src/radiointerface.h @@ -40,7 +40,9 @@ QStringList getWriteFirmwareArgs(const QString &filename); bool readFirmware(const QString &filename, ProgressWidget *progress); bool writeFirmware(const QString &filename, ProgressWidget *progress); -bool readEeprom(const QString &filename, ProgressWidget *progress); -bool writeEeprom(const QString &filename, ProgressWidget *progress); +bool readSettings(const QString &filename, ProgressWidget *progress); +bool readSettingsSDCard(const QString &filename, ProgressWidget *progress); +bool readSettingsEeprom(const QString &filename, ProgressWidget *progress); +bool writeSettings(const QString &filename, ProgressWidget *progress); #endif // _RADIOINTERFACE_H_ From 44e2d6371dc9d2d01451cc8492c7140b82b947b2 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 28 Nov 2021 22:46:54 +1100 Subject: [PATCH 017/180] Fix return values --- companion/src/radiointerface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index 21fd4af5c..eb90a5a2c 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -187,9 +187,9 @@ bool readSettings(const QString & filename, ProgressWidget * progress) } if (Boards::getCapability(board, Board::HasSDCard)) - readSettingsSDCard(filename, progress); + return readSettingsSDCard(filename, progress); else - readSettingsEeprom(filename, progress); + return readSettingsEeprom(filename, progress); } bool readSettingsSDCard(const QString & filename, ProgressWidget * progress) From 88ea3f8b20cd8085ad7e05328d64ef3eb38aaae1 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 28 Nov 2021 16:20:49 +0100 Subject: [PATCH 018/180] Add enum lookup tables --- .../firmwares/edgetx/yaml_generalsettings.h | 69 ++++++++++++++++--- companion/src/firmwares/edgetx/yaml_ops.h | 49 ++++++++++++- 2 files changed, 105 insertions(+), 13 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 1cda57076..3c76cabb3 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -22,8 +22,58 @@ #include "generalsettings.h" #include "yaml_trainerdata.h" +typedef std::pair YamlLookupTableElmt; +typedef std::vector YamlLookupTable; + +const YamlLookupTable beeperModeLut = { + { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, + { GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" }, + { GeneralSettings::BEEPER_NOKEYS, "mode_nokeys" }, + { GeneralSettings::BEEPER_ALL, "mode_all" }, +}; + +enum BacklightMode { + e_backlight_mode_off = 0, + e_backlight_mode_keys = 1, + e_backlight_mode_sticks = 2, + e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks, + e_backlight_mode_on +}; + +const YamlLookupTable backlightModeLut = { + { e_backlight_mode_off, "backlight_mode_off" }, + { e_backlight_mode_keys, "backlight_mode_keys" }, + { e_backlight_mode_sticks, "backlight_mode_sticks" }, + { e_backlight_mode_all, "backlight_mode_all" }, + { e_backlight_mode_on, "backlight_mode_on" }, +}; + +const YamlLookupTable bluetoothModeLut = { + { GeneralSettings::BLUETOOTH_MODE_OFF, "OFF" }, + { GeneralSettings::BLUETOOTH_MODE_TELEMETRY, "TELEMETRY" }, + { GeneralSettings::BLUETOOTH_MODE_TRAINER, "TRAINER" }, +}; + +const YamlLookupTable uartModeLut = { + { GeneralSettings::AUX_SERIAL_OFF, "MODE_NONE" }, + { GeneralSettings::AUX_SERIAL_TELE_MIRROR, "MODE_TELEMETRY_MIRROR" }, + { GeneralSettings::AUX_SERIAL_TELE_IN, "MODE_TELEMETRY" }, + { GeneralSettings::AUX_SERIAL_SBUS_TRAINER, "MODE_SBUS_TRAINER" }, + { GeneralSettings::AUX_SERIAL_LUA, "MODE_LUA" }, +}; + +const YamlLookupTable antennaModeLut = { + { GeneralSettings::ANTENNA_MODE_INTERNAL, "MODE_INTERNAL" }, + { GeneralSettings::ANTENNA_MODE_ASK, "MODE_ASK" }, + { GeneralSettings::ANTENNA_MODE_PER_MODEL, "MODE_PER_MODEL" }, + { GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" }, + { GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" }, +}; + namespace YAML { - + + ENUM_CONVERTER(GeneralSettings::BeeperMode, beeperModeLut); + template<> struct convert { @@ -45,20 +95,17 @@ namespace YAML { node["txVoltageCalibration"] >> rhs.txVoltageCalibration; node["vBatMin"] >> rhs.vBatMin; node["vBatMax"] >> rhs.vBatMax; - - // TODO: lookup table - //rhs.backlightMode = node["backlightMode"].as(); // backlight_mode_all - + node["backlightMode"] >> backlightModeLut >> rhs.backlightMode; node["trainer"] >> rhs.trainer; node["view"] >> rhs.view; node["fai"] >> rhs.fai; node["disableMemoryWarning"] >> rhs.disableMemoryWarning; - //node["beepMode"] >> rhs.beeperMode; // TODO: string mapping + node["beepMode"] >> rhs.beeperMode; node["disableAlarmWarning"] >> rhs.disableAlarmWarning; node["disableRssiPoweroffAlarm"] >> rhs.disableRssiPoweroffAlarm; node["USBMode"] >> rhs.usbMode; node["jackMode"] >> rhs.jackMode; - //node["hapticMode"] >> rhs.hapticMode; // TODO: strin mapping + node["hapticMode"] >> rhs.hapticMode; node["stickMode"] >> rhs.stickMode; node["timezone"] >> rhs.timezone; node["adjustRTC"] >> rhs.adjustRTC; @@ -77,7 +124,7 @@ namespace YAML { node["globalTimer"] >> rhs.globalTimer; node["bluetoothName"] >> rhs.bluetoothName; node["bluetoothBaudrate"] >> rhs.bluetoothBaudrate; - node["bluetoothMode"] >> rhs.bluetoothMode; + node["bluetoothMode"] >> bluetoothModeLut >> rhs.bluetoothMode; node["countryCode"] >> rhs.countryCode; node["jitterFilter"] >> rhs.jitterFilter; node["disableRtcWarning"] >> rhs.rtcCheckDisable; // TODO: verify @@ -91,9 +138,9 @@ namespace YAML { node["varioRange"] >> rhs.varioRange; node["varioRepeat"] >> rhs.varioRepeat; node["backgroundVolume"] >> rhs.backgroundVolume; - //node["auxSerialMode"] >> rhs.auxSerialMode; - //node["aux2SerialMode"] >> rhs.aux2SerialMode; - //node["antennaMode"] >> rhs.antennaMode; + node["auxSerialMode"] >> uartModeLut >> rhs.auxSerialMode; + node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode; + node["antennaMode"] >> antennaModeLut >> rhs.antennaMode; node["backlightColor"] >> rhs.backlightColor; // if (node["customFn"]) { diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 4dc4d6608..e84adca3d 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -22,20 +22,65 @@ #include +typedef std::pair YamlLookupTableElmt; +typedef std::vector YamlLookupTable; + +YAML::Node operator>>(const YAML::Node& node, const YamlLookupTable& lut) +{ + if (node) { + std::string str = node.as(); + const auto& it = + find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { + if (elmt.second == str) return true; + return false; + }); + + if (it != lut.end()) { + return YAML::Node(it->first); + } + return YAML::Node(); + } + + return node; +} + template void operator>>(const YAML::Node& node, T& value) { - if (node) { + if (node && !node.IsNull()) { value = node.as(); } } +template <> +void operator>>(const YAML::Node& node, bool& value) +{ + if (node && node.IsScalar()) { + value = node.as(); + } +} + template void operator>>(const YAML::Node& node, char (&value)[N]) { - if (node) { + if (node && node.IsScalar()) { auto str = node.as(); str.copy(value, N-1); value[std::min(str.size(), N-1)] = '\0'; } } + +#define ENUM_CONVERTER(enum_type, lut) \ + template <> \ + struct convert { \ + static bool decode(const YAML::Node& node, enum_type& rhs) \ + { \ + if (node) { \ + YAML::Node conv = node >> lut; \ + if (conv.IsScalar()) { \ + rhs = (enum_type)conv.as(); \ + } \ + } \ + return true; \ + } \ + } From 30c1e703b16d14d700dcb786f066b0bd9e442ced Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 28 Nov 2021 18:12:57 +0100 Subject: [PATCH 019/180] Added offset capabilities for integers --- .../firmwares/edgetx/yaml_generalsettings.h | 8 +++-- companion/src/firmwares/edgetx/yaml_ops.h | 32 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 3c76cabb3..19bbc971e 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -83,7 +83,7 @@ namespace YAML { // return node; // } - static bool decode(const YAML::Node& node, GeneralSettings& rhs) { + static bool decode(const Node& node, GeneralSettings& rhs) { node["version"] >> rhs.version; node["versionBla"] >> rhs.version; @@ -93,8 +93,10 @@ namespace YAML { node["contrast"] >> rhs.contrast; node["vBatWarn"] >> rhs.vBatWarn; node["txVoltageCalibration"] >> rhs.txVoltageCalibration; - node["vBatMin"] >> rhs.vBatMin; - node["vBatMax"] >> rhs.vBatMax; + + node["vBatMin"] >> ioffset_int(rhs.vBatMin, 90); + node["vBatMax"] >> ioffset_int(rhs.vBatMax, 120); + node["backlightMode"] >> backlightModeLut >> rhs.backlightMode; node["trainer"] >> rhs.trainer; node["view"] >> rhs.view; diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index e84adca3d..e2c71a836 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -25,7 +25,24 @@ typedef std::pair YamlLookupTableElmt; typedef std::vector YamlLookupTable; -YAML::Node operator>>(const YAML::Node& node, const YamlLookupTable& lut) +class ioffset_int { + +public: + ioffset_int(int& val, int offset) + : value(val), offset(offset) + {} + + void assign(int newValue) const { + value = newValue - offset; + } + +private: + int& value; + int offset; +}; + + +YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) { if (node) { std::string str = node.as(); @@ -44,8 +61,15 @@ YAML::Node operator>>(const YAML::Node& node, const YamlLookupTable& lut) return node; } +void operator >> (const YAML::Node& node, const ioffset_int& value) +{ + if (node && node.IsScalar()) { + value.assign(node.as()); + } +} + template -void operator>>(const YAML::Node& node, T& value) +void operator >> (const YAML::Node& node, T& value) { if (node && !node.IsNull()) { value = node.as(); @@ -53,7 +77,7 @@ void operator>>(const YAML::Node& node, T& value) } template <> -void operator>>(const YAML::Node& node, bool& value) +void operator >> (const YAML::Node& node, bool& value) { if (node && node.IsScalar()) { value = node.as(); @@ -61,7 +85,7 @@ void operator>>(const YAML::Node& node, bool& value) } template -void operator>>(const YAML::Node& node, char (&value)[N]) +void operator >> (const YAML::Node& node, char (&value)[N]) { if (node && node.IsScalar()) { auto str = node.as(); From 703f14d1537a44f92694372d2c554399fd168fe9 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 29 Nov 2021 08:50:47 +1100 Subject: [PATCH 020/180] Rename functions from eeprom to settings --- companion/src/mainwindow.cpp | 8 ++++---- companion/src/mainwindow.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index c76351781..973cc372a 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -912,9 +912,9 @@ void MainWindow::readSettings() else tempFile = generateProcessUniqueTempFileName("temp.bin"); - qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile; + qDebug() << "Reading models and settings into temp file: " << tempFile; - if (readEepromFromRadio(tempFile)) { + if (readSettingsFromRadio(tempFile)) { MdiChild * child = createMdiChild(); child->newFile(false); child->loadFile(tempFile, false); @@ -933,7 +933,7 @@ bool MainWindow::readFirmwareFromRadio(const QString & filename) return result; } -bool MainWindow::readEepromFromRadio(const QString & filename) +bool MainWindow::readSettingsFromRadio(const QString & filename) { ProgressDialog progressDialog(this, tr("Read Models and Settings from Radio"), CompanionIcon("read_eeprom.png")); bool result = ::readSettings(filename, progressDialog.progress()); @@ -974,7 +974,7 @@ void MainWindow::readBackup() } QString fileName = QFileDialog::getSaveFileName(this, tr("Save Radio Backup to File"), g.eepromDir(), EXTERNAL_EEPROM_FILES_FILTER); if (!fileName.isEmpty()) { - if (!readEepromFromRadio(fileName)) + if (!readSettingsFromRadio(fileName)) return; } } diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index 87202acf2..a93a8a84b 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -156,7 +156,7 @@ class MainWindow : public QMainWindow QMdiSubWindow * findMdiChild(const QString & fileName); bool anyChildrenDirty(); - bool readEepromFromRadio(const QString & filename); + bool readSettingsFromRadio(const QString & filename); bool readFirmwareFromRadio(const QString & filename); bool checkProfileRadioExists(int profId); From d98a697aca170a5a09cdbd2e5cad165778a524d4 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 10:47:05 +0100 Subject: [PATCH 021/180] Add "board" field and remove a few useless ones --- radio/src/datastructs_private.h | 5 ++--- .../storage/conversions/yaml/yaml_datastructs_funcs.cpp | 6 ++++++ .../storage/conversions/yaml/yaml_datastructs_nv14.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_t12.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_t8.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_tlite.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_tx12.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_x10.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_x12s.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_x7.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_x9d.cpp | 3 ++- .../src/storage/conversions/yaml/yaml_datastructs_x9e.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_x9lite.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_x9lites.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_xlite.cpp | 3 ++- .../storage/conversions/yaml/yaml_datastructs_xlites.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_funcs.cpp | 8 ++++++++ radio/src/storage/yaml/yaml_datastructs_nv14.cpp | 5 ++--- radio/src/storage/yaml/yaml_datastructs_t12.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_t8.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_tlite.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_tx12.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x10.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x12s.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x7.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x9d.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x9e.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x9lite.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_x9lites.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_xlite.cpp | 3 ++- radio/src/storage/yaml/yaml_datastructs_xlites.cpp | 3 ++- 31 files changed, 72 insertions(+), 33 deletions(-) diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index c4453ee69..fffec8530 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -834,6 +834,7 @@ PACK(struct RadioData { // Real attributes NOBACKUP(uint8_t version); + CUST_ATTR(board,nullptr,w_board); NOBACKUP(uint16_t variant SKIP); CalibData calib[NUM_STICKS + STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS + STORAGE_NUM_MOUSE_ANALOGS] NO_IDX; NOBACKUP(uint16_t chkSum SKIP); @@ -867,12 +868,10 @@ PACK(struct RadioData { NOBACKUP(uint8_t templateSetup); // RETA order for receiver channels NOBACKUP(int8_t PPM_Multiplier); NOBACKUP(int8_t hapticLength CUST(r_5pos,w_5pos)); - N_HORUS_FIELD(N_TARANIS_FIELD(uint8_t spare2 SKIP)); - N_HORUS_FIELD(N_TARANIS_FIELD(uint8_t stickReverse)); NOBACKUP(int8_t beepLength:3 CUST(r_5pos,w_5pos)); NOBACKUP(int8_t hapticStrength:3 CUST(r_5pos,w_5pos)); NOBACKUP(uint8_t gpsFormat:1); - NOBACKUP(uint8_t unexpectedShutdown:1); + NOBACKUP(uint8_t unexpectedShutdown:1 SKIP); NOBACKUP(uint8_t speakerPitch CUST(r_spPitch,w_spPitch)); NOBACKUP(int8_t speakerVolume CUST(r_vol,w_vol)); NOBACKUP(int8_t vBatMin CUST(r_vbat_min,w_vbat_min)); diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index cb1104166..5a8951c25 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -26,6 +26,12 @@ #define GVAR_SMALL 128 #define VOLUME_LEVEL_DEF 12 +bool w_board(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + return wf(opaque, FLAVOUR, sizeof(FLAVOUR)-1); +} + #define in_read_weight nullptr bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index 557bb9ad6..09ad00b27 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -357,6 +357,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 9, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -394,7 +395,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp index e6ae90e4e..c8571e569 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -363,7 +364,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp index 6fa0070ef..34add024b 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -363,7 +364,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp index 6fa0070ef..34add024b 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -363,7 +364,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp index ed52b20f5..35ee08c95 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -363,7 +364,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index 0617009af..4c6e21435 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -378,6 +378,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -411,7 +412,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index fd88dba4a..4da434bc0 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -378,6 +378,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -411,7 +412,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp index 6fa0070ef..34add024b 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -363,7 +364,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp index cc7bde834..3bb475d99 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp @@ -335,6 +335,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 9, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -370,7 +371,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp index 3b0533b24..8e7bad62a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp @@ -374,6 +374,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -409,7 +410,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp index 6c80e26d0..cfe00a6d1 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp @@ -315,6 +315,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 5, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -350,7 +351,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp index c07bf178b..e0aaeba99 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp @@ -323,6 +323,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 5, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -358,7 +359,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp index eb8e383a1..f579825bb 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp @@ -320,6 +320,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -355,7 +356,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp index fdbfae806..761e32c11 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp @@ -322,6 +322,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -357,7 +358,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 4774f437e..5d4922497 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -28,6 +28,8 @@ // Use definitions from v220 conversions as long as nothing changes namespace yaml_conv_220 { + bool w_board(void* user, uint8_t* data, uint32_t bitoffs, yaml_writer_func wf, void* opaque); + bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque); bool output_source_1_param(const char* src_prefix, size_t src_len, uint32_t n, @@ -135,6 +137,12 @@ static inline void check_yaml_funcs() #endif } +static bool w_board(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + return yaml_conv_220::w_board(user, data, bitoffs, wf, opaque); +} + #define GVAR_SMALL 128 static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t val_len) diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 71e0dc879..33c9ffe3c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -357,6 +357,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 9, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -390,12 +391,10 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "templateSetup", 8 ), YAML_SIGNED( "PPM_Multiplier", 8 ), YAML_SIGNED_CUST( "hapticLength", 8, r_5pos, w_5pos ), - YAML_PADDING( 8 ), - YAML_UNSIGNED( "stickReverse", 8 ), YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index 218804cb1..4ddcadc24 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index c364bb3aa..becdd13c4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index c364bb3aa..becdd13c4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 68e5bdf06..cb33916c6 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 026ea7d1f..5bf3dbaa9 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -380,6 +380,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 17, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -414,7 +415,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 0c81b1704..b3417d332 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -378,6 +378,7 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -412,7 +413,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index c364bb3aa..becdd13c4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 43b797e14..831f68c5a 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -335,6 +335,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 9, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -371,7 +372,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 0488418f1..22f18fd9d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -374,6 +374,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -410,7 +411,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 10faef18a..0a7d205a0 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -315,6 +315,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 5, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -351,7 +352,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index d1b807e11..4db4cf1f3 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -323,6 +323,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 5, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -359,7 +360,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index f42fab1a3..b591daf19 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -320,6 +320,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -356,7 +357,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index f7dabf4da..828436b96 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -322,6 +322,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -358,7 +359,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), From f57a1fd6c3f2c55054e37eb63632e761c5a60ffd Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 11:14:50 +0100 Subject: [PATCH 022/180] Add support for radio calibration --- companion/src/firmwares/CMakeLists.txt | 3 + .../src/firmwares/edgetx/yaml_calibdata.cpp | 57 +++++++++++++++ .../src/firmwares/edgetx/yaml_calibdata.h | 64 ++++++++++++++++ .../firmwares/edgetx/yaml_generalsettings.cpp | 66 +++++++++++++++++ .../firmwares/edgetx/yaml_generalsettings.h | 73 ++++++------------- companion/src/firmwares/edgetx/yaml_ops.cpp | 55 ++++++++++++++ companion/src/firmwares/edgetx/yaml_ops.h | 36 +-------- 7 files changed, 271 insertions(+), 83 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_calibdata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_calibdata.h create mode 100644 companion/src/firmwares/edgetx/yaml_generalsettings.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_ops.cpp diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 2185e3676..16aa92710 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -30,6 +30,9 @@ set(firmwares_SRCS opentx/opentxeeprom.cpp opentx/opentxinterface.cpp edgetx/edgetxinterface.cpp + edgetx/yaml_ops.cpp + edgetx/yaml_generalsettings.cpp + edgetx/yaml_calibdata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp new file mode 100644 index 000000000..b5cd83a4e --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_calibdata.h" + +// TODO: we need a function that +// does the opposite of Boards::getAnalogInputName() +// +// This is only valid for X10, T16, TX16S (not X12S) +// +const YamlLookupTable calibIdxLut = { + { 0, "Rud" }, + { 1, "Ele" }, + { 2, "Thr" }, + { 3, "Ail" }, + { 4, "S1" }, + { 5, "6POS" }, + { 6, "S2" }, + { 7, "EXT1" }, + { 8, "EXT2" }, + // not yet supported in Companion: + // { 9, "EXT3" }, + // { 10, "EXT4" }, + { 9, "LS" }, + { 10, "RS" }, + { 11, "MOUSE1" }, + { 12, "MOUSE2" }, +}; + +YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); } + +void YamlCalibData::copy(int* calibMid, int* calibSpanNeg, + int* calibSpanPos) const +{ + for (int i = 0; i < CPN_MAX_ANALOGS; i++) { + calibMid[i] = calib[i].mid; + calibSpanNeg[i] = calib[i].spanNeg; + calibSpanPos[i] = calib[i].spanPos; + } +} diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.h b/companion/src/firmwares/edgetx/yaml_calibdata.h new file mode 100644 index 000000000..a0de4c915 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_calibdata.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "generalsettings.h" + +struct CalibData { + int16_t mid; + int16_t spanNeg; + int16_t spanPos; +}; + +struct YamlCalibData { + CalibData calib[CPN_MAX_ANALOGS]; + + YamlCalibData(); + void copy(int* calibMid, int* calibSpanNeg, int* calibSpanPos) const; +}; + +extern const YamlLookupTable calibIdxLut; + +namespace YAML { + + template<> + struct convert { + static bool decode(const Node& node, CalibData& rhs) { + if (!node.IsMap()) return false; + node["mid"] >> rhs.mid; + node["spanNeg"] >> rhs.spanNeg; + node["spanPos"] >> rhs.spanPos; + return true; + } + }; + + template<> + struct convert { + static bool decode(const Node& node, YamlCalibData& rhs) { + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> calibIdxLut >> idx; + kv.second >> rhs.calib[idx]; + } + return true; + } + }; +} diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp new file mode 100644 index 000000000..5c4c1e3dd --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_generalsettings.h" + +const YamlLookupTable beeperModeLut = { + { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, + { GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" }, + { GeneralSettings::BEEPER_NOKEYS, "mode_nokeys" }, + { GeneralSettings::BEEPER_ALL, "mode_all" }, +}; + +enum BacklightMode { + e_backlight_mode_off = 0, + e_backlight_mode_keys = 1, + e_backlight_mode_sticks = 2, + e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks, + e_backlight_mode_on +}; + +const YamlLookupTable backlightModeLut = { + { e_backlight_mode_off, "backlight_mode_off" }, + { e_backlight_mode_keys, "backlight_mode_keys" }, + { e_backlight_mode_sticks, "backlight_mode_sticks" }, + { e_backlight_mode_all, "backlight_mode_all" }, + { e_backlight_mode_on, "backlight_mode_on" }, +}; + +const YamlLookupTable bluetoothModeLut = { + { GeneralSettings::BLUETOOTH_MODE_OFF, "OFF" }, + { GeneralSettings::BLUETOOTH_MODE_TELEMETRY, "TELEMETRY" }, + { GeneralSettings::BLUETOOTH_MODE_TRAINER, "TRAINER" }, +}; + +const YamlLookupTable uartModeLut = { + { GeneralSettings::AUX_SERIAL_OFF, "MODE_NONE" }, + { GeneralSettings::AUX_SERIAL_TELE_MIRROR, "MODE_TELEMETRY_MIRROR" }, + { GeneralSettings::AUX_SERIAL_TELE_IN, "MODE_TELEMETRY" }, + { GeneralSettings::AUX_SERIAL_SBUS_TRAINER, "MODE_SBUS_TRAINER" }, + { GeneralSettings::AUX_SERIAL_LUA, "MODE_LUA" }, +}; + +const YamlLookupTable antennaModeLut = { + { GeneralSettings::ANTENNA_MODE_INTERNAL, "MODE_INTERNAL" }, + { GeneralSettings::ANTENNA_MODE_ASK, "MODE_ASK" }, + { GeneralSettings::ANTENNA_MODE_PER_MODEL, "MODE_PER_MODEL" }, + { GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" }, + { GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" }, +}; diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 19bbc971e..da3d0ada0 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -21,54 +21,13 @@ #include "yaml_ops.h" #include "generalsettings.h" #include "yaml_trainerdata.h" +#include "yaml_calibdata.h" -typedef std::pair YamlLookupTableElmt; -typedef std::vector YamlLookupTable; - -const YamlLookupTable beeperModeLut = { - { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, - { GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" }, - { GeneralSettings::BEEPER_NOKEYS, "mode_nokeys" }, - { GeneralSettings::BEEPER_ALL, "mode_all" }, -}; - -enum BacklightMode { - e_backlight_mode_off = 0, - e_backlight_mode_keys = 1, - e_backlight_mode_sticks = 2, - e_backlight_mode_all = e_backlight_mode_keys+e_backlight_mode_sticks, - e_backlight_mode_on -}; - -const YamlLookupTable backlightModeLut = { - { e_backlight_mode_off, "backlight_mode_off" }, - { e_backlight_mode_keys, "backlight_mode_keys" }, - { e_backlight_mode_sticks, "backlight_mode_sticks" }, - { e_backlight_mode_all, "backlight_mode_all" }, - { e_backlight_mode_on, "backlight_mode_on" }, -}; - -const YamlLookupTable bluetoothModeLut = { - { GeneralSettings::BLUETOOTH_MODE_OFF, "OFF" }, - { GeneralSettings::BLUETOOTH_MODE_TELEMETRY, "TELEMETRY" }, - { GeneralSettings::BLUETOOTH_MODE_TRAINER, "TRAINER" }, -}; - -const YamlLookupTable uartModeLut = { - { GeneralSettings::AUX_SERIAL_OFF, "MODE_NONE" }, - { GeneralSettings::AUX_SERIAL_TELE_MIRROR, "MODE_TELEMETRY_MIRROR" }, - { GeneralSettings::AUX_SERIAL_TELE_IN, "MODE_TELEMETRY" }, - { GeneralSettings::AUX_SERIAL_SBUS_TRAINER, "MODE_SBUS_TRAINER" }, - { GeneralSettings::AUX_SERIAL_LUA, "MODE_LUA" }, -}; - -const YamlLookupTable antennaModeLut = { - { GeneralSettings::ANTENNA_MODE_INTERNAL, "MODE_INTERNAL" }, - { GeneralSettings::ANTENNA_MODE_ASK, "MODE_ASK" }, - { GeneralSettings::ANTENNA_MODE_PER_MODEL, "MODE_PER_MODEL" }, - { GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" }, - { GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" }, -}; +extern const YamlLookupTable beeperModeLut; +extern const YamlLookupTable backlightModeLut; +extern const YamlLookupTable bluetoothModeLut; +extern const YamlLookupTable uartModeLut; +extern const YamlLookupTable antennaModeLut; namespace YAML { @@ -85,11 +44,18 @@ namespace YAML { static bool decode(const Node& node, GeneralSettings& rhs) { + // TODO: check board string and fetch Board instance + std::string board; + node["board"] >> board; node["version"] >> rhs.version; - node["versionBla"] >> rhs.version; - // // calib + + // Radio calib + YamlCalibData calib; + node["calib"] >> calib; + calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + node["currModel"] >> rhs.currModelIndex; - // // filename + node["currModelFilename"] >> rhs.currModelFilename; node["contrast"] >> rhs.contrast; node["vBatWarn"] >> rhs.vBatWarn; node["txVoltageCalibration"] >> rhs.txVoltageCalibration; @@ -153,13 +119,18 @@ namespace YAML { // } // TODO: + // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; + // char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; // unsigned int switchConfig[CPN_MAX_SWITCHES]; - // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; + // char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; // unsigned int potConfig[CPN_MAX_KNOBS]; + // char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; // unsigned int sliderConfig[CPN_MAX_SLIDERS]; + + // Color lcd theme settings are probably obsolete // RadioTheme::ThemeData themeData; node["ownerRegistrationID"] >> rhs.registrationId; diff --git a/companion/src/firmwares/edgetx/yaml_ops.cpp b/companion/src/firmwares/edgetx/yaml_ops.cpp new file mode 100644 index 000000000..6c148dd94 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_ops.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" + +YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) +{ + if (node) { + std::string str = node.as(); + const auto& it = + find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { + if (elmt.second == str) return true; + return false; + }); + + if (it != lut.end()) { + return YAML::Node(it->first); + } + return YAML::Node(); + } + + return node; +} + +void operator >> (const YAML::Node& node, const ioffset_int& value) +{ + if (node && node.IsScalar()) { + value.assign(node.as()); + } +} + +template <> +void operator >> (const YAML::Node& node, bool& value) +{ + if (node && node.IsScalar()) { + value = node.as(); + } +} diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index e2c71a836..06d974872 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -42,31 +42,8 @@ private: }; -YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) -{ - if (node) { - std::string str = node.as(); - const auto& it = - find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { - if (elmt.second == str) return true; - return false; - }); - - if (it != lut.end()) { - return YAML::Node(it->first); - } - return YAML::Node(); - } - - return node; -} - -void operator >> (const YAML::Node& node, const ioffset_int& value) -{ - if (node && node.IsScalar()) { - value.assign(node.as()); - } -} +YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut); +void operator >> (const YAML::Node& node, const ioffset_int& value); template void operator >> (const YAML::Node& node, T& value) @@ -76,13 +53,8 @@ void operator >> (const YAML::Node& node, T& value) } } -template <> -void operator >> (const YAML::Node& node, bool& value) -{ - if (node && node.IsScalar()) { - value = node.as(); - } -} +// type specialisation +template <> void operator >> (const YAML::Node& node, bool& value); template void operator >> (const YAML::Node& node, char (&value)[N]) From 278a27b65f05edea1150b08bddbdab954b6b2879 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 29 Nov 2021 22:16:54 +1100 Subject: [PATCH 023/180] Fix blank error messages --- companion/src/radiointerface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index eb90a5a2c..9b5cca0dd 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -211,12 +211,12 @@ bool readSettingsSDCard(const QString & filename, ProgressWidget * progress) RadioData radioData; Storage inputStorage(radioPath); if (!inputStorage.load(radioData)) { - QMessageBox::critical(progress, CPN_STR_TTL_ERROR, inputStorage.error()); + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QCoreApplication::translate("RadioInterface", "Failed to read Models and Settings from") % radioPath); return false; } Storage outputStorage(filename); if (!outputStorage.write(radioData)) { - QMessageBox::critical(progress, CPN_STR_TTL_ERROR, outputStorage.error()); + QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QCoreApplication::translate("RadioInterface", "Failed to write Models and Setting file") % filename); return false; } From 9dd8917ab4d211fbc22a41bf6cc1f12ae6ae0d67 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 13:28:16 +0100 Subject: [PATCH 024/180] Add stick, switch, pots & slider config --- companion/src/firmwares/CMakeLists.txt | 1 + .../firmwares/edgetx/yaml_generalsettings.h | 19 ++-- .../firmwares/edgetx/yaml_switchconfig.cpp | 64 +++++++++++ .../src/firmwares/edgetx/yaml_switchconfig.h | 101 ++++++++++++++++++ 4 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_switchconfig.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_switchconfig.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 16aa92710..e419ad923 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -33,6 +33,7 @@ set(firmwares_SRCS edgetx/yaml_ops.cpp edgetx/yaml_generalsettings.cpp edgetx/yaml_calibdata.cpp + edgetx/yaml_switchconfig.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index da3d0ada0..a11f2d066 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -22,6 +22,7 @@ #include "generalsettings.h" #include "yaml_trainerdata.h" #include "yaml_calibdata.h" +#include "yaml_switchconfig.h" extern const YamlLookupTable beeperModeLut; extern const YamlLookupTable backlightModeLut; @@ -120,15 +121,21 @@ namespace YAML { // TODO: // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; + + YamlStickConfig stickConfig; + node["sticksConfig"] >> stickConfig; - // char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; - // unsigned int switchConfig[CPN_MAX_SWITCHES]; + YamlSwitchConfig switchConfig; + node["switchConfig"] >> switchConfig; + switchConfig.copy(rhs.switchName, rhs.switchConfig); - // char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; - // unsigned int potConfig[CPN_MAX_KNOBS]; + YamlPotConfig potsConfig; + node["potsConfig"] >> potsConfig; + potsConfig.copy(rhs.potName, rhs.potConfig); - // char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; - // unsigned int sliderConfig[CPN_MAX_SLIDERS]; + YamlSliderConfig slidersConfig; + node["slidersConfig"] >> slidersConfig; + slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); // Color lcd theme settings are probably obsolete // RadioTheme::ThemeData themeData; diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp new file mode 100644 index 000000000..2fabedf19 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_switchconfig.h" +#include "boards.h" + +const YamlLookupTable sticksLut = { + {0, "0"}, + {1, "1"}, + {2, "2"}, + {3, "3"}, +}; + +const YamlLookupTable switchesLut = { + {0, "SA"}, {1, "SB"}, {2, "SC"}, {3, "SD"}, {4, "SE"}, + {5, "SF"}, {6, "SG"}, {7, "SH"}, {8, "SI"}, {9, "SJ"}, +}; + +const YamlLookupTable switchConfigLut = { + {Board::SWITCH_NOT_AVAILABLE, "none"}, + {Board::SWITCH_TOGGLE, "toggle"}, + {Board::SWITCH_2POS, "2pos"}, + {Board::SWITCH_3POS, "3pos"}, +}; + +const YamlLookupTable potsLut = { + {0, "S1"}, {1, "6POS"}, {2, "S2"}, {3, "EXT1"}, {4, "EXT2"}, + // { 5, "EXT3" }, + // { 6, "EXT4" }, +}; + +const YamlLookupTable potConfigLut = { + {Board::POT_NONE, "none"}, + {Board::POT_WITH_DETENT, "with_detent"}, + {Board::POT_MULTIPOS_SWITCH, "multipos_switch"}, + {Board::POT_WITHOUT_DETENT, "without_detent"}, +}; + +const YamlLookupTable slidersLut = { + {0, "LS"}, + {1, "RS"}, +}; + +const YamlLookupTable sliderConfigLut = { + {Board::SLIDER_NONE, "none"}, + {Board::SLIDER_WITH_DETENT, "with_detent"}, +}; diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h new file mode 100644 index 000000000..0fac60bc3 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include "yaml_ops.h" +#include "generalsettings.h" + +template +struct YamlNameConfig { + + char name[N][HARDWARE_NAME_LEN + 1]; + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1]) { + memcpy(out_names, name, sizeof(name)); + } +}; + +extern const YamlLookupTable sticksLut; +typedef YamlNameConfig YamlStickConfig; + +template +struct YamlKnobConfig : public YamlNameConfig { + + unsigned int config[N]; + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1], unsigned int out_configs[N]) { + YamlNameConfig::copy(out_names); + memcpy(out_configs, config, sizeof(config)); + } +}; + +// SA: +// type: 3pos +// name: +extern const YamlLookupTable switchesLut; +extern const YamlLookupTable switchConfigLut; +typedef YamlKnobConfig YamlSwitchConfig; + +// S1: +// type: with_detent +// name: +extern const YamlLookupTable potsLut; +extern const YamlLookupTable potConfigLut; +typedef YamlKnobConfig YamlPotConfig; + +// S1: +// type: with_detent +// name: +extern const YamlLookupTable slidersLut; +extern const YamlLookupTable sliderConfigLut; +typedef YamlKnobConfig YamlSliderConfig; + +namespace YAML +{ +template +struct convert > { + static bool decode(const Node& node, YamlNameConfig& rhs) + { + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> name_lut >> idx; + kv.second["name"] >> rhs.name[idx]; + } + return true; + } +}; + +template +struct convert > { + static bool decode(const Node& node, YamlKnobConfig& rhs) + { + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> name_lut >> idx; + kv.second["type"] >> cfg_lut >> rhs.config[idx]; + kv.second["name"] >> rhs.name[idx]; + } + return true; + } +}; +} // namespace YAML From daa49350f2197b04085305567d379b71e442a64e Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 13:58:17 +0100 Subject: [PATCH 025/180] Add value shifts and factors --- .../firmwares/edgetx/yaml_generalsettings.h | 22 ++++++++-------- companion/src/firmwares/edgetx/yaml_ops.h | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index a11f2d066..30eb683cc 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -82,12 +82,12 @@ namespace YAML { node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? node["splashMode"] >> rhs.splashMode; // TODO: B&W only node["templateSetup"] >> rhs.templateSetup; - node["hapticLength"] >> rhs.hapticLength; // TODO: conversion??? - node["speakerPitch"] >> rhs.speakerPitch; // TODO: conversion??? - node["hapticStrength"] >> rhs.hapticStrength; // TODO: conversion??? - node["beepLength"] >> rhs.beeperLength; // TODO: conversion??? + node["hapticLength"] >> ioffset_int(rhs.hapticLength, 2); + node["speakerPitch"] >> ifactor(rhs.speakerPitch, 15); + node["hapticStrength"] >> ioffset_int(rhs.hapticStrength, 2); + node["beepLength"] >> ioffset_int(rhs.beeperLength, 2); node["gpsFormat"] >> rhs.gpsFormat; - node["speakerVolume"] >> rhs.speakerVolume; // TODO: conversion??? + node["speakerVolume"] >> ioffset_int(rhs.speakerVolume, 12); node["backlightBright"] >> rhs.backlightBright; node["switchesDelay"] >> rhs.switchesDelay; node["globalTimer"] >> rhs.globalTimer; @@ -100,13 +100,13 @@ namespace YAML { node["keysBacklight"] >> rhs.keysBacklight; node["imperial"] >> rhs.imperial; node["ttsLanguage"] >> rhs.ttsLanguage; - node["beepVolume"] >> rhs.beepVolume; // TODO: conversion??? - node["wavVolume"] >> rhs.wavVolume; - node["varioVolume"] >> rhs.varioVolume; - node["varioPitch"] >> rhs.varioPitch; - node["varioRange"] >> rhs.varioRange; + node["beepVolume"] >> ioffset_int(rhs.beepVolume, 2); + node["wavVolume"] >> ioffset_int(rhs.wavVolume, 2); + node["varioVolume"] >> ioffset_int(rhs.varioVolume, 2); + node["varioPitch"] >> ifactor(rhs.varioPitch, 10); + node["varioRange"] >> ifactor(rhs.varioRange, 15); node["varioRepeat"] >> rhs.varioRepeat; - node["backgroundVolume"] >> rhs.backgroundVolume; + node["backgroundVolume"] >> ioffset_int(rhs.backgroundVolume, 2); node["auxSerialMode"] >> uartModeLut >> rhs.auxSerialMode; node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode; node["antennaMode"] >> antennaModeLut >> rhs.antennaMode; diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 06d974872..d4d6c255d 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -41,10 +41,35 @@ private: int offset; }; +template +class ifactor { + +public: + ifactor(T& val, int factor) + : value(val), factor(factor) + {} + + void assign(T newValue) const { + value = newValue / factor; + } + +private: + T& value; + T factor; +}; + YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut); void operator >> (const YAML::Node& node, const ioffset_int& value); +template +void operator >> (const YAML::Node& node, const ifactor& value) +{ + if (node && node.IsScalar()) { + value.assign(node.as()); + } +} + template void operator >> (const YAML::Node& node, T& value) { From 3f7ddb48cb93d42f5634f50c75c9b2a51e06d10a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 16:55:16 +0100 Subject: [PATCH 026/180] Fixed missing include --- companion/src/firmwares/edgetx/yaml_ops.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/companion/src/firmwares/edgetx/yaml_ops.cpp b/companion/src/firmwares/edgetx/yaml_ops.cpp index 6c148dd94..bde2129b2 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.cpp +++ b/companion/src/firmwares/edgetx/yaml_ops.cpp @@ -19,6 +19,7 @@ */ #include "yaml_ops.h" +#include YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) { From ac60ad87f83e90031d759e38480a028d06e05795 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 29 Nov 2021 17:34:44 +0100 Subject: [PATCH 027/180] Check "firmware/board" and added gyro settings --- .../firmwares/edgetx/yaml_generalsettings.h | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 30eb683cc..ef3d8d144 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -19,11 +19,13 @@ */ #include "yaml_ops.h" -#include "generalsettings.h" #include "yaml_trainerdata.h" #include "yaml_calibdata.h" #include "yaml_switchconfig.h" +#include "generalsettings.h" +#include "eeprominterface.h" + extern const YamlLookupTable beeperModeLut; extern const YamlLookupTable backlightModeLut; extern const YamlLookupTable bluetoothModeLut; @@ -48,6 +50,13 @@ namespace YAML { // TODO: check board string and fetch Board instance std::string board; node["board"] >> board; + + // TODO: we should be able to fetch the board based on 'board' + auto fw = getCurrentFirmware(); + if (fw && fw->getId().toStdString() != ("edgetx-" + board)) { + throw std::runtime_error("Wrong board"); + } + node["version"] >> rhs.version; // Radio calib @@ -119,9 +128,6 @@ namespace YAML { // } // } - // TODO: - // char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; - YamlStickConfig stickConfig; node["sticksConfig"] >> stickConfig; @@ -137,11 +143,18 @@ namespace YAML { node["slidersConfig"] >> slidersConfig; slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); - // Color lcd theme settings are probably obsolete + // Color lcd theme settings are not used in EdgeTx // RadioTheme::ThemeData themeData; node["ownerRegistrationID"] >> rhs.registrationId; + // Gyro (for now only xlites) + node["gyroMax"] >> rhs.gyroMax; + node["gyroOffset"] >> rhs.gyroOffset; + + // OneBit sampling (X9D only?) + node["uartSampleMode"] >> rhs.uartSampleMode; + return true; } }; From d0293013ec5cb0d02f47c69be7ec3d026fc11539 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 30 Nov 2021 13:39:44 +0100 Subject: [PATCH 028/180] WiP: Add model loading --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/edgetx/edgetxinterface.cpp | 37 ++++- .../src/firmwares/edgetx/edgetxinterface.h | 11 ++ .../firmwares/edgetx/yaml_generalsettings.h | 20 ++- .../src/firmwares/edgetx/yaml_modeldata.cpp | 43 ++++++ .../src/firmwares/edgetx/yaml_modeldata.h | 140 ++++++++++++++++++ companion/src/firmwares/edgetx/yaml_ops.h | 20 +++ companion/src/storage/categorized.cpp | 53 ++++++- 8 files changed, 315 insertions(+), 10 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_modeldata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_modeldata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index e419ad923..0b3d501da 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -34,6 +34,7 @@ set(firmwares_SRCS edgetx/yaml_generalsettings.cpp edgetx/yaml_calibdata.cpp edgetx/yaml_switchconfig.cpp + edgetx/yaml_modeldata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index b38f0fbc0..ddab0fc0d 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -22,6 +22,7 @@ #include "yaml_ops.h" #include "yaml_generalsettings.h" +#include "yaml_modeldata.h" static YAML::Node loadYamlFromByteArray(const QByteArray& data) { @@ -30,11 +31,45 @@ static YAML::Node loadYamlFromByteArray(const QByteArray& data) return YAML::Load(data_istream); } +bool loadModelsListFromYaml(std::vector categories, + EtxModelfiles& modelFiles, + const QByteArray& data) +{ + try { + YAML::Node node = loadYamlFromByteArray(data); + if (!node.IsSequence()) return false; + + for (const auto& cat : node) { + + if (!cat.IsMap()) continue; + + for (const auto& cat_map : cat) { + categories.push_back(cat_map.first.Scalar().c_str()); + + const auto& models = cat_map.second; + if (!models.IsSequence()) continue; + + for (const auto& model : models) { + std::string filename; + model["filename"] >> filename; + modelFiles.push_back({ filename, categories.size()-1 }); + } + } + } + + } catch (const std::runtime_error& e) { + qDebug() << "YAML::ParserException: " << e.what(); + return false; + } + + return true; +} + bool loadModelFromYaml(ModelData& model, const QByteArray& data) { try { YAML::Node node = loadYamlFromByteArray(data); - //model << node; + node >> model; } catch (const std::runtime_error& e) { qDebug() << "YAML::ParserException: " << e.what(); return false; diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index bdfe01bf7..1a87cb181 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -23,6 +23,17 @@ #include "radiodata.h" #include +#include +#include +#include + +typedef std::pair EtxModelfileCategoryPair; +typedef std::list EtxModelfiles; + +bool loadModelsListFromYaml(std::vector categories, + EtxModelfiles& modelFiles, + const QByteArray& data); + bool loadModelFromYaml(ModelData& model, const QByteArray& data); bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data); diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index ef3d8d144..47307816b 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -47,16 +47,24 @@ namespace YAML { static bool decode(const Node& node, GeneralSettings& rhs) { + if (!node.IsMap()) return false; + + // for (const auto& n : node) { + // qDebug() << QString::fromStdString(n.first.Scalar()); + // } + // TODO: check board string and fetch Board instance std::string board; node["board"] >> board; - // TODO: we should be able to fetch the board based on 'board' - auto fw = getCurrentFirmware(); - if (fw && fw->getId().toStdString() != ("edgetx-" + board)) { - throw std::runtime_error("Wrong board"); - } - + // auto fw = getCurrentFirmware(); + // if (fw) { + // qDebug() << "FW Id: " << fw->getId(); + // if (fw->getId() != ("edgetx-" + radioData.generalSettings.board)) { + // throw std::runtime_error("Wrong board"); + // } + // } + node["version"] >> rhs.version; // Radio calib diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp new file mode 100644 index 000000000..968f7949a --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_modeldata.h" +#include "modeldata.h" + +const YamlLookupTable timerModeLut = { + {TimerData::TIMERMODE_OFF, "OFF"}, + {TimerData::TIMERMODE_ON, "ON"}, + {TimerData::TIMERMODE_START, "START"}, + {TimerData::TIMERMODE_THR, "THR"}, + {TimerData::TIMERMODE_THR_REL, "THR_REL"}, + {TimerData::TIMERMODE_THR_START, "THR_START"}, +}; + +const YamlLookupTable trainerModeLut = { + { TRAINER_MODE_OFF, "OFF" }, + { TRAINER_MODE_MASTER_JACK, "MASTER_TRAINER_JACK" }, + { TRAINER_MODE_SLAVE_JACK, "SLAVE" }, + { TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE, "MASTER_SBUS_EXT" }, + { TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE, "MASTER_CPPM_EXT" }, + { TRAINER_MODE_MASTER_BATTERY_COMPARTMENT, "MASTER_BATT_COMP" }, + { TRAINER_MODE_MASTER_BLUETOOTH, "MASTER_BT" }, + { TRAINER_MODE_SLAVE_BLUETOOTH, "SLAVE_BT" }, + { TRAINER_MODE_MULTI, "MASTER_MULTI" }, +}; diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.h b/companion/src/firmwares/edgetx/yaml_modeldata.h new file mode 100644 index 000000000..6573a02ef --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_modeldata.h @@ -0,0 +1,140 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "modeldata.h" + +#include + +extern const YamlLookupTable timerModeLut; +extern const YamlLookupTable trainerModeLut; + +// extern const YamlLookupTable backlightModeLut; +// extern const YamlLookupTable bluetoothModeLut; +// extern const YamlLookupTable uartModeLut; +// extern const YamlLookupTable antennaModeLut; + +namespace YAML { + +// ENUM_CONVERTER(GeneralSettings::BeeperMode, beeperModeLut); + +template <> +struct convert { + // static YAML::Node encode(const GeneralSettings& rhs) { + // Node node; + // // TODO: convert struct into Node + // return node; + // } + + static bool decode(const Node& node, TimerData& rhs) + { + // TODO: node["swtch"] >> rhs.swtch; + node["mode"] >> timerModeLut >> rhs.mode; + node["name"] >> rhs.name; + node["minuteBeep"] >> rhs.minuteBeep; + node["countdownBeep"] >> rhs.countdownBeep; + node["start"] >> rhs.val; + node["persistent"] >> rhs.persistent; + node["countdownStart"] >> rhs.countdownStart; + node["value"] >> rhs.pvalue; + return true; + } +}; + +template <> +struct convert { + // static YAML::Node encode(const GeneralSettings& rhs) { + // Node node; + // // TODO: convert struct into Node + // return node; + // } + + static bool decode(const Node& node, ModelData& rhs) + { + if (!node.IsMap()) return false; + + if (node["header"]) { + const auto& header = node["header"]; + if (!header.IsMap()) return false; + + header["name"] >> rhs.name; + header["bitmap"] >> rhs.bitmap; + // TODO: modelId + } + + if (node["timers"]) { + const auto& timers = node["timers"]; + if (!timers.IsMap()) return false; + timers >> rhs.timers; + } + + node["noGlobalFunctions"] >> rhs.noGlobalFunctions; + node["thrTrim"] >> rhs.thrTrim; + node["trimInc"] >> rhs.trimInc; + node["displayTrims"] >> rhs.trimsDisplay; + node["disableThrottleWarning"] >> rhs.disableThrottleWarning; + //node[] >> rhs.beepANACenter; + node["extendedLimits"] >> rhs.extendedLimits; + node["extendedTrims"] >> rhs.extendedTrims; + node["throttleReversed"] >> rhs.throttleReversed; + + //flightModeData[] + //mixData[] + //limitData[] + //inputNames[] + //expoData[] + //curves[] + //logicalSw[] + //customFn[] + + //swashRingData + //thrTraceSrc + //switchWarningStates + //thrTrimSwitch + //potsWarningMode + //potsWarnEnabled[] + //potsWarnPosition[] + + node["displayChecklist"] >> rhs.displayChecklist; + + //gvarData[] + //mavlink ??? + //telemetryProtocol ??? + //frsky + //rssiSource + //rssiAlarms + + node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; + + //moduleData[] + //scriptData[] + //sensorData[] + + node["toplcdTimer"] >> rhs.toplcdTimer; + + //customScreens + //topBarData + node["view"] >> rhs.view; + node["modelRegistrationID"] >> rhs.registrationId; + + return true; + } +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index d4d6c255d..af79fba0c 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -21,6 +21,7 @@ #pragma once #include +#include typedef std::pair YamlLookupTableElmt; typedef std::vector YamlLookupTable; @@ -91,6 +92,25 @@ void operator >> (const YAML::Node& node, char (&value)[N]) } } +template +void operator>>(const YAML::Node& node, T (&value)[N]) +{ + if (!node.IsMap()) return;// false; + + for (const auto& elmt : node) { + try { + int idx = std::stoi(elmt.first.Scalar()); + if (idx < 0 || idx >= N) return;// false; + + elmt.second >> value[idx]; + } catch (...) { + //return false; + return; + } + } + //return true; +} + #define ENUM_CONVERTER(enum_type, lut) \ template <> \ struct convert { \ diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 984c01842..24f0c9979 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -175,7 +175,7 @@ bool CategorizedStorageFormat::writeBin(const RadioData & radioData) if (!getCurrentFirmware()->getCapability(HasModelCategories)) { // Use format with model number and file name. This is needed because // radios without category support can have unused model slots - modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename)); + modelsList.append(QString("%1 %2\n").arg(m).arg(model.filename).toLocal8Bit()); } else { sortedModels[model.category].push_back(QString("%1\n").arg(model.filename)); } @@ -183,10 +183,12 @@ bool CategorizedStorageFormat::writeBin(const RadioData & radioData) if (getCurrentFirmware()->getCapability(HasModelCategories)) { for (size_t c=0; c + EtxModelfiles modelFiles; + + if (!loadModelsListFromYaml(radioData.categories, modelFiles, modelslistBuffer)) { + setError(tr("Can't load MODELS/models.yml")); + return false; + } + + radioData.models.reserve(modelFiles.size()); + + int modelIdx = 0; + for (const auto& mc : modelFiles) { + qDebug() << "Filename: " << mc.first.c_str() << " / Category: " << mc.second; + + QByteArray modelBuffer; + QString filename = "MODELS/" + QString::fromStdString(mc.first); + if (!loadFile(modelBuffer, filename)) { + setError(tr("Can't extract ") + filename); + return false; + } + + // Please note: + // ModelData() use memset to clear everything to 0 + // + auto& model = radioData.models[modelIdx]; + model.category = mc.second; + model.modelIndex = modelIdx; + strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); + + if (!loadModelFromYaml(radioData.models[modelIdx],modelBuffer)) { + setError(tr("Can't load ") + filename); + return false; + } + + modelIdx++; + } + + } else { + // fetch "MODELS/modelXX.yml" + } + return true; } From 0e437ca4928743a347987036b62117515257cda9 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 30 Nov 2021 15:34:41 +0100 Subject: [PATCH 029/180] Add RawSwitch converter --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/edgetx/yaml_modeldata.h | 4 +- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 103 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_rawswitch.h | 32 ++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 companion/src/firmwares/edgetx/yaml_rawswitch.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_rawswitch.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 0b3d501da..9768c01f4 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -35,6 +35,7 @@ set(firmwares_SRCS edgetx/yaml_calibdata.cpp edgetx/yaml_switchconfig.cpp edgetx/yaml_modeldata.cpp + edgetx/yaml_rawswitch.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.h b/companion/src/firmwares/edgetx/yaml_modeldata.h index 6573a02ef..afdee120f 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.h +++ b/companion/src/firmwares/edgetx/yaml_modeldata.h @@ -19,6 +19,8 @@ */ #include "yaml_ops.h" +#include "yaml_rawswitch.h" + #include "modeldata.h" #include @@ -45,7 +47,7 @@ struct convert { static bool decode(const Node& node, TimerData& rhs) { - // TODO: node["swtch"] >> rhs.swtch; + node["swtch"] >> rhs.swtch; node["mode"] >> timerModeLut >> rhs.mode; node["name"] >> rhs.name; node["minuteBeep"] >> rhs.minuteBeep; diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp new file mode 100644 index 000000000..4794dc2f4 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_rawswitch.h" + +#define XPOTS_MULTIPOS_COUNT 6 + +const YamlLookupTable trimSwitchLut = { + { 0, "TrimRudLeft" }, + { 1, "TrimRudRight" }, + { 2, "TrimEleDown" }, + { 3, "TrimEleUp" }, + { 4, "TrimThrDown" }, + { 5, "TrimThrUp" }, + { 6, "TrimAilLeft" }, + { 7, "TrimAilRight" }, + { 8, "TrimT5Down" }, + { 9, "TrimT5Up" }, + { 10, "TrimT6Down" }, + { 11, "TrimT6Up" }, +}; + +const YamlLookupTable switchTypeLut = { + { SWITCH_TYPE_NONE, "NONE" }, + { SWITCH_TYPE_ON, "ON" }, + { SWITCH_TYPE_ONE, "ONE" }, + { SWITCH_TYPE_TELEMETRY, "TELEMETRY_STREAMING" }, + { SWITCH_TYPE_ACT, "RADIO_ACTIVITY" }, + { SWITCH_TYPE_OFF, "OFF" }, +}; + +namespace YAML { + +ENUM_CONVERTER(RawSwitchType, switchTypeLut); + +bool convert::decode(const Node& node, RawSwitch& rhs) +{ + const std::string& sw_str = node.Scalar(); + const char* val = sw_str.data(); + size_t val_len = sw_str.size(); + + bool neg = false; + if (val_len > 0 && val[0] == '!') { + neg = true; + val++; + val_len--; + } + + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { + rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && + (val[2] >= '0' && val[2] <= '9') && + (val[3] >= '0' && val[3] < (XPOTS_MULTIPOS_COUNT + '0'))) { + rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, + (val[2] - '0') * XPOTS_MULTIPOS_COUNT + (val[3] - '0')); + } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && + (val[2] >= '0' && val[2] <= '9')) { + rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); + } else if (val_len >= 2 && val[0] == 'T' && + (val[1] >= '0' && val[1] <= '9')) { + rhs = RawSwitch(SWITCH_TYPE_SENSOR, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } else if (sw_str.substr(0, 3) == std::string("Trim")) { // "Trim" + + rhs.type = SWITCH_TYPE_TRIM; + node >> trimSwitchLut >> rhs.index; + } else if (val_len >= 3 && val[0] == 'S' && + (val[1] >= 'A' && val[1] <= 'Z') && + (val[2] >= '0' && val[2] <= '2')) { + rhs = RawSwitch(SWITCH_TYPE_SWITCH, (val[1] - 'A') * 3 + val[2] - '0'); + } else { + // TODO: check if we have a match? + // or does RawSwitch default to NONE anyway? + // + node >> switchTypeLut >> rhs.type; + rhs.index = 0; + } + + if (neg) { + rhs.index = -rhs.index; + } + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.h b/companion/src/firmwares/edgetx/yaml_rawswitch.h new file mode 100644 index 000000000..ce0031e57 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "rawswitch.h" + +namespace YAML { + +template <> +struct convert { + // static YAML::Node encode(const GeneralSettings& rhs); + static bool decode(const Node& node, RawSwitch& rhs); +}; + +} From c5d686a6f0b31090d7759711110035506a1a761f Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 10:14:01 +0100 Subject: [PATCH 030/180] WiP: write GeneralSettings to YAML --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/edgetx/edgetxinterface.cpp | 13 ++- .../src/firmwares/edgetx/edgetxinterface.h | 4 +- .../firmwares/edgetx/yaml_generalsettings.h | 109 +++++++++++++++++- companion/src/firmwares/edgetx/yaml_ops.cpp | 19 ++- companion/src/firmwares/edgetx/yaml_ops.h | 39 +++++-- .../src/firmwares/edgetx/yaml_trainerdata.cpp | 73 ++++++++++++ .../src/firmwares/edgetx/yaml_trainerdata.h | 60 +++------- companion/src/storage/categorized.cpp | 15 +-- 9 files changed, 261 insertions(+), 72 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_trainerdata.cpp diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 9768c01f4..4d149548f 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -33,6 +33,7 @@ set(firmwares_SRCS edgetx/yaml_ops.cpp edgetx/yaml_generalsettings.cpp edgetx/yaml_calibdata.cpp + edgetx/yaml_trainerdata.cpp edgetx/yaml_switchconfig.cpp edgetx/yaml_modeldata.cpp edgetx/yaml_rawswitch.cpp diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index ddab0fc0d..3ee882abe 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -31,6 +31,14 @@ static YAML::Node loadYamlFromByteArray(const QByteArray& data) return YAML::Load(data_istream); } +static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data) +{ + // TODO: use real streaming to avoid memory copies + std::stringstream data_ostream; + data_ostream << node; + data = QByteArray::fromStdString(data_ostream.str()); +} + bool loadModelsListFromYaml(std::vector categories, EtxModelfiles& modelFiles, const QByteArray& data) @@ -98,5 +106,8 @@ bool writeModelToYaml(const ModelData& model, QByteArray& data) bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) { - return false; + YAML::Node node; + node = settings; + writeYamlToByteArray(node, data); + return true; } diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index 1a87cb181..641f080ee 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -37,5 +37,5 @@ bool loadModelsListFromYaml(std::vector categories, bool loadModelFromYaml(ModelData& model, const QByteArray& data); bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data); -bool writeModelToByteArray(const ModelData& model, QByteArray& data); -bool writeRadioSettingsToByteArray(const GeneralSettings& settings, QByteArray& data); +bool writeModelToYaml(const ModelData& model, QByteArray& data); +bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data); diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 47307816b..b7c95b263 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -39,11 +39,109 @@ namespace YAML { template<> struct convert { - // static YAML::Node encode(const GeneralSettings& rhs) { - // Node node; - // // TODO: convert struct into Node - // return node; - // } + static YAML::Node encode(const GeneralSettings& rhs) { + Node node; + + node["version"] = rhs.version; + + // Radio calib + // YamlCalibData calib; + // node["calib"] = calib; + // calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + + node["currModel"] = rhs.currModelIndex; + node["currModelFilename"] = rhs.currModelFilename; + node["contrast"] = rhs.contrast; + node["vBatWarn"] = rhs.vBatWarn; + node["txVoltageCalibration"] = rhs.txVoltageCalibration; + + node["vBatMin"] = rhs.vBatMin + 90; + node["vBatMax"] = rhs.vBatMax + 120; + + node["backlightMode"] = backlightModeLut << rhs.backlightMode; + node["trainer"] = rhs.trainer; + node["view"] = rhs.view; + node["fai"] = rhs.fai; + node["disableMemoryWarning"] = rhs.disableMemoryWarning; + node["beepMode"] = rhs.beeperMode; + node["disableAlarmWarning"] = rhs.disableAlarmWarning; + node["disableRssiPoweroffAlarm"] = rhs.disableRssiPoweroffAlarm; + node["USBMode"] = rhs.usbMode; + node["jackMode"] = rhs.jackMode; + node["hapticMode"] = rhs.hapticMode; + node["stickMode"] = rhs.stickMode; + node["timezone"] = rhs.timezone; + node["adjustRTC"] = rhs.adjustRTC; + node["inactivityTimer"] = rhs.inactivityTimer; + node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? + node["splashMode"] = rhs.splashMode; // TODO: B&W only + node["templateSetup"] = rhs.templateSetup; + node["hapticLength"] = rhs.hapticLength + 2; + node["speakerPitch"] = rhs.speakerPitch * 15; + node["hapticStrength"] = rhs.hapticStrength + 2; + node["beepLength"] = rhs.beeperLength + 2; + node["gpsFormat"] = rhs.gpsFormat; + node["speakerVolume"] = rhs.speakerVolume + 12 ; + node["backlightBright"] = rhs.backlightBright; + node["switchesDelay"] = rhs.switchesDelay; + node["globalTimer"] = rhs.globalTimer; + node["bluetoothName"] = rhs.bluetoothName; + node["bluetoothBaudrate"] = rhs.bluetoothBaudrate; + node["bluetoothMode"] = bluetoothModeLut << rhs.bluetoothMode; + node["countryCode"] = rhs.countryCode; + node["jitterFilter"] = rhs.jitterFilter; + node["disableRtcWarning"] = rhs.rtcCheckDisable; // TODO: verify + node["keysBacklight"] = rhs.keysBacklight; + node["imperial"] = rhs.imperial; + node["ttsLanguage"] = rhs.ttsLanguage; + node["beepVolume"] = rhs.beepVolume + 2; + node["wavVolume"] = rhs.wavVolume + 2; + node["varioVolume"] = rhs.varioVolume + 2; + node["varioPitch"] = rhs.varioPitch * 10; + node["varioRange"] = rhs.varioRange * 15; + node["varioRepeat"] = rhs.varioRepeat; + node["backgroundVolume"] = rhs.backgroundVolume + 2; + node["auxSerialMode"] = uartModeLut << rhs.auxSerialMode; + node["aux2SerialMode"] = uartModeLut << rhs.aux2SerialMode; + node["antennaMode"] = antennaModeLut << rhs.antennaMode; + node["backlightColor"] = rhs.backlightColor; + + // if (node["customFn"]) { + // const YAML::Node& cfn = node["customFn"]; + // for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { + // cfn[i] = rhs.customFn[i]; + // } + // } + + // YamlStickConfig stickConfig; + // node["sticksConfig"] = stickConfig; + + // YamlSwitchConfig switchConfig; + // node["switchConfig"] = switchConfig; + // switchConfig.copy(rhs.switchName, rhs.switchConfig); + + // YamlPotConfig potsConfig; + // node["potsConfig"] = potsConfig; + // potsConfig.copy(rhs.potName, rhs.potConfig); + + // YamlSliderConfig slidersConfig; + // node["slidersConfig"] = slidersConfig; + // slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); + + // Color lcd theme settings are not used in EdgeTx + // RadioTheme::ThemeData themeData; + + node["ownerRegistrationID"] = rhs.registrationId; + + // Gyro (for now only xlites) + node["gyroMax"] = rhs.gyroMax; + node["gyroOffset"] = rhs.gyroOffset; + + // OneBit sampling (X9D only?) + node["uartSampleMode"] = rhs.uartSampleMode; + + return node; + } static bool decode(const Node& node, GeneralSettings& rhs) { @@ -138,6 +236,7 @@ namespace YAML { YamlStickConfig stickConfig; node["sticksConfig"] >> stickConfig; + stickConfig.copy(rhs.stickName); YamlSwitchConfig switchConfig; node["switchConfig"] >> switchConfig; diff --git a/companion/src/firmwares/edgetx/yaml_ops.cpp b/companion/src/firmwares/edgetx/yaml_ops.cpp index bde2129b2..4cb877175 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.cpp +++ b/companion/src/firmwares/edgetx/yaml_ops.cpp @@ -19,7 +19,6 @@ */ #include "yaml_ops.h" -#include YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) { @@ -54,3 +53,21 @@ void operator >> (const YAML::Node& node, bool& value) value = node.as(); } } + +namespace YAML { + +Node operator << (const YamlLookupTable& lut, const int& value) +{ + const auto& it = + find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { + if (elmt.first == value) return true; + return false; + }); + + if (it != lut.end()) { + return Node(it->second); + } + return Node(); +} + +} diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index af79fba0c..cbd323c0a 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -21,6 +21,7 @@ #pragma once #include +#include #include typedef std::pair YamlLookupTableElmt; @@ -59,7 +60,6 @@ private: T factor; }; - YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut); void operator >> (const YAML::Node& node, const ioffset_int& value); @@ -111,17 +111,40 @@ void operator>>(const YAML::Node& node, T (&value)[N]) //return true; } +namespace YAML { + +Node operator << (const YamlLookupTable& lut, const int& value); + +template +struct convert_enum +{ + static YAML::Node encode(const T& rhs) + { + return lut << rhs; + } + static bool decode(const YAML::Node& node, T& rhs) + { + if (node) { + YAML::Node conv = node >> lut; + if (conv.IsScalar()) { + rhs = (T)conv.as(); + } + } + return true; + } +}; + +} + #define ENUM_CONVERTER(enum_type, lut) \ template <> \ struct convert { \ + static YAML::Node encode(const enum_type& rhs) \ + { \ + return convert_enum::encode(rhs); \ + } \ static bool decode(const YAML::Node& node, enum_type& rhs) \ { \ - if (node) { \ - YAML::Node conv = node >> lut; \ - if (conv.IsScalar()) { \ - rhs = (enum_type)conv.as(); \ - } \ - } \ - return true; \ + return convert_enum::decode(node, rhs); \ } \ } diff --git a/companion/src/firmwares/edgetx/yaml_trainerdata.cpp b/companion/src/firmwares/edgetx/yaml_trainerdata.cpp new file mode 100644 index 000000000..702628526 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_trainerdata.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_trainerdata.h" +#include "generalsettings.h" + +const YamlLookupTable trainerMixMode = { + {TrainerMix::TRN_MIX_MODE_OFF, "OFF"}, + {TrainerMix::TRN_MIX_MODE_ADD, "ADD"}, + {TrainerMix::TRN_MIX_MODE_SUBST, "REPL"}, +}; + +namespace YAML +{ + +Node convert::encode(const TrainerMix& rhs) +{ + Node node; + // TODO: convert struct into Node + return node; +} + +bool convert::decode(const Node& node, TrainerMix& rhs) +{ + node["srcChn"] >> rhs.src; + // node["mode"] >> rhs.mode; // TODO: string mapping + node["studWeight"] >> rhs.weight; + return true; +} + +Node convert::encode(const TrainerData& rhs) +{ + Node node; + // TODO: convert struct into Node + return node; +} + +bool convert::decode(const Node& node, TrainerData& rhs) +{ + if (node["calib"]) { + const Node& calib = node["calib"]; + for (int i = 0; i < 4; i++) { + calib[i] >> rhs.calib[i]; + } + } + + if (node["mix"]) { + const Node& mix = node["mix"]; + for (int i = 0; i < 4; i++) { + mix[i] >> rhs.mix[i]; + } + } + return true; +} + +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_trainerdata.h b/companion/src/firmwares/edgetx/yaml_trainerdata.h index 766c0930b..7bbcac2cd 100644 --- a/companion/src/firmwares/edgetx/yaml_trainerdata.h +++ b/companion/src/firmwares/edgetx/yaml_trainerdata.h @@ -21,51 +21,19 @@ #include "yaml_ops.h" #include "generalsettings.h" -namespace YAML { +extern const YamlLookupTable trainerMixMode; - template<> - struct convert { +namespace YAML +{ +template <> +struct convert { + static Node encode(const TrainerMix& rhs); + static bool decode(const Node& node, TrainerMix& rhs); +}; - // static YAML::Node encode(const TrainerMix& rhs) { - // Node node; - // // TODO: convert struct into Node - // return node; - // } - - static bool decode(const YAML::Node& node, TrainerMix& rhs) - { - node["srcChn"] >> rhs.src; - //node["mode"] >> rhs.mode; // TODO: string mapping - node["studWeight"] >> rhs.weight; - return true; - } - }; - - template<> - struct convert { - - // static YAML::Node encode(const TrainerData& rhs) { - // Node node; - // // TODO: convert struct into Node - // return node; - // } - - static bool decode(const YAML::Node& node, TrainerData& rhs) - { - if (node["calib"]) { - const YAML::Node& calib = node["calib"]; - for (int i = 0; i < 4; i++) { - calib[i] >> rhs.calib[i]; - } - } - - if (node["mix"]) { - const YAML::Node& mix = node["mix"]; - for (int i = 0; i < 4; i++) { - mix[i] >> rhs.mix[i]; - } - } - return true; - } - }; -} +template <> +struct convert { + static Node encode(const TrainerData& rhs); + static bool decode(const Node& node, TrainerData& rhs); +}; +} // namespace YAML diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 24f0c9979..f09253280 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -220,13 +220,6 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) qDebug() << tr("Found %1").arg(filename); } - // setError(tr("Error: Yaml format ignored - under development")); - // return false; // force failure until fully developed - - /* - This code a copy of loadBin with yaml file extensions ONLY - */ - QByteArray radioSettingsBuffer; if (!loadFile(radioSettingsBuffer, "RADIO/radio.yml")) { setError(tr("Can't extract RADIO/radio.yml")); @@ -291,6 +284,10 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) { - setError("Error: Yaml format ignored - under development"); - return false; // force failure until fully developed + QByteArray radioSettingsBuffer; + if (!writeRadioSettingsToYaml(radioData.generalSettings, radioSettingsBuffer)) { + return false; + } + + return writeFile(radioSettingsBuffer, "RADIO/radio.yml"); } From f3bf1d4d428bcf09525d47de79b91676f7f261c3 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 10:49:06 +0100 Subject: [PATCH 031/180] Add calib data write --- .../src/firmwares/edgetx/edgetxinterface.cpp | 6 +- .../src/firmwares/edgetx/yaml_calibdata.cpp | 56 ++++++++++++++++++- .../src/firmwares/edgetx/yaml_calibdata.h | 41 +++++--------- .../firmwares/edgetx/yaml_generalsettings.h | 19 +++---- .../src/firmwares/edgetx/yaml_trainerdata.cpp | 17 ++++-- 5 files changed, 95 insertions(+), 44 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 3ee882abe..ad31f1f15 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -37,6 +37,9 @@ static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data) std::stringstream data_ostream; data_ostream << node; data = QByteArray::fromStdString(data_ostream.str()); + + qDebug() << "Saving radio.yml:"; + qDebug() << data_ostream.str().c_str(); } bool loadModelsListFromYaml(std::vector categories, @@ -109,5 +112,6 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) YAML::Node node; node = settings; writeYamlToByteArray(node, data); - return true; + + return false; } diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp index b5cd83a4e..5dbfbb27e 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -25,7 +25,7 @@ // // This is only valid for X10, T16, TX16S (not X12S) // -const YamlLookupTable calibIdxLut = { +static const YamlLookupTable calibIdxLut = { { 0, "Rud" }, { 1, "Ele" }, { 2, "Thr" }, @@ -46,6 +46,16 @@ const YamlLookupTable calibIdxLut = { YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); } +YamlCalibData::YamlCalibData(const int* calibMid, const int* calibSpanNeg, + const int* calibSpanPos) +{ + for (int i = 0; i < CPN_MAX_ANALOGS; i++) { + calib[i].mid = calibMid[i]; + calib[i].spanNeg = calibSpanNeg[i]; + calib[i].spanPos = calibSpanPos[i]; + } +} + void YamlCalibData::copy(int* calibMid, int* calibSpanNeg, int* calibSpanPos) const { @@ -55,3 +65,47 @@ void YamlCalibData::copy(int* calibMid, int* calibSpanNeg, calibSpanPos[i] = calib[i].spanPos; } } + +namespace YAML +{ + +Node convert::encode(const CalibData& rhs) +{ + Node node; + node["mid"] = rhs.mid; + node["spanNeg"] = rhs.spanNeg; + node["spanPos"] = rhs.spanPos; + return node; +} + +bool convert::decode(const Node& node, CalibData& rhs) +{ + if (!node.IsMap()) return false; + node["mid"] >> rhs.mid; + node["spanNeg"] >> rhs.spanNeg; + node["spanPos"] >> rhs.spanPos; + return true; +} + +Node convert::encode(const YamlCalibData& rhs) +{ + Node node; + // TODO: we need something better here! + for (const auto& kv : calibIdxLut) { + node[kv.second] = rhs.calib[kv.first]; + } + return node; +} + +bool convert::decode(const Node& node, YamlCalibData& rhs) +{ + if (!node.IsMap()) return false; + int idx = 0; + for (const auto& kv : node) { + kv.first >> calibIdxLut >> idx; + kv.second >> rhs.calib[idx]; + } + return true; +} + +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.h b/companion/src/firmwares/edgetx/yaml_calibdata.h index a0de4c915..be8f37981 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.h +++ b/companion/src/firmwares/edgetx/yaml_calibdata.h @@ -31,34 +31,21 @@ struct YamlCalibData { CalibData calib[CPN_MAX_ANALOGS]; YamlCalibData(); + YamlCalibData(const int* calibMid, const int* calibSpanNeg, const int* calibSpanPos); void copy(int* calibMid, int* calibSpanNeg, int* calibSpanPos) const; }; -extern const YamlLookupTable calibIdxLut; +namespace YAML +{ +template <> +struct convert { + static Node encode(const CalibData& rhs); + static bool decode(const Node& node, CalibData& rhs); +}; -namespace YAML { - - template<> - struct convert { - static bool decode(const Node& node, CalibData& rhs) { - if (!node.IsMap()) return false; - node["mid"] >> rhs.mid; - node["spanNeg"] >> rhs.spanNeg; - node["spanPos"] >> rhs.spanPos; - return true; - } - }; - - template<> - struct convert { - static bool decode(const Node& node, YamlCalibData& rhs) { - if (!node.IsMap()) return false; - int idx = 0; - for (const auto& kv : node) { - kv.first >> calibIdxLut >> idx; - kv.second >> rhs.calib[idx]; - } - return true; - } - }; -} +template <> +struct convert { + static Node encode(const YamlCalibData& rhs); + static bool decode(const Node& node, YamlCalibData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index b7c95b263..270ed3edb 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -45,9 +45,8 @@ namespace YAML { node["version"] = rhs.version; // Radio calib - // YamlCalibData calib; - // node["calib"] = calib; - // calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + node["calib"] = calib; node["currModel"] = rhs.currModelIndex; node["currModelFilename"] = rhs.currModelFilename; @@ -61,11 +60,11 @@ namespace YAML { node["backlightMode"] = backlightModeLut << rhs.backlightMode; node["trainer"] = rhs.trainer; node["view"] = rhs.view; - node["fai"] = rhs.fai; - node["disableMemoryWarning"] = rhs.disableMemoryWarning; + node["fai"] = (int)rhs.fai; + node["disableMemoryWarning"] = (int)rhs.disableMemoryWarning; node["beepMode"] = rhs.beeperMode; - node["disableAlarmWarning"] = rhs.disableAlarmWarning; - node["disableRssiPoweroffAlarm"] = rhs.disableRssiPoweroffAlarm; + node["disableAlarmWarning"] = (int)rhs.disableAlarmWarning; + node["disableRssiPoweroffAlarm"] = (int)rhs.disableRssiPoweroffAlarm; node["USBMode"] = rhs.usbMode; node["jackMode"] = rhs.jackMode; node["hapticMode"] = rhs.hapticMode; @@ -89,9 +88,9 @@ namespace YAML { node["bluetoothBaudrate"] = rhs.bluetoothBaudrate; node["bluetoothMode"] = bluetoothModeLut << rhs.bluetoothMode; node["countryCode"] = rhs.countryCode; - node["jitterFilter"] = rhs.jitterFilter; - node["disableRtcWarning"] = rhs.rtcCheckDisable; // TODO: verify - node["keysBacklight"] = rhs.keysBacklight; + node["jitterFilter"] = (int)rhs.jitterFilter; + node["disableRtcWarning"] = (int)rhs.rtcCheckDisable; // TODO: verify + node["keysBacklight"] = (int)rhs.keysBacklight; node["imperial"] = rhs.imperial; node["ttsLanguage"] = rhs.ttsLanguage; node["beepVolume"] = rhs.beepVolume + 2; diff --git a/companion/src/firmwares/edgetx/yaml_trainerdata.cpp b/companion/src/firmwares/edgetx/yaml_trainerdata.cpp index 702628526..b1952827d 100644 --- a/companion/src/firmwares/edgetx/yaml_trainerdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_trainerdata.cpp @@ -33,14 +33,16 @@ namespace YAML Node convert::encode(const TrainerMix& rhs) { Node node; - // TODO: convert struct into Node + node["srcChn"] = rhs.src; + node["mode"] = trainerMixMode << rhs.mode; + node["studWeight"] = rhs.weight; return node; } bool convert::decode(const Node& node, TrainerMix& rhs) { node["srcChn"] >> rhs.src; - // node["mode"] >> rhs.mode; // TODO: string mapping + node["mode"] >> trainerMixMode >> rhs.mode; node["studWeight"] >> rhs.weight; return true; } @@ -48,7 +50,12 @@ bool convert::decode(const Node& node, TrainerMix& rhs) Node convert::encode(const TrainerData& rhs) { Node node; - // TODO: convert struct into Node + for (int i = 0; i < 4; i++) { + node["calib"][std::to_string(i)]["val"] = rhs.calib[i]; + } + for (int i = 0; i < 4; i++) { + node["mix"][std::to_string(i)] = rhs.mix[i]; + } return node; } @@ -57,14 +64,14 @@ bool convert::decode(const Node& node, TrainerData& rhs) if (node["calib"]) { const Node& calib = node["calib"]; for (int i = 0; i < 4; i++) { - calib[i] >> rhs.calib[i]; + calib[std::to_string(i)]["val"] >> rhs.calib[i]; } } if (node["mix"]) { const Node& mix = node["mix"]; for (int i = 0; i < 4; i++) { - mix[i] >> rhs.mix[i]; + mix[std::to_string(i)] >> rhs.mix[i]; } } return true; From 8a10ffa43dc5f2c9e28a66379b5bfb98bf526598 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 12:01:05 +0100 Subject: [PATCH 032/180] Output knobs config --- .../firmwares/edgetx/yaml_generalsettings.h | 18 ++--- .../firmwares/edgetx/yaml_switchconfig.cpp | 1 + .../src/firmwares/edgetx/yaml_switchconfig.h | 70 +++++++++++++++---- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 270ed3edb..2548d6b73 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -112,20 +112,10 @@ namespace YAML { // } // } - // YamlStickConfig stickConfig; - // node["sticksConfig"] = stickConfig; - - // YamlSwitchConfig switchConfig; - // node["switchConfig"] = switchConfig; - // switchConfig.copy(rhs.switchName, rhs.switchConfig); - - // YamlPotConfig potsConfig; - // node["potsConfig"] = potsConfig; - // potsConfig.copy(rhs.potName, rhs.potConfig); - - // YamlSliderConfig slidersConfig; - // node["slidersConfig"] = slidersConfig; - // slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); + node["sticksConfig"] = YamlStickConfig(rhs.stickName); + node["switchConfig"] = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); + node["potsConfig"] = YamlPotConfig(rhs.potName, rhs.potConfig); + node["slidersConfig"] = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); // Color lcd theme settings are not used in EdgeTx // RadioTheme::ThemeData themeData; diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 2fabedf19..25d8ea75d 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -62,3 +62,4 @@ const YamlLookupTable sliderConfigLut = { {Board::SLIDER_NONE, "none"}, {Board::SLIDER_WITH_DETENT, "with_detent"}, }; + diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 0fac60bc3..5cc2cc7d9 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -22,28 +22,47 @@ #include "yaml_ops.h" #include "generalsettings.h" +#include -template +template struct YamlNameConfig { - char name[N][HARDWARE_NAME_LEN + 1]; - void copy(char out_names[N][HARDWARE_NAME_LEN + 1]) { - memcpy(out_names, name, sizeof(name)); + YamlNameConfig() { memset(name, 0, sizeof(name)); } + + YamlNameConfig(const char in_names[N][HARDWARE_NAME_LEN + 1]) + { + memcpy(name, in_names, sizeof(name)); + } + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1]) + { + memcpy(out_names, name, sizeof(name)); } }; extern const YamlLookupTable sticksLut; typedef YamlNameConfig YamlStickConfig; -template +template struct YamlKnobConfig : public YamlNameConfig { - unsigned int config[N]; - void copy(char out_names[N][HARDWARE_NAME_LEN + 1], unsigned int out_configs[N]) { - YamlNameConfig::copy(out_names); - memcpy(out_configs, config, sizeof(config)); + YamlKnobConfig() { memset(config, 0, sizeof(config)); } + + YamlKnobConfig(const char in_names[N][HARDWARE_NAME_LEN + 1], + const unsigned int in_configs[N]) : + YamlNameConfig(in_names) + { + memset(config, 0, sizeof(config)); + } + + void copy(char out_names[N][HARDWARE_NAME_LEN + 1], + unsigned int out_configs[N]) + { + YamlNameConfig::copy(out_names); + memcpy(out_configs, config, sizeof(config)); } }; @@ -52,26 +71,36 @@ struct YamlKnobConfig : public YamlNameConfig { // name: extern const YamlLookupTable switchesLut; extern const YamlLookupTable switchConfigLut; -typedef YamlKnobConfig YamlSwitchConfig; +typedef YamlKnobConfig + YamlSwitchConfig; // S1: // type: with_detent -// name: +// name: extern const YamlLookupTable potsLut; extern const YamlLookupTable potConfigLut; typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent -// name: +// name: extern const YamlLookupTable slidersLut; extern const YamlLookupTable sliderConfigLut; -typedef YamlKnobConfig YamlSliderConfig; +typedef YamlKnobConfig + YamlSliderConfig; namespace YAML { template struct convert > { + static Node encode(const YamlNameConfig& rhs) + { + Node node; + for (const auto& kv : name_lut) { + node[kv.second]["name"] = rhs.name[kv.first]; + } + return node; + } static bool decode(const Node& node, YamlNameConfig& rhs) { if (!node.IsMap()) return false; @@ -84,9 +113,20 @@ struct convert > { } }; -template +template struct convert > { - static bool decode(const Node& node, YamlKnobConfig& rhs) + static Node encode(const YamlKnobConfig& rhs) + { + Node node; + for (const auto& kv : name_lut) { + node[kv.second]["type"] = cfg_lut << rhs.config[kv.first]; + node[kv.second]["name"] = rhs.name[kv.first]; + } + return node; + } + static bool decode(const Node& node, + YamlKnobConfig& rhs) { if (!node.IsMap()) return false; int idx = 0; From 2335d39fb51d5895caa5bbf4a41aa7ecefebcb70 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 12:21:38 +0100 Subject: [PATCH 033/180] Make GCC happy --- companion/src/firmwares/edgetx/yaml_ops.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index cbd323c0a..9b5c81d26 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -115,14 +115,14 @@ namespace YAML { Node operator << (const YamlLookupTable& lut, const int& value); -template +template struct convert_enum { - static YAML::Node encode(const T& rhs) + static YAML::Node encode(const YamlLookupTable& lut, const T& rhs) { return lut << rhs; } - static bool decode(const YAML::Node& node, T& rhs) + static bool decode(const YAML::Node& node, const YamlLookupTable& lut, T& rhs) { if (node) { YAML::Node conv = node >> lut; @@ -141,10 +141,10 @@ struct convert_enum struct convert { \ static YAML::Node encode(const enum_type& rhs) \ { \ - return convert_enum::encode(rhs); \ + return convert_enum::encode(lut,rhs); \ } \ static bool decode(const YAML::Node& node, enum_type& rhs) \ { \ - return convert_enum::decode(node, rhs); \ + return convert_enum::decode(node, lut, rhs); \ } \ } From a7781deb6a5f136b81e245215ad86e81da38319d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 12:34:25 +0100 Subject: [PATCH 034/180] Mark read models as "used" --- companion/src/storage/categorized.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index f09253280..420a9b666 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -246,7 +246,7 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) return false; } - radioData.models.reserve(modelFiles.size()); + radioData.models.resize(modelFiles.size()); int modelIdx = 0; for (const auto& mc : modelFiles) { @@ -267,11 +267,12 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) model.modelIndex = modelIdx; strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); - if (!loadModelFromYaml(radioData.models[modelIdx],modelBuffer)) { + if (!loadModelFromYaml(model,modelBuffer)) { setError(tr("Can't load ") + filename); return false; } - + + model.used = true; modelIdx++; } From b73ffb5e08b529efb4275779234950ca7ccb2c0e Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 14:08:37 +0100 Subject: [PATCH 035/180] WiP: write basic model data and models list --- .../src/firmwares/edgetx/edgetxinterface.cpp | 32 +++- .../src/firmwares/edgetx/edgetxinterface.h | 6 +- .../src/firmwares/edgetx/yaml_modeldata.cpp | 173 +++++++++++++++++- .../src/firmwares/edgetx/yaml_modeldata.h | 109 +---------- companion/src/firmwares/edgetx/yaml_ops.cpp | 14 +- companion/src/firmwares/edgetx/yaml_ops.h | 1 + .../src/firmwares/edgetx/yaml_rawswitch.cpp | 49 +++++ .../src/firmwares/edgetx/yaml_rawswitch.h | 2 +- companion/src/storage/categorized.cpp | 27 ++- 9 files changed, 298 insertions(+), 115 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index ad31f1f15..e75428b2b 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -42,7 +42,7 @@ static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data) qDebug() << data_ostream.str().c_str(); } -bool loadModelsListFromYaml(std::vector categories, +bool loadModelsListFromYaml(std::vector& categories, EtxModelfiles& modelFiles, const QByteArray& data) { @@ -102,16 +102,42 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data return true; } +// TODO: +// 'modelFiles' should be ordered by Category index to avoid +// turning the sequence into a map. +// +bool writeModelsListToYaml(const std::vector& categories, + const EtxModelfiles& modelFiles, + QByteArray& data) +{ + YAML::Node node; + for (const auto& modelFile: modelFiles) { + + YAML::Node cat_attrs; + cat_attrs["filename"] = modelFile.first; + + const std::string cat_name = categories[modelFile.second].name; + node[modelFile.second][cat_name].push_back(cat_attrs); + } + + writeYamlToByteArray(node, data); + return true; +} + bool writeModelToYaml(const ModelData& model, QByteArray& data) { - return false; + YAML::Node node; + node = model; + + writeYamlToByteArray(node, data); + return true; } bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) { YAML::Node node; node = settings; - writeYamlToByteArray(node, data); + writeYamlToByteArray(node, data); return false; } diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index 641f080ee..e3743c829 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -30,12 +30,16 @@ typedef std::pair EtxModelfileCategoryPair; typedef std::list EtxModelfiles; -bool loadModelsListFromYaml(std::vector categories, +bool loadModelsListFromYaml(std::vector& categories, EtxModelfiles& modelFiles, const QByteArray& data); bool loadModelFromYaml(ModelData& model, const QByteArray& data); bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data); +bool writeModelsListToYaml(const std::vector& categories, + const EtxModelfiles& modelFiles, + QByteArray& data); + bool writeModelToYaml(const ModelData& model, QByteArray& data); bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data); diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 968f7949a..e31989958 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -21,7 +21,7 @@ #include "yaml_modeldata.h" #include "modeldata.h" -const YamlLookupTable timerModeLut = { +static const YamlLookupTable timerModeLut = { {TimerData::TIMERMODE_OFF, "OFF"}, {TimerData::TIMERMODE_ON, "ON"}, {TimerData::TIMERMODE_START, "START"}, @@ -30,7 +30,7 @@ const YamlLookupTable timerModeLut = { {TimerData::TIMERMODE_THR_START, "THR_START"}, }; -const YamlLookupTable trainerModeLut = { +static const YamlLookupTable trainerModeLut = { { TRAINER_MODE_OFF, "OFF" }, { TRAINER_MODE_MASTER_JACK, "MASTER_TRAINER_JACK" }, { TRAINER_MODE_SLAVE_JACK, "SLAVE" }, @@ -41,3 +41,172 @@ const YamlLookupTable trainerModeLut = { { TRAINER_MODE_SLAVE_BLUETOOTH, "SLAVE_BT" }, { TRAINER_MODE_MULTI, "MASTER_MULTI" }, }; + +namespace YAML +{ +Node convert::encode(const TimerData& rhs) +{ + Node node; + node["swtch"] = rhs.swtch; + node["mode"] = timerModeLut << rhs.mode; + node["name"] = rhs.name; + node["minuteBeep"] = rhs.minuteBeep; + node["countdownBeep"] = rhs.countdownBeep; + node["start"] = rhs.val; + node["persistent"] = rhs.persistent; + node["countdownStart"] = rhs.countdownStart; + node["value"] = rhs.pvalue; + return node; +} + +bool convert::decode(const Node& node, TimerData& rhs) +{ + node["swtch"] >> rhs.swtch; + node["mode"] >> timerModeLut >> rhs.mode; + node["name"] >> rhs.name; + node["minuteBeep"] >> rhs.minuteBeep; + node["countdownBeep"] >> rhs.countdownBeep; + node["start"] >> rhs.val; + node["persistent"] >> rhs.persistent; + node["countdownStart"] >> rhs.countdownStart; + node["value"] >> rhs.pvalue; + return true; +} + +Node convert::encode(const ModelData& rhs) +{ + Node node; + node["header"]["name"] = rhs.name; + node["header"]["bitmap"] = rhs.bitmap; + // TODO: modelId + + for (int i=0; i::decode(const Node& node, ModelData& rhs) +{ + if (!node.IsMap()) return false; + + if (node["header"]) { + const auto& header = node["header"]; + if (!header.IsMap()) return false; + + header["name"] >> rhs.name; + header["bitmap"] >> rhs.bitmap; + // TODO: modelId + } + + if (node["timers"]) { + const auto& timers = node["timers"]; + if (!timers.IsMap()) return false; + timers >> rhs.timers; + } + + node["noGlobalFunctions"] >> rhs.noGlobalFunctions; + node["thrTrim"] >> rhs.thrTrim; + node["trimInc"] >> rhs.trimInc; + node["displayTrims"] >> rhs.trimsDisplay; + node["disableThrottleWarning"] >> rhs.disableThrottleWarning; + // node[] >> rhs.beepANACenter; + node["extendedLimits"] >> rhs.extendedLimits; + node["extendedTrims"] >> rhs.extendedTrims; + node["throttleReversed"] >> rhs.throttleReversed; + + // flightModeData[] + // mixData[] + // limitData[] + // inputNames[] + // expoData[] + // curves[] + // logicalSw[] + // customFn[] + + // swashRingData + // thrTraceSrc + // switchWarningStates + // thrTrimSwitch + // potsWarningMode + // potsWarnEnabled[] + // potsWarnPosition[] + + node["displayChecklist"] >> rhs.displayChecklist; + + // gvarData[] + // mavlink ??? + // telemetryProtocol ??? + // frsky + // rssiSource + // rssiAlarms + + node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; + + // moduleData[] + // scriptData[] + // sensorData[] + + node["toplcdTimer"] >> rhs.toplcdTimer; + + // customScreens + // topBarData + node["view"] >> rhs.view; + node["modelRegistrationID"] >> rhs.registrationId; + + return true; +} + +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.h b/companion/src/firmwares/edgetx/yaml_modeldata.h index afdee120f..5150d25da 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.h +++ b/companion/src/firmwares/edgetx/yaml_modeldata.h @@ -25,118 +25,17 @@ #include -extern const YamlLookupTable timerModeLut; -extern const YamlLookupTable trainerModeLut; - -// extern const YamlLookupTable backlightModeLut; -// extern const YamlLookupTable bluetoothModeLut; -// extern const YamlLookupTable uartModeLut; -// extern const YamlLookupTable antennaModeLut; - namespace YAML { -// ENUM_CONVERTER(GeneralSettings::BeeperMode, beeperModeLut); - template <> struct convert { - // static YAML::Node encode(const GeneralSettings& rhs) { - // Node node; - // // TODO: convert struct into Node - // return node; - // } - - static bool decode(const Node& node, TimerData& rhs) - { - node["swtch"] >> rhs.swtch; - node["mode"] >> timerModeLut >> rhs.mode; - node["name"] >> rhs.name; - node["minuteBeep"] >> rhs.minuteBeep; - node["countdownBeep"] >> rhs.countdownBeep; - node["start"] >> rhs.val; - node["persistent"] >> rhs.persistent; - node["countdownStart"] >> rhs.countdownStart; - node["value"] >> rhs.pvalue; - return true; - } + static Node encode(const TimerData& rhs); + static bool decode(const Node& node, TimerData& rhs); }; template <> struct convert { - // static YAML::Node encode(const GeneralSettings& rhs) { - // Node node; - // // TODO: convert struct into Node - // return node; - // } - - static bool decode(const Node& node, ModelData& rhs) - { - if (!node.IsMap()) return false; - - if (node["header"]) { - const auto& header = node["header"]; - if (!header.IsMap()) return false; - - header["name"] >> rhs.name; - header["bitmap"] >> rhs.bitmap; - // TODO: modelId - } - - if (node["timers"]) { - const auto& timers = node["timers"]; - if (!timers.IsMap()) return false; - timers >> rhs.timers; - } - - node["noGlobalFunctions"] >> rhs.noGlobalFunctions; - node["thrTrim"] >> rhs.thrTrim; - node["trimInc"] >> rhs.trimInc; - node["displayTrims"] >> rhs.trimsDisplay; - node["disableThrottleWarning"] >> rhs.disableThrottleWarning; - //node[] >> rhs.beepANACenter; - node["extendedLimits"] >> rhs.extendedLimits; - node["extendedTrims"] >> rhs.extendedTrims; - node["throttleReversed"] >> rhs.throttleReversed; - - //flightModeData[] - //mixData[] - //limitData[] - //inputNames[] - //expoData[] - //curves[] - //logicalSw[] - //customFn[] - - //swashRingData - //thrTraceSrc - //switchWarningStates - //thrTrimSwitch - //potsWarningMode - //potsWarnEnabled[] - //potsWarnPosition[] - - node["displayChecklist"] >> rhs.displayChecklist; - - //gvarData[] - //mavlink ??? - //telemetryProtocol ??? - //frsky - //rssiSource - //rssiAlarms - - node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; - - //moduleData[] - //scriptData[] - //sensorData[] - - node["toplcdTimer"] >> rhs.toplcdTimer; - - //customScreens - //topBarData - node["view"] >> rhs.view; - node["modelRegistrationID"] >> rhs.registrationId; - - return true; - } + static Node encode(const ModelData& rhs); + static bool decode(const Node& node, ModelData& rhs); }; } // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_ops.cpp b/companion/src/firmwares/edgetx/yaml_ops.cpp index 4cb877175..ed7983fb3 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.cpp +++ b/companion/src/firmwares/edgetx/yaml_ops.cpp @@ -56,7 +56,7 @@ void operator >> (const YAML::Node& node, bool& value) namespace YAML { -Node operator << (const YamlLookupTable& lut, const int& value) +std::string LookupValue(const YamlLookupTable& lut, const int& value) { const auto& it = find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { @@ -65,7 +65,17 @@ Node operator << (const YamlLookupTable& lut, const int& value) }); if (it != lut.end()) { - return Node(it->second); + return it->second; + } + + return std::string(); +} + +Node operator << (const YamlLookupTable& lut, const int& value) +{ + std::string str = LookupValue(lut, value); + if (!str.empty()) { + return Node(str); } return Node(); } diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 9b5c81d26..52f90082a 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -113,6 +113,7 @@ void operator>>(const YAML::Node& node, T (&value)[N]) namespace YAML { +std::string LookupValue(const YamlLookupTable& lut, const int& value); Node operator << (const YamlLookupTable& lut, const int& value); template diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 4794dc2f4..9bad86be9 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -50,6 +50,55 @@ namespace YAML { ENUM_CONVERTER(RawSwitchType, switchTypeLut); +Node convert::encode(const RawSwitch& rhs) +{ + std::string sw_str; + + int32_t sval = rhs.index; + if (rhs.index < 0) { + sval = -sval; + sw_str += "!"; + } + + switch (rhs.type) { + case SWITCH_TYPE_SWITCH: + sw_str += 'S'; + sw_str += 'A' + sval; + break; + + case SWITCH_TYPE_VIRTUAL: + sw_str += "L"; + sw_str += std::to_string(sval + 1); + break; + + case SWITCH_TYPE_MULTIPOS_POT: + sw_str += "6P"; + sw_str += std::to_string(sval / XPOTS_MULTIPOS_COUNT); + sw_str += std::to_string(sval % XPOTS_MULTIPOS_COUNT); + break; + + case SWITCH_TYPE_TRIM: + sw_str += LookupValue(trimSwitchLut, sval); + break; + + case SWITCH_TYPE_FLIGHT_MODE: + sw_str += "FM"; + sw_str += std::to_string(sval); + break; + + case SWITCH_TYPE_SENSOR: + sw_str += "T"; + sw_str += std::to_string(sval + 1); + break; + + default: + sw_str += LookupValue(switchTypeLut, rhs.type); + break; + } + + return Node(sw_str); +} + bool convert::decode(const Node& node, RawSwitch& rhs) { const std::string& sw_str = node.Scalar(); diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.h b/companion/src/firmwares/edgetx/yaml_rawswitch.h index ce0031e57..95128aac2 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.h +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.h @@ -25,7 +25,7 @@ namespace YAML { template <> struct convert { - // static YAML::Node encode(const GeneralSettings& rhs); + static Node encode(const RawSwitch& rhs); static bool decode(const Node& node, RawSwitch& rhs); }; diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 420a9b666..a32442587 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -290,5 +290,30 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) return false; } - return writeFile(radioSettingsBuffer, "RADIO/radio.yml"); + if (!writeFile(radioSettingsBuffer, "RADIO/radio.yml")) { + return false; + } + + EtxModelfiles modelFiles; + for (const auto& model : radioData.models) { + + // TODO: verify '.yml' (in case we moved from '.bin') + QString modelFilename = QString("MODELS/%1").arg(model.filename); + QByteArray modelData; + writeModelToYaml(model, modelData); + if (!writeFile(modelData, modelFilename)) { + return false; + } + + modelFiles.push_back({ std::string(model.filename), model.category }); + } + + // TODO: sort 'modelFiles' by category index + QByteArray modelslistBuffer; + if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer) + || writeFile(modelslistBuffer, "MODELS/models.yml")) { + return false; + } + + return true; } From cd7585091ce4223f7bba2ae606bb1eace065adcf Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 14:16:53 +0100 Subject: [PATCH 036/180] Disable yaml-cpp tests --- companion/src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index c3e2928f1..901d26436 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -197,6 +197,8 @@ add_subdirectory(simulation) add_subdirectory(storage) add_subdirectory(thirdparty/qcustomplot) add_subdirectory(thirdparty/maxlibqt/src/widgets) + +set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Enable testing" FORCE) add_subdirectory(thirdparty/yaml-cpp) ############# Companion ############### From f5dd81627d6f20b5209302b3c87be7e7f4204495 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 2 Dec 2021 00:42:30 +1100 Subject: [PATCH 037/180] Refactor getAnalogInputName --- companion/src/firmwares/boards.cpp | 163 +++++++++++++++-------------- companion/src/firmwares/boards.h | 8 ++ 2 files changed, 92 insertions(+), 79 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 344b3119e..bcb8572c1 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -510,102 +510,107 @@ QString Boards::getAxisName(int index) return CPN_STR_UNKNOWN_ITEM; } -QString Boards::getAnalogInputName(Board::Type board, int index) +#define ANALOGINDEXNAMEENTRY(name) tbl.push_back( { cnt++, name } ); + +AnalogIndexNamesLookupTable Boards::getAnalogNamesLookupTable(Board::Type board) { - if (index < 0) - return CPN_STR_UNKNOWN_ITEM; + AnalogIndexNamesLookupTable tbl; + int cnt = 0; - if (index < getBoardCapability(board, Board::Sticks)) { - const QString sticks[] = { - tr("Rud"), - tr("Ele"), - tr("Thr"), - tr("Ail") - }; - return sticks[index]; + if (getBoardCapability(board, Board::Sticks)) { + ANALOGINDEXNAMEENTRY("Rud") + ANALOGINDEXNAMEENTRY("Ele") + ANALOGINDEXNAMEENTRY("Thr") + ANALOGINDEXNAMEENTRY("Ail") } - index -= getCapability(board, Board::Sticks); - if (IS_SKY9X(board)) { - const QString pots[] = { - "P1", - "P2", - "P3" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("P1") + ANALOGINDEXNAMEENTRY("P2") + ANALOGINDEXNAMEENTRY("P3") } else if (IS_TARANIS_X9E(board)) { - const QString pots[] = { - "F1", - "F2", - "F3", - "F4", - "S1", - "S2", - "LS", - "RS" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("F1") + ANALOGINDEXNAMEENTRY("F2") + ANALOGINDEXNAMEENTRY("F3") + ANALOGINDEXNAMEENTRY("F4") + ANALOGINDEXNAMEENTRY("S1") + ANALOGINDEXNAMEENTRY("S2") + ANALOGINDEXNAMEENTRY("LS") + ANALOGINDEXNAMEENTRY("RS") } else if (IS_TARANIS_XLITE(board)) { - const QString pots[] = { - "S1", - "S2", - "GyrX", - "GyrY" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("S1") + ANALOGINDEXNAMEENTRY("S2") + ANALOGINDEXNAMEENTRY("GyrX") + ANALOGINDEXNAMEENTRY("GyrY") } else if (IS_TARANIS(board)) { - const QString pots[] = { - "S1", - "S2", - "S3", - "LS", - "RS" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("S1") + ANALOGINDEXNAMEENTRY("S2") + ANALOGINDEXNAMEENTRY("S3") + ANALOGINDEXNAMEENTRY("LS") + ANALOGINDEXNAMEENTRY("RS") } else if (IS_HORUS_X12S(board)) { - const QString pots[] = { - "S1", - "6P", - "S2", - "L1", - "L2", - "LS", - "RS", - "JSx", - "JSy" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("S1") + ANALOGINDEXNAMEENTRY("6P") + ANALOGINDEXNAMEENTRY("S2") + ANALOGINDEXNAMEENTRY("L1") + ANALOGINDEXNAMEENTRY("L2") + ANALOGINDEXNAMEENTRY("LS") + ANALOGINDEXNAMEENTRY("RS") + ANALOGINDEXNAMEENTRY("JSx") + ANALOGINDEXNAMEENTRY("JSy") } else if (IS_FLYSKY_NV14(board)) { - const QString pots[] = { - "VRA", - "VRB", - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("VRA") + ANALOGINDEXNAMEENTRY("VRB") } else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) { - const QString pots[] = { - "S1", - "6P", - "S2", - "EX1", - "EX2", - "LS", - "RS" - }; - if (index < DIM(pots)) - return pots[index]; + ANALOGINDEXNAMEENTRY("S1") + ANALOGINDEXNAMEENTRY("6P") + ANALOGINDEXNAMEENTRY("S2") + ANALOGINDEXNAMEENTRY("EX1") + ANALOGINDEXNAMEENTRY("EX2" ) + //ANALOGINDEXNAMEENTRY("EX3") // not yet implemented + //ANALOGINDEXNAMEENTRY("EX4") // not yet implemented + ANALOGINDEXNAMEENTRY("LS") + ANALOGINDEXNAMEENTRY("RS") + } + + return tbl; +} + +int Boards::getAnalogInputIndex(Board::Type board, char * name) +{ + AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board); + + const auto& it = + find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) { + if (elmt.second == name) return true; + return false; + }); + + if (it != lut.end()) { + return it->first; + } + + return 0; +} + +QString Boards::getAnalogInputName(Board::Type board, int index) +{ + AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board); + + const auto& it = + find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) { + if (elmt.first == index) return true; + return false; + }); + + if (it != lut.end()) { + return QString::fromUtf8(it->second.data(), it->second.size()); } return CPN_STR_UNKNOWN_ITEM; diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 050cf87e3..4aa2a0b02 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -24,6 +24,9 @@ #include #include +#include +#include + class AbstractStaticItemModel; // identiying names of static abstract item models @@ -174,6 +177,9 @@ namespace Board { } +typedef std::pair AnalogIndexNamesLookupElmt; +typedef std::vector AnalogIndexNamesLookupTable; + class Boards { Q_DECLARE_TR_FUNCTIONS(Boards) @@ -202,6 +208,8 @@ class Boards static Board::SwitchInfo getSwitchInfo(Board::Type board, int index); static int getCapability(Board::Type board, Board::Capability capability); static QString getAxisName(int index); + static AnalogIndexNamesLookupTable getAnalogNamesLookupTable(Board::Type board); + static int getAnalogInputIndex(Board::Type board, char * name); static QString getAnalogInputName(Board::Type board, int index); static bool isBoardCompatible(Board::Type board1, Board::Type board2); static QString getBoardName(Board::Type board); From 763964193e904ae6b9f0ef68bd45e7b9a1a93607 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 1 Dec 2021 14:37:05 +0100 Subject: [PATCH 038/180] Small fixes --- .../src/firmwares/edgetx/edgetxinterface.cpp | 4 ++-- .../src/firmwares/edgetx/yaml_modeldata.cpp | 16 ++++++++-------- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 2 +- .../src/firmwares/edgetx/yaml_switchconfig.h | 2 +- companion/src/storage/categorized.cpp | 5 +++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index e75428b2b..da1f12891 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -38,7 +38,7 @@ static void writeYamlToByteArray(const YAML::Node& node, QByteArray& data) data_ostream << node; data = QByteArray::fromStdString(data_ostream.str()); - qDebug() << "Saving radio.yml:"; + qDebug() << "Saving YAML:"; qDebug() << data_ostream.str().c_str(); } @@ -139,5 +139,5 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) node = settings; writeYamlToByteArray(node, data); - return false; + return true; } diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index e31989958..c762ee5fa 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -50,7 +50,7 @@ Node convert::encode(const TimerData& rhs) node["swtch"] = rhs.swtch; node["mode"] = timerModeLut << rhs.mode; node["name"] = rhs.name; - node["minuteBeep"] = rhs.minuteBeep; + node["minuteBeep"] = (int)rhs.minuteBeep; node["countdownBeep"] = rhs.countdownBeep; node["start"] = rhs.val; node["persistent"] = rhs.persistent; @@ -86,15 +86,15 @@ Node convert::encode(const ModelData& rhs) node["timers"][std::to_string(i)] = timer; } - node["noGlobalFunctions"] = rhs.noGlobalFunctions; - node["thrTrim"] = rhs.thrTrim; + node["noGlobalFunctions"] = (int)rhs.noGlobalFunctions; + node["thrTrim"] = (int)rhs.thrTrim; node["trimInc"] = rhs.trimInc; node["displayTrims"] = rhs.trimsDisplay; - node["disableThrottleWarning"] = rhs.disableThrottleWarning; + node["disableThrottleWarning"] = (int)rhs.disableThrottleWarning; // node[] = rhs.beepANACenter; - node["extendedLimits"] = rhs.extendedLimits; - node["extendedTrims"] = rhs.extendedTrims; - node["throttleReversed"] = rhs.throttleReversed; + node["extendedLimits"] = (int)rhs.extendedLimits; + node["extendedTrims"] = (int)rhs.extendedTrims; + node["throttleReversed"] = (int)rhs.throttleReversed; // flightModeData[] // mixData[] @@ -113,7 +113,7 @@ Node convert::encode(const ModelData& rhs) // potsWarnEnabled[] // potsWarnPosition[] - node["displayChecklist"] = rhs.displayChecklist; + node["displayChecklist"] = (int)rhs.displayChecklist; // gvarData[] // mavlink ??? diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 9bad86be9..af1a9f0ea 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -139,7 +139,7 @@ bool convert::decode(const Node& node, RawSwitch& rhs) // TODO: check if we have a match? // or does RawSwitch default to NONE anyway? // - node >> switchTypeLut >> rhs.type; + node >> rhs.type; rhs.index = 0; } diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 5cc2cc7d9..0a846d15b 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -55,7 +55,7 @@ struct YamlKnobConfig : public YamlNameConfig { const unsigned int in_configs[N]) : YamlNameConfig(in_names) { - memset(config, 0, sizeof(config)); + memcpy(config, in_configs, sizeof(config)); } void copy(char out_names[N][HARDWARE_NAME_LEN + 1], diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index a32442587..262ed4ac5 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -311,9 +311,10 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) // TODO: sort 'modelFiles' by category index QByteArray modelslistBuffer; if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer) - || writeFile(modelslistBuffer, "MODELS/models.yml")) { + || !writeFile(modelslistBuffer, "MODELS/models.yml")) { return false; } - return true; + // force error to avoid overwriting the archive... + return false; } From 98a6156889b9dc6c6aa9050661c706a73c7456ef Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 2 Dec 2021 09:20:54 +0100 Subject: [PATCH 039/180] WiP: mix data --- companion/src/firmwares/CMakeLists.txt | 2 + .../src/firmwares/edgetx/yaml_mixdata.cpp | 192 +++++++++++++++++ companion/src/firmwares/edgetx/yaml_mixdata.h | 31 +++ .../src/firmwares/edgetx/yaml_modeldata.cpp | 14 +- .../src/firmwares/edgetx/yaml_modeldata.h | 4 - companion/src/firmwares/edgetx/yaml_ops.h | 27 ++- .../src/firmwares/edgetx/yaml_rawsource.cpp | 197 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_rawsource.h | 32 +++ 8 files changed, 483 insertions(+), 16 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_mixdata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_mixdata.h create mode 100644 companion/src/firmwares/edgetx/yaml_rawsource.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_rawsource.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 4d149548f..0a984b8f3 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -37,6 +37,8 @@ set(firmwares_SRCS edgetx/yaml_switchconfig.cpp edgetx/yaml_modeldata.cpp edgetx/yaml_rawswitch.cpp + edgetx/yaml_rawsource.cpp + edgetx/yaml_mixdata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp new file mode 100644 index 000000000..614497450 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -0,0 +1,192 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_mixdata.h" +#include "yaml_rawswitch.h" +#include "yaml_rawsource.h" +#include "curvereference.h" + +// static const YamlLookupTable timerModeLut = { +// {TimerData::TIMERMODE_OFF, "OFF"}, +// {TimerData::TIMERMODE_ON, "ON"}, +// {TimerData::TIMERMODE_START, "START"}, +// {TimerData::TIMERMODE_THR, "THR"}, +// {TimerData::TIMERMODE_THR_REL, "THR_REL"}, +// {TimerData::TIMERMODE_THR_START, "THR_START"}, +// }; + +// static const YamlLookupTable trainerModeLut = { +// { TRAINER_MODE_OFF, "OFF" }, +// { TRAINER_MODE_MASTER_JACK, "MASTER_TRAINER_JACK" }, +// { TRAINER_MODE_SLAVE_JACK, "SLAVE" }, +// { TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE, "MASTER_SBUS_EXT" }, +// { TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE, "MASTER_CPPM_EXT" }, +// { TRAINER_MODE_MASTER_BATTERY_COMPARTMENT, "MASTER_BATT_COMP" }, +// { TRAINER_MODE_MASTER_BLUETOOTH, "MASTER_BT" }, +// { TRAINER_MODE_SLAVE_BLUETOOTH, "SLAVE_BT" }, +// { TRAINER_MODE_MULTI, "MASTER_MULTI" }, +// }; + +static const YamlLookupTable mixMultiplexLut = { + { MLTPX_ADD, "ADD" }, + { MLTPX_MUL, "MUL" }, + { MLTPX_REP, "REPL" }, +}; + +#define GVAR_SMALL 128 +#define CPN_GV1 1024 + +static int32_t readMixWeight(const std::string& val) +{ + if ((val.size() >= 4) + && (val[0] == '-') + && (val[1] == 'G') + && (val[2] == 'V') + && (val[3] >= '1') + && (val[3] <= '9')) { + + return -10000 - std::stoi(val.substr(3)); + } + + if ((val.size() >= 3) + && (val[0] == 'G') + && (val[1] == 'V') + && (val[2] >= '1') + && (val[2] <= '9')) { + + return 10000 + std::stoi(val.substr(2)); + } + + return std::stoi(val); +} + +static std::string writeMixWeight(int32_t sval) +{ + if (sval < -10000) { + int n = -sval - 10000; + return std::string("-GV") + std::to_string(n); + } else if (sval > 10000) { + int n = sval - 10000; + return std::string("GV") + std::to_string(n); + } + + return std::to_string(sval); +} + +static const YamlLookupTable dummy = {}; + +namespace YAML +{ +ENUM_CONVERTER(MltpxValue, mixMultiplexLut); + +template <> +struct convert { + static Node encode(const CurveReference& rhs) + { + Node node; + node["type"] = (int)rhs.type; + node["value"] = rhs.value; + return node; + } + + static bool decode(const Node& node, CurveReference& rhs) + { + // no symbolic value defined in radio + int type = 0; + node["type"] >> type; + rhs.type = (CurveReference::CurveRefType)type; + + node["value"] >> rhs.value; + return true; + } +}; + +Node convert::encode(const MixData& rhs) +{ + Node node; + node["destCh"] = rhs.destCh - 1; + + // node["srcRaw"] = rhs.srcRaw; // r_mixSrcRaw + + node["weight"] = writeMixWeight(rhs.weight); + node["swtch"] = rhs.swtch; + node["curve"] = rhs.curve; + node["delayUp"] = rhs.delayUp; + node["delayDown"] = rhs.delayDown; + node["speedUp"] = rhs.speedUp; + node["speedDown"] = rhs.speedDown; + node["carryTrim"] = rhs.carryTrim; + node["mltpx"] = rhs.mltpx; + node["mixWarn"] = rhs.mixWarn; + + // TODO: constant for number of flight modes + std::string fm_str; + for (int i=0; i<9; i++) { + uint32_t bit = (rhs.flightModes >> i) & 1; + fm_str += bit ? "1" : "0"; + } + node["flightModes"] = fm_str; + + node["offset"] = rhs.sOffset; // TODO: use writeMixWeight() + node["name"] = rhs.name; + return node; +} + +bool convert::decode(const Node& node, MixData& rhs) +{ + node["destCh"] >> ioffset_int((int&)rhs.destCh, -1); + node["srcRaw"] >> rhs.srcRaw; + + std::string weight_str; + node["weight"] >> weight_str; + if (!weight_str.empty()) { + rhs.weight = readMixWeight(weight_str); + } + + node["swtch"] >> rhs.swtch; + node["curve"] >> rhs.curve; + node["delayUp"] >> rhs.delayUp; + node["delayDown"] >> rhs.delayDown; + node["speedUp"] >> rhs.speedUp; + node["speedDown"] >> rhs.speedDown; + node["carryTrim"] >> rhs.carryTrim; + node["mltpx"] >> rhs.mltpx; + node["mixWarn"] >> rhs.mixWarn; + + if (node["flightModes"]) { + std::string fm_str; + node["flightModes"] >> fm_str; + + uint32_t bits = 0; + uint32_t mask = 1; + + for (uint32_t i = 0; i < fm_str.size(); i++) { + if (fm_str[i] == '1') bits |= mask; + mask <<= 1; + } + + rhs.flightModes = bits; + } + + node["offset"] >> rhs.sOffset; // TODO: use readMixWeight() + node["name"] >> rhs.name; + return true; +} +} diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.h b/companion/src/firmwares/edgetx/yaml_mixdata.h new file mode 100644 index 000000000..1ef01db7a --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_mixdata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "mixdata.h" + +namespace YAML { + +template <> +struct convert { + static Node encode(const MixData& rhs); + static bool decode(const Node& node, MixData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index c762ee5fa..2adb23b6e 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -19,8 +19,12 @@ */ #include "yaml_modeldata.h" +#include "yaml_rawswitch.h" +#include "yaml_mixdata.h" #include "modeldata.h" +#include + static const YamlLookupTable timerModeLut = { {TimerData::TIMERMODE_OFF, "OFF"}, {TimerData::TIMERMODE_ON, "ON"}, @@ -97,7 +101,14 @@ Node convert::encode(const ModelData& rhs) node["throttleReversed"] = (int)rhs.throttleReversed; // flightModeData[] - // mixData[] + for (int i=0; i::decode(const Node& node, ModelData& rhs) // flightModeData[] // mixData[] + node["mixData"] >> rhs.mixData; // limitData[] // inputNames[] // expoData[] diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.h b/companion/src/firmwares/edgetx/yaml_modeldata.h index 5150d25da..25b05a471 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.h +++ b/companion/src/firmwares/edgetx/yaml_modeldata.h @@ -19,12 +19,8 @@ */ #include "yaml_ops.h" -#include "yaml_rawswitch.h" - #include "modeldata.h" -#include - namespace YAML { template <> diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 52f90082a..5597bba42 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -95,20 +95,25 @@ void operator >> (const YAML::Node& node, char (&value)[N]) template void operator>>(const YAML::Node& node, T (&value)[N]) { - if (!node.IsMap()) return;// false; + if (node.IsMap()) { + for (const auto& elmt : node) { + try { + int idx = std::stoi(elmt.first.Scalar()); + if (idx < 0 || idx >= N) return; // false; - for (const auto& elmt : node) { - try { - int idx = std::stoi(elmt.first.Scalar()); - if (idx < 0 || idx >= N) return;// false; - - elmt.second >> value[idx]; - } catch (...) { - //return false; - return; + elmt.second >> value[idx]; + } catch (...) { + // return false; + return; + } + } + } else if (node.IsSequence()) { + int idx = 0; + for (const auto& elmt : node) { + elmt >> value[idx]; + idx++; } } - //return true; } namespace YAML { diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp new file mode 100644 index 000000000..426a9a743 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_rawsource.h" + +// SOURCE_TYPE_STICK +const YamlLookupTable analogSourceLut = { + { 0, "Rud" }, + { 1, "Ele" }, + { 2, "Thr" }, + { 3, "Ail" }, + { 4, "S1" }, + { 5, "6POS" }, + { 6, "S2" }, + { 7, "EXT1" }, { 7, "S3" }, // rename to use only S3 + { 8, "EXT2" }, { 8, "S4" }, // rename to use only S4 + // { 9, "EXT3" }, + // { 10, "EXT4" }, + { 9, "LS" }, + { 10, "RS" }, + { 11, "MOUSE1" }, + { 12, "MOUSE2" }, +}; + +// SOURCE_TYPE_TRIM +const YamlLookupTable trimSourceLut = { + { 0, "TrimRud" }, + { 1, "TrimEle" }, + { 2, "TrimThr" }, + { 3, "TrimAil" }, + { 4, "TrimT5" }, + { 5, "TrimT6" }, +}; + +// SOURCE_TYPE_CYC +const YamlLookupTable cycSourceLut = { + { 0, "CYC1" }, + { 1, "CYC2" }, + { 2, "CYC3" }, +}; + +// SOURCE_TYPE_MAX + // { MIXSRC_MAX, "MAX" }, + +const YamlLookupTable specialSourceLut = { + { 0, "TX_VOLTAGE" }, + { 1, "TX_TIME" }, + { 2, "ONE" }, + { 3, "TIMER1" }, + { 4, "TIMER2" }, + { 5, "TIMER3" }, + // TODO: { ???, "TX_GPS" }, +}; + +namespace YAML { + +//ENUM_CONVERTER(RawSourceType, sourceTypeLut); + +Node convert::encode(const RawSource& rhs) +{ + std::string src_str; + return Node(src_str); +} + +bool convert::decode(const Node& node, RawSource& rhs) +{ + std::string src_str = node.Scalar(); + const char* val = src_str.data(); + size_t val_len = src_str.size(); + + if (val_len > 0 && val[0] == 'I') { + + rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, std::stoi(src_str.substr(1))); + + } else if (val_len > 4 && + val[0] == 'l' && + val[1] == 'u' && + val[2] == 'a' && + val[3] == '(') { + + src_str = src_str.substr(4); + + size_t next_pos = 0; + int script = std::stoi(src_str, &next_pos); + + if (next_pos >= src_str.size()) return false; + src_str = src_str.substr(next_pos + 1); + + int output = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_LUA_OUTPUT, script * 16 + output); + + } else if (val_len > 3 && + val[0] == 'l' && + val[1] == 's' && + val[2] == '(') { + + src_str = src_str.substr(3); + int ls = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls); + + } else if (val_len > 3 && + val[0] == 't' && + val[1] == 'r' && + val[2] == '(') { + + src_str = src_str.substr(3); + int tr = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_PPM, tr); + + } else if (val_len > 3 && + val[0] == 'c' && + val[1] == 'h' && + val[2] == '(') { + + src_str = src_str.substr(3); + int ch = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_CH, ch); + + } else if (val_len > 3 && + val[0] == 'g' && + val[1] == 'v' && + val[2] == '(') { + + src_str = src_str.substr(3); + int gv = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_GVAR, gv); + + } else if (val_len > 5 && + val[0] == 't' && + val[1] == 'e' && + val[2] == 'l' && + val[3] == 'e' && + val[4] == '(') { + + src_str = src_str.substr(5); + + // parse sign + uint8_t sign = 0; + if (src_str[0] == '-') { + sign = 1; + src_str = src_str.substr(1); + } else if (src_str[0] == '+') { + sign = 2; + src_str = src_str.substr(1); + } + + int sensor = std::stoi(src_str); + rhs = RawSource(SOURCE_TYPE_TELEMETRY, sensor * 3 + sign); + + } else { + + YAML::Node conv = node >> analogSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_STICK; + rhs.index = conv.as(); + } + + conv = node >> trimSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_TRIM; + rhs.index = conv.as(); + } + + conv = node >> cycSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_CYC; + rhs.index = conv.as(); + } + + conv = node >> specialSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_SPECIAL; + rhs.index = conv.as(); + } + } + // TODO: raw analogs + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.h b/companion/src/firmwares/edgetx/yaml_rawsource.h new file mode 100644 index 000000000..6cf25ba82 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_rawsource.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "rawsource.h" + +namespace YAML { + +template <> +struct convert { + static Node encode(const RawSource& rhs); + static bool decode(const Node& node, RawSource& rhs); +}; + +} From f5271b806eaec46e1b0a160371a570855364f501 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 2 Dec 2021 17:28:13 +0100 Subject: [PATCH 040/180] Raw source encoding and limit data --- .../src/firmwares/edgetx/yaml_mixdata.cpp | 40 ++++------ companion/src/firmwares/edgetx/yaml_mixdata.h | 8 +- .../src/firmwares/edgetx/yaml_modeldata.cpp | 50 +++++++++++- .../src/firmwares/edgetx/yaml_rawsource.cpp | 80 ++++++++++++++++++- 4 files changed, 149 insertions(+), 29 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index 614497450..4fbb0daa3 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -96,35 +96,30 @@ namespace YAML { ENUM_CONVERTER(MltpxValue, mixMultiplexLut); -template <> -struct convert { - static Node encode(const CurveReference& rhs) - { - Node node; - node["type"] = (int)rhs.type; - node["value"] = rhs.value; - return node; - } +Node convert::encode(const CurveReference& rhs) +{ + Node node; + node["type"] = (int)rhs.type; + node["value"] = rhs.value; + return node; +} - static bool decode(const Node& node, CurveReference& rhs) - { - // no symbolic value defined in radio - int type = 0; - node["type"] >> type; - rhs.type = (CurveReference::CurveRefType)type; +bool convert::decode(const Node& node, CurveReference& rhs) +{ + // no symbolic value defined in radio + int type = 0; + node["type"] >> type; + rhs.type = (CurveReference::CurveRefType)type; - node["value"] >> rhs.value; - return true; - } -}; + node["value"] >> rhs.value; + return true; +} Node convert::encode(const MixData& rhs) { Node node; node["destCh"] = rhs.destCh - 1; - - // node["srcRaw"] = rhs.srcRaw; // r_mixSrcRaw - + node["srcRaw"] = rhs.srcRaw; node["weight"] = writeMixWeight(rhs.weight); node["swtch"] = rhs.swtch; node["curve"] = rhs.curve; @@ -159,7 +154,6 @@ bool convert::decode(const Node& node, MixData& rhs) if (!weight_str.empty()) { rhs.weight = readMixWeight(weight_str); } - node["swtch"] >> rhs.swtch; node["curve"] >> rhs.curve; node["delayUp"] >> rhs.delayUp; diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.h b/companion/src/firmwares/edgetx/yaml_mixdata.h index 1ef01db7a..2c20166a8 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.h +++ b/companion/src/firmwares/edgetx/yaml_mixdata.h @@ -21,7 +21,13 @@ #include "yaml_ops.h" #include "mixdata.h" -namespace YAML { +namespace YAML +{ +template <> +struct convert { + static Node encode(const CurveReference& rhs); + static bool decode(const Node& node, CurveReference& rhs); +}; template <> struct convert { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 2adb23b6e..cf8348129 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -22,6 +22,7 @@ #include "yaml_rawswitch.h" #include "yaml_mixdata.h" #include "modeldata.h" +#include "output_data.h" #include @@ -77,6 +78,38 @@ bool convert::decode(const Node& node, TimerData& rhs) return true; } +template <> +struct convert { + static Node encode(const LimitData& rhs) + { + Node node; + node["min"] = rhs.min; + node["max"] = rhs.max; + node["revert"] = rhs.revert; + node["offset"] = rhs.offset; + node["ppmCenter"] = rhs.ppmCenter; + node["symetrical"] = rhs.symetrical; + node["failsafe"] = rhs.failsafe; + node["name"] = rhs.name; + node["curve"] = rhs.curve; + return node; + } + + static bool decode(const Node& node, LimitData& rhs) + { + node["min"] >> rhs.min; + node["max"] >> rhs.max; + node["revert"] >> rhs.revert; + node["offset"] >> rhs.offset; + node["ppmCenter"] >> rhs.ppmCenter; + node["symetrical"] >> rhs.symetrical; + node["failsafe"] >> rhs.failsafe; + node["name"] >> rhs.name; + node["curve"] >> rhs.curve; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -101,6 +134,7 @@ Node convert::encode(const ModelData& rhs) node["throttleReversed"] = (int)rhs.throttleReversed; // flightModeData[] + for (int i=0; i::encode(const ModelData& rhs) node["mixData"].push_back(mixNode); } } - // limitData[] + + for (int i=0; i::decode(const Node& node, ModelData& rhs) node["throttleReversed"] >> rhs.throttleReversed; // flightModeData[] - // mixData[] + node["mixData"] >> rhs.mixData; - // limitData[] + node["limitData"] >> rhs.limitData; + // inputNames[] // expoData[] // curves[] diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 426a9a743..0c459fbce 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -71,11 +71,74 @@ const YamlLookupTable specialSourceLut = { namespace YAML { -//ENUM_CONVERTER(RawSourceType, sourceTypeLut); - Node convert::encode(const RawSource& rhs) { std::string src_str; + switch(rhs.type) { + case SOURCE_TYPE_VIRTUAL_INPUT: + src_str += "I" + std::to_string(rhs.index); + break; + case SOURCE_TYPE_LUA_OUTPUT: + src_str += "lua("; + src_str += std::to_string(rhs.index / 16); + src_str += ","; + src_str += std::to_string(rhs.index % 16); + src_str += ")"; + break; + case SOURCE_TYPE_STICK: + src_str = LookupValue(analogSourceLut, rhs.index); + break; + case SOURCE_TYPE_TRIM: + src_str = LookupValue(trimSourceLut, rhs.index); + break; + case SOURCE_TYPE_MAX: + src_str += "MAX"; + break; + case SOURCE_TYPE_SWITCH: + src_str += "S" + (rhs.index + 'A'); + break; + case SOURCE_TYPE_CUSTOM_SWITCH: + src_str += "ls("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_CYC: + src_str = LookupValue(cycSourceLut, rhs.index); + break; + case SOURCE_TYPE_PPM: + src_str += "tr("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_CH: + src_str += "ch("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_GVAR: + src_str += "gv("; + src_str += std::to_string(rhs.index); + src_str += ")"; + break; + case SOURCE_TYPE_SPECIAL: + src_str = LookupValue(specialSourceLut, rhs.index); + break; + case SOURCE_TYPE_TELEMETRY: + src_str = "tele("; + switch(rhs.index % 3) { + case 0: + break; + case 1: + src_str += '-'; + break; + case 2: + src_str += '+'; + break; + } + src_str += std::to_string(rhs.index / 3); + break; + } + return Node(src_str); } @@ -89,6 +152,13 @@ bool convert::decode(const Node& node, RawSource& rhs) rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, std::stoi(src_str.substr(1))); + } else if (val_len >= 2 + && val[0] == 'S' + && val[1] >= 'A' + && val[1] <= 'Z') { + + rhs = RawSource(SOURCE_TYPE_SWITCH, val[1] - 'A'); + } else if (val_len > 4 && val[0] == 'l' && val[1] == 'u' && @@ -189,6 +259,12 @@ bool convert::decode(const Node& node, RawSource& rhs) rhs.type = SOURCE_TYPE_SPECIAL; rhs.index = conv.as(); } + + if (node.IsScalar() + && node.as() == "MAX") { + rhs.type = SOURCE_TYPE_MAX; + rhs.index = 0; + } } // TODO: raw analogs From e73d9c5707d54b8adfc6f67bd9f2e3197dc35e03 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 3 Dec 2021 09:49:15 +0100 Subject: [PATCH 041/180] Added flight mode data --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 106 +++++++++++++++--- companion/src/firmwares/edgetx/yaml_ops.h | 18 ++- .../src/firmwares/edgetx/yaml_rawsource.cpp | 43 +++---- 3 files changed, 132 insertions(+), 35 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index cf8348129..61a4f077d 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -47,6 +47,17 @@ static const YamlLookupTable trainerModeLut = { { TRAINER_MODE_MULTI, "MASTER_MULTI" }, }; +struct YamlTrim { + int mode = 0; + int ref = 0; + int value = 0; + + YamlTrim() = default; + YamlTrim(int mode, int ref, int value): + mode(mode), ref(ref), value(value) + {} +}; + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -110,6 +121,72 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const YamlTrim& rhs) + { + Node node; + node["value"] = rhs.value; + if (rhs.mode < 0) { + node["mode"] = -1; + } else { + node["mode"] = 2 * rhs.ref + rhs.mode; + } + return node; + } + static bool decode(const Node& node, YamlTrim& rhs) + { + node["value"] >> rhs.value; + + int trimMode = 0; + node["mode"] >> trimMode; + if (trimMode < 0) { + rhs.mode = trimMode; + } else { + rhs.mode = trimMode % 2; + rhs.ref = trimMode / 2; + } + return true; + } +}; + +template <> +struct convert { + static Node encode(const FlightModeData& rhs) + { + Node node; + // TODO: use max number of trims for radio instead + YamlTrim yt[CPN_MAX_TRIMS]; + for (int i=0; i::encode(yt); + node["swtch"] = rhs.swtch; + node["name"] = rhs.name; + node["fadeIn"] = rhs.fadeIn; + node["fadeOut"] = rhs.fadeOut; + node["gvars"] = convert_array::encode(rhs.gvars); + return node; + } + + static bool decode(const Node& node, FlightModeData& rhs) + { + YamlTrim trims[CPN_MAX_TRIMS]; + node["trim"] >> trims; + for (size_t i=0; i> rhs.swtch; + node["name"] >> rhs.name; + node["fadeIn"] >> rhs.fadeIn; + node["fadeOut"] >> rhs.fadeOut; + node["gvars"] >> rhs.gvars; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -133,22 +210,26 @@ Node convert::encode(const ModelData& rhs) node["extendedTrims"] = (int)rhs.extendedTrims; node["throttleReversed"] = (int)rhs.throttleReversed; - // flightModeData[] - - for (int i=0; i::decode(const Node& node, ModelData& rhs) node["extendedTrims"] >> rhs.extendedTrims; node["throttleReversed"] >> rhs.throttleReversed; - // flightModeData[] - + node["flightModeData"] >> rhs.flightModeData; node["mixData"] >> rhs.mixData; node["limitData"] >> rhs.limitData; diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 5597bba42..9e9f67967 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -99,11 +99,10 @@ void operator>>(const YAML::Node& node, T (&value)[N]) for (const auto& elmt : node) { try { int idx = std::stoi(elmt.first.Scalar()); - if (idx < 0 || idx >= N) return; // false; + if (idx < 0 || idx >= N) return; elmt.second >> value[idx]; } catch (...) { - // return false; return; } } @@ -121,6 +120,21 @@ namespace YAML { std::string LookupValue(const YamlLookupTable& lut, const int& value); Node operator << (const YamlLookupTable& lut, const int& value); +template +struct convert_array +{ + static YAML::Node encode(const T (&rhs)[N]) + { + Node node; + for (size_t i=0; i struct convert_enum { diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 0c459fbce..1b345d3a1 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -70,73 +70,76 @@ const YamlLookupTable specialSourceLut = { }; namespace YAML { - Node convert::encode(const RawSource& rhs) { std::string src_str; - switch(rhs.type) { - case SOURCE_TYPE_VIRTUAL_INPUT: + switch (rhs.type) { + case SOURCE_TYPE_VIRTUAL_INPUT: src_str += "I" + std::to_string(rhs.index); break; - case SOURCE_TYPE_LUA_OUTPUT: + case SOURCE_TYPE_LUA_OUTPUT: src_str += "lua("; src_str += std::to_string(rhs.index / 16); src_str += ","; src_str += std::to_string(rhs.index % 16); src_str += ")"; break; - case SOURCE_TYPE_STICK: + case SOURCE_TYPE_STICK: src_str = LookupValue(analogSourceLut, rhs.index); break; - case SOURCE_TYPE_TRIM: + case SOURCE_TYPE_TRIM: src_str = LookupValue(trimSourceLut, rhs.index); break; - case SOURCE_TYPE_MAX: + case SOURCE_TYPE_MAX: src_str += "MAX"; break; - case SOURCE_TYPE_SWITCH: - src_str += "S" + (rhs.index + 'A'); + case SOURCE_TYPE_SWITCH: + src_str += "S"; + src_str += (rhs.index + 'A'); break; - case SOURCE_TYPE_CUSTOM_SWITCH: + case SOURCE_TYPE_CUSTOM_SWITCH: src_str += "ls("; src_str += std::to_string(rhs.index); src_str += ")"; break; - case SOURCE_TYPE_CYC: + case SOURCE_TYPE_CYC: src_str = LookupValue(cycSourceLut, rhs.index); break; - case SOURCE_TYPE_PPM: + case SOURCE_TYPE_PPM: src_str += "tr("; src_str += std::to_string(rhs.index); src_str += ")"; break; - case SOURCE_TYPE_CH: + case SOURCE_TYPE_CH: src_str += "ch("; src_str += std::to_string(rhs.index); src_str += ")"; break; - case SOURCE_TYPE_GVAR: + case SOURCE_TYPE_GVAR: src_str += "gv("; src_str += std::to_string(rhs.index); src_str += ")"; break; - case SOURCE_TYPE_SPECIAL: + case SOURCE_TYPE_SPECIAL: src_str = LookupValue(specialSourceLut, rhs.index); break; - case SOURCE_TYPE_TELEMETRY: + case SOURCE_TYPE_TELEMETRY: src_str = "tele("; - switch(rhs.index % 3) { - case 0: + switch (rhs.index % 3) { + case 0: break; - case 1: + case 1: src_str += '-'; break; - case 2: + case 2: src_str += '+'; break; } src_str += std::to_string(rhs.index / 3); break; + default: + src_str = "NONE"; + break; } return Node(src_str); From 8fd3e0d5c891da4c330049d949ba49e386b30e75 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 3 Dec 2021 10:45:10 +0100 Subject: [PATCH 042/180] Throttle trace --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 61 ++++++++++++++++++- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 61a4f077d..02d2cfb7d 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -21,8 +21,10 @@ #include "yaml_modeldata.h" #include "yaml_rawswitch.h" #include "yaml_mixdata.h" +#include "yaml_rawsource.h" #include "modeldata.h" #include "output_data.h" +#include "eeprominterface.h" #include @@ -58,6 +60,53 @@ struct YamlTrim { {} }; +struct YamlThrTrace { + RawSource src; + + YamlThrTrace() = default; + + YamlThrTrace(unsigned int cpn_value) + { + if (cpn_value == 0) { + src = RawSource(SOURCE_TYPE_STICK, 2/* throttle */); + return; + } + cpn_value--; + Boards board(getCurrentBoard()); + int pots = board.getCapability(Board::Pots); + int sliders = board.getCapability(Board::Sliders); + if (cpn_value < pots + sliders) { + src = RawSource(SOURCE_TYPE_STICK, 4/* sticks */ + cpn_value); + } + else { + cpn_value -= pots + sliders; + src = RawSource(SOURCE_TYPE_CH, cpn_value); + } + } + + unsigned int toCpn() + { + switch (src.type) { + case SOURCE_TYPE_STICK: + if (src.index == 2 /* throttle */) { + return 0; + } else { + return src.index - 4/* sticks */ + 1; + } + break; + case SOURCE_TYPE_CH: { + Boards board(getCurrentBoard()); + int pots = board.getCapability(Board::Pots); + int sliders = board.getCapability(Board::Sliders); + return pots + sliders + src.index; + } break; + default: + break; + } + return 0; + } +}; + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -239,9 +288,11 @@ Node convert::encode(const ModelData& rhs) // curves[] // logicalSw[] // customFn[] - // swashRingData - // thrTraceSrc + + YamlThrTrace thrTrace(rhs.thrTraceSrc); + node["thrTraceSrc"] = thrTrace.src; + // switchWarningStates // thrTrimSwitch // potsWarningMode @@ -313,7 +364,11 @@ bool convert::decode(const Node& node, ModelData& rhs) // customFn[] // swashRingData - // thrTraceSrc + + YamlThrTrace thrTrace; + node["thrTraceSrc"] >> thrTrace.src; + rhs.thrTraceSrc = thrTrace.toCpn(); + // switchWarningStates // thrTrimSwitch // potsWarningMode From f33d5c005ee83f95f52250bbf28446e3890e387e Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 4 Dec 2021 07:03:27 +1100 Subject: [PATCH 043/180] Calibration use dynamic analogs array --- .../src/firmwares/edgetx/yaml_calibdata.cpp | 30 ++++--------------- .../src/firmwares/edgetx/yaml_calibdata.h | 1 + 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp index 5dbfbb27e..a3e647458 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -20,30 +20,6 @@ #include "yaml_calibdata.h" -// TODO: we need a function that -// does the opposite of Boards::getAnalogInputName() -// -// This is only valid for X10, T16, TX16S (not X12S) -// -static const YamlLookupTable calibIdxLut = { - { 0, "Rud" }, - { 1, "Ele" }, - { 2, "Thr" }, - { 3, "Ail" }, - { 4, "S1" }, - { 5, "6POS" }, - { 6, "S2" }, - { 7, "EXT1" }, - { 8, "EXT2" }, - // not yet supported in Companion: - // { 9, "EXT3" }, - // { 10, "EXT4" }, - { 9, "LS" }, - { 10, "RS" }, - { 11, "MOUSE1" }, - { 12, "MOUSE2" }, -}; - YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); } YamlCalibData::YamlCalibData(const int* calibMid, const int* calibSpanNeg, @@ -53,7 +29,7 @@ YamlCalibData::YamlCalibData(const int* calibMid, const int* calibSpanNeg, calib[i].mid = calibMid[i]; calib[i].spanNeg = calibSpanNeg[i]; calib[i].spanPos = calibSpanPos[i]; - } + } } void YamlCalibData::copy(int* calibMid, int* calibSpanNeg, @@ -90,6 +66,8 @@ bool convert::decode(const Node& node, CalibData& rhs) Node convert::encode(const YamlCalibData& rhs) { Node node; + // TODO: for efficiency construct once at an outer level possibly add to Firmware? + const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard()); // TODO: we need something better here! for (const auto& kv : calibIdxLut) { node[kv.second] = rhs.calib[kv.first]; @@ -100,6 +78,8 @@ Node convert::encode(const YamlCalibData& rhs) bool convert::decode(const Node& node, YamlCalibData& rhs) { if (!node.IsMap()) return false; + // TODO: for efficiency construct once at an outer level possibly add to Firmware? + const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard()); int idx = 0; for (const auto& kv : node) { kv.first >> calibIdxLut >> idx; diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.h b/companion/src/firmwares/edgetx/yaml_calibdata.h index be8f37981..59deafa88 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.h +++ b/companion/src/firmwares/edgetx/yaml_calibdata.h @@ -20,6 +20,7 @@ #include "yaml_ops.h" #include "generalsettings.h" +#include "eeprominterface.h" struct CalibData { int16_t mid; From d636487663824767d2403482fe6d1fbf89ac121a Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 4 Dec 2021 09:30:56 +1100 Subject: [PATCH 044/180] Fix more compiler warnings --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 4 ++-- companion/src/firmwares/edgetx/yaml_ops.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 02d2cfb7d..83ebbdab2 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -75,7 +75,7 @@ struct YamlThrTrace { Boards board(getCurrentBoard()); int pots = board.getCapability(Board::Pots); int sliders = board.getCapability(Board::Sliders); - if (cpn_value < pots + sliders) { + if (cpn_value < (unsigned int)(pots + sliders)) { src = RawSource(SOURCE_TYPE_STICK, 4/* sticks */ + cpn_value); } else { @@ -198,7 +198,7 @@ struct convert { return true; } }; - + template <> struct convert { static Node encode(const FlightModeData& rhs) diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 9e9f67967..17e04173e 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -99,7 +99,7 @@ void operator>>(const YAML::Node& node, T (&value)[N]) for (const auto& elmt : node) { try { int idx = std::stoi(elmt.first.Scalar()); - if (idx < 0 || idx >= N) return; + if (idx < 0 || idx >= (int)N) return; elmt.second >> value[idx]; } catch (...) { @@ -134,7 +134,7 @@ struct convert_array return node; } }; - + template struct convert_enum { From df4a4a6960f34c9c48d9ff48bcfb61e857e4f131 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 4 Dec 2021 21:41:23 +1100 Subject: [PATCH 045/180] Move analogInputNamesLookupTable to Firmware --- companion/src/firmwares/boards.cpp | 110 +++++++++--------- companion/src/firmwares/boards.h | 9 +- companion/src/firmwares/datahelpers.h | 5 + .../src/firmwares/edgetx/yaml_calibdata.cpp | 13 ++- companion/src/firmwares/eeprominterface.h | 19 ++- 5 files changed, 86 insertions(+), 70 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index bcb8572c1..4381c7cf5 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -510,73 +510,73 @@ QString Boards::getAxisName(int index) return CPN_STR_UNKNOWN_ITEM; } -#define ANALOGINDEXNAMEENTRY(name) tbl.push_back( { cnt++, name } ); +#define ADDINDEXNAMEPAIR(name) tbl.push_back( { cnt++, name } ); -AnalogIndexNamesLookupTable Boards::getAnalogNamesLookupTable(Board::Type board) +Int2StringMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) { - AnalogIndexNamesLookupTable tbl; + Int2StringMappingTable tbl; int cnt = 0; if (getBoardCapability(board, Board::Sticks)) { - ANALOGINDEXNAMEENTRY("Rud") - ANALOGINDEXNAMEENTRY("Ele") - ANALOGINDEXNAMEENTRY("Thr") - ANALOGINDEXNAMEENTRY("Ail") + ADDINDEXNAMEPAIR("Rud") + ADDINDEXNAMEPAIR("Ele") + ADDINDEXNAMEPAIR("Thr") + ADDINDEXNAMEPAIR("Ail") } if (IS_SKY9X(board)) { - ANALOGINDEXNAMEENTRY("P1") - ANALOGINDEXNAMEENTRY("P2") - ANALOGINDEXNAMEENTRY("P3") + ADDINDEXNAMEPAIR("P1") + ADDINDEXNAMEPAIR("P2") + ADDINDEXNAMEPAIR("P3") } else if (IS_TARANIS_X9E(board)) { - ANALOGINDEXNAMEENTRY("F1") - ANALOGINDEXNAMEENTRY("F2") - ANALOGINDEXNAMEENTRY("F3") - ANALOGINDEXNAMEENTRY("F4") - ANALOGINDEXNAMEENTRY("S1") - ANALOGINDEXNAMEENTRY("S2") - ANALOGINDEXNAMEENTRY("LS") - ANALOGINDEXNAMEENTRY("RS") + ADDINDEXNAMEPAIR("F1") + ADDINDEXNAMEPAIR("F2") + ADDINDEXNAMEPAIR("F3") + ADDINDEXNAMEPAIR("F4") + ADDINDEXNAMEPAIR("S1") + ADDINDEXNAMEPAIR("S2") + ADDINDEXNAMEPAIR("LS") + ADDINDEXNAMEPAIR("RS") } else if (IS_TARANIS_XLITE(board)) { - ANALOGINDEXNAMEENTRY("S1") - ANALOGINDEXNAMEENTRY("S2") - ANALOGINDEXNAMEENTRY("GyrX") - ANALOGINDEXNAMEENTRY("GyrY") + ADDINDEXNAMEPAIR("S1") + ADDINDEXNAMEPAIR("S2") + ADDINDEXNAMEPAIR("GyrX") + ADDINDEXNAMEPAIR("GyrY") } else if (IS_TARANIS(board)) { - ANALOGINDEXNAMEENTRY("S1") - ANALOGINDEXNAMEENTRY("S2") - ANALOGINDEXNAMEENTRY("S3") - ANALOGINDEXNAMEENTRY("LS") - ANALOGINDEXNAMEENTRY("RS") + ADDINDEXNAMEPAIR("S1") + ADDINDEXNAMEPAIR("S2") + ADDINDEXNAMEPAIR("S3") + ADDINDEXNAMEPAIR("LS") + ADDINDEXNAMEPAIR("RS") } else if (IS_HORUS_X12S(board)) { - ANALOGINDEXNAMEENTRY("S1") - ANALOGINDEXNAMEENTRY("6P") - ANALOGINDEXNAMEENTRY("S2") - ANALOGINDEXNAMEENTRY("L1") - ANALOGINDEXNAMEENTRY("L2") - ANALOGINDEXNAMEENTRY("LS") - ANALOGINDEXNAMEENTRY("RS") - ANALOGINDEXNAMEENTRY("JSx") - ANALOGINDEXNAMEENTRY("JSy") + ADDINDEXNAMEPAIR("S1") + ADDINDEXNAMEPAIR("6P") + ADDINDEXNAMEPAIR("S2") + ADDINDEXNAMEPAIR("L1") + ADDINDEXNAMEPAIR("L2") + ADDINDEXNAMEPAIR("LS") + ADDINDEXNAMEPAIR("RS") + ADDINDEXNAMEPAIR("JSx") + ADDINDEXNAMEPAIR("JSy") } else if (IS_FLYSKY_NV14(board)) { - ANALOGINDEXNAMEENTRY("VRA") - ANALOGINDEXNAMEENTRY("VRB") + ADDINDEXNAMEPAIR("VRA") + ADDINDEXNAMEPAIR("VRB") } else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) { - ANALOGINDEXNAMEENTRY("S1") - ANALOGINDEXNAMEENTRY("6P") - ANALOGINDEXNAMEENTRY("S2") - ANALOGINDEXNAMEENTRY("EX1") - ANALOGINDEXNAMEENTRY("EX2" ) - //ANALOGINDEXNAMEENTRY("EX3") // not yet implemented - //ANALOGINDEXNAMEENTRY("EX4") // not yet implemented - ANALOGINDEXNAMEENTRY("LS") - ANALOGINDEXNAMEENTRY("RS") + ADDINDEXNAMEPAIR("S1") + ADDINDEXNAMEPAIR("6P") + ADDINDEXNAMEPAIR("S2") + ADDINDEXNAMEPAIR("EX1") + ADDINDEXNAMEPAIR("EX2" ) + //ADDINDEXNAMEPAIR("EX3") // not yet implemented + //ADDINDEXNAMEPAIR("EX4") // not yet implemented + ADDINDEXNAMEPAIR("LS") + ADDINDEXNAMEPAIR("RS") } return tbl; @@ -584,15 +584,15 @@ AnalogIndexNamesLookupTable Boards::getAnalogNamesLookupTable(Board::Type board) int Boards::getAnalogInputIndex(Board::Type board, char * name) { - AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board); + Int2StringMappingTable tbl = getAnalogNamesLookupTable(board); const auto& it = - find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) { - if (elmt.second == name) return true; + find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) { + if (row.second == name) return true; return false; }); - if (it != lut.end()) { + if (it != tbl.end()) { return it->first; } @@ -601,15 +601,15 @@ int Boards::getAnalogInputIndex(Board::Type board, char * name) QString Boards::getAnalogInputName(Board::Type board, int index) { - AnalogIndexNamesLookupTable lut = getAnalogNamesLookupTable(board); + Int2StringMappingTable tbl = getAnalogNamesLookupTable(board); const auto& it = - find_if(lut.begin(), lut.end(), [=](const AnalogIndexNamesLookupElmt& elmt) { - if (elmt.first == index) return true; + find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) { + if (row.first == index) return true; return false; }); - if (it != lut.end()) { + if (it != tbl.end()) { return QString::fromUtf8(it->second.data(), it->second.size()); } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 4aa2a0b02..28635be1c 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -19,14 +19,12 @@ */ #pragma once +#include "datahelpers.h" #include #include #include -#include -#include - class AbstractStaticItemModel; // identiying names of static abstract item models @@ -177,9 +175,6 @@ namespace Board { } -typedef std::pair AnalogIndexNamesLookupElmt; -typedef std::vector AnalogIndexNamesLookupTable; - class Boards { Q_DECLARE_TR_FUNCTIONS(Boards) @@ -208,7 +203,7 @@ class Boards static Board::SwitchInfo getSwitchInfo(Board::Type board, int index); static int getCapability(Board::Type board, Board::Capability capability); static QString getAxisName(int index); - static AnalogIndexNamesLookupTable getAnalogNamesLookupTable(Board::Type board); + static Int2StringMappingTable getAnalogNamesLookupTable(Board::Type board); static int getAnalogInputIndex(Board::Type board, char * name); static QString getAnalogInputName(Board::Type board, int index); static bool isBoardCompatible(Board::Type board1, Board::Type board2); diff --git a/companion/src/firmwares/datahelpers.h b/companion/src/firmwares/datahelpers.h index ccd3b0f64..1797be76e 100644 --- a/companion/src/firmwares/datahelpers.h +++ b/companion/src/firmwares/datahelpers.h @@ -21,6 +21,11 @@ #pragma once #include +#include +#include + +typedef std::pair Int2StringMapping; +typedef std::vector Int2StringMappingTable; class FieldRange { diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp index a3e647458..d96faebcf 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -66,10 +66,9 @@ bool convert::decode(const Node& node, CalibData& rhs) Node convert::encode(const YamlCalibData& rhs) { Node node; - // TODO: for efficiency construct once at an outer level possibly add to Firmware? - const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard()); + const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); // TODO: we need something better here! - for (const auto& kv : calibIdxLut) { + for (const auto& kv : *calibIdxLut) { node[kv.second] = rhs.calib[kv.first]; } return node; @@ -78,11 +77,13 @@ Node convert::encode(const YamlCalibData& rhs) bool convert::decode(const Node& node, YamlCalibData& rhs) { if (!node.IsMap()) return false; - // TODO: for efficiency construct once at an outer level possibly add to Firmware? - const YamlLookupTable calibIdxLut = Boards::getAnalogNamesLookupTable(getCurrentBoard()); + const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); + //for_each(calibIdxLut->begin(), calibIdxLut->end(), [=](const Int2StringMapping& row) { + // qDebug() << "index:" << row.first << "value:" << row.second.c_str(); + // }); int idx = 0; for (const auto& kv : node) { - kv.first >> calibIdxLut >> idx; + kv.first >> *calibIdxLut >> idx; kv.second >> rhs.calib[idx]; } return true; diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index df7c6d9f4..dd4c49912 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -26,6 +26,7 @@ #include "radiodata.h" #include "../../radio/src/definitions.h" #include "simulatorinterface.h" +#include "datahelpers.h" #include #include @@ -287,8 +288,15 @@ class Firmware board(board), variantBase(0), base(base), - eepromInterface(nullptr) - { } + eepromInterface(nullptr), + analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)) + { +/* qDebug() << "board:" << Boards::getBoardName(board); + * for_each(analogInputNamesLookupTable.begin(), analogInputNamesLookupTable.end(), [=](const Int2StringMapping& row) { + * qDebug() << "index:" << row.first << "value:" << row.second.c_str(); + * }); + */ + } virtual ~Firmware() { } @@ -395,6 +403,11 @@ class Firmware currentVariant = value; } + const Int2StringMappingTable * getAnalogIndexNamesLookupTable() + { + return &analogInputNamesLookupTable; + } + protected: QString id; QString name; @@ -402,6 +415,7 @@ class Firmware unsigned int variantBase; Firmware * base; EEPROMInterface * eepromInterface; + const Int2StringMappingTable analogInputNamesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; @@ -409,6 +423,7 @@ class Firmware static QVector registeredFirmwares; static Firmware * defaultVariant; static Firmware * currentVariant; + }; inline Firmware * getCurrentFirmware() From 6018765107f67fb57a97fcaf36387b7125ace3e1 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 4 Dec 2021 10:40:35 +0100 Subject: [PATCH 046/180] Added inputs and curves --- companion/src/firmwares/CMakeLists.txt | 2 + .../src/firmwares/edgetx/yaml_curvedata.cpp | 106 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_curvedata.h | 34 ++++++ .../src/firmwares/edgetx/yaml_expodata.cpp | 67 +++++++++++ .../src/firmwares/edgetx/yaml_expodata.h | 31 +++++ .../src/firmwares/edgetx/yaml_mixdata.cpp | 69 ++++++------ companion/src/firmwares/edgetx/yaml_mixdata.h | 7 ++ .../src/firmwares/edgetx/yaml_modeldata.cpp | 38 ++++++- companion/src/firmwares/edgetx/yaml_ops.h | 1 + 9 files changed, 317 insertions(+), 38 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_curvedata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_curvedata.h create mode 100644 companion/src/firmwares/edgetx/yaml_expodata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_expodata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 0a984b8f3..926ad2da8 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -39,6 +39,8 @@ set(firmwares_SRCS edgetx/yaml_rawswitch.cpp edgetx/yaml_rawsource.cpp edgetx/yaml_mixdata.cpp + edgetx/yaml_expodata.cpp + edgetx/yaml_curvedata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_curvedata.cpp b/companion/src/firmwares/edgetx/yaml_curvedata.cpp new file mode 100644 index 000000000..ec02f0b38 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_curvedata.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_curvedata.h" + +// CurveHeader curves[MAX_CURVES]; +// int8_t points[MAX_CURVE_POINTS]; + +void YamlReadCurvePoints(const YAML::Node& node, CurveData* curves) +{ + int pidx = 0; + for (int i = 0; i < CPN_MAX_CURVES; i++) { + CurveData& curve = curves[i]; + for (int j = 0; j < curve.count; j++) { + std::string pidx_str = std::to_string(pidx++); + if (node[pidx_str]) { + int y = 0; + node[pidx_str]["val"] >> y; + curve.points[j].y = (int8_t)y; + } + } + if (curve.type == CurveData::CURVE_TYPE_CUSTOM) { + // Custom curve: X points are trailing Y points + curve.points[0].x = -100; + for (int k = 1; k < curve.count - 1; k++) { + std::string pidx_str = std::to_string(pidx++); + if (node[pidx_str]) { + int x = 0; + node[pidx_str]["val"] >> x; + curve.points[k].x = (int8_t)x; + } + } + curve.points[curve.count - 1].x = +100; + } else { + // Standard curve: X points are generated + for (int k = 0; k < curve.count; k++) { + curve.points[k].x = -100 + (200 * k) / (curve.count - 1); + } + } + } +} + +void YamlWriteCurvePoints(YAML::Node& node, const CurveData* curves) +{ + int pidx = 0; + for (int i = 0; i < CPN_MAX_CURVES; i++) { + + //TODO: assert max number of points + // and raise exception + + const CurveData& curve = curves[i]; + if (!curve.isEmpty()) { + for (int k = 0; k < curve.count; k++) { + node[std::to_string(pidx++)]["val"] = (int)curve.points[k].y; + } + if (curve.type == CurveData::CURVE_TYPE_CUSTOM) { + for (int k = 1; k < curve.count - 1; k++) { + node[std::to_string(pidx++)]["val"] = (int)curve.points[k].x; + } + } + } else { + pidx += 5; + } + } +} + +namespace YAML +{ +Node convert::encode(const CurveData& rhs) +{ + Node node; + node["type"] = (int)rhs.type; + node["smooth"] = (int)rhs.smooth; + node["points"] = rhs.count - 5; + node["name"] = rhs.name; + return node; +} + +bool convert::decode(const Node& node, CurveData& rhs) +{ + int curve_type = 0; + node["type"] >> curve_type; + rhs.type = (CurveData::CurveType)curve_type; + node["smooth"] >> rhs.smooth; + node["points"] >> ioffset_int(rhs.count, -5); + node["name"] >> rhs.name; + return true; +} +} diff --git a/companion/src/firmwares/edgetx/yaml_curvedata.h b/companion/src/firmwares/edgetx/yaml_curvedata.h new file mode 100644 index 000000000..c33e7eeab --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_curvedata.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "curvedata.h" + +void YamlReadCurvePoints(const YAML::Node& node, CurveData* curves); +void YamlWriteCurvePoints(YAML::Node& node, const CurveData* curves); + +namespace YAML +{ +template <> +struct convert { + static Node encode(const CurveData& rhs); + static bool decode(const Node& node, CurveData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_expodata.cpp b/companion/src/firmwares/edgetx/yaml_expodata.cpp new file mode 100644 index 000000000..2a4987022 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_expodata.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_expodata.h" +#include "yaml_mixdata.h" +#include "yaml_rawswitch.h" +#include "yaml_rawsource.h" +#include "curvereference.h" + +namespace YAML +{ +Node convert::encode(const ExpoData& rhs) +{ + Node node; + node["srcRaw"] = rhs.srcRaw; + node["scale"] = rhs.scale; + node["mode"] = rhs.mode; // InputMode + node["chn"] = rhs.chn; + node["swtch"] = rhs.swtch; + node["flightModes"] = YamlWriteFlightModes(rhs.flightModes); + node["weight"] = YamlWriteMixWeight(rhs.weight); + node["offset"] = rhs.offset; // YamlWriteMixWeight + node["curve"] = rhs.curve; + node["carryTrim"] = rhs.carryTrim; + node["name"] = rhs.name; + return node; +} + +bool convert::decode(const Node& node, ExpoData& rhs) +{ + node["srcRaw"] >> rhs.srcRaw; + node["scale"] >> rhs.scale; + node["mode"] >> rhs.mode; // InputMode + node["chn"] >> rhs.chn; + node["swtch"] >> rhs.swtch; + if (node["flightModes"]) { + rhs.flightModes = YamlReadFlightModes(node["flightModes"]); + } + if (node["weight"]) { + rhs.weight = YamlReadMixWeight(node["weight"]); + } + if (node["offset"]) { + rhs.offset = YamlReadMixWeight(node["offset"]); + } + node["curve"] >> rhs.curve; + node["carryTrim"] >> rhs.carryTrim; + node["name"] >> rhs.name; + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_expodata.h b/companion/src/firmwares/edgetx/yaml_expodata.h new file mode 100644 index 000000000..1495bce6d --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_expodata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "input_data.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const ExpoData& rhs); + static bool decode(const Node& node, ExpoData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index 4fbb0daa3..979539228 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -53,8 +53,9 @@ static const YamlLookupTable mixMultiplexLut = { #define GVAR_SMALL 128 #define CPN_GV1 1024 -static int32_t readMixWeight(const std::string& val) +int32_t YamlReadMixWeight(const YAML::Node& node) { + std::string val = node.as(); if ((val.size() >= 4) && (val[0] == '-') && (val[1] == 'G') @@ -77,7 +78,7 @@ static int32_t readMixWeight(const std::string& val) return std::stoi(val); } -static std::string writeMixWeight(int32_t sval) +std::string YamlWriteMixWeight(int32_t sval) { if (sval < -10000) { int n = -sval - 10000; @@ -90,6 +91,30 @@ static std::string writeMixWeight(int32_t sval) return std::to_string(sval); } +uint32_t YamlReadFlightModes(const YAML::Node& node) +{ + std::string fm_str = node.as(); + uint32_t bits = 0; + uint32_t mask = 1; + + for (uint32_t i = 0; i < fm_str.size(); i++) { + if (fm_str[i] == '1') bits |= mask; + mask <<= 1; + } + return bits; +} + +std::string YamlWriteFlightModes(uint32_t val) +{ + std::string fm_str; + // TODO: constant for number of flight modes + for (int i=0; i<9; i++) { + uint32_t bit = (val >> i) & 1; + fm_str += bit ? "1" : "0"; + } + return fm_str; +} + static const YamlLookupTable dummy = {}; namespace YAML @@ -120,7 +145,7 @@ Node convert::encode(const MixData& rhs) Node node; node["destCh"] = rhs.destCh - 1; node["srcRaw"] = rhs.srcRaw; - node["weight"] = writeMixWeight(rhs.weight); + node["weight"] = YamlWriteMixWeight(rhs.weight); node["swtch"] = rhs.swtch; node["curve"] = rhs.curve; node["delayUp"] = rhs.delayUp; @@ -130,16 +155,8 @@ Node convert::encode(const MixData& rhs) node["carryTrim"] = rhs.carryTrim; node["mltpx"] = rhs.mltpx; node["mixWarn"] = rhs.mixWarn; - - // TODO: constant for number of flight modes - std::string fm_str; - for (int i=0; i<9; i++) { - uint32_t bit = (rhs.flightModes >> i) & 1; - fm_str += bit ? "1" : "0"; - } - node["flightModes"] = fm_str; - - node["offset"] = rhs.sOffset; // TODO: use writeMixWeight() + node["flightModes"] = YamlWriteFlightModes(rhs.flightModes); + node["offset"] = YamlWriteMixWeight(rhs.sOffset); node["name"] = rhs.name; return node; } @@ -148,11 +165,8 @@ bool convert::decode(const Node& node, MixData& rhs) { node["destCh"] >> ioffset_int((int&)rhs.destCh, -1); node["srcRaw"] >> rhs.srcRaw; - - std::string weight_str; - node["weight"] >> weight_str; - if (!weight_str.empty()) { - rhs.weight = readMixWeight(weight_str); + if (node["weight"]) { + rhs.weight = YamlReadMixWeight(node["weight"]); } node["swtch"] >> rhs.swtch; node["curve"] >> rhs.curve; @@ -163,23 +177,12 @@ bool convert::decode(const Node& node, MixData& rhs) node["carryTrim"] >> rhs.carryTrim; node["mltpx"] >> rhs.mltpx; node["mixWarn"] >> rhs.mixWarn; - if (node["flightModes"]) { - std::string fm_str; - node["flightModes"] >> fm_str; - - uint32_t bits = 0; - uint32_t mask = 1; - - for (uint32_t i = 0; i < fm_str.size(); i++) { - if (fm_str[i] == '1') bits |= mask; - mask <<= 1; - } - - rhs.flightModes = bits; + rhs.flightModes = YamlReadFlightModes(node["flightModes"]); + } + if (node["offset"]) { + rhs.sOffset = YamlReadMixWeight(node["offset"]); } - - node["offset"] >> rhs.sOffset; // TODO: use readMixWeight() node["name"] >> rhs.name; return true; } diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.h b/companion/src/firmwares/edgetx/yaml_mixdata.h index 2c20166a8..0b08702f6 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.h +++ b/companion/src/firmwares/edgetx/yaml_mixdata.h @@ -21,6 +21,13 @@ #include "yaml_ops.h" #include "mixdata.h" +int32_t YamlReadMixWeight(const YAML::Node& node); +std::string YamlWriteMixWeight(int32_t sval); + +uint32_t YamlReadFlightModes(const YAML::Node& node); +std::string YamlWriteFlightModes(uint32_t val); + + namespace YAML { template <> diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 83ebbdab2..f2697eeb6 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -22,6 +22,9 @@ #include "yaml_rawswitch.h" #include "yaml_mixdata.h" #include "yaml_rawsource.h" +#include "yaml_expodata.h" +#include "yaml_curvedata.h" + #include "modeldata.h" #include "output_data.h" #include "eeprominterface.h" @@ -283,9 +286,30 @@ Node convert::encode(const ModelData& rhs) } } - // inputNames[] - // expoData[] - // curves[] + node["inputNames"] = + convert_array::encode( + rhs.inputNames); + + for (int i = 0; i < CPN_MAX_EXPOS; i++) { + const ExpoData& expo = rhs.expoData[i]; + if (!expo.isEmpty()) { + Node expoNode; + expoNode = expo; + node["expoData"].push_back(expoNode); + } + } + + for (int i = 0; i < CPN_MAX_CURVES; i++) { + const CurveData& curve = rhs.curves[i]; + if (!curve.isEmpty()) { + node["curves"][std::to_string(i)] = curve; + } + } + + YAML::Node points; + YamlWriteCurvePoints(points, rhs.curves); + node["points"] = points; + // logicalSw[] // customFn[] // swashRingData @@ -357,9 +381,13 @@ bool convert::decode(const Node& node, ModelData& rhs) node["mixData"] >> rhs.mixData; node["limitData"] >> rhs.limitData; - // inputNames[] - // expoData[] + node["inputNames"] >> rhs.inputNames; + node["expoData"] >> rhs.expoData; + // curves[] + node["curves"] >> rhs.curves; + YamlReadCurvePoints(node["points"], rhs.curves); + // logicalSw[] // customFn[] diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 17e04173e..09d2f9783 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -95,6 +95,7 @@ void operator >> (const YAML::Node& node, char (&value)[N]) template void operator>>(const YAML::Node& node, T (&value)[N]) { + if (!node) return; if (node.IsMap()) { for (const auto& elmt : node) { try { From 91ea5998b77f1356e2c8d21b40635b672301e5c6 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 4 Dec 2021 10:41:02 +0100 Subject: [PATCH 047/180] Translate offset to support gvars --- radio/src/datastructs_private.h | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp | 4 ++-- .../src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp | 4 ++-- .../src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp | 4 ++-- radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp | 4 ++-- .../src/storage/conversions/yaml/yaml_datastructs_xlites.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_nv14.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_t12.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_t8.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_tlite.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_tx12.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x10.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x12s.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x7.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x9d.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x9e.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x9lite.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_x9lites.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_xlite.cpp | 4 ++-- radio/src/storage/yaml/yaml_datastructs_xlites.cpp | 4 ++-- 29 files changed, 58 insertions(+), 58 deletions(-) diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index fffec8530..99775f4d7 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -76,7 +76,7 @@ PACK(struct MixData { uint16_t mixWarn:2; // mixer warning uint16_t mltpx:2 ENUM(MixerMultiplex); uint16_t spare:1 SKIP; - int32_t offset:14; + int32_t offset:14 CUST(in_read_weight,in_write_weight); int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc); uint32_t flightModes:9 CUST(r_flightModes, w_flightModes); CurveRef curve; @@ -102,7 +102,7 @@ PACK(struct ExpoData { int32_t weight:8 CUST(in_read_weight,in_write_weight); int32_t spare:1 SKIP; NOBACKUP(char name[LEN_EXPOMIX_NAME]); - int8_t offset; + int8_t offset CUST(in_read_weight,in_write_weight); CurveRef curve; }); diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index 09ad00b27..254c4a604 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -477,7 +477,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -512,7 +512,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp index c8571e569..9aec3504d 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp index 34add024b..4d7211cb3 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp index 34add024b..4d7211cb3 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp index 35ee08c95..255ff3dec 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index 4c6e21435..c19cf30ab 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -494,7 +494,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -529,7 +529,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index 4da434bc0..e9080a1eb 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -494,7 +494,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -529,7 +529,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp index 34add024b..4d7211cb3 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp index 3bb475d99..65038c815 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp @@ -450,7 +450,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -485,7 +485,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp index 8e7bad62a..be3b6c6cb 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp @@ -489,7 +489,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -524,7 +524,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp index cfe00a6d1..63cf15877 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp @@ -427,7 +427,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -462,7 +462,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp index e0aaeba99..7acca6e5c 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp @@ -437,7 +437,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -472,7 +472,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp index f579825bb..e0f1a8c2f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp @@ -434,7 +434,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -469,7 +469,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp index 761e32c11..5a8978845 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp @@ -438,7 +438,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -473,7 +473,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 33c9ffe3c..d3ad55534 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -476,7 +476,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -511,7 +511,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index 4ddcadc24..70afcd933 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index becdd13c4..726868e50 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index becdd13c4..726868e50 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index cb33916c6..4e3d7af25 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 5bf3dbaa9..f0b84b3b7 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -497,7 +497,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -532,7 +532,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index b3417d332..06356a794 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -495,7 +495,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -530,7 +530,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index becdd13c4..726868e50 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -442,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -477,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 831f68c5a..b50050d00 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -450,7 +450,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -485,7 +485,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 22f18fd9d..87cd0815f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -489,7 +489,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -524,7 +524,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 0a7d205a0..6d3d90d78 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -427,7 +427,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -462,7 +462,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 4db4cf1f3..97b3feed3 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -437,7 +437,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -472,7 +472,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index b591daf19..58bbb5417 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -434,7 +434,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -469,7 +469,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 828436b96..1b69f0491 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -438,7 +438,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -473,7 +473,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; From ac3e2a7c883c4ce613eb49576dec9880b5014a34 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 4 Dec 2021 11:45:00 +0100 Subject: [PATCH 048/180] Add support for analogs with name different from tag --- companion/src/firmwares/boards.cpp | 151 +++++++----------- companion/src/firmwares/boards.h | 3 +- companion/src/firmwares/datahelpers.h | 26 ++- .../src/firmwares/edgetx/yaml_calibdata.cpp | 22 +-- .../src/firmwares/edgetx/yaml_calibdata.h | 1 - companion/src/firmwares/eeprominterface.cpp | 17 ++ companion/src/firmwares/eeprominterface.h | 11 +- 7 files changed, 120 insertions(+), 111 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 4381c7cf5..b8b17406e 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -510,108 +510,81 @@ QString Boards::getAxisName(int index) return CPN_STR_UNKNOWN_ITEM; } -#define ADDINDEXNAMEPAIR(name) tbl.push_back( { cnt++, name } ); - -Int2StringMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) +StringTagMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) { - Int2StringMappingTable tbl; - int cnt = 0; + StringTagMappingTable tbl; if (getBoardCapability(board, Board::Sticks)) { - ADDINDEXNAMEPAIR("Rud") - ADDINDEXNAMEPAIR("Ele") - ADDINDEXNAMEPAIR("Thr") - ADDINDEXNAMEPAIR("Ail") + tbl.insert(tbl.end(), {"Rud", "Ele", "Thr", "Ail"}); } if (IS_SKY9X(board)) { - ADDINDEXNAMEPAIR("P1") - ADDINDEXNAMEPAIR("P2") - ADDINDEXNAMEPAIR("P3") - } - else if (IS_TARANIS_X9E(board)) { - ADDINDEXNAMEPAIR("F1") - ADDINDEXNAMEPAIR("F2") - ADDINDEXNAMEPAIR("F3") - ADDINDEXNAMEPAIR("F4") - ADDINDEXNAMEPAIR("S1") - ADDINDEXNAMEPAIR("S2") - ADDINDEXNAMEPAIR("LS") - ADDINDEXNAMEPAIR("RS") - } - else if (IS_TARANIS_XLITE(board)) { - ADDINDEXNAMEPAIR("S1") - ADDINDEXNAMEPAIR("S2") - ADDINDEXNAMEPAIR("GyrX") - ADDINDEXNAMEPAIR("GyrY") - } - else if (IS_TARANIS(board)) { - ADDINDEXNAMEPAIR("S1") - ADDINDEXNAMEPAIR("S2") - ADDINDEXNAMEPAIR("S3") - ADDINDEXNAMEPAIR("LS") - ADDINDEXNAMEPAIR("RS") - } - else if (IS_HORUS_X12S(board)) { - ADDINDEXNAMEPAIR("S1") - ADDINDEXNAMEPAIR("6P") - ADDINDEXNAMEPAIR("S2") - ADDINDEXNAMEPAIR("L1") - ADDINDEXNAMEPAIR("L2") - ADDINDEXNAMEPAIR("LS") - ADDINDEXNAMEPAIR("RS") - ADDINDEXNAMEPAIR("JSx") - ADDINDEXNAMEPAIR("JSy") - } - else if (IS_FLYSKY_NV14(board)) { - ADDINDEXNAMEPAIR("VRA") - ADDINDEXNAMEPAIR("VRB") - } - else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) { - ADDINDEXNAMEPAIR("S1") - ADDINDEXNAMEPAIR("6P") - ADDINDEXNAMEPAIR("S2") - ADDINDEXNAMEPAIR("EX1") - ADDINDEXNAMEPAIR("EX2" ) - //ADDINDEXNAMEPAIR("EX3") // not yet implemented - //ADDINDEXNAMEPAIR("EX4") // not yet implemented - ADDINDEXNAMEPAIR("LS") - ADDINDEXNAMEPAIR("RS") + tbl.insert(tbl.end(), {"P1", "P2", "P3"}); + } else if (IS_TARANIS_X9E(board)) { + tbl.insert(tbl.end(), { + {"F1", "POT1"}, + {"F2", "POT2"}, + {"F3", "POT3"}, + {"F4", "POT4"}, + {"S1", "SLIDER1"}, + {"S2", "SLIDER2"}, + {"LS", "SLIDER3"}, + {"RS", "SLIDER4"}, + }); + } else if (IS_TARANIS_XLITE(board)) { + tbl.insert(tbl.end(), { + {"S1", "POT1"}, + {"S2", "POT2"}, + {"GyrX", "GYRO1"}, + {"GyrY", "GYRO2"}, + }); + } else if (IS_TARANIS(board)) { + tbl.insert(tbl.end(), { + {"S1", "POT1"}, + {"S2", "POT2"}, + {"S3", "POT3"}, + {"LS", "SLIDER1"}, + {"RS", "SLIDER2"}, + }); + } else if (IS_HORUS_X12S(board)) { + tbl.insert(tbl.end(), { + {"S1", "S1"}, + {"6P", "6POS"}, + {"S2", "S2"}, + {"L1", "S3"}, + {"L2", "S4"}, + {"LS", "LS"}, + {"RS", "RS"}, + {"JSx", "MOUSE1"}, + {"JSy", "MOUSE2"}, + }); + } else if (IS_FLYSKY_NV14(board)) { + tbl.insert(tbl.end(), { + {"VRA", "POT1"}, + {"VRB", "POT2"}, + }); + } else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) { + tbl.insert(tbl.end(), { + {"S1", "S1"}, + {"6P", "6POS"}, + {"S2", "S2"}, + {"EX1", "EXT1"}, + {"EX2", "EXT2"}, + // {"EX3", "EXT3"}, + // {"EX4", "EXT4"}, + {"LS", "LS"}, + {"RS", "RS"}, + }); } return tbl; } -int Boards::getAnalogInputIndex(Board::Type board, char * name) -{ - Int2StringMappingTable tbl = getAnalogNamesLookupTable(board); - - const auto& it = - find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) { - if (row.second == name) return true; - return false; - }); - - if (it != tbl.end()) { - return it->first; - } - - return 0; -} - QString Boards::getAnalogInputName(Board::Type board, int index) { - Int2StringMappingTable tbl = getAnalogNamesLookupTable(board); - - const auto& it = - find_if(tbl.begin(), tbl.end(), [=](const Int2StringMapping& row) { - if (row.first == index) return true; - return false; - }); - - if (it != tbl.end()) { - return QString::fromUtf8(it->second.data(), it->second.size()); - } + const StringTagMappingTable& lut = getAnalogNamesLookupTable(board); + if (index < lut.size()) + return QString::fromStdString(lut[index].name); return CPN_STR_UNKNOWN_ITEM; } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 28635be1c..c6662133e 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -203,8 +203,7 @@ class Boards static Board::SwitchInfo getSwitchInfo(Board::Type board, int index); static int getCapability(Board::Type board, Board::Capability capability); static QString getAxisName(int index); - static Int2StringMappingTable getAnalogNamesLookupTable(Board::Type board); - static int getAnalogInputIndex(Board::Type board, char * name); + static StringTagMappingTable getAnalogNamesLookupTable(Board::Type board); static QString getAnalogInputName(Board::Type board, int index); static bool isBoardCompatible(Board::Type board1, Board::Type board2); static QString getBoardName(Board::Type board); diff --git a/companion/src/firmwares/datahelpers.h b/companion/src/firmwares/datahelpers.h index 1797be76e..336616dbe 100644 --- a/companion/src/firmwares/datahelpers.h +++ b/companion/src/firmwares/datahelpers.h @@ -24,8 +24,30 @@ #include #include -typedef std::pair Int2StringMapping; -typedef std::vector Int2StringMappingTable; +struct StringTagMapping { + std::string name; + std::string tag; + + StringTagMapping() = default; + StringTagMapping(const char* name) : + name(name), tag(name) + { + } + StringTagMapping(const std::string& name) : + name(name), tag(name) + { + } + StringTagMapping(const char* name, const char* tag) : + name(name), tag(tag) + { + } + StringTagMapping(const std::string& name, const std::string& tag) : + name(name), tag(tag) + { + } +}; + +typedef std::vector StringTagMappingTable; class FieldRange { diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp index d96faebcf..45f1fd407 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -19,6 +19,7 @@ */ #include "yaml_calibdata.h" +#include "eeprominterface.h" YamlCalibData::YamlCalibData() { memset(calib, 0, sizeof(calib)); } @@ -66,10 +67,11 @@ bool convert::decode(const Node& node, CalibData& rhs) Node convert::encode(const YamlCalibData& rhs) { Node node; - const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); - // TODO: we need something better here! + int idx = 0; + // TODO: for efficiency construct once at an outer level possibly add to Firmware? + const auto* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); for (const auto& kv : *calibIdxLut) { - node[kv.second] = rhs.calib[kv.first]; + node[kv.tag] = rhs.calib[idx++]; } return node; } @@ -77,14 +79,14 @@ Node convert::encode(const YamlCalibData& rhs) bool convert::decode(const Node& node, YamlCalibData& rhs) { if (!node.IsMap()) return false; - const YamlLookupTable* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); - //for_each(calibIdxLut->begin(), calibIdxLut->end(), [=](const Int2StringMapping& row) { - // qDebug() << "index:" << row.first << "value:" << row.second.c_str(); - // }); - int idx = 0; + for (const auto& kv : node) { - kv.first >> *calibIdxLut >> idx; - kv.second >> rhs.calib[idx]; + std::string tag; + kv.first >> tag; + int idx = getCurrentFirmware()->getAnalogInputIndex(tag.c_str()); + if (idx >= 0) { + kv.second >> rhs.calib[idx]; + } } return true; } diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.h b/companion/src/firmwares/edgetx/yaml_calibdata.h index 59deafa88..be8f37981 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.h +++ b/companion/src/firmwares/edgetx/yaml_calibdata.h @@ -20,7 +20,6 @@ #include "yaml_ops.h" #include "generalsettings.h" -#include "eeprominterface.h" struct CalibData { int16_t mid; diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 90272d0ad..e11716cba 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -178,3 +178,20 @@ void Firmware::addOptionsGroup(const OptionsGroup & options) { this->opts.append(options); } + +int Firmware::getAnalogInputIndex(const char * tag) +{ + const StringTagMappingTable& lut = analogInputNamesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index dd4c49912..6024ef1fd 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -291,11 +291,6 @@ class Firmware eepromInterface(nullptr), analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)) { -/* qDebug() << "board:" << Boards::getBoardName(board); - * for_each(analogInputNamesLookupTable.begin(), analogInputNamesLookupTable.end(), [=](const Int2StringMapping& row) { - * qDebug() << "index:" << row.first << "value:" << row.second.c_str(); - * }); - */ } virtual ~Firmware() { } @@ -403,11 +398,13 @@ class Firmware currentVariant = value; } - const Int2StringMappingTable * getAnalogIndexNamesLookupTable() + const StringTagMappingTable* getAnalogIndexNamesLookupTable() { return &analogInputNamesLookupTable; } + int getAnalogInputIndex(const char * tag); + protected: QString id; QString name; @@ -415,7 +412,7 @@ class Firmware unsigned int variantBase; Firmware * base; EEPROMInterface * eepromInterface; - const Int2StringMappingTable analogInputNamesLookupTable; + const StringTagMappingTable analogInputNamesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; From eec0c305894dd981dba4df039f03e45b6a7fd7fd Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 4 Dec 2021 12:11:04 +0100 Subject: [PATCH 049/180] Use analog lookup table in RawSource conversion as well --- .../src/firmwares/edgetx/yaml_rawsource.cpp | 73 +++++++------------ companion/src/firmwares/eeprominterface.cpp | 9 +++ companion/src/firmwares/eeprominterface.h | 2 + 3 files changed, 39 insertions(+), 45 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 1b345d3a1..e05c10dd2 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -19,25 +19,7 @@ */ #include "yaml_rawsource.h" - -// SOURCE_TYPE_STICK -const YamlLookupTable analogSourceLut = { - { 0, "Rud" }, - { 1, "Ele" }, - { 2, "Thr" }, - { 3, "Ail" }, - { 4, "S1" }, - { 5, "6POS" }, - { 6, "S2" }, - { 7, "EXT1" }, { 7, "S3" }, // rename to use only S3 - { 8, "EXT2" }, { 8, "S4" }, // rename to use only S4 - // { 9, "EXT3" }, - // { 10, "EXT4" }, - { 9, "LS" }, - { 10, "RS" }, - { 11, "MOUSE1" }, - { 12, "MOUSE2" }, -}; +#include "eeprominterface.h" // SOURCE_TYPE_TRIM const YamlLookupTable trimSourceLut = { @@ -85,7 +67,7 @@ Node convert::encode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_STICK: - src_str = LookupValue(analogSourceLut, rhs.index); + src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index); break; case SOURCE_TYPE_TRIM: src_str = LookupValue(trimSourceLut, rhs.index); @@ -239,35 +221,36 @@ bool convert::decode(const Node& node, RawSource& rhs) } else { - YAML::Node conv = node >> analogSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_STICK; - rhs.index = conv.as(); - } + std::string ana_str; + node >> ana_str; + int ana_idx = getCurrentFirmware()->getAnalogInputIndex(ana_str.c_str()); + if (ana_idx >= 0) { + rhs.type = SOURCE_TYPE_STICK; + rhs.index = ana_idx; + } - conv = node >> trimSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_TRIM; - rhs.index = conv.as(); - } + YAML::Node conv = node >> trimSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_TRIM; + rhs.index = conv.as(); + } - conv = node >> cycSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_CYC; - rhs.index = conv.as(); - } + conv = node >> cycSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_CYC; + rhs.index = conv.as(); + } - conv = node >> specialSourceLut; - if (conv.IsScalar()) { - rhs.type = SOURCE_TYPE_SPECIAL; - rhs.index = conv.as(); - } + conv = node >> specialSourceLut; + if (conv.IsScalar()) { + rhs.type = SOURCE_TYPE_SPECIAL; + rhs.index = conv.as(); + } - if (node.IsScalar() - && node.as() == "MAX") { - rhs.type = SOURCE_TYPE_MAX; - rhs.index = 0; - } + if (node.IsScalar() && node.as() == "MAX") { + rhs.type = SOURCE_TYPE_MAX; + rhs.index = 0; + } } // TODO: raw analogs diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index e11716cba..cfa5ab5d1 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -195,3 +195,12 @@ int Firmware::getAnalogInputIndex(const char * tag) return -1; } + +std::string Firmware::getAnalogInputTag(unsigned int index) +{ + const StringTagMappingTable& lut = analogInputNamesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 6024ef1fd..cba7362fb 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -34,6 +34,7 @@ #include #include +#include const uint8_t modn12x3[4][4]= { {1, 2, 3, 4}, @@ -404,6 +405,7 @@ class Firmware } int getAnalogInputIndex(const char * tag); + std::string getAnalogInputTag(unsigned int index); protected: QString id; From d0089232ff16711f7e561dd95afb26549ea8a7b5 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 4 Dec 2021 15:16:55 +0100 Subject: [PATCH 050/180] Fixes saving b&w models --- .../src/firmwares/edgetx/edgetxinterface.cpp | 4 +++ .../src/firmwares/edgetx/yaml_modeldata.cpp | 15 +++++---- companion/src/storage/categorized.cpp | 32 +++++++++++++------ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index da1f12891..ca51cfa92 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -116,6 +116,10 @@ bool writeModelsListToYaml(const std::vector& categories, YAML::Node cat_attrs; cat_attrs["filename"] = modelFile.first; + if (modelFile.second >= categories.size()) { + return false; + } + const std::string cat_name = categories[modelFile.second].name; node[modelFile.second][cat_name].push_back(cat_attrs); } diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index f2697eeb6..b348a375b 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -286,19 +286,21 @@ Node convert::encode(const ModelData& rhs) } } - node["inputNames"] = - convert_array::encode( - rhs.inputNames); - + std::set inputs; for (int i = 0; i < CPN_MAX_EXPOS; i++) { const ExpoData& expo = rhs.expoData[i]; if (!expo.isEmpty()) { Node expoNode; expoNode = expo; node["expoData"].push_back(expoNode); + inputs.insert(expo.chn); } } + for (auto input : inputs) { + node["inputNames"][std::to_string(input)]["val"] = rhs.inputNames[input]; + } + for (int i = 0; i < CPN_MAX_CURVES; i++) { const CurveData& curve = rhs.curves[i]; if (!curve.isEmpty()) { @@ -308,7 +310,9 @@ Node convert::encode(const ModelData& rhs) YAML::Node points; YamlWriteCurvePoints(points, rhs.curves); - node["points"] = points; + if (points && (points.IsMap() || points.IsSequence())) { + node["points"] = points; + } // logicalSw[] // customFn[] @@ -384,7 +388,6 @@ bool convert::decode(const Node& node, ModelData& rhs) node["inputNames"] >> rhs.inputNames; node["expoData"] >> rhs.expoData; - // curves[] node["curves"] >> rhs.curves; YamlReadCurvePoints(node["points"], rhs.curves); diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 262ed4ac5..b057c56df 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -294,25 +294,39 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) return false; } + bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories); + EtxModelfiles modelFiles; for (const auto& model : radioData.models) { - // TODO: verify '.yml' (in case we moved from '.bin') - QString modelFilename = QString("MODELS/%1").arg(model.filename); + qDebug() << "Model index: " << model.modelIndex; + if (model.isEmpty()) + continue; + + // TODO: verify '.yml' (in case we moved from '.bin') + + QString modelFilename; + if (hasCategories) { + modelFilename = QString("MODELS/%1").arg(model.filename); + modelFiles.push_back({ std::string(model.filename), model.category }); + } else { + modelFilename = QString("MODELS/model%1").arg(model.modelIndex, 2, QLatin1Char('0')); + } + QByteArray modelData; writeModelToYaml(model, modelData); if (!writeFile(modelData, modelFilename)) { return false; } - - modelFiles.push_back({ std::string(model.filename), model.category }); } - // TODO: sort 'modelFiles' by category index - QByteArray modelslistBuffer; - if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer) - || !writeFile(modelslistBuffer, "MODELS/models.yml")) { - return false; + if (hasCategories) { + // TODO: sort 'modelFiles' by category index + QByteArray modelslistBuffer; + if (!writeModelsListToYaml(radioData.categories, modelFiles, modelslistBuffer) + || !writeFile(modelslistBuffer, "MODELS/models.yml")) { + return false; + } } // force error to avoid overwriting the archive... From 2d47701b722a0f160b77b0e10204853a16e2eb82 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 5 Dec 2021 06:03:05 +1100 Subject: [PATCH 051/180] Fix compiler warnings --- companion/src/firmwares/boards.cpp | 2 +- companion/src/firmwares/edgetx/edgetxinterface.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index b8b17406e..014b63cca 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -583,7 +583,7 @@ StringTagMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) QString Boards::getAnalogInputName(Board::Type board, int index) { const StringTagMappingTable& lut = getAnalogNamesLookupTable(board); - if (index < lut.size()) + if (index < (int)lut.size()) return QString::fromStdString(lut[index].name); return CPN_STR_UNKNOWN_ITEM; diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index ca51cfa92..8c704ef92 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -67,13 +67,13 @@ bool loadModelsListFromYaml(std::vector& categories, } } } - + } catch (const std::runtime_error& e) { qDebug() << "YAML::ParserException: " << e.what(); return false; } - return true; + return true; } bool loadModelFromYaml(ModelData& model, const QByteArray& data) @@ -116,7 +116,7 @@ bool writeModelsListToYaml(const std::vector& categories, YAML::Node cat_attrs; cat_attrs["filename"] = modelFile.first; - if (modelFile.second >= categories.size()) { + if (modelFile.second >= (int)categories.size()) { return false; } @@ -132,7 +132,7 @@ bool writeModelToYaml(const ModelData& model, QByteArray& data) { YAML::Node node; node = model; - + writeYamlToByteArray(node, data); return true; } From 136d14af297fcf8303b78c35f1ad3a2e3c6731e7 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 5 Dec 2021 06:49:10 +1100 Subject: [PATCH 052/180] Fix model file name extensions --- companion/src/firmwares/radiodata.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/radiodata.cpp b/companion/src/firmwares/radiodata.cpp index c833281fd..56f68a5c8 100644 --- a/companion/src/firmwares/radiodata.cpp +++ b/companion/src/firmwares/radiodata.cpp @@ -39,7 +39,8 @@ void RadioData::fixModelFilename(unsigned int index) { ModelData & model = models[index]; QString filename(model.filename); - bool ok = filename.endsWith(".bin"); + const bool hasSDCard = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::HasSDCard); + bool ok = hasSDCard ? filename.endsWith(".yml") : filename.endsWith(".bin"); if (ok) { if (filename.startsWith("model") && filename.mid(5, filename.length()-9).toInt() > 0) { ok = false; @@ -54,7 +55,7 @@ void RadioData::fixModelFilename(unsigned int index) } } if (!ok) { - sprintf(model.filename, "model%d.bin", index+1); + sprintf(model.filename, "model%d.%s", index + 1, hasSDCard ? "yml" : "bin"); } } @@ -68,11 +69,12 @@ void RadioData::fixModelFilenames() QString RadioData::getNextModelFilename() { + const bool hasSDCard = Boards::getCapability(getCurrentFirmware()->getBoard(), Board::HasSDCard); char filename[sizeof(ModelData::filename)]; int index = 0; bool found = true; while (found) { - sprintf(filename, "model%d.bin", ++index); + sprintf(filename, "model%d.%s", ++index, hasSDCard ? "yml" : "bin"); found = false; for (unsigned int i=0; i Date: Sun, 5 Dec 2021 07:49:06 +1100 Subject: [PATCH 053/180] Fix raw switch encode --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index af1a9f0ea..b43fea0db 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -63,7 +63,8 @@ Node convert::encode(const RawSwitch& rhs) switch (rhs.type) { case SWITCH_TYPE_SWITCH: sw_str += 'S'; - sw_str += 'A' + sval; + sw_str += 'A' + (sval - 1) / 3; + sw_str += std::to_string((sval - 1) % 3); break; case SWITCH_TYPE_VIRTUAL: From b07114069228fe736148a20d7dae70b04ebf3ea7 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 5 Dec 2021 08:28:11 +1100 Subject: [PATCH 054/180] Set current data format version --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 2 ++ companion/src/firmwares/edgetx/edgetxinterface.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 8c704ef92..315b9ee71 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -139,6 +139,8 @@ bool writeModelToYaml(const ModelData& model, QByteArray& data) bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) { + settings.version = CURRENT_DATA_VERSION; + YAML::Node node; node = settings; diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index e3743c829..64f95d12e 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -27,6 +27,8 @@ #include #include +constexpr unsigned int CURRENT_DATA_VERSION = { 221 }; + typedef std::pair EtxModelfileCategoryPair; typedef std::list EtxModelfiles; From e679af93512ea0067431fc8107f6dc907b9223c5 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 5 Dec 2021 08:36:47 +1100 Subject: [PATCH 055/180] Revert "Set current data format version" This reverts commit cbc856c6520b4043f53b38d83efd65b9fcaf4875. --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 2 -- companion/src/firmwares/edgetx/edgetxinterface.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 315b9ee71..8c704ef92 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -139,8 +139,6 @@ bool writeModelToYaml(const ModelData& model, QByteArray& data) bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) { - settings.version = CURRENT_DATA_VERSION; - YAML::Node node; node = settings; diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index 64f95d12e..e3743c829 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -27,8 +27,6 @@ #include #include -constexpr unsigned int CURRENT_DATA_VERSION = { 221 }; - typedef std::pair EtxModelfileCategoryPair; typedef std::list EtxModelfiles; From 80c62bb1f01827c6153ad037749c3ec7f595b6e6 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 5 Dec 2021 14:45:39 +0100 Subject: [PATCH 056/180] Module settings --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/edgetx/yaml_modeldata.cpp | 11 +- .../src/firmwares/edgetx/yaml_moduledata.cpp | 390 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_moduledata.h | 31 ++ 4 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_moduledata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_moduledata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 926ad2da8..e298b2a82 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -41,6 +41,7 @@ set(firmwares_SRCS edgetx/yaml_mixdata.cpp edgetx/yaml_expodata.cpp edgetx/yaml_curvedata.cpp + edgetx/yaml_moduledata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b348a375b..ffca31292 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -24,6 +24,7 @@ #include "yaml_rawsource.h" #include "yaml_expodata.h" #include "yaml_curvedata.h" +#include "yaml_moduledata.h" #include "modeldata.h" #include "output_data.h" @@ -338,7 +339,12 @@ Node convert::encode(const ModelData& rhs) node["trainerMode"] = trainerModeLut << rhs.trainerMode; - // moduleData[] + for (int i=0; i::decode(const Node& node, ModelData& rhs) // rssiAlarms node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; - - // moduleData[] + node["moduleData"] >> rhs.moduleData; // scriptData[] // sensorData[] diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.cpp b/companion/src/firmwares/edgetx/yaml_moduledata.cpp new file mode 100644 index 000000000..9fb1f407e --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_moduledata.cpp @@ -0,0 +1,390 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_moduledata.h" +#include "moduledata.h" +#include "rawsource.h" + +// type: TYPE_MULTIMODULE +// subType: 15,2 +// channelsStart: 0 +// channelsCount: 12 +// failsafeMode: NOT_SET +// mod: +// multi: +// disableTelemetry: 0 +// disableMapping: 0 +// autoBindMode: 0 +// lowPowerMode: 0 +// optionValue: 0 +// receiverTelemetryOff: 0 +// receiverHigherChannels: 0 + +static const YamlLookupTable protocolLut = { + { PULSES_OFF, "TYPE_NONE" }, + { PULSES_PPM, "TYPE_PPM" }, + { PULSES_PXX_XJT_X16, "TYPE_XJT_PXX1" }, + { PULSES_ACCESS_ISRM, "TYPE_ISRM_PXX2" }, + { PULSES_LP45, "TYPE_DSM2" }, + { PULSES_CROSSFIRE, "TYPE_CROSSFIRE" }, + { PULSES_MULTIMODULE, "TYPE_MULTIMODULE" }, + { PULSES_PXX_R9M, "TYPE_R9M_PXX1" }, + { PULSES_ACCESS_R9M, "TYPE_R9M_PXX2" }, + { PULSES_PXX_R9M_LITE, "TYPE_R9M_LITE_PXX1" }, + { PULSES_ACCESS_R9M_LITE, "TYPE_R9M_LITE_PXX2" }, + { PULSES_GHOST, "TYPE_GHOST" }, + { PULSES_ACCESS_R9M_LITE_PRO, "TYPE_R9M_LITE_PRO_PXX2" }, + { PULSES_SBUS, "TYPE_SBUS" }, + { PULSES_XJT_LITE_X16, "TYPE_XJT_LITE_PXX2" }, + { PULSES_AFHDS3, "TYPE_FLYSKY" }, +}; + +static const YamlLookupTable xjtLut = { + { 0, "D16" }, + { 1, "D8" }, + { 2, "LR12" }, +}; + +static const YamlLookupTable isrmLut = { + { 0, "ACCESS" }, + { 1, "D16" }, +}; + +static const YamlLookupTable r9mLut = { + { MODULE_SUBTYPE_R9M_FCC, "FCC" }, + { MODULE_SUBTYPE_R9M_EU, "EU" }, + { MODULE_SUBTYPE_R9M_EUPLUS, "EUPLUS" }, + { MODULE_SUBTYPE_R9M_AUPLUS, "AUPLUS" }, +}; + +static const YamlLookupTable dsmLut = { + { 0, "LP45" }, + { 1, "DSM2" }, + { 3, "DSMX" }, +}; + +static const YamlLookupTable failsafeLut = { + { FAILSAFE_NOT_SET, "NOT_SET" }, + { FAILSAFE_HOLD, "HOLD" }, + { FAILSAFE_CUSTOM, "CUSTOM" }, + { FAILSAFE_NOPULSES, "NOPULSES" }, + { FAILSAFE_RECEIVER, "RECEIVER" }, +}; + +enum MMRFrskySubtypes { + MM_RF_FRSKY_SUBTYPE_D16, + MM_RF_FRSKY_SUBTYPE_D8, + MM_RF_FRSKY_SUBTYPE_D16_8CH, + MM_RF_FRSKY_SUBTYPE_V8, + MM_RF_FRSKY_SUBTYPE_D16_LBT, + MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH, + MM_RF_FRSKY_SUBTYPE_D8_CLONED, + MM_RF_FRSKY_SUBTYPE_D16_CLONED +}; + +// from radio/src/pulses/multi.cpp +static void convertMultiProtocolToEtx(int *protocol, int *subprotocol) +{ + if (*protocol == 3 && *subprotocol == 0) { + *protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1; + *subprotocol = MM_RF_FRSKY_SUBTYPE_D8; + return; + } + + if (*protocol == 3 && *subprotocol == 1) { + *protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1; + *subprotocol = MM_RF_FRSKY_SUBTYPE_D8_CLONED; + return; + } + + if (*protocol == 25) { + *protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1; + *subprotocol = MM_RF_FRSKY_SUBTYPE_V8; + return; + } + + if (*protocol == 15) { + *protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1; + + if (*subprotocol == 0) + *subprotocol = MM_RF_FRSKY_SUBTYPE_D16; + else if (*subprotocol == 1) + *subprotocol = MM_RF_FRSKY_SUBTYPE_D16_8CH; + else if (*subprotocol == 2) + *subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT; + else if (*subprotocol == 3) + *subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH; + else if (*subprotocol == 4) + *subprotocol = MM_RF_FRSKY_SUBTYPE_D16_CLONED; + + return; + } + + if (*protocol >= 25) + *protocol -= 1; + + if (*protocol >= 16) + *protocol -= 1; +} + +void convertEtxProtocolToMulti(int *protocol, int *subprotocol) +{ + // Special treatment for the FrSky entry... + if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY + 1) { + if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D8) { + //D8 + *protocol = 3; + *subprotocol = 0; + } + else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D8_CLONED) { + //D8 + *protocol = 3; + *subprotocol = 1; + } + else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_V8) { + //V8 + *protocol = 25; + *subprotocol = 0; + } + else { + *protocol = 15; + if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D16_8CH) + *subprotocol = 1; + else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D16) + *subprotocol = 0; // D16 + else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D16_LBT) + *subprotocol = 2; + else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH) + *subprotocol = 3; + else + *subprotocol = 4; // D16_CLONED + } + } + else { + // 15 for Multimodule is FrskyX or D16 which we map as a protocol of 3 (FrSky) + // all protos > frskyx are therefore also off by one + if (*protocol >= 15) + *protocol += 1; + // 25 is again a FrSky *protocol (FrskyV) so shift again + if (*protocol >= 25) + *protocol += 1; + } +} + +namespace YAML +{ +Node convert::encode(const ModuleData& rhs) +{ + Node node; + int protocol = rhs.protocol; + int subtype = rhs.subType; + if (rhs.protocol >= PULSES_LP45 && rhs.protocol <= PULSES_DSMX) { + protocol = PULSES_LP45; + subtype = rhs.protocol - PULSES_LP45; + } else if (rhs.protocol == PULSES_ACCST_ISRM_D16 || rhs.protocol == PULSES_ACCESS_ISRM) { + protocol = PULSES_ACCESS_ISRM; + subtype = rhs.protocol - PULSES_ACCESS_ISRM; + } else if (rhs.protocol >= PULSES_PXX_XJT_X16 && rhs.protocol <= PULSES_PXX_XJT_LR12) { + protocol = PULSES_PXX_XJT_X16; + subtype = rhs.protocol - PULSES_PXX_XJT_X16; + } else if (rhs.protocol >= PULSES_XJT_LITE_X16 && rhs.protocol <= PULSES_XJT_LITE_LR12) { + protocol = PULSES_XJT_LITE_X16; + subtype = rhs.protocol - PULSES_XJT_LITE_X16; + } + node["type"] = LookupValue(protocolLut, protocol); + + switch (protocol) { + case PULSES_PXX_XJT_X16: + case PULSES_XJT_LITE_X16: + node["subType"] = LookupValue(xjtLut, subtype); + break; + case PULSES_ACCESS_ISRM: + node["subType"] = LookupValue(isrmLut, subtype); + break; + case PULSES_PXX_R9M: + case PULSES_PXX_R9M_LITE: + node["subType"] = LookupValue(r9mLut, subtype); + break; + case PULSES_LP45: + node["subType"] = LookupValue(dsmLut, subtype); + break; + case PULSES_MULTIMODULE: { + int rfProtocol = rhs.multi.rfProtocol + 1; + int subType = rhs.subType; + convertEtxProtocolToMulti(&rfProtocol, &subType); + std::string st_str = std::to_string(rfProtocol); + st_str += ","; + st_str += std::to_string(subType); + node["subType"] = st_str; + } break; + } + + node["channelsStart"] = rhs.channelsStart; + node["channelsCount"] = rhs.channelsCount; + node["failsafeMode"] = LookupValue(failsafeLut, rhs.failsafeMode); + + Node mod; + switch (protocol) { + case PULSES_PXX_XJT_X16: + case PULSES_PXX_R9M: + case PULSES_PXX_R9M_LITE: { + Node pxx; + pxx["power"] = rhs.pxx.power; + // pxx["receiverTelemetryOff"] = rhs.pxx.receiverTelemetryOff; + // pxx["receiverHigherChannels"] = rhs.pxx.receiverHigherChannels; + pxx["antennaMode"] = rhs.pxx.antennaMode; + mod["pxx"] = pxx; + } break; + case PULSES_ACCESS_ISRM: + case PULSES_ACCESS_R9M: + case PULSES_ACCESS_R9M_LITE: + case PULSES_ACCESS_R9M_LITE_PRO: + case PULSES_XJT_LITE_X16: { + Node pxx2; + pxx2["receivers"] = rhs.access.receivers; + pxx2["racingMode"] = rhs.access.racingMode; + for (int i=0; i::decode(const Node& node, ModuleData& rhs) +{ + node["type"] >> protocolLut >> rhs.protocol; + + Node subType; + node["subType"] >> subType; + + switch (rhs.protocol) { + case PULSES_PXX_XJT_X16: + case PULSES_XJT_LITE_X16: { + int subProto = 0; + subType >> xjtLut >> subProto; + rhs.protocol += subProto; + } break; + case PULSES_ACCESS_ISRM: { + int subProto = 0; + subType >> isrmLut >> subProto; + rhs.protocol += subProto; + } break; + case PULSES_PXX_R9M: + case PULSES_PXX_R9M_LITE: { + subType >> r9mLut >> rhs.subType; + } break; + case PULSES_LP45: { + int subProto = 0; + subType >> dsmLut >> subProto; + rhs.protocol += subProto; + } break; + case PULSES_MULTIMODULE: { + std::string st_str; + subType >> st_str; + if (!st_str.empty()) { + size_t pos = 0; + int rfProtocol = std::stoi(st_str, &pos); + st_str = st_str.substr(pos + 1); + int rfSubType = std::stoi(st_str); + convertMultiProtocolToEtx(&rfProtocol, &rfSubType); + if (rfProtocol > 0) { + rhs.multi.rfProtocol = rfProtocol - 1; + rhs.subType = rfSubType; + } + } + } break; + } + + node["channelsStart"] >> rhs.channelsStart; + node["channelsCount"] >> rhs.channelsCount; + node["failsafeMode"] >> failsafeLut >> rhs.failsafeMode; + + if (node["mod"]) { + Node mod = node["mod"]; + if (mod["ppm"]) { + Node ppm = mod["ppm"]; + ppm["delay"] >> rhs.ppm.delay; + ppm["pulsePol"] >> rhs.ppm.pulsePol; + ppm["outputType"] >> rhs.ppm.outputType; + ppm["frameLength"] >> rhs.ppm.frameLength; + } else if (mod["multi"]) { + Node multi = mod["multi"]; + multi["disableTelemetry"] >> rhs.multi.disableTelemetry; + multi["disableMapping"] >> rhs.multi.disableMapping; + multi["autoBindMode"] >> rhs.multi.autoBindMode; + multi["lowPowerMode"] >> rhs.multi.lowPowerMode; + multi["optionValue"] >> rhs.multi.optionValue; + // multi["receiverTelemetryOff"] >> rhs.pxx.receiverTelemetryOff; + // multi["receiverHigherChannels"] >> rhs.pxx.receiverHigherChannels; + } else if (mod["pxx"]) { + Node pxx = mod["pxx"]; + pxx["power"] >> rhs.pxx.power; + // pxx["receiverTelemetryOff"] >> rhs.pxx.receiverTelemetryOff; + // pxx["receiverHigherChannels"] >> rhs.pxx.receiverHigherChannels; + pxx["antennaMode"] >> rhs.pxx.antennaMode; + } else if (mod["sbus"]) { + mod["sbus"]["refreshRate"] >> rhs.ppm.frameLength; + } else if (mod["pxx2"]) { + Node pxx2 = mod["pxx2"]; + pxx2["receivers"] >> rhs.access.receivers; + pxx2["racingMode"] >> rhs.access.racingMode; + for (const auto& rx : pxx2["receiverName"]) { + rx >> rhs.access.receiverName; + } + } else if (mod["flysky"]) { + //TODO + } else if (mod["afhds3"]) { + //TODO + } + } + + return true; +} +} diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.h b/companion/src/firmwares/edgetx/yaml_moduledata.h new file mode 100644 index 000000000..90b4cb67b --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_moduledata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "moduledata.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const ModuleData& rhs); + static bool decode(const Node& node, ModuleData& rhs); +}; +} // namespace YAML From c6b23797a728edc2a4fc5fe9fa0451d6677716a7 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 5 Dec 2021 17:22:16 +0100 Subject: [PATCH 057/180] Logical switches --- companion/src/firmwares/CMakeLists.txt | 1 + .../edgetx/yaml_logicalswitchdata.cpp | 186 ++++++++++++++++++ .../firmwares/edgetx/yaml_logicalswitchdata.h | 31 +++ .../src/firmwares/edgetx/yaml_modeldata.cpp | 13 +- .../src/firmwares/edgetx/yaml_rawsource.cpp | 24 ++- .../src/firmwares/edgetx/yaml_rawsource.h | 5 +- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 28 ++- .../src/firmwares/edgetx/yaml_rawswitch.h | 3 + 8 files changed, 269 insertions(+), 22 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_logicalswitchdata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index e298b2a82..c2b258537 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -42,6 +42,7 @@ set(firmwares_SRCS edgetx/yaml_expodata.cpp edgetx/yaml_curvedata.cpp edgetx/yaml_moduledata.cpp + edgetx/yaml_logicalswitchdata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp new file mode 100644 index 000000000..10b3b133e --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_logicalswitchdata.h" +#include "yaml_rawswitch.h" +#include "yaml_rawsource.h" + +static const YamlLookupTable funcLut = { + {LS_FN_OFF, "FUNC_NONE"}, + {LS_FN_VEQUAL, "FUNC_VEQUAL"}, + {LS_FN_VALMOSTEQUAL, "FUNC_VALMOSTEQUAL"}, + {LS_FN_VPOS, "FUNC_VPOS"}, + {LS_FN_VNEG, "FUNC_VNEG"}, + {LS_FN_APOS, "FUNC_APOS"}, + {LS_FN_ANEG, "FUNC_ANEG"}, + {LS_FN_AND, "FUNC_AND"}, + {LS_FN_OR, "FUNC_OR"}, + {LS_FN_XOR, "FUNC_XOR"}, + {LS_FN_EDGE, "FUNC_EDGE"}, + {LS_FN_EQUAL, "FUNC_EQUAL"}, + {LS_FN_GREATER, "FUNC_GREATER"}, + {LS_FN_LESS, "FUNC_LESS"}, + {LS_FN_DPOS, "FUNC_DIFFEGREATER"}, + {LS_FN_DAPOS, "FUNC_ADIFFEGREATER"}, + {LS_FN_TIMER, "FUNC_TIMER"}, + {LS_FN_STICKY, "FUNC_STICKY"}, +}; + +static int timerValue2lsw(uint32_t t) +{ + if (t < 20) { + return t - 129; + } else if (600) { + return t / 5 - 113; + } else { + return t / 10 - 53; + } +} +// val = [-129,-110] => [0,19] (step 1) +// val = [-109,6] => [20,595] (step 5) +// val = [7,122] => [600,1750] (step 10) +// +static int lswTimerValue(int val) +{ + return (val < -109 ? 129+val : (val < 7 ? (113+val)*5 : (53+val)*10)); +} + +namespace YAML +{ +Node convert::encode(const LogicalSwitchData& rhs) +{ + Node node; + node["func"] = funcLut << rhs.func; + + std::string def; + + switch (rhs.getFunctionFamily()) { + case LS_FAMILY_VBOOL: + case LS_FAMILY_STICKY: { + def += YamlRawSwitchEncode(RawSwitch(rhs.val1)); + def += ","; + def += YamlRawSwitchEncode(RawSwitch(rhs.val2)); + } break; + + case LS_FAMILY_EDGE: { + def += YamlRawSwitchEncode(RawSwitch(rhs.val1)); + def += ","; + def += std::to_string(lswTimerValue(rhs.val2)); + def += ","; + def += std::to_string(lswTimerValue(rhs.val3)); + } break; + + case LS_FAMILY_VCOMP: { + def += YamlRawSourceEncode(RawSource(rhs.val1)); + def += ","; + def += YamlRawSourceEncode(RawSource(rhs.val2)); + } break; + + case LS_FAMILY_TIMER: { + def += std::to_string(lswTimerValue(rhs.val1)); + def += ","; + def += std::to_string(lswTimerValue(rhs.val2)); + } break; + + default: { + def += YamlRawSourceEncode(RawSource(rhs.val1)); + def += ","; + def += std::to_string(rhs.val2); + } break; + } + + node["def"] = def; + node["delay"] = rhs.delay; + node["duration"] = rhs.duration; + node["andsw"] = YamlRawSwitchEncode(RawSwitch(rhs.andsw)); + + return node; +} + +bool convert::decode(const Node& node, + LogicalSwitchData& rhs) +{ + node["func"] >> funcLut >> rhs.func; + + std::string def_str; + node["def"] >> def_str; + std::stringstream def(def_str); + + switch (rhs.getFunctionFamily()) { + case LS_FAMILY_VBOOL: + case LS_FAMILY_STICKY: { + std::string sw_str; + getline(def, sw_str, ','); + rhs.val1 = YamlRawSwitchDecode(sw_str).toValue(); + rhs.val2 = YamlRawSwitchDecode(def.str()).toValue(); + } break; + + case LS_FAMILY_EDGE: { + std::string sw_str; + getline(def, sw_str, ','); + rhs.val1 = YamlRawSwitchDecode(sw_str).toValue(); + int v2=0, v3=0; + def >> v2; + rhs.val2 = timerValue2lsw(v2); + def.ignore(); + if (def.peek() == '<') { + rhs.val3 = -1; + } else if (def.peek() == '-') { + rhs.val3 = 0; + } else { + def >> v3; + rhs.val3 = timerValue2lsw(v3); + } + } break; + + case LS_FAMILY_VCOMP: { + std::string src_str; + getline(def, src_str, ','); + rhs.val1 = YamlRawSourceDecode(src_str).toValue(); + rhs.val2 = YamlRawSourceDecode(def.str()).toValue(); + } break; + + case LS_FAMILY_TIMER: { + int v1=0, v2=0; + def >> v1; + rhs.val1 = timerValue2lsw(v1); + def.ignore(); + def >> v2; + rhs.val2 = timerValue2lsw(v2); + } break; + + default: { + std::string src_str; + getline(def, src_str, ','); + rhs.val1 = YamlRawSourceDecode(src_str).toValue(); + def >> rhs.val2; + } break; + } + + node["delay"] >> rhs.delay; + node["duration"] >> rhs.duration; + + RawSwitch andsw; + node["andsw"] >> andsw; + rhs.andsw = andsw.toValue(); + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.h b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.h new file mode 100644 index 000000000..738a6fc8a --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "logicalswitchdata.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const LogicalSwitchData& rhs); + static bool decode(const Node& node, LogicalSwitchData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index ffca31292..242e95f1c 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -25,6 +25,7 @@ #include "yaml_expodata.h" #include "yaml_curvedata.h" #include "yaml_moduledata.h" +#include "yaml_logicalswitchdata.h" #include "modeldata.h" #include "output_data.h" @@ -315,7 +316,13 @@ Node convert::encode(const ModelData& rhs) node["points"] = points; } - // logicalSw[] + for (int i = 0; i < CPN_MAX_LOGICAL_SWITCHES; i++) { + const LogicalSwitchData& ls = rhs.logicalSw[i]; + if (!ls.isEmpty()) { + node["logicalSw"][std::to_string(i)] = ls; + } + } + // customFn[] // swashRingData @@ -397,8 +404,8 @@ bool convert::decode(const Node& node, ModelData& rhs) node["curves"] >> rhs.curves; YamlReadCurvePoints(node["points"], rhs.curves); - // logicalSw[] - // customFn[] + node["logicalSw"] >> rhs.logicalSw; + node["customFn"] >> rhs.customFn; // swashRingData diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index e05c10dd2..fc6f41103 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -51,8 +51,7 @@ const YamlLookupTable specialSourceLut = { // TODO: { ???, "TX_GPS" }, }; -namespace YAML { -Node convert::encode(const RawSource& rhs) +std::string YamlRawSourceEncode(const RawSource& rhs) { std::string src_str; switch (rhs.type) { @@ -123,13 +122,12 @@ Node convert::encode(const RawSource& rhs) src_str = "NONE"; break; } - - return Node(src_str); + return src_str; } -bool convert::decode(const Node& node, RawSource& rhs) +RawSource YamlRawSourceDecode(const std::string& src_str) { - std::string src_str = node.Scalar(); + RawSource rhs; const char* val = src_str.data(); size_t val_len = src_str.size(); @@ -252,8 +250,20 @@ bool convert::decode(const Node& node, RawSource& rhs) rhs.index = 0; } } - // TODO: raw analogs + + return rhs; +} +namespace YAML { +Node convert::encode(const RawSource& rhs) +{ + return Node(YamlRawSourceEncode(rhs)); +} + +bool convert::decode(const Node& node, RawSource& rhs) +{ + std::string src_str = node.Scalar(); + rhs = YamlRawSourceDecode(src_str); return true; } } // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.h b/companion/src/firmwares/edgetx/yaml_rawsource.h index 6cf25ba82..9775793b5 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.h +++ b/companion/src/firmwares/edgetx/yaml_rawsource.h @@ -21,12 +21,13 @@ #include "yaml_ops.h" #include "rawsource.h" -namespace YAML { +std::string YamlRawSourceEncode(const RawSource& rhs); +RawSource YamlRawSourceDecode(const std::string& src_str); +namespace YAML { template <> struct convert { static Node encode(const RawSource& rhs); static bool decode(const Node& node, RawSource& rhs); }; - } diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index b43fea0db..59727c179 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -46,14 +46,9 @@ const YamlLookupTable switchTypeLut = { { SWITCH_TYPE_OFF, "OFF" }, }; -namespace YAML { - -ENUM_CONVERTER(RawSwitchType, switchTypeLut); - -Node convert::encode(const RawSwitch& rhs) +std::string YamlRawSwitchEncode(const RawSwitch& rhs) { std::string sw_str; - int32_t sval = rhs.index; if (rhs.index < 0) { sval = -sval; @@ -96,13 +91,12 @@ Node convert::encode(const RawSwitch& rhs) sw_str += LookupValue(switchTypeLut, rhs.type); break; } - - return Node(sw_str); + return sw_str; } -bool convert::decode(const Node& node, RawSwitch& rhs) +RawSwitch YamlRawSwitchDecode(const std::string& sw_str) { - const std::string& sw_str = node.Scalar(); + RawSwitch rhs; const char* val = sw_str.data(); size_t val_len = sw_str.size(); @@ -147,7 +141,21 @@ bool convert::decode(const Node& node, RawSwitch& rhs) if (neg) { rhs.index = -rhs.index; } + return rhs; +} +namespace YAML { + +ENUM_CONVERTER(RawSwitchType, switchTypeLut); + +Node convert::encode(const RawSwitch& rhs) +{ + return Node(YamlRawSwitchEncode(rhs)); +} + +bool convert::decode(const Node& node, RawSwitch& rhs) +{ + rhs = YamlRawSwitchDecode(node.Scalar()); return true; } } // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.h b/companion/src/firmwares/edgetx/yaml_rawswitch.h index 95128aac2..fa0a824a1 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.h +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.h @@ -21,6 +21,9 @@ #include "yaml_ops.h" #include "rawswitch.h" +std::string YamlRawSwitchEncode(const RawSwitch& rhs); +RawSwitch YamlRawSwitchDecode(const std::string& sw_str); + namespace YAML { template <> From 112a606ed5a8437d1d6692d81aa8396487083400 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 8 Dec 2021 07:30:18 +1100 Subject: [PATCH 058/180] Add version checks and enforce current version on write --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 8 ++++++++ companion/src/firmwares/edgetx/edgetxinterface.h | 2 ++ .../src/firmwares/edgetx/yaml_generalsettings.h | 13 +++++++------ companion/src/firmwares/opentx/opentxinterface.cpp | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 8c704ef92..3ca78fccc 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -94,6 +94,14 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data try { YAML::Node node = loadYamlFromByteArray(data); node >> settings; + if (settings.version < CPN_CURRENT_SETTINGS_VERSION) { + qDebug() << "Older version of settings detected:" << settings.version; + } + else if (settings.version > CPN_CURRENT_SETTINGS_VERSION) { + qDebug() << "Newer version of settings detected:" << settings.version; + QMessageBox::critical(NULL, CPN_STR_APP_NAME, QCoreApplication::translate("EdgeTXInterface", "Companion does not support settings version %1!").arg(settings.version)); + return false; + } } catch (const std::runtime_error& e) { qDebug() << "YAML::ParserException: " << e.what(); return false; diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index e3743c829..e82771562 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -27,6 +27,8 @@ #include #include +constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 }; + typedef std::pair EtxModelfileCategoryPair; typedef std::list EtxModelfiles; diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index 2548d6b73..cd398631b 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -25,6 +25,7 @@ #include "generalsettings.h" #include "eeprominterface.h" +#include "edgetxinterface.h" extern const YamlLookupTable beeperModeLut; extern const YamlLookupTable backlightModeLut; @@ -41,8 +42,8 @@ namespace YAML { static YAML::Node encode(const GeneralSettings& rhs) { Node node; - - node["version"] = rhs.version; + + node["version"] = CPN_CURRENT_SETTINGS_VERSION; // Radio calib YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); @@ -135,11 +136,11 @@ namespace YAML { static bool decode(const Node& node, GeneralSettings& rhs) { if (!node.IsMap()) return false; - + // for (const auto& n : node) { // qDebug() << QString::fromStdString(n.first.Scalar()); // } - + // TODO: check board string and fetch Board instance std::string board; node["board"] >> board; @@ -226,7 +227,7 @@ namespace YAML { YamlStickConfig stickConfig; node["sticksConfig"] >> stickConfig; stickConfig.copy(rhs.stickName); - + YamlSwitchConfig switchConfig; node["switchConfig"] >> switchConfig; switchConfig.copy(rhs.switchName, rhs.switchConfig); @@ -250,7 +251,7 @@ namespace YAML { // OneBit sampling (X9D only?) node["uartSampleMode"] >> rhs.uartSampleMode; - + return true; } }; diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 2ca769f35..e3e9761b5 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -254,7 +254,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t * errors.set(HAS_WARNINGS); } else if (version_error == NOT_OPENTX) { - dbg << " not open9x"; + dbg << " not OpenTX"; errors.set(version_error); return errors.to_ulong(); } @@ -286,7 +286,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t * uint8_t OpenTxEepromInterface::getLastDataVersion(Board::Type board) { - return 220; + return 220; // Note: this is the last bin format before the switch to YAML introduced in Companion version 2.6 } void OpenTxEepromInterface::showErrors(const QString & title, const QStringList & errors) From 7fc49637599b575aedae51185cfc07ae8626e7f8 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 8 Dec 2021 10:44:22 +0100 Subject: [PATCH 059/180] Some fixes --- .../edgetx/yaml_logicalswitchdata.cpp | 6 +- .../src/firmwares/edgetx/yaml_modeldata.cpp | 2 +- .../src/firmwares/edgetx/yaml_rawsource.cpp | 55 ++++++++++--------- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 8 +-- 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp index 10b3b133e..852179b12 100644 --- a/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp @@ -129,7 +129,8 @@ bool convert::decode(const Node& node, std::string sw_str; getline(def, sw_str, ','); rhs.val1 = YamlRawSwitchDecode(sw_str).toValue(); - rhs.val2 = YamlRawSwitchDecode(def.str()).toValue(); + getline(def, sw_str); + rhs.val2 = YamlRawSwitchDecode(sw_str).toValue(); } break; case LS_FAMILY_EDGE: { @@ -154,7 +155,8 @@ bool convert::decode(const Node& node, std::string src_str; getline(def, src_str, ','); rhs.val1 = YamlRawSourceDecode(src_str).toValue(); - rhs.val2 = YamlRawSourceDecode(def.str()).toValue(); + getline(def, src_str); + rhs.val2 = YamlRawSourceDecode(src_str).toValue(); } break; case LS_FAMILY_TIMER: { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 242e95f1c..d565b63b2 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -405,7 +405,7 @@ bool convert::decode(const Node& node, ModelData& rhs) YamlReadCurvePoints(node["points"], rhs.curves); node["logicalSw"] >> rhs.logicalSw; - node["customFn"] >> rhs.customFn; + //node["customFn"] >> rhs.customFn; // swashRingData diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index fc6f41103..756aa0697 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -69,7 +69,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index); break; case SOURCE_TYPE_TRIM: - src_str = LookupValue(trimSourceLut, rhs.index); + src_str = YAML::LookupValue(trimSourceLut, rhs.index); break; case SOURCE_TYPE_MAX: src_str += "MAX"; @@ -84,7 +84,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_CYC: - src_str = LookupValue(cycSourceLut, rhs.index); + src_str = YAML::LookupValue(cycSourceLut, rhs.index); break; case SOURCE_TYPE_PPM: src_str += "tr("; @@ -102,7 +102,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_SPECIAL: - src_str = LookupValue(specialSourceLut, rhs.index); + src_str = YAML::LookupValue(specialSourceLut, rhs.index); break; case SOURCE_TYPE_TELEMETRY: src_str = "tele("; @@ -148,15 +148,11 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[2] == 'a' && val[3] == '(') { - src_str = src_str.substr(4); - - size_t next_pos = 0; - int script = std::stoi(src_str, &next_pos); - - if (next_pos >= src_str.size()) return false; - src_str = src_str.substr(next_pos + 1); - - int output = std::stoi(src_str); + std::stringstream src(src_str.substr(4)); + int script = 0, output = 0; + src >> script; + src.ignore(); + src >> output; rhs = RawSource(SOURCE_TYPE_LUA_OUTPUT, script * 16 + output); } else if (val_len > 3 && @@ -164,8 +160,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[1] == 's' && val[2] == '(') { - src_str = src_str.substr(3); - int ls = std::stoi(src_str); + std::stringstream src(src_str.substr(3)); + int ls = 0; + src >> ls; rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls); } else if (val_len > 3 && @@ -173,8 +170,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[1] == 'r' && val[2] == '(') { - src_str = src_str.substr(3); - int tr = std::stoi(src_str); + std::stringstream src(src_str.substr(3)); + int tr = 0; + src >> tr; rhs = RawSource(SOURCE_TYPE_PPM, tr); } else if (val_len > 3 && @@ -182,8 +180,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[1] == 'h' && val[2] == '(') { - src_str = src_str.substr(3); - int ch = std::stoi(src_str); + std::stringstream src(src_str.substr(3)); + int ch = 0; + src >> ch; rhs = RawSource(SOURCE_TYPE_CH, ch); } else if (val_len > 3 && @@ -191,8 +190,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[1] == 'v' && val[2] == '(') { - src_str = src_str.substr(3); - int gv = std::stoi(src_str); + std::stringstream src(src_str.substr(3)); + int gv = 0; + src >> gv; rhs = RawSource(SOURCE_TYPE_GVAR, gv); } else if (val_len > 5 && @@ -202,23 +202,26 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[3] == 'e' && val[4] == '(') { - src_str = src_str.substr(5); + std::stringstream src(src_str.substr(5)); // parse sign uint8_t sign = 0; - if (src_str[0] == '-') { + char c = src.peek(); + if (c == '-') { sign = 1; - src_str = src_str.substr(1); - } else if (src_str[0] == '+') { + src.ignore(); + } else if (c == '+') { sign = 2; - src_str = src_str.substr(1); + src.ignore(); } - int sensor = std::stoi(src_str); + int sensor = 0; + src >> sensor; rhs = RawSource(SOURCE_TYPE_TELEMETRY, sensor * 3 + sign); } else { + YAML::Node node(src_str); std::string ana_str; node >> ana_str; int ana_idx = getCurrentFirmware()->getAnalogInputIndex(ana_str.c_str()); diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 59727c179..0b9762009 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -74,7 +74,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; case SWITCH_TYPE_TRIM: - sw_str += LookupValue(trimSwitchLut, sval); + sw_str += YAML::LookupValue(trimSwitchLut, sval); break; case SWITCH_TYPE_FLIGHT_MODE: @@ -88,7 +88,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; default: - sw_str += LookupValue(switchTypeLut, rhs.type); + sw_str += YAML::LookupValue(switchTypeLut, rhs.type); break; } return sw_str; @@ -125,7 +125,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (sw_str.substr(0, 3) == std::string("Trim")) { // "Trim" rhs.type = SWITCH_TYPE_TRIM; - node >> trimSwitchLut >> rhs.index; + YAML::Node(sw_str) >> trimSwitchLut >> rhs.index; } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { @@ -134,7 +134,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) // TODO: check if we have a match? // or does RawSwitch default to NONE anyway? // - node >> rhs.type; + YAML::Node(sw_str) >> rhs.type; rhs.index = 0; } From 54f7f420314c9bf0e9ceaa65a9a974b82e97aee0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 8 Dec 2021 11:55:30 +0100 Subject: [PATCH 060/180] Fixed missing include --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 3ca78fccc..7c5b88dc8 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -24,6 +24,8 @@ #include "yaml_generalsettings.h" #include "yaml_modeldata.h" +#include + static YAML::Node loadYamlFromByteArray(const QByteArray& data) { // TODO: use real streaming to avoid memory copies From f6329895a83ed8a50e06d9e07ec57e9466d1aaf0 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 9 Dec 2021 07:33:50 +1100 Subject: [PATCH 061/180] Fix compiler warning --- .../src/firmwares/edgetx/yaml_moduledata.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.cpp b/companion/src/firmwares/edgetx/yaml_moduledata.cpp index 9fb1f407e..55d41058f 100644 --- a/companion/src/firmwares/edgetx/yaml_moduledata.cpp +++ b/companion/src/firmwares/edgetx/yaml_moduledata.cpp @@ -27,8 +27,8 @@ // channelsStart: 0 // channelsCount: 12 // failsafeMode: NOT_SET -// mod: -// multi: +// mod: +// multi: // disableTelemetry: 0 // disableMapping: 0 // autoBindMode: 0 @@ -152,17 +152,17 @@ void convertEtxProtocolToMulti(int *protocol, int *subprotocol) //D8 *protocol = 3; *subprotocol = 0; - } + } else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D8_CLONED) { //D8 *protocol = 3; *subprotocol = 1; - } + } else if (*subprotocol == MM_RF_FRSKY_SUBTYPE_V8) { //V8 *protocol = 25; *subprotocol = 0; - } + } else { *protocol = 15; if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D16_8CH) @@ -260,7 +260,7 @@ Node convert::encode(const ModuleData& rhs) Node pxx2; pxx2["receivers"] = rhs.access.receivers; pxx2["racingMode"] = rhs.access.racingMode; - for (int i=0; i::decode(const Node& node, ModuleData& rhs) node["channelsStart"] >> rhs.channelsStart; node["channelsCount"] >> rhs.channelsCount; node["failsafeMode"] >> failsafeLut >> rhs.failsafeMode; - + if (node["mod"]) { Node mod = node["mod"]; if (mod["ppm"]) { @@ -384,7 +384,7 @@ bool convert::decode(const Node& node, ModuleData& rhs) //TODO } } - + return true; } } From 23c84633da0d56cbd91e059434b04421343a7ac6 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 11 Dec 2021 09:06:14 +1100 Subject: [PATCH 062/180] Companion support for EXT3 EXT4 and FlySky gimbals --- companion/src/constants.h | 5 ++--- companion/src/firmwares/boards.cpp | 6 +++--- companion/src/firmwares/edgetx/yaml_switchconfig.cpp | 5 ++--- companion/src/firmwares/edgetx/yaml_switchconfig.h | 2 +- companion/src/firmwares/eeprominterface.h | 3 ++- companion/src/firmwares/generalsettings.cpp | 8 ++++++-- companion/src/firmwares/generalsettings.h | 4 ++-- companion/src/firmwares/modeldata.h | 4 ++-- companion/src/firmwares/opentx/opentxeeprom.cpp | 11 ++++++++++- companion/src/firmwares/opentx/opentxinterface.cpp | 9 +++++++++ companion/src/generaledit/calibration.cpp | 11 +++++++++-- companion/src/generaledit/hardware.cpp | 3 ++- companion/src/simulation/joystickdialog.cpp | 2 +- 13 files changed, 51 insertions(+), 22 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 4e66ff214..3bc547d81 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -38,15 +38,14 @@ #define CPN_MAX_MODULES 2 #define CPN_MAX_STICKS Board::STICK_AXIS_COUNT #define CPN_MAX_TRIMS Board::TRIM_AXIS_COUNT -#define CPN_MAX_KNOBS 8 +#define CPN_MAX_POTS 8 #define CPN_MAX_SLIDERS 4 -#define CPN_MAX_POTS (CPN_MAX_KNOBS + CPN_MAX_SLIDERS) #define CPN_MAX_CYC 3 #define CPN_MAX_SWITCHES 32 #define CPN_MAX_FUNCTION_SWITCHES 6 #define CPN_MAX_MOUSE_ANALOGS 2 #define CPN_MAX_GYRO_ANALOGS 2 -#define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) +#define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_SLIDERS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) #define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion") #define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 014b63cca..3f498b804 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -374,7 +374,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) else if (IS_TARANIS_X9E(board)) return 4; else if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) - return 5; + return 7; else if (IS_HORUS_X12S(board)) return 3; else if (IS_FLYSKY_NV14(board)) @@ -570,8 +570,8 @@ StringTagMappingTable Boards::getAnalogNamesLookupTable(Board::Type board) {"S2", "S2"}, {"EX1", "EXT1"}, {"EX2", "EXT2"}, - // {"EX3", "EXT3"}, - // {"EX4", "EXT4"}, + {"EX3", "EXT3"}, + {"EX4", "EXT4"}, {"LS", "LS"}, {"RS", "RS"}, }); diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 25d8ea75d..f10b21a80 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -41,9 +41,8 @@ const YamlLookupTable switchConfigLut = { }; const YamlLookupTable potsLut = { - {0, "S1"}, {1, "6POS"}, {2, "S2"}, {3, "EXT1"}, {4, "EXT2"}, - // { 5, "EXT3" }, - // { 6, "EXT4" }, + {0, "S1"}, {1, "6POS"}, {2, "S2"}, + {3, "EXT1"}, {4, "EXT2"}, {5, "EXT3"}, {6, "EXT4"}, }; const YamlLookupTable potConfigLut = { diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 0a846d15b..fbdd5b8b6 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -79,7 +79,7 @@ typedef YamlKnobConfig // name: extern const YamlLookupTable potsLut; extern const YamlLookupTable potConfigLut; -typedef YamlKnobConfig YamlPotConfig; +typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index cba7362fb..99a2a3953 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -167,7 +167,8 @@ enum Capability { TopBarZones, FunctionSwitches, Has, - HasModelsList + HasModelsList, + HasFlySkyGimbals }; class EEPROMInterface diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index 2ccb66254..c5b09e76f 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -54,14 +54,18 @@ bool GeneralSettings::switchSourceAllowedTaranis(int index) const bool GeneralSettings::isPotAvailable(int index) const { - if (index < 0 || index > Boards::getCapability(getCurrentBoard(), Board::Pots)) + int numPots = Boards::getCapability(getCurrentBoard(), Board::Pots); + if (getCurrentFirmware()->getCapability(HasFlySkyGimbals)) + numPots -= 2; + + if (index < 0 || index >= numPots) return false; return potConfig[index] != Board::POT_NONE; } bool GeneralSettings::isSliderAvailable(int index) const { - if (index < 0 || index > Boards::getCapability(getCurrentBoard(), Board::Sliders)) + if (index < 0 || index >= Boards::getCapability(getCurrentBoard(), Board::Sliders)) return false; return sliderConfig[index] != Board::SLIDER_NONE; } diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index 6904cc1a4..f7115cc46 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -231,8 +231,8 @@ class GeneralSettings { char switchName[CPN_MAX_SWITCHES][HARDWARE_NAME_LEN + 1]; unsigned int switchConfig[CPN_MAX_SWITCHES]; char stickName[CPN_MAX_STICKS][HARDWARE_NAME_LEN + 1]; - char potName[CPN_MAX_KNOBS][HARDWARE_NAME_LEN + 1]; - unsigned int potConfig[CPN_MAX_KNOBS]; + char potName[CPN_MAX_POTS][HARDWARE_NAME_LEN + 1]; + unsigned int potConfig[CPN_MAX_POTS]; char sliderName[CPN_MAX_SLIDERS][HARDWARE_NAME_LEN + 1]; unsigned int sliderConfig[CPN_MAX_SLIDERS]; diff --git a/companion/src/firmwares/modeldata.h b/companion/src/firmwares/modeldata.h index 6a1443c12..9eb918982 100644 --- a/companion/src/firmwares/modeldata.h +++ b/companion/src/firmwares/modeldata.h @@ -145,8 +145,8 @@ class ModelData { unsigned int switchWarningEnable; unsigned int thrTrimSwitch; unsigned int potsWarningMode; - bool potsWarnEnabled[CPN_MAX_POTS]; - int potsWarnPosition[CPN_MAX_POTS]; + bool potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]; + int potsWarnPosition[CPN_MAX_POTS + CPN_MAX_SLIDERS]; bool displayChecklist; GVarData gvarData[CPN_MAX_GVARS]; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 421138999..5017308cc 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -79,6 +79,8 @@ inline int MAX_POTS(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) return 3; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board))) + return 5; if (IS_FAMILY_T12(board)) return 2; return Boards::getCapability(board, Board::Pots); @@ -95,7 +97,7 @@ inline int MAX_POTS_STORAGE(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) return 3; - if (version >= 219 && IS_FAMILY_HORUS_OR_T16(board)) + if (version <= 220 && IS_FAMILY_HORUS_OR_T16(board) && !IS_FLYSKY_NV14(board)) return 5; if (IS_FAMILY_T12(board)) return 2; @@ -105,6 +107,8 @@ inline int MAX_POTS_STORAGE(Board::Type board, int version) inline int MAX_POTS_SOURCES(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) + return 3; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board))) return 5; if (IS_FAMILY_T12(board)) return 2; @@ -340,6 +344,8 @@ class SourcesConversionTable: public ConversionTable { int offset = 0; if (version <= 218 && IS_HORUS_X10(board) && i >= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version)) offset += 2; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) && i >= CPN_MAX_STICKS + MAX_POTS_STORAGE(board, version)) + offset += 2; addConversion(RawSource(SOURCE_TYPE_STICK, i + offset), val++); } @@ -2947,6 +2953,9 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type if (version <= 218 && IS_HORUS_X10(board) && (i == CPN_MAX_STICKS + 3)) { input += 2; } + if (version <= 220 && IS_FAMILY_HORUS_OR_T16(board) && (i == CPN_MAX_STICKS + 5)) { // make room for EXT3 and EXT4 + input += 2; + } internalField.Append(new SignedField<16>(this, generalData.calibMid[input])); internalField.Append(new SignedField<16>(this, generalData.calibSpanNeg[input])); internalField.Append(new SignedField<16>(this, generalData.calibSpanPos[input])); diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index e3e9761b5..4a9f7ea44 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -761,6 +761,8 @@ int OpenTxFirmware::getCapability(::Capability capability) return IS_JUMPER_TPRO(board) ? 6 : 0; case HasModelsList: return IS_FAMILY_HORUS_OR_T16(board); + case HasFlySkyGimbals: + return (IS_RADIOMASTER_TX16S(board) && id.contains("flyskygimbals")); default: return 0; } @@ -982,6 +984,12 @@ EepromLoadErrors OpenTxEepromInterface::checkVersion(unsigned int version) // ALL: TimerData countdownStart invert value // ALL: convert more fields from zchar to normal string // COLORLCD: change CustomScreenData and TopBarPersistentData + return OLD_VERSION; + + case 221: + // ALL: YAML storage + // X10PCB: add pots EXT3 and EXT4 (conversion required as shifts slider settings in multiple fields) + // RM TX16S: add Flysky gimbals firmware build option and repurpose EXT3 and EXT4 if selected break; default: @@ -1444,6 +1452,7 @@ void registerOpenTxFirmwares() static const Firmware::Option opt_internal_gps("internalgps", Firmware::tr("Support internal GPS")); firmware->addOptionsGroup({opt_bt, opt_internal_gps}); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); + firmware->addOption("flyskygimbals", Firmware::tr("Support hardware mod: FlySky Paladin EV Gimbals")); registerOpenTxFirmware(firmware); /* Jumper T18 board */ diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index e43b61a53..d955e0e6b 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -25,15 +25,22 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware): GeneralPanel(parent, generalSettings, firmware) { - int rows = Boards::getCapability(getCurrentBoard(), Board::MaxAnalogs); + Board::Type board = getCurrentBoard(); + int rows = Boards::getCapability(board, Board::MaxAnalogs); QStringList headerLabels; headerLabels << "" << tr("Negative span") << tr("Mid value") << tr("Positive span"); TableLayout * tableLayout = new TableLayout(this, rows, headerLabels); - for (int i = 0; i < rows; i++) { + for (int i = 0, row = 0; i < rows; i++) { int col = 0; + if (firmware->getCapability(HasFlySkyGimbals) && + i >= (Boards::getCapability(board, Board::Sticks) + 5) && + i < (Boards::getCapability(board, Board::Sticks) + 7)) + continue; + + row++; QLabel * label = new QLabel(this); label->setText(firmware->getAnalogInputName(i)); tableLayout->addWidget(i, col++, label); diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 477287b2e..69a2a6de4 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -64,7 +64,8 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings } count = Boards::getCapability(board, Board::Pots); - if (count) { + count -= firmware->getCapability(HasFlySkyGimbals) ? 2 : 0; + if (count > 0) { for (int i = 0; i < count; i++) { addPot(i, row); } diff --git a/companion/src/simulation/joystickdialog.cpp b/companion/src/simulation/joystickdialog.cpp index 223e2d77d..1be3dd508 100644 --- a/companion/src/simulation/joystickdialog.cpp +++ b/companion/src/simulation/joystickdialog.cpp @@ -103,7 +103,7 @@ void joystickDialog::populateSourceCombo(QComboBox * cb) for (i=0; i < Board::STICK_AXIS_COUNT; ++i) { cb->addItem(Boards::getAxisName(i) % tr(" Stick"), i); } - for (; i < Board::STICK_AXIS_COUNT + CPN_MAX_POTS; ++i) { + for (; i < Board::STICK_AXIS_COUNT + CPN_MAX_POTS + CPN_MAX_SLIDERS; ++i) { cb->addItem(tr("Knob/Slider %1").arg(i - Board::STICK_AXIS_COUNT + 1), i); } } From cd757ced2f58fa5ccd7b7da311d556e660a33af2 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 11 Dec 2021 22:37:46 +1100 Subject: [PATCH 063/180] No need to calculate file and eeprom sizes --- companion/src/modelslist.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index 864c10028..b11b15723 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -651,7 +651,7 @@ void TreeModel::refresh() EEPROMInterface * eepromInterface = getCurrentEEpromInterface(); Board::Type board = eepromInterface->getBoard(); TreeItem * defaultCategoryItem = NULL; - bool hasEepromSizeData = (IS_FAMILY_HORUS_OR_T16(board) ? false : true); + bool hasEepromSizeData = false; // not necessary with move to YAML storage for all boards TODO: remove unused code if (hasEepromSizeData) { availableEEpromSize = Boards::getEEpromSize(board) - 64; // let's consider fat @@ -753,7 +753,7 @@ bool TreeModel::isModelIdUnique(unsigned modelIdx, unsigned module, unsigned pro int cnt = 0; if (protocol== PULSES_PXX_XJT_D8) return true; - + for (auto const& model: radioData->models) { if (!model.isEmpty()) { const ModuleData& moduleData = model.moduleData[module]; From 4efa5bbed7987bd5dbaa29fd588bd54c4f66dfbf Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 12 Dec 2021 15:00:21 +0100 Subject: [PATCH 064/180] Added custom functions --- companion/src/firmwares/CMakeLists.txt | 1 + .../edgetx/yaml_customfunctiondata.cpp | 333 ++++++++++++++++++ .../edgetx/yaml_customfunctiondata.h | 31 ++ .../firmwares/edgetx/yaml_generalsettings.cpp | 223 ++++++++++++ .../firmwares/edgetx/yaml_generalsettings.h | 230 +----------- .../src/firmwares/edgetx/yaml_modeldata.cpp | 10 +- 6 files changed, 598 insertions(+), 230 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_customfunctiondata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index c2b258537..f7eea5186 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -43,6 +43,7 @@ set(firmwares_SRCS edgetx/yaml_curvedata.cpp edgetx/yaml_moduledata.cpp edgetx/yaml_logicalswitchdata.cpp + edgetx/yaml_customfunctiondata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp new file mode 100644 index 000000000..4f9db6a41 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -0,0 +1,333 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_customfunctiondata.h" +#include "yaml_rawswitch.h" +#include "yaml_rawsource.h" + +static bool fnHasEnable(AssignFunc fn) +{ + return (fn <= FuncInstantTrim) + || (fn >= FuncReset && fn <= FuncSetTimerLast) + || (fn >= FuncAdjustGV1 && fn <= FuncBindExternalModule) + || (fn == FuncVolume); +} + +static bool fnHasRepeat(AssignFunc fn) +{ + return (fn == FuncPlayPrompt) + || (fn == FuncPlayValue) + || (fn == FuncPlayHaptic) + || (fn == FuncPlaySound); +} + +static const YamlLookupTable customFnLut = { + { FuncOverrideCH1, "OVERRIDE_CHANNEL" }, + { FuncTrainer, "TRAINER" }, + { FuncInstantTrim, "INSTANT_TRIM" }, + { FuncReset, "RESET" }, + { FuncSetTimer1, "SET_TIMER" }, + { FuncAdjustGV1, "ADJUST_GVAR" }, + { FuncVolume, "VOLUME" }, + { FuncSetFailsafe, "SET_FAILSAFE" }, + { FuncRangeCheckInternalModule, "RANGECHECK" }, + { FuncBindInternalModule, "BIND" }, + { FuncPlaySound, "PLAY_SOUND" }, + { FuncPlayPrompt, "PLAY_TRACK" }, + { FuncPlayValue, "PLAY_VALUE" }, + { FuncPlayScript, "PLAY_SCRIPT" }, + { FuncBackgroundMusic, "BACKGND_MUSIC" }, + { FuncBackgroundMusicPause, "BACKGND_MUSIC_PAUSE" }, + { FuncVario, "VARIO" }, + { FuncPlayHaptic, "HAPTIC" }, + { FuncLogs, "LOGS" }, + { FuncBacklight, "BACKLIGHT" }, + { FuncScreenshot, "SCREENSHOT" }, + { FuncRacingMode, "RACING_MODE" }, + { FuncDisableTouch, "DISABLE_TOUCH" }, +}; + +static const YamlLookupTable trainerLut = { + { 0, "sticks" }, + { 1, "Rud" }, + { 2, "Ele" }, + { 3, "Thr" }, + { 4, "Ail" }, + { 5, "chans" }, +}; + +static const YamlLookupTable soundLut = { + { 0, "Bp1" }, + { 1, "Bp2" }, + { 2, "Bp3" }, + { 3, "Wrn1" }, + { 5, "Wrn2" }, + { 6, "Chee" }, + { 7, "Rata" }, + { 8, "Tick" }, + { 9, "Sirn" }, + { 10, "Ring" }, + { 11, "SciF" }, + { 12, "Robt" }, + { 13, "Chrp" }, + { 14, "Tada" }, + { 15, "Crck" }, + { 16, "Alrm" }, +}; + +static const YamlLookupTable resetLut = { + { 0, "Tmr1" }, + { 1, "Tmr2" }, + { 2, "Tmr3" }, + { 3, "All" }, + { 5, "Tele" }, +}; + +static const YamlLookupTable gvarModeLut = { + { FUNC_ADJUST_GVAR_CONSTANT, "Cst" }, + { FUNC_ADJUST_GVAR_SOURCE, "Src" }, + { FUNC_ADJUST_GVAR_GVAR, "GVar" }, + { FUNC_ADJUST_GVAR_INCDEC, "IncDec" }, +}; + +static const YamlLookupTable moduleLut = { + { 0, "Int" }, + { 1, "Ext" }, +}; + +namespace YAML +{ +Node convert::encode(const CustomFunctionData& rhs) +{ + Node node; + node["swtch"] = rhs.swtch; + + int fn = rhs.func; + int p1 = 0; + if(fn >= FuncOverrideCH1 && fn <= FuncOverrideCHLast) { + p1 = fn - (int)FuncOverrideCH1; + fn = (int)FuncOverrideCH1; + } else if (fn >= FuncTrainer && fn <= FuncTrainerChannels) { + p1 = fn - (int)FuncTrainer; + fn = (int)FuncTrainer; + } else if (fn >= FuncSetTimer1 && fn <= FuncSetTimerLast) { + p1 = fn - (int)FuncSetTimer1; + fn = (int)FuncSetTimer1; + } else if (fn >= FuncAdjustGV1 && fn <= FuncAdjustGVLast) { + p1 = fn - (int)FuncAdjustGV1; + fn = (int)FuncAdjustGV1; + } else if (fn >= FuncRangeCheckInternalModule && fn <= FuncRangeCheckExternalModule) { + p1 = fn - (int)FuncRangeCheckInternalModule; + fn = (int)FuncRangeCheckInternalModule; + } else if (fn >= FuncBindInternalModule && fn <= FuncBindExternalModule) { + p1 = fn - (int)FuncBindInternalModule; + fn = (int)FuncBindInternalModule; + } + node["func"] = LookupValue(customFnLut, fn); + + std::string def; + switch(fn) { + case FuncOverrideCH1: + def += std::to_string(p1); + def += ","; + def += std::to_string(rhs.param); + break; + case FuncTrainer: + def += LookupValue(trainerLut, p1); + break; + case FuncPlaySound: + def += std::to_string(rhs.param); + break; + case FuncPlayPrompt: + case FuncPlayScript: + case FuncBackgroundMusic: + def += std::string(rhs.paramarm); + break; + case FuncReset: + def += LookupValue(resetLut, rhs.param); + if (def.empty()) { + def += std::to_string(rhs.param); + } + break; + case FuncSetTimer1: { + def += LookupValue(resetLut, p1); + def += ","; + def += std::to_string(rhs.param); + } break; + case FuncAdjustGV1: { + // + GV # + def += std::to_string(p1); + def += ","; + def += LookupValue(gvarModeLut, rhs.adjustMode); + def += ","; + + switch(rhs.adjustMode) { + case FUNC_ADJUST_GVAR_CONSTANT: + case FUNC_ADJUST_GVAR_INCDEC: + def += std::to_string(rhs.param); + break; + case FUNC_ADJUST_GVAR_GVAR: + case FUNC_ADJUST_GVAR_SOURCE: { + def += YamlRawSourceEncode(RawSource(rhs.param)); + } break; + } + } break; + case FuncRangeCheckInternalModule: + case FuncBindInternalModule: { + def += LookupValue(moduleLut, p1); + } break; + default: + break; + } + + if (fnHasEnable(rhs.func)) { + if (!def.empty()) { + def += ","; + } + def += std::to_string((int)rhs.enabled); + } else if(fnHasRepeat(rhs.func)) { + if (!def.empty()) { + def += ","; + } + if (rhs.repeatParam == 0) { + def += "1x"; + } else if (rhs.repeatParam == 0xFF) { + def += "!1x"; + } else { + def += std::to_string(rhs.repeatParam); + } + } + + if (!def.empty()) { + node["def"] = def; + } + + return node; +} + +bool convert::decode(const Node& node, + CustomFunctionData& rhs) +{ + node["swtch"] >> rhs.swtch; + + int func = 0; + node["func"] >> func; + rhs.func = (AssignFunc)func; + + std::string def_str; + node["def"] >> def_str; + std::stringstream def(def_str); + + switch(rhs.func) { + case FuncOverrideCH1: { + int ch=0; + def >> ch; + rhs.func = (AssignFunc)((int)rhs.func + ch); + def.ignore(); + def >> rhs.param; + } break; + case FuncTrainer: { + int value=0; + Node(def.str()) >> trainerLut >> value; + rhs.func = (AssignFunc)((int)rhs.func + value); + } break; + case FuncPlaySound: + Node(def.str()) >> soundLut >> rhs.param; + break; + case FuncPlayPrompt: + case FuncPlayScript: + case FuncBackgroundMusic: + strncpy(rhs.paramarm, def.str().c_str(), sizeof(rhs.paramarm)-1); + break; + case FuncReset: { + try { + def >> rhs.param; + rhs.param += 5; // + FUNC_RESET_PARAM_FIRST_TELEM + break; + } catch(...) {} + Node(def.str()) >> resetLut >> rhs.param; + } break; + case FuncSetTimer1: { + // + timer # + std::string tmr_str; + getline(def, tmr_str, ','); + int tmr = 0; + Node(tmr_str) >> resetLut >> tmr; + rhs.func = (AssignFunc)((int)rhs.func + tmr); + def >> rhs.param; + } break; + case FuncAdjustGV1: { + // + GV # + int gvar_idx=0; + def >> gvar_idx; + rhs.func = (AssignFunc)((int)rhs.func + gvar_idx); + def.ignore(); + + std::string mode; + getline(def, mode, ','); + Node(mode) >> gvarModeLut >> rhs.adjustMode; + switch(rhs.adjustMode) { + case FUNC_ADJUST_GVAR_CONSTANT: + case FUNC_ADJUST_GVAR_INCDEC: + def >> rhs.param; + break; + case FUNC_ADJUST_GVAR_GVAR: + case FUNC_ADJUST_GVAR_SOURCE: { + std::string src_str; + getline(def, src_str, ','); + RawSource src; + Node(src_str) >> src; + rhs.param = src.toValue(); + } break; + } + } break; + case FuncRangeCheckInternalModule: + case FuncBindInternalModule: { + // DANGEROUS_FUNCTIONS... + // + module # ??? + std::string mod; + getline(def, mod, ','); + int module=0; + Node(mod) >> moduleLut >> module; + rhs.func = (AssignFunc)((int)rhs.func + module); + } break; + default: + break; + } + + if (fnHasEnable(rhs.func)) { + int en = 0; + def >> en; + rhs.enabled = en; + } else if(fnHasRepeat(rhs.func)) { + std::string repeat; + getline(def, repeat); + if (repeat == "1x") { + rhs.repeatParam = 0; + } else if (repeat == "!1x") { + rhs.repeatParam = 0xFF; + } else { + rhs.repeatParam = std::stoi(repeat); + } + } + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.h b/companion/src/firmwares/edgetx/yaml_customfunctiondata.h new file mode 100644 index 000000000..00e4700e1 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "customfunctiondata.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const CustomFunctionData& rhs); + static bool decode(const Node& node, CustomFunctionData& rhs); +}; +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 5c4c1e3dd..ec1ee53d2 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -19,6 +19,13 @@ */ #include "yaml_generalsettings.h" +#include "yaml_customfunctiondata.h" +#include "yaml_trainerdata.h" +#include "yaml_calibdata.h" +#include "yaml_switchconfig.h" + +#include "eeprominterface.h" +#include "edgetxinterface.h" const YamlLookupTable beeperModeLut = { { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, @@ -64,3 +71,219 @@ const YamlLookupTable antennaModeLut = { { GeneralSettings::ANTENNA_MODE_EXTERNAL, "MODE_EXTERNAL" }, { GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" }, }; + +namespace YAML +{ + +ENUM_CONVERTER(GeneralSettings::BeeperMode, beeperModeLut); + +Node convert::encode(const GeneralSettings& rhs) +{ + Node node; + + node["version"] = CPN_CURRENT_SETTINGS_VERSION; + + // Radio calib + YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + node["calib"] = calib; + + node["currModel"] = rhs.currModelIndex; + node["currModelFilename"] = rhs.currModelFilename; + node["contrast"] = rhs.contrast; + node["vBatWarn"] = rhs.vBatWarn; + node["txVoltageCalibration"] = rhs.txVoltageCalibration; + + node["vBatMin"] = rhs.vBatMin + 90; + node["vBatMax"] = rhs.vBatMax + 120; + + node["backlightMode"] = backlightModeLut << rhs.backlightMode; + node["trainer"] = rhs.trainer; + node["view"] = rhs.view; + node["fai"] = (int)rhs.fai; + node["disableMemoryWarning"] = (int)rhs.disableMemoryWarning; + node["beepMode"] = rhs.beeperMode; + node["disableAlarmWarning"] = (int)rhs.disableAlarmWarning; + node["disableRssiPoweroffAlarm"] = (int)rhs.disableRssiPoweroffAlarm; + node["USBMode"] = rhs.usbMode; + node["jackMode"] = rhs.jackMode; + node["hapticMode"] = rhs.hapticMode; + node["stickMode"] = rhs.stickMode; + node["timezone"] = rhs.timezone; + node["adjustRTC"] = rhs.adjustRTC; + node["inactivityTimer"] = rhs.inactivityTimer; + node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? + node["splashMode"] = rhs.splashMode; // TODO: B&W only + node["templateSetup"] = rhs.templateSetup; + node["hapticLength"] = rhs.hapticLength + 2; + node["speakerPitch"] = rhs.speakerPitch * 15; + node["hapticStrength"] = rhs.hapticStrength + 2; + node["beepLength"] = rhs.beeperLength + 2; + node["gpsFormat"] = rhs.gpsFormat; + node["speakerVolume"] = rhs.speakerVolume + 12; + node["backlightBright"] = rhs.backlightBright; + node["switchesDelay"] = rhs.switchesDelay; + node["globalTimer"] = rhs.globalTimer; + node["bluetoothName"] = rhs.bluetoothName; + node["bluetoothBaudrate"] = rhs.bluetoothBaudrate; + node["bluetoothMode"] = bluetoothModeLut << rhs.bluetoothMode; + node["countryCode"] = rhs.countryCode; + node["jitterFilter"] = (int)rhs.jitterFilter; + node["disableRtcWarning"] = (int)rhs.rtcCheckDisable; // TODO: verify + node["keysBacklight"] = (int)rhs.keysBacklight; + node["imperial"] = rhs.imperial; + node["ttsLanguage"] = rhs.ttsLanguage; + node["beepVolume"] = rhs.beepVolume + 2; + node["wavVolume"] = rhs.wavVolume + 2; + node["varioVolume"] = rhs.varioVolume + 2; + node["varioPitch"] = rhs.varioPitch * 10; + node["varioRange"] = rhs.varioRange * 15; + node["varioRepeat"] = rhs.varioRepeat; + node["backgroundVolume"] = rhs.backgroundVolume + 2; + node["auxSerialMode"] = uartModeLut << rhs.auxSerialMode; + node["aux2SerialMode"] = uartModeLut << rhs.aux2SerialMode; + node["antennaMode"] = antennaModeLut << rhs.antennaMode; + node["backlightColor"] = rhs.backlightColor; + + for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { + const CustomFunctionData& fn = rhs.customFn[i]; + if (!fn.isEmpty()) { + node["customFn"][std::to_string(i)] = fn; + } + } + + node["sticksConfig"] = YamlStickConfig(rhs.stickName); + node["switchConfig"] = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); + node["potsConfig"] = YamlPotConfig(rhs.potName, rhs.potConfig); + node["slidersConfig"] = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); + + // Color lcd theme settings are not used in EdgeTx + // RadioTheme::ThemeData themeData; + + node["ownerRegistrationID"] = rhs.registrationId; + + // Gyro (for now only xlites) + node["gyroMax"] = rhs.gyroMax; + node["gyroOffset"] = rhs.gyroOffset; + + // OneBit sampling (X9D only?) + node["uartSampleMode"] = rhs.uartSampleMode; + + return node; +} + +bool convert::decode(const Node& node, GeneralSettings& rhs) +{ + if (!node.IsMap()) return false; + + // for (const auto& n : node) { + // qDebug() << QString::fromStdString(n.first.Scalar()); + // } + + // TODO: check board string and fetch Board instance + std::string board; + node["board"] >> board; + // TODO: we should be able to fetch the board based on 'board' + // auto fw = getCurrentFirmware(); + // if (fw) { + // qDebug() << "FW Id: " << fw->getId(); + // if (fw->getId() != ("edgetx-" + radioData.generalSettings.board)) { + // throw std::runtime_error("Wrong board"); + // } + // } + + node["version"] >> rhs.version; + + // Radio calib + YamlCalibData calib; + node["calib"] >> calib; + calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); + + node["currModel"] >> rhs.currModelIndex; + node["currModelFilename"] >> rhs.currModelFilename; + node["contrast"] >> rhs.contrast; + node["vBatWarn"] >> rhs.vBatWarn; + node["txVoltageCalibration"] >> rhs.txVoltageCalibration; + + node["vBatMin"] >> ioffset_int(rhs.vBatMin, 90); + node["vBatMax"] >> ioffset_int(rhs.vBatMax, 120); + + node["backlightMode"] >> backlightModeLut >> rhs.backlightMode; + node["trainer"] >> rhs.trainer; + node["view"] >> rhs.view; + node["fai"] >> rhs.fai; + node["disableMemoryWarning"] >> rhs.disableMemoryWarning; + node["beepMode"] >> rhs.beeperMode; + node["disableAlarmWarning"] >> rhs.disableAlarmWarning; + node["disableRssiPoweroffAlarm"] >> rhs.disableRssiPoweroffAlarm; + node["USBMode"] >> rhs.usbMode; + node["jackMode"] >> rhs.jackMode; + node["hapticMode"] >> rhs.hapticMode; + node["stickMode"] >> rhs.stickMode; + node["timezone"] >> rhs.timezone; + node["adjustRTC"] >> rhs.adjustRTC; + node["inactivityTimer"] >> rhs.inactivityTimer; + node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? + node["splashMode"] >> rhs.splashMode; // TODO: B&W only + node["templateSetup"] >> rhs.templateSetup; + node["hapticLength"] >> ioffset_int(rhs.hapticLength, 2); + node["speakerPitch"] >> ifactor(rhs.speakerPitch, 15); + node["hapticStrength"] >> ioffset_int(rhs.hapticStrength, 2); + node["beepLength"] >> ioffset_int(rhs.beeperLength, 2); + node["gpsFormat"] >> rhs.gpsFormat; + node["speakerVolume"] >> ioffset_int(rhs.speakerVolume, 12); + node["backlightBright"] >> rhs.backlightBright; + node["switchesDelay"] >> rhs.switchesDelay; + node["globalTimer"] >> rhs.globalTimer; + node["bluetoothName"] >> rhs.bluetoothName; + node["bluetoothBaudrate"] >> rhs.bluetoothBaudrate; + node["bluetoothMode"] >> bluetoothModeLut >> rhs.bluetoothMode; + node["countryCode"] >> rhs.countryCode; + node["jitterFilter"] >> rhs.jitterFilter; + node["disableRtcWarning"] >> rhs.rtcCheckDisable; // TODO: verify + node["keysBacklight"] >> rhs.keysBacklight; + node["imperial"] >> rhs.imperial; + node["ttsLanguage"] >> rhs.ttsLanguage; + node["beepVolume"] >> ioffset_int(rhs.beepVolume, 2); + node["wavVolume"] >> ioffset_int(rhs.wavVolume, 2); + node["varioVolume"] >> ioffset_int(rhs.varioVolume, 2); + node["varioPitch"] >> ifactor(rhs.varioPitch, 10); + node["varioRange"] >> ifactor(rhs.varioRange, 15); + node["varioRepeat"] >> rhs.varioRepeat; + node["backgroundVolume"] >> ioffset_int(rhs.backgroundVolume, 2); + node["auxSerialMode"] >> uartModeLut >> rhs.auxSerialMode; + node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode; + node["antennaMode"] >> antennaModeLut >> rhs.antennaMode; + node["backlightColor"] >> rhs.backlightColor; + node["customFn"] >> rhs.customFn; + + YamlStickConfig stickConfig; + node["sticksConfig"] >> stickConfig; + stickConfig.copy(rhs.stickName); + + YamlSwitchConfig switchConfig; + node["switchConfig"] >> switchConfig; + switchConfig.copy(rhs.switchName, rhs.switchConfig); + + YamlPotConfig potsConfig; + node["potsConfig"] >> potsConfig; + potsConfig.copy(rhs.potName, rhs.potConfig); + + YamlSliderConfig slidersConfig; + node["slidersConfig"] >> slidersConfig; + slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); + + // Color lcd theme settings are not used in EdgeTx + // RadioTheme::ThemeData themeData; + + node["ownerRegistrationID"] >> rhs.registrationId; + + // Gyro (for now only xlites) + node["gyroMax"] >> rhs.gyroMax; + node["gyroOffset"] >> rhs.gyroOffset; + + // OneBit sampling (X9D only?) + node["uartSampleMode"] >> rhs.uartSampleMode; + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.h b/companion/src/firmwares/edgetx/yaml_generalsettings.h index cd398631b..401f6e4a1 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.h +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.h @@ -19,241 +19,15 @@ */ #include "yaml_ops.h" -#include "yaml_trainerdata.h" -#include "yaml_calibdata.h" -#include "yaml_switchconfig.h" - #include "generalsettings.h" -#include "eeprominterface.h" -#include "edgetxinterface.h" - -extern const YamlLookupTable beeperModeLut; -extern const YamlLookupTable backlightModeLut; -extern const YamlLookupTable bluetoothModeLut; -extern const YamlLookupTable uartModeLut; -extern const YamlLookupTable antennaModeLut; namespace YAML { - ENUM_CONVERTER(GeneralSettings::BeeperMode, beeperModeLut); - template<> struct convert { - static YAML::Node encode(const GeneralSettings& rhs) { - Node node; - - node["version"] = CPN_CURRENT_SETTINGS_VERSION; - - // Radio calib - YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); - node["calib"] = calib; - - node["currModel"] = rhs.currModelIndex; - node["currModelFilename"] = rhs.currModelFilename; - node["contrast"] = rhs.contrast; - node["vBatWarn"] = rhs.vBatWarn; - node["txVoltageCalibration"] = rhs.txVoltageCalibration; - - node["vBatMin"] = rhs.vBatMin + 90; - node["vBatMax"] = rhs.vBatMax + 120; - - node["backlightMode"] = backlightModeLut << rhs.backlightMode; - node["trainer"] = rhs.trainer; - node["view"] = rhs.view; - node["fai"] = (int)rhs.fai; - node["disableMemoryWarning"] = (int)rhs.disableMemoryWarning; - node["beepMode"] = rhs.beeperMode; - node["disableAlarmWarning"] = (int)rhs.disableAlarmWarning; - node["disableRssiPoweroffAlarm"] = (int)rhs.disableRssiPoweroffAlarm; - node["USBMode"] = rhs.usbMode; - node["jackMode"] = rhs.jackMode; - node["hapticMode"] = rhs.hapticMode; - node["stickMode"] = rhs.stickMode; - node["timezone"] = rhs.timezone; - node["adjustRTC"] = rhs.adjustRTC; - node["inactivityTimer"] = rhs.inactivityTimer; - node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? - node["splashMode"] = rhs.splashMode; // TODO: B&W only - node["templateSetup"] = rhs.templateSetup; - node["hapticLength"] = rhs.hapticLength + 2; - node["speakerPitch"] = rhs.speakerPitch * 15; - node["hapticStrength"] = rhs.hapticStrength + 2; - node["beepLength"] = rhs.beeperLength + 2; - node["gpsFormat"] = rhs.gpsFormat; - node["speakerVolume"] = rhs.speakerVolume + 12 ; - node["backlightBright"] = rhs.backlightBright; - node["switchesDelay"] = rhs.switchesDelay; - node["globalTimer"] = rhs.globalTimer; - node["bluetoothName"] = rhs.bluetoothName; - node["bluetoothBaudrate"] = rhs.bluetoothBaudrate; - node["bluetoothMode"] = bluetoothModeLut << rhs.bluetoothMode; - node["countryCode"] = rhs.countryCode; - node["jitterFilter"] = (int)rhs.jitterFilter; - node["disableRtcWarning"] = (int)rhs.rtcCheckDisable; // TODO: verify - node["keysBacklight"] = (int)rhs.keysBacklight; - node["imperial"] = rhs.imperial; - node["ttsLanguage"] = rhs.ttsLanguage; - node["beepVolume"] = rhs.beepVolume + 2; - node["wavVolume"] = rhs.wavVolume + 2; - node["varioVolume"] = rhs.varioVolume + 2; - node["varioPitch"] = rhs.varioPitch * 10; - node["varioRange"] = rhs.varioRange * 15; - node["varioRepeat"] = rhs.varioRepeat; - node["backgroundVolume"] = rhs.backgroundVolume + 2; - node["auxSerialMode"] = uartModeLut << rhs.auxSerialMode; - node["aux2SerialMode"] = uartModeLut << rhs.aux2SerialMode; - node["antennaMode"] = antennaModeLut << rhs.antennaMode; - node["backlightColor"] = rhs.backlightColor; - - // if (node["customFn"]) { - // const YAML::Node& cfn = node["customFn"]; - // for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { - // cfn[i] = rhs.customFn[i]; - // } - // } - - node["sticksConfig"] = YamlStickConfig(rhs.stickName); - node["switchConfig"] = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); - node["potsConfig"] = YamlPotConfig(rhs.potName, rhs.potConfig); - node["slidersConfig"] = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); - - // Color lcd theme settings are not used in EdgeTx - // RadioTheme::ThemeData themeData; - - node["ownerRegistrationID"] = rhs.registrationId; - - // Gyro (for now only xlites) - node["gyroMax"] = rhs.gyroMax; - node["gyroOffset"] = rhs.gyroOffset; - - // OneBit sampling (X9D only?) - node["uartSampleMode"] = rhs.uartSampleMode; - - return node; - } - - static bool decode(const Node& node, GeneralSettings& rhs) { - - if (!node.IsMap()) return false; - - // for (const auto& n : node) { - // qDebug() << QString::fromStdString(n.first.Scalar()); - // } - - // TODO: check board string and fetch Board instance - std::string board; - node["board"] >> board; - // TODO: we should be able to fetch the board based on 'board' - // auto fw = getCurrentFirmware(); - // if (fw) { - // qDebug() << "FW Id: " << fw->getId(); - // if (fw->getId() != ("edgetx-" + radioData.generalSettings.board)) { - // throw std::runtime_error("Wrong board"); - // } - // } - - node["version"] >> rhs.version; - - // Radio calib - YamlCalibData calib; - node["calib"] >> calib; - calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); - - node["currModel"] >> rhs.currModelIndex; - node["currModelFilename"] >> rhs.currModelFilename; - node["contrast"] >> rhs.contrast; - node["vBatWarn"] >> rhs.vBatWarn; - node["txVoltageCalibration"] >> rhs.txVoltageCalibration; - - node["vBatMin"] >> ioffset_int(rhs.vBatMin, 90); - node["vBatMax"] >> ioffset_int(rhs.vBatMax, 120); - - node["backlightMode"] >> backlightModeLut >> rhs.backlightMode; - node["trainer"] >> rhs.trainer; - node["view"] >> rhs.view; - node["fai"] >> rhs.fai; - node["disableMemoryWarning"] >> rhs.disableMemoryWarning; - node["beepMode"] >> rhs.beeperMode; - node["disableAlarmWarning"] >> rhs.disableAlarmWarning; - node["disableRssiPoweroffAlarm"] >> rhs.disableRssiPoweroffAlarm; - node["USBMode"] >> rhs.usbMode; - node["jackMode"] >> rhs.jackMode; - node["hapticMode"] >> rhs.hapticMode; - node["stickMode"] >> rhs.stickMode; - node["timezone"] >> rhs.timezone; - node["adjustRTC"] >> rhs.adjustRTC; - node["inactivityTimer"] >> rhs.inactivityTimer; - node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? - node["splashMode"] >> rhs.splashMode; // TODO: B&W only - node["templateSetup"] >> rhs.templateSetup; - node["hapticLength"] >> ioffset_int(rhs.hapticLength, 2); - node["speakerPitch"] >> ifactor(rhs.speakerPitch, 15); - node["hapticStrength"] >> ioffset_int(rhs.hapticStrength, 2); - node["beepLength"] >> ioffset_int(rhs.beeperLength, 2); - node["gpsFormat"] >> rhs.gpsFormat; - node["speakerVolume"] >> ioffset_int(rhs.speakerVolume, 12); - node["backlightBright"] >> rhs.backlightBright; - node["switchesDelay"] >> rhs.switchesDelay; - node["globalTimer"] >> rhs.globalTimer; - node["bluetoothName"] >> rhs.bluetoothName; - node["bluetoothBaudrate"] >> rhs.bluetoothBaudrate; - node["bluetoothMode"] >> bluetoothModeLut >> rhs.bluetoothMode; - node["countryCode"] >> rhs.countryCode; - node["jitterFilter"] >> rhs.jitterFilter; - node["disableRtcWarning"] >> rhs.rtcCheckDisable; // TODO: verify - node["keysBacklight"] >> rhs.keysBacklight; - node["imperial"] >> rhs.imperial; - node["ttsLanguage"] >> rhs.ttsLanguage; - node["beepVolume"] >> ioffset_int(rhs.beepVolume, 2); - node["wavVolume"] >> ioffset_int(rhs.wavVolume, 2); - node["varioVolume"] >> ioffset_int(rhs.varioVolume, 2); - node["varioPitch"] >> ifactor(rhs.varioPitch, 10); - node["varioRange"] >> ifactor(rhs.varioRange, 15); - node["varioRepeat"] >> rhs.varioRepeat; - node["backgroundVolume"] >> ioffset_int(rhs.backgroundVolume, 2); - node["auxSerialMode"] >> uartModeLut >> rhs.auxSerialMode; - node["aux2SerialMode"] >> uartModeLut >> rhs.aux2SerialMode; - node["antennaMode"] >> antennaModeLut >> rhs.antennaMode; - node["backlightColor"] >> rhs.backlightColor; - - // if (node["customFn"]) { - // const YAML::Node& cfn = node["customFn"]; - // for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { - // cfn[i] >> rhs.customFn[i]; - // } - // } - - YamlStickConfig stickConfig; - node["sticksConfig"] >> stickConfig; - stickConfig.copy(rhs.stickName); - - YamlSwitchConfig switchConfig; - node["switchConfig"] >> switchConfig; - switchConfig.copy(rhs.switchName, rhs.switchConfig); - - YamlPotConfig potsConfig; - node["potsConfig"] >> potsConfig; - potsConfig.copy(rhs.potName, rhs.potConfig); - - YamlSliderConfig slidersConfig; - node["slidersConfig"] >> slidersConfig; - slidersConfig.copy(rhs.sliderName, rhs.sliderConfig); - - // Color lcd theme settings are not used in EdgeTx - // RadioTheme::ThemeData themeData; - - node["ownerRegistrationID"] >> rhs.registrationId; - - // Gyro (for now only xlites) - node["gyroMax"] >> rhs.gyroMax; - node["gyroOffset"] >> rhs.gyroOffset; - - // OneBit sampling (X9D only?) - node["uartSampleMode"] >> rhs.uartSampleMode; - - return true; - } + static Node encode(const GeneralSettings& rhs); + static bool decode(const Node& node, GeneralSettings& rhs); }; } diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index d565b63b2..6350f313f 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -26,6 +26,7 @@ #include "yaml_curvedata.h" #include "yaml_moduledata.h" #include "yaml_logicalswitchdata.h" +#include "yaml_customfunctiondata.h" #include "modeldata.h" #include "output_data.h" @@ -323,7 +324,12 @@ Node convert::encode(const ModelData& rhs) } } - // customFn[] + for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { + const CustomFunctionData& fn = rhs.customFn[i]; + if (!fn.isEmpty()) { + node["customFn"][std::to_string(i)] = fn; + } + } // swashRingData YamlThrTrace thrTrace(rhs.thrTraceSrc); @@ -405,7 +411,7 @@ bool convert::decode(const Node& node, ModelData& rhs) YamlReadCurvePoints(node["points"], rhs.curves); node["logicalSw"] >> rhs.logicalSw; - //node["customFn"] >> rhs.customFn; + node["customFn"] >> rhs.customFn; // swashRingData From a6d212735233ca3aeb7a7466e1dfa555a8806e12 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 13 Dec 2021 08:25:42 +1100 Subject: [PATCH 065/180] SwashRing and center beep --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 6350f313f..c09a15292 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -55,6 +55,14 @@ static const YamlLookupTable trainerModeLut = { { TRAINER_MODE_MULTI, "MASTER_MULTI" }, }; +static const YamlLookupTable swashTypeLut = { + { 0, "TYPE_NONE" }, + { 1, "TYPE_120" }, + { 2, "TYPE_120X" }, + { 3, "TYPE_140" }, + { 4, "TYPE_90" }, +}; + struct YamlTrim { int mode = 0; int ref = 0; @@ -242,6 +250,36 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const SwashRingData& rhs) + { + Node node; + node["type"] = swashTypeLut << rhs.type; + node["value"] = rhs.value; + node["collectiveSource"] = rhs.collectiveSource; + node["aileronSource"] = rhs.aileronSource; + node["elevatorSource"] = rhs.elevatorSource; + node["collectiveWeight"] = rhs.collectiveWeight; + node["aileronWeight"] = rhs.aileronWeight; + node["elevatorWeight"] = rhs.elevatorWeight; + return node; + } + + static bool decode(const Node& node, SwashRingData& rhs) + { + node["type"] >> swashTypeLut >> rhs.type; + node["value"] >> rhs.value; + node["collectiveSource"] >> rhs.collectiveSource; + node["aileronSource"] >> rhs.aileronSource; + node["elevatorSource"] >> rhs.elevatorSource; + node["collectiveWeight"] >> rhs.collectiveWeight; + node["aileronWeight"] >> rhs.aileronWeight; + node["elevatorWeight"] >> rhs.elevatorWeight; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -260,7 +298,7 @@ Node convert::encode(const ModelData& rhs) node["trimInc"] = rhs.trimInc; node["displayTrims"] = rhs.trimsDisplay; node["disableThrottleWarning"] = (int)rhs.disableThrottleWarning; - // node[] = rhs.beepANACenter; + node["beepANACenter"] = rhs.beepANACenter; node["extendedLimits"] = (int)rhs.extendedLimits; node["extendedTrims"] = (int)rhs.extendedTrims; node["throttleReversed"] = (int)rhs.throttleReversed; @@ -323,14 +361,16 @@ Node convert::encode(const ModelData& rhs) node["logicalSw"][std::to_string(i)] = ls; } } - + for (int i = 0; i < CPN_MAX_SPECIAL_FUNCTIONS; i++) { const CustomFunctionData& fn = rhs.customFn[i]; if (!fn.isEmpty()) { node["customFn"][std::to_string(i)] = fn; } } - // swashRingData + + if (getCurrentFirmware()->getCapability(Heli)) + node["swashR"] = rhs.swashRingData; YamlThrTrace thrTrace(rhs.thrTraceSrc); node["thrTraceSrc"] = thrTrace.src; @@ -357,7 +397,7 @@ Node convert::encode(const ModelData& rhs) node["moduleData"][std::to_string(i)] = rhs.moduleData[i]; } } - + // scriptData[] // sensorData[] @@ -395,7 +435,7 @@ bool convert::decode(const Node& node, ModelData& rhs) node["trimInc"] >> rhs.trimInc; node["displayTrims"] >> rhs.trimsDisplay; node["disableThrottleWarning"] >> rhs.disableThrottleWarning; - // node[] >> rhs.beepANACenter; + node["beepANACenter"] >> rhs.beepANACenter; node["extendedLimits"] >> rhs.extendedLimits; node["extendedTrims"] >> rhs.extendedTrims; node["throttleReversed"] >> rhs.throttleReversed; @@ -414,6 +454,11 @@ bool convert::decode(const Node& node, ModelData& rhs) node["customFn"] >> rhs.customFn; // swashRingData + if (node["swashR"]) { + const auto& swashR = node["swashR"]; + if (!swashR.IsMap()) return false; + swashR >> rhs.swashRingData; + } YamlThrTrace thrTrace; node["thrTraceSrc"] >> thrTrace.src; From d37b5d3c5704e184b982d192e204c114fb92507b Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 13 Dec 2021 09:48:16 +1100 Subject: [PATCH 066/180] Thr trim switch --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index c09a15292..4ebb6952d 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -376,7 +376,7 @@ Node convert::encode(const ModelData& rhs) node["thrTraceSrc"] = thrTrace.src; // switchWarningStates - // thrTrimSwitch + node["thrTrimSw"] = rhs.thrTrimSwitch; // potsWarningMode // potsWarnEnabled[] // potsWarnPosition[] @@ -453,7 +453,6 @@ bool convert::decode(const Node& node, ModelData& rhs) node["logicalSw"] >> rhs.logicalSw; node["customFn"] >> rhs.customFn; - // swashRingData if (node["swashR"]) { const auto& swashR = node["swashR"]; if (!swashR.IsMap()) return false; @@ -465,7 +464,7 @@ bool convert::decode(const Node& node, ModelData& rhs) rhs.thrTraceSrc = thrTrace.toCpn(); // switchWarningStates - // thrTrimSwitch + node["thrTrimSw"] >> rhs.thrTrimSwitch; // potsWarningMode // potsWarnEnabled[] // potsWarnPosition[] From 56997f4d3cee7bedba59d4e37afb9d984d68747a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 13 Dec 2021 09:59:40 +0100 Subject: [PATCH 067/180] Use definitions in Boards for pots/sliders config --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 2 + .../src/firmwares/edgetx/yaml_rawswitch.cpp | 2 + .../firmwares/edgetx/yaml_switchconfig.cpp | 106 +++++++++++++++--- .../src/firmwares/edgetx/yaml_switchconfig.h | 87 ++++++++------ 4 files changed, 148 insertions(+), 49 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 4ebb6952d..ee983ccbc 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -403,8 +403,10 @@ Node convert::encode(const ModelData& rhs) node["toplcdTimer"] = rhs.toplcdTimer; + // B&W only // customScreens // topBarData + node["view"] = rhs.view; node["modelRegistrationID"] = rhs.registrationId; diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 0b9762009..b215f2787 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -58,6 +58,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) switch (rhs.type) { case SWITCH_TYPE_SWITCH: sw_str += 'S'; + // TODO: use lookup of switches in Boards ??? sw_str += 'A' + (sval - 1) / 3; sw_str += std::to_string((sval - 1) % 3); break; @@ -129,6 +130,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { + // TODO: use lookup of switches in Boards ??? rhs = RawSwitch(SWITCH_TYPE_SWITCH, (val[1] - 'A') * 3 + val[2] - '0'); } else { // TODO: check if we have a match? diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index f10b21a80..70218dc03 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -19,19 +19,9 @@ */ #include "yaml_switchconfig.h" + #include "boards.h" - -const YamlLookupTable sticksLut = { - {0, "0"}, - {1, "1"}, - {2, "2"}, - {3, "3"}, -}; - -const YamlLookupTable switchesLut = { - {0, "SA"}, {1, "SB"}, {2, "SC"}, {3, "SD"}, {4, "SE"}, - {5, "SF"}, {6, "SG"}, {7, "SH"}, {8, "SI"}, {9, "SJ"}, -}; +#include "eeprominterface.h" const YamlLookupTable switchConfigLut = { {Board::SWITCH_NOT_AVAILABLE, "none"}, @@ -40,10 +30,6 @@ const YamlLookupTable switchConfigLut = { {Board::SWITCH_3POS, "3pos"}, }; -const YamlLookupTable potsLut = { - {0, "S1"}, {1, "6POS"}, {2, "S2"}, - {3, "EXT1"}, {4, "EXT2"}, {5, "EXT3"}, {6, "EXT4"}, -}; const YamlLookupTable potConfigLut = { {Board::POT_NONE, "none"}, @@ -62,3 +48,91 @@ const YamlLookupTable sliderConfigLut = { {Board::SLIDER_WITH_DETENT, "with_detent"}, }; +int YamlStickLookup::name2idx(const std::string& name) +{ + int idx = std::stoi(name); + if (idx < 4) { + return idx; + } + + return -1; +} + +std::string YamlStickLookup::idx2name(unsigned int idx) +{ + if (idx < 4) { + return std::to_string(idx); + } + + return std::string(); +} + +int YamlSwitchLookup::name2idx(const std::string& name) +{ + // TODO: replace this with a real lookup of available switches + if (name.size() == 2 + && name[0] == 'S' + && (name[1] >= 'A' && name[1] <= 'J')) { + + return name[1] - 'A'; + } + + return -1; +} + +std::string YamlSwitchLookup::idx2name(unsigned int idx) +{ + // TODO: replace this with a real lookup of available switches + if (idx < 10) { + return std::string("S") + (char)('A' + idx); + } + + return std::string(); +} + +int YamlPotLookup::name2idx(const std::string& name) +{ + auto fw = getCurrentFirmware(); + int idx = fw->getAnalogInputIndex(name.c_str()); + if (idx < 0) return idx; + + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + if (idx >= pots) return -1; + + return idx; +} + +std::string YamlPotLookup::idx2name(unsigned int idx) +{ + auto fw = getCurrentFirmware(); + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + if (idx >= pots) return std::string(); + + return fw->getAnalogInputTag(idx); +} + +int YamlSliderLookup::name2idx(const std::string& name) +{ + auto fw = getCurrentFirmware(); + int idx = fw->getAnalogInputIndex(name.c_str()); + if (idx < 0) return idx; + + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + if (idx < pots) return -1; + idx -= pots; + + int sliders = Boards::getCapability(fw->getBoard(), Board::Sliders); + if (idx >= sliders) return -1; + + return idx; +} + +std::string YamlSliderLookup::idx2name(unsigned int idx) +{ + auto fw = getCurrentFirmware(); + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + int sliders = Boards::getCapability(fw->getBoard(), Board::Sliders); + if (idx >= sliders) return std::string(); + + return fw->getAnalogInputTag(idx + pots); +} diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index fbdd5b8b6..37e3e5fd3 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -24,7 +24,12 @@ #include "generalsettings.h" #include -template +struct YamlStickLookup { + static int name2idx(const std::string& name); + static std::string idx2name(unsigned int idx); +}; + +template struct YamlNameConfig { char name[N][HARDWARE_NAME_LEN + 1]; @@ -41,19 +46,17 @@ struct YamlNameConfig { } }; -extern const YamlLookupTable sticksLut; -typedef YamlNameConfig YamlStickConfig; +typedef YamlNameConfig YamlStickConfig; -template -struct YamlKnobConfig : public YamlNameConfig { +template +struct YamlKnobConfig : public YamlNameConfig { unsigned int config[N]; YamlKnobConfig() { memset(config, 0, sizeof(config)); } YamlKnobConfig(const char in_names[N][HARDWARE_NAME_LEN + 1], const unsigned int in_configs[N]) : - YamlNameConfig(in_names) + YamlNameConfig(in_names) { memcpy(config, in_configs, sizeof(config)); } @@ -61,7 +64,7 @@ struct YamlKnobConfig : public YamlNameConfig { void copy(char out_names[N][HARDWARE_NAME_LEN + 1], unsigned int out_configs[N]) { - YamlNameConfig::copy(out_names); + YamlNameConfig::copy(out_names); memcpy(out_configs, config, sizeof(config)); } }; @@ -69,71 +72,89 @@ struct YamlKnobConfig : public YamlNameConfig { // SA: // type: 3pos // name: -extern const YamlLookupTable switchesLut; +struct YamlSwitchLookup { + static int name2idx(const std::string& name); + static std::string idx2name(unsigned int idx); +}; extern const YamlLookupTable switchConfigLut; -typedef YamlKnobConfig +typedef YamlKnobConfig YamlSwitchConfig; // S1: // type: with_detent // name: -extern const YamlLookupTable potsLut; +struct YamlPotLookup { + static int name2idx(const std::string& name); + static std::string idx2name(unsigned int idx); +}; extern const YamlLookupTable potConfigLut; -typedef YamlKnobConfig YamlPotConfig; +typedef YamlKnobConfig YamlPotConfig; // S1: // type: with_detent // name: -extern const YamlLookupTable slidersLut; +struct YamlSliderLookup { + static int name2idx(const std::string& name); + static std::string idx2name(unsigned int idx); +}; extern const YamlLookupTable sliderConfigLut; -typedef YamlKnobConfig +typedef YamlKnobConfig YamlSliderConfig; namespace YAML { -template -struct convert > { - static Node encode(const YamlNameConfig& rhs) +template +struct convert > { + static Node encode(const YamlNameConfig& rhs) { Node node; - for (const auto& kv : name_lut) { - node[kv.second]["name"] = rhs.name[kv.first]; + for (unsigned int i=0; i& rhs) + static bool decode(const Node& node, YamlNameConfig& rhs) { if (!node.IsMap()) return false; int idx = 0; for (const auto& kv : node) { - kv.first >> name_lut >> idx; - kv.second["name"] >> rhs.name[idx]; + idx = name_lookup::name2idx(kv.first.Scalar()); + if (idx >= 0) { + kv.second["name"] >> rhs.name[idx]; + } } return true; } }; -template -struct convert > { - static Node encode(const YamlKnobConfig& rhs) +template +struct convert > { + static Node encode(const YamlKnobConfig& rhs) { Node node; - for (const auto& kv : name_lut) { - node[kv.second]["type"] = cfg_lut << rhs.config[kv.first]; - node[kv.second]["name"] = rhs.name[kv.first]; + for (unsigned int i=0; i& rhs) + YamlKnobConfig& rhs) { if (!node.IsMap()) return false; int idx = 0; for (const auto& kv : node) { - kv.first >> name_lut >> idx; - kv.second["type"] >> cfg_lut >> rhs.config[idx]; - kv.second["name"] >> rhs.name[idx]; + idx = name_lookup::name2idx(kv.first.Scalar()); + if (idx >= 0) { + kv.second["type"] >> cfg_lut >> rhs.config[idx]; + kv.second["name"] >> rhs.name[idx]; + } } return true; } From 703bc20c6e931933e239cc41cf7312ff340403ab Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 14 Dec 2021 09:57:44 +1100 Subject: [PATCH 068/180] Use definitions in Boards for switches --- companion/src/firmwares/boards.cpp | 14 ++++++++ companion/src/firmwares/boards.h | 1 + .../src/firmwares/edgetx/yaml_rawswitch.cpp | 34 +++++++++---------- companion/src/firmwares/eeprominterface.cpp | 26 ++++++++++++++ companion/src/firmwares/eeprominterface.h | 11 +++++- 5 files changed, 68 insertions(+), 18 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 3f498b804..2c85e2a88 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -743,3 +743,17 @@ AbstractStaticItemModel * Boards::switchTypeItemModel() mdl->loadItemList(); return mdl; } + +// static +StringTagMappingTable Boards::getSwitchesLookupTable(Board::Type board) +{ + StringTagMappingTable tbl; + + for (int i = 0; i < Boards::getCapability(board, Board::Switches); i++) { + SwitchInfo si = Boards::getSwitchInfo(board, i); + if (si.config != SWITCH_NOT_AVAILABLE) // safety check in case Switches does not align + tbl.insert(tbl.end(), si.name.toStdString()); + } + + return tbl; +} diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index c6662133e..5188cb655 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -201,6 +201,7 @@ class Boards static int getEEpromSize(Board::Type board); static int getFlashSize(Board::Type board); static Board::SwitchInfo getSwitchInfo(Board::Type board, int index); + static StringTagMappingTable getSwitchesLookupTable(Board::Type board); static int getCapability(Board::Type board, Board::Capability capability); static QString getAxisName(int index); static StringTagMappingTable getAnalogNamesLookupTable(Board::Type board); diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index b215f2787..b96083e78 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -19,9 +19,11 @@ */ #include "yaml_rawswitch.h" +#include "eeprominterface.h" -#define XPOTS_MULTIPOS_COUNT 6 +#define XPOTS_MULTIPOS_COUNT 6 // TODO: use Boards::getCapability(board, Board::MultiposPotsPositions) +// TODO: use lookup of trims in Boards ??? const YamlLookupTable trimSwitchLut = { { 0, "TrimRudLeft" }, { 1, "TrimRudRight" }, @@ -57,9 +59,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) switch (rhs.type) { case SWITCH_TYPE_SWITCH: - sw_str += 'S'; - // TODO: use lookup of switches in Boards ??? - sw_str += 'A' + (sval - 1) / 3; + sw_str += getCurrentFirmware()->getSwitchesTag((sval - 1) / 3); sw_str += std::to_string((sval - 1) % 3); break; @@ -75,6 +75,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; case SWITCH_TYPE_TRIM: + // TODO: use lookup of trims in Boards ??? sw_str += YAML::LookupValue(trimSwitchLut, sval); break; @@ -97,7 +98,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) RawSwitch YamlRawSwitchDecode(const std::string& sw_str) { - RawSwitch rhs; + RawSwitch rhs; // constructor sets to SWITCH_TYPE_NONE const char* val = sw_str.data(); size_t val_len = sw_str.size(); @@ -108,7 +109,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) val_len--; } - if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_LOGICAL_SWITCHES rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, std::stoi(sw_str.substr(1, val_len - 1)) - 1); } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && @@ -117,27 +118,26 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, (val[2] - '0') * XPOTS_MULTIPOS_COUNT + (val[3] - '0')); } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && - (val[2] >= '0' && val[2] <= '9')) { + (val[2] >= '0' && val[2] <= '9')) { // TODO: range check < CPN_MAX_FLIGHT_MODES rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); } else if (val_len >= 2 && val[0] == 'T' && - (val[1] >= '0' && val[1] <= '9')) { + (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_SENSORS rhs = RawSwitch(SWITCH_TYPE_SENSOR, std::stoi(sw_str.substr(1, val_len - 1)) - 1); - } else if (sw_str.substr(0, 3) == std::string("Trim")) { // "Trim" - + } else if (sw_str.substr(0, 3) == std::string("Trim")) { + // TODO: use lookup of trims in Boards ??? rhs.type = SWITCH_TYPE_TRIM; YAML::Node(sw_str) >> trimSwitchLut >> rhs.index; } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { - // TODO: use lookup of switches in Boards ??? - rhs = RawSwitch(SWITCH_TYPE_SWITCH, (val[1] - 'A') * 3 + val[2] - '0'); + int sw_idx = getCurrentFirmware()->getSwitchesIndex(sw_str.substr(0, 2).c_str()); + if (sw_idx >= 0) { + rhs.type = SWITCH_TYPE_SWITCH; + rhs.index = sw_idx * 3 + val[2] - '0'; + } } else { - // TODO: check if we have a match? - // or does RawSwitch default to NONE anyway? - // - YAML::Node(sw_str) >> rhs.type; - rhs.index = 0; + // no match found } if (neg) { diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index cfa5ab5d1..9e87097ac 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -204,3 +204,29 @@ std::string Firmware::getAnalogInputTag(unsigned int index) return std::string(); } + +int Firmware::getSwitchesIndex(const char * tag) +{ + const StringTagMappingTable& lut = switchesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getSwitchesTag(unsigned int index) +{ + const StringTagMappingTable& lut = switchesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 99a2a3953..cdd8370f6 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -291,7 +291,8 @@ class Firmware variantBase(0), base(base), eepromInterface(nullptr), - analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)) + analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)), + switchesLookupTable(Boards::getSwitchesLookupTable(board)) { } @@ -405,8 +406,15 @@ class Firmware return &analogInputNamesLookupTable; } + const StringTagMappingTable* getSwitchesLookupTable() + { + return &switchesLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); + int getSwitchesIndex(const char * tag); + std::string getSwitchesTag(unsigned int index); protected: QString id; @@ -416,6 +424,7 @@ class Firmware Firmware * base; EEPROMInterface * eepromInterface; const StringTagMappingTable analogInputNamesLookupTable; + const StringTagMappingTable switchesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; From 8383ee5363d34f5882ed3d17c3d6e5b3569e69f8 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 14 Dec 2021 10:05:37 +1100 Subject: [PATCH 069/180] Use Boards for multiposcnt --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index b96083e78..3e7512aa4 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -21,8 +21,6 @@ #include "yaml_rawswitch.h" #include "eeprominterface.h" -#define XPOTS_MULTIPOS_COUNT 6 // TODO: use Boards::getCapability(board, Board::MultiposPotsPositions) - // TODO: use lookup of trims in Boards ??? const YamlLookupTable trimSwitchLut = { { 0, "TrimRudLeft" }, @@ -57,6 +55,8 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) sw_str += "!"; } + int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); + switch (rhs.type) { case SWITCH_TYPE_SWITCH: sw_str += getCurrentFirmware()->getSwitchesTag((sval - 1) / 3); @@ -70,8 +70,8 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) case SWITCH_TYPE_MULTIPOS_POT: sw_str += "6P"; - sw_str += std::to_string(sval / XPOTS_MULTIPOS_COUNT); - sw_str += std::to_string(sval % XPOTS_MULTIPOS_COUNT); + sw_str += std::to_string(sval / multiposcnt); + sw_str += std::to_string(sval % multiposcnt); break; case SWITCH_TYPE_TRIM: @@ -109,14 +109,16 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) val_len--; } + int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_LOGICAL_SWITCHES rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, std::stoi(sw_str.substr(1, val_len - 1)) - 1); } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && (val[2] >= '0' && val[2] <= '9') && - (val[3] >= '0' && val[3] < (XPOTS_MULTIPOS_COUNT + '0'))) { + (val[3] >= '0' && val[3] < (multiposcnt + '0'))) { rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, - (val[2] - '0') * XPOTS_MULTIPOS_COUNT + (val[3] - '0')); + (val[2] - '0') * multiposcnt + (val[3] - '0')); } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && (val[2] >= '0' && val[2] <= '9')) { // TODO: range check < CPN_MAX_FLIGHT_MODES rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); From 8228dd6b034e27af926137fa3e5b98d679d0f9ea Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 14 Dec 2021 10:30:07 +1100 Subject: [PATCH 070/180] Add range checks to switches --- companion/src/constants.h | 1 + .../src/firmwares/edgetx/yaml_rawswitch.cpp | 18 +++++++++++------- companion/src/firmwares/sensordata.h | 1 - 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index 3bc547d81..c3b8b9d74 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -46,6 +46,7 @@ #define CPN_MAX_MOUSE_ANALOGS 2 #define CPN_MAX_GYRO_ANALOGS 2 #define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_SLIDERS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) +#define CPN_MAX_SENSORS 60 #define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion") #define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 3e7512aa4..35a6d1f18 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -111,21 +111,25 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); - if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_LOGICAL_SWITCHES - rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { + rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && (val[2] >= '0' && val[2] <= '9') && (val[3] >= '0' && val[3] < (multiposcnt + '0'))) { rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, (val[2] - '0') * multiposcnt + (val[3] - '0')); } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && - (val[2] >= '0' && val[2] <= '9')) { // TODO: range check < CPN_MAX_FLIGHT_MODES + (val[2] >= '0' && val[2] <= '9')) { rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); } else if (val_len >= 2 && val[0] == 'T' && - (val[1] >= '0' && val[1] <= '9')) { // TODO: range check < CPN_MAX_SENSORS - rhs = RawSwitch(SWITCH_TYPE_SENSOR, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { + rhs = RawSwitch(SWITCH_TYPE_SENSOR, + std::stoi(sw_str.substr(1, val_len - 1)) - 1); + } } else if (sw_str.substr(0, 3) == std::string("Trim")) { // TODO: use lookup of trims in Boards ??? rhs.type = SWITCH_TYPE_TRIM; diff --git a/companion/src/firmwares/sensordata.h b/companion/src/firmwares/sensordata.h index cec9a6a63..4722f9453 100644 --- a/companion/src/firmwares/sensordata.h +++ b/companion/src/firmwares/sensordata.h @@ -24,7 +24,6 @@ #include -constexpr int CPN_MAX_SENSORS { 60 }; constexpr int SENSOR_LABEL_LEN { 4 }; constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 }; From e99e890cb4186789c11eed00a359c0f40c924d6f Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 14 Dec 2021 10:34:11 +1100 Subject: [PATCH 071/180] Cosmetics --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 35a6d1f18..c35bf04a7 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -116,24 +116,29 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, std::stoi(sw_str.substr(1, val_len - 1)) - 1); } + } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && (val[2] >= '0' && val[2] <= '9') && (val[3] >= '0' && val[3] < (multiposcnt + '0'))) { rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, (val[2] - '0') * multiposcnt + (val[3] - '0')); + } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && (val[2] >= '0' && val[2] <= '9')) { rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); + } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { rhs = RawSwitch(SWITCH_TYPE_SENSOR, std::stoi(sw_str.substr(1, val_len - 1)) - 1); } + } else if (sw_str.substr(0, 3) == std::string("Trim")) { // TODO: use lookup of trims in Boards ??? rhs.type = SWITCH_TYPE_TRIM; YAML::Node(sw_str) >> trimSwitchLut >> rhs.index; + } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { @@ -142,6 +147,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) rhs.type = SWITCH_TYPE_SWITCH; rhs.index = sw_idx * 3 + val[2] - '0'; } + } else { // no match found } From 609604d141d682c3f0595e58f0976607c14991bd Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 15 Dec 2021 06:23:08 +1100 Subject: [PATCH 072/180] Fix rawswitch decode --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index c35bf04a7..21b78a197 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -149,7 +149,8 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } } else { - // no match found + YAML::Node(sw_str) >> rhs.type; + rhs.index = 0; } if (neg) { From 1c7bece09044b3fadaaa99b4501e987d9abb2db1 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 15 Dec 2021 08:01:04 +1100 Subject: [PATCH 073/180] Use Boards for trim switches --- companion/src/firmwares/boards.cpp | 27 +++++++++++++++++ companion/src/firmwares/boards.h | 1 + .../src/firmwares/edgetx/yaml_rawswitch.cpp | 29 +++++-------------- companion/src/firmwares/eeprominterface.cpp | 26 +++++++++++++++++ companion/src/firmwares/eeprominterface.h | 11 ++++++- 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 2c85e2a88..3c790fd7a 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -757,3 +757,30 @@ StringTagMappingTable Boards::getSwitchesLookupTable(Board::Type board) return tbl; } + +// static +StringTagMappingTable Boards::getTrimSwitchesLookupTable(Board::Type board) +{ + StringTagMappingTable tbl; + + tbl.insert(tbl.end(), { + {std::to_string(TRIM_SW_LH_DEC), "TrimRudLeft"}, + {std::to_string(TRIM_SW_LH_INC), "TrimRudRight"}, + {std::to_string(TRIM_SW_LV_DEC), "TrimEleDown"}, + {std::to_string(TRIM_SW_LV_INC), "TrimEleUp"}, + {std::to_string(TRIM_SW_RV_DEC), "TrimThrDown"}, + {std::to_string(TRIM_SW_RV_INC), "TrimThrUp"}, + {std::to_string(TRIM_SW_RH_DEC), "TrimAilLeft"}, + {std::to_string(TRIM_SW_RH_INC), "TrimAilRight"}, + }); + + if (getCapability(board, Board::NumTrims) > 4) + tbl.insert(tbl.end(), { + {std::to_string(TRIM_SW_T5_DEC), "TrimT5Down"}, + {std::to_string(TRIM_SW_T5_INC), "TrimT5Up"}, + {std::to_string(TRIM_SW_T6_DEC), "TrimT6Down"}, + {std::to_string(TRIM_SW_T6_INC), "TrimT6Up"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 5188cb655..1cf1fb353 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -214,6 +214,7 @@ class Boards static AbstractStaticItemModel * potTypeItemModel(); static AbstractStaticItemModel * sliderTypeItemModel(); static AbstractStaticItemModel * switchTypeItemModel(); + static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board); protected: diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 21b78a197..61c3ca463 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -21,22 +21,6 @@ #include "yaml_rawswitch.h" #include "eeprominterface.h" -// TODO: use lookup of trims in Boards ??? -const YamlLookupTable trimSwitchLut = { - { 0, "TrimRudLeft" }, - { 1, "TrimRudRight" }, - { 2, "TrimEleDown" }, - { 3, "TrimEleUp" }, - { 4, "TrimThrDown" }, - { 5, "TrimThrUp" }, - { 6, "TrimAilLeft" }, - { 7, "TrimAilRight" }, - { 8, "TrimT5Down" }, - { 9, "TrimT5Up" }, - { 10, "TrimT6Down" }, - { 11, "TrimT6Up" }, -}; - const YamlLookupTable switchTypeLut = { { SWITCH_TYPE_NONE, "NONE" }, { SWITCH_TYPE_ON, "ON" }, @@ -75,8 +59,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; case SWITCH_TYPE_TRIM: - // TODO: use lookup of trims in Boards ??? - sw_str += YAML::LookupValue(trimSwitchLut, sval); + sw_str += getCurrentFirmware()->getTrimSwitchesTag(sval); break; case SWITCH_TYPE_FLIGHT_MODE: @@ -134,10 +117,12 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) std::stoi(sw_str.substr(1, val_len - 1)) - 1); } - } else if (sw_str.substr(0, 3) == std::string("Trim")) { - // TODO: use lookup of trims in Boards ??? - rhs.type = SWITCH_TYPE_TRIM; - YAML::Node(sw_str) >> trimSwitchLut >> rhs.index; + } else if (sw_str.substr(0, 4) == std::string("Trim")) { + int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str.c_str()); + if (tsw_idx >= 0) { + rhs.type = SWITCH_TYPE_TRIM; + rhs.index = tsw_idx; + } } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 9e87097ac..4fcef3f1d 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -230,3 +230,29 @@ std::string Firmware::getSwitchesTag(unsigned int index) return std::string(); } + +int Firmware::getTrimSwitchesIndex(const char * tag) +{ + const StringTagMappingTable& lut = trimSwitchesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getTrimSwitchesTag(unsigned int index) +{ + const StringTagMappingTable& lut = trimSwitchesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index cdd8370f6..b2bdf4c61 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -292,7 +292,8 @@ class Firmware base(base), eepromInterface(nullptr), analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)), - switchesLookupTable(Boards::getSwitchesLookupTable(board)) + switchesLookupTable(Boards::getSwitchesLookupTable(board)), + trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)) { } @@ -411,10 +412,17 @@ class Firmware return &switchesLookupTable; } + const StringTagMappingTable* getTrimSwitchesLookupTable() + { + return &trimSwitchesLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); int getSwitchesIndex(const char * tag); std::string getSwitchesTag(unsigned int index); + int getTrimSwitchesIndex(const char * tag); + std::string getTrimSwitchesTag(unsigned int index); protected: QString id; @@ -425,6 +433,7 @@ class Firmware EEPROMInterface * eepromInterface; const StringTagMappingTable analogInputNamesLookupTable; const StringTagMappingTable switchesLookupTable; + const StringTagMappingTable trimSwitchesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; From 245d64f521e3793799016df3e2b7855340e46cec Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 15 Dec 2021 08:55:19 +1100 Subject: [PATCH 074/180] Add more validation to rawswitch decode --- companion/src/constants.h | 2 ++ .../src/firmwares/edgetx/yaml_rawsource.cpp | 36 ++++++++++++------- companion/src/firmwares/modeldata.h | 2 -- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/companion/src/constants.h b/companion/src/constants.h index c3b8b9d74..53796f6fc 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -47,6 +47,8 @@ #define CPN_MAX_GYRO_ANALOGS 2 #define CPN_MAX_ANALOGS (CPN_MAX_STICKS + CPN_MAX_POTS + CPN_MAX_SLIDERS + CPN_MAX_MOUSE_ANALOGS + CPN_MAX_GYRO_ANALOGS) #define CPN_MAX_SENSORS 60 +#define CPN_MAX_SCRIPTS 9 +#define CPN_MAX_SCRIPT_INPUTS 10 #define CPN_STR_APP_NAME QCoreApplication::translate("Companion", "EdgeTX Companion") #define CPN_STR_TTL_INFO QCoreApplication::translate("Companion", "Information") // shared Title Case words, eg. for a window title or section heading diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 756aa0697..f0ffff324 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -133,15 +133,19 @@ RawSource YamlRawSourceDecode(const std::string& src_str) if (val_len > 0 && val[0] == 'I') { - rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, std::stoi(src_str.substr(1))); + int idx = std::stoi(src_str.substr(1)); + if (idx < CPN_MAX_INPUTS) + rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, idx); } else if (val_len >= 2 && val[0] == 'S' && val[1] >= 'A' && val[1] <= 'Z') { - rhs = RawSource(SOURCE_TYPE_SWITCH, val[1] - 'A'); - + int idx = val[1] - 'A'; + if (idx < CPN_MAX_SWITCHES) + rhs = RawSource(SOURCE_TYPE_SWITCH, idx); + } else if (val_len > 4 && val[0] == 'l' && val[1] == 'u' && @@ -149,11 +153,12 @@ RawSource YamlRawSourceDecode(const std::string& src_str) val[3] == '(') { std::stringstream src(src_str.substr(4)); - int script = 0, output = 0; + int script = 0, output = 0; // TODO: check rename outputs to inputs??? src >> script; src.ignore(); src >> output; - rhs = RawSource(SOURCE_TYPE_LUA_OUTPUT, script * 16 + output); + if (script < CPN_MAX_SCRIPTS && output < CPN_MAX_SCRIPT_INPUTS) + rhs = RawSource(SOURCE_TYPE_LUA_OUTPUT, script * 16 + output); } else if (val_len > 3 && val[0] == 'l' && @@ -163,7 +168,8 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::stringstream src(src_str.substr(3)); int ls = 0; src >> ls; - rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls); + if (ls < CPN_MAX_LOGICAL_SWITCHES) + rhs = RawSource(SOURCE_TYPE_CUSTOM_SWITCH, ls); } else if (val_len > 3 && val[0] == 't' && @@ -173,8 +179,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::stringstream src(src_str.substr(3)); int tr = 0; src >> tr; - rhs = RawSource(SOURCE_TYPE_PPM, tr); - + if (tr < getCurrentFirmware()->getCapability(TrainerInputs)) + rhs = RawSource(SOURCE_TYPE_PPM, tr); + } else if (val_len > 3 && val[0] == 'c' && val[1] == 'h' && @@ -183,8 +190,9 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::stringstream src(src_str.substr(3)); int ch = 0; src >> ch; - rhs = RawSource(SOURCE_TYPE_CH, ch); - + if (ch < CPN_MAX_CHNOUT) + rhs = RawSource(SOURCE_TYPE_CH, ch); + } else if (val_len > 3 && val[0] == 'g' && val[1] == 'v' && @@ -193,7 +201,8 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::stringstream src(src_str.substr(3)); int gv = 0; src >> gv; - rhs = RawSource(SOURCE_TYPE_GVAR, gv); + if (gv < CPN_MAX_GVARS) + rhs = RawSource(SOURCE_TYPE_GVAR, gv); } else if (val_len > 5 && val[0] == 't' && @@ -217,7 +226,8 @@ RawSource YamlRawSourceDecode(const std::string& src_str) int sensor = 0; src >> sensor; - rhs = RawSource(SOURCE_TYPE_TELEMETRY, sensor * 3 + sign); + if (sensor < CPN_MAX_SENSORS) + rhs = RawSource(SOURCE_TYPE_TELEMETRY, sensor * 3 + sign); } else { @@ -253,7 +263,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str) rhs.index = 0; } } - + return rhs; } diff --git a/companion/src/firmwares/modeldata.h b/companion/src/firmwares/modeldata.h index 9eb918982..71fb32a71 100644 --- a/companion/src/firmwares/modeldata.h +++ b/companion/src/firmwares/modeldata.h @@ -63,8 +63,6 @@ class RSSIAlarmData { } }; -#define CPN_MAX_SCRIPTS 9 -#define CPN_MAX_SCRIPT_INPUTS 10 class ScriptData { public: ScriptData() { clear(); } From 924942ca0d09b20663bfe0cef9b8f99d476dfc44 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 12:45:21 +1100 Subject: [PATCH 075/180] Move switch types lookup to rawswitch and firmware --- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 30 ++++++++++--------- companion/src/firmwares/eeprominterface.cpp | 26 ++++++++++++++++ companion/src/firmwares/eeprominterface.h | 11 ++++++- companion/src/firmwares/rawswitch.cpp | 25 ++++++++++++++++ companion/src/firmwares/rawswitch.h | 2 ++ 5 files changed, 79 insertions(+), 15 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 61c3ca463..f4d07d777 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -21,15 +21,6 @@ #include "yaml_rawswitch.h" #include "eeprominterface.h" -const YamlLookupTable switchTypeLut = { - { SWITCH_TYPE_NONE, "NONE" }, - { SWITCH_TYPE_ON, "ON" }, - { SWITCH_TYPE_ONE, "ONE" }, - { SWITCH_TYPE_TELEMETRY, "TELEMETRY_STREAMING" }, - { SWITCH_TYPE_ACT, "RADIO_ACTIVITY" }, - { SWITCH_TYPE_OFF, "OFF" }, -}; - std::string YamlRawSwitchEncode(const RawSwitch& rhs) { std::string sw_str; @@ -73,7 +64,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; default: - sw_str += YAML::LookupValue(switchTypeLut, rhs.type); + sw_str += getCurrentFirmware()->getRawSwitchTypesTag(sval); break; } return sw_str; @@ -95,6 +86,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, std::stoi(sw_str.substr(1, val_len - 1)) - 1); @@ -103,21 +95,25 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && (val[2] >= '0' && val[2] <= '9') && (val[3] >= '0' && val[3] < (multiposcnt + '0'))) { + rhs = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, (val[2] - '0') * multiposcnt + (val[3] - '0')); } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && (val[2] >= '0' && val[2] <= '9')) { + rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { + if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { rhs = RawSwitch(SWITCH_TYPE_SENSOR, std::stoi(sw_str.substr(1, val_len - 1)) - 1); } } else if (sw_str.substr(0, 4) == std::string("Trim")) { + int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str.c_str()); if (tsw_idx >= 0) { rhs.type = SWITCH_TYPE_TRIM; @@ -127,15 +123,23 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len >= 3 && val[0] == 'S' && (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { + int sw_idx = getCurrentFirmware()->getSwitchesIndex(sw_str.substr(0, 2).c_str()); if (sw_idx >= 0) { rhs.type = SWITCH_TYPE_SWITCH; rhs.index = sw_idx * 3 + val[2] - '0'; } + // TODO: SWITCH_TYPE_TIMER_MODE + //} else if (sw_str.substr(0, ?) == std::string("????")) { + } else { - YAML::Node(sw_str) >> rhs.type; - rhs.index = 0; + // types which do not use index + int sw_type = getCurrentFirmware()->getRawSwitchTypesIndex(sw_str.c_str()); + if (sw_type >= 0) { + rhs.type = (RawSwitchType)sw_type; + rhs.index = 0; + } } if (neg) { @@ -146,8 +150,6 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) namespace YAML { -ENUM_CONVERTER(RawSwitchType, switchTypeLut); - Node convert::encode(const RawSwitch& rhs) { return Node(YamlRawSwitchEncode(rhs)); diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 4fcef3f1d..e7f36875b 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -256,3 +256,29 @@ std::string Firmware::getTrimSwitchesTag(unsigned int index) return std::string(); } + +int Firmware::getRawSwitchTypesIndex(const char * tag) +{ + const StringTagMappingTable& lut = rawSwitchTypesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getRawSwitchTypesTag(unsigned int index) +{ + const StringTagMappingTable& lut = rawSwitchTypesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index b2bdf4c61..2632224d9 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -293,7 +293,8 @@ class Firmware eepromInterface(nullptr), analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)), switchesLookupTable(Boards::getSwitchesLookupTable(board)), - trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)) + trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)), + rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()) { } @@ -417,12 +418,19 @@ class Firmware return &trimSwitchesLookupTable; } + const StringTagMappingTable* getRawSwitchTypesLookupTable() + { + return &rawSwitchTypesLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); int getSwitchesIndex(const char * tag); std::string getSwitchesTag(unsigned int index); int getTrimSwitchesIndex(const char * tag); std::string getTrimSwitchesTag(unsigned int index); + int getRawSwitchTypesIndex(const char * tag); + std::string getRawSwitchTypesTag(unsigned int index); protected: QString id; @@ -434,6 +442,7 @@ class Firmware const StringTagMappingTable analogInputNamesLookupTable; const StringTagMappingTable switchesLookupTable; const StringTagMappingTable trimSwitchesLookupTable; + const StringTagMappingTable rawSwitchTypesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; diff --git a/companion/src/firmwares/rawswitch.cpp b/companion/src/firmwares/rawswitch.cpp index 45d13b1fc..5ed4d1c68 100644 --- a/companion/src/firmwares/rawswitch.cpp +++ b/companion/src/firmwares/rawswitch.cpp @@ -241,3 +241,28 @@ QStringList RawSwitch::getSwitchList(Boards board) const } return ret; } + +// static +StringTagMappingTable RawSwitch::getRawSwitchTypesLookupTable() +{ + StringTagMappingTable tbl; + + tbl.insert(tbl.end(), { + {std::to_string(SWITCH_TYPE_NONE), "NONE"}, + {std::to_string(SWITCH_TYPE_SWITCH), "Sxn"}, + {std::to_string(SWITCH_TYPE_VIRTUAL), "Ln"}, + {std::to_string(SWITCH_TYPE_MULTIPOS_POT), "6Pn"}, + {std::to_string(SWITCH_TYPE_TRIM), "Trim"}, + {std::to_string(SWITCH_TYPE_ROTARY_ENCODER), "RE"}, + {std::to_string(SWITCH_TYPE_ON), "ON"}, + {std::to_string(SWITCH_TYPE_OFF), "OFF"}, + {std::to_string(SWITCH_TYPE_ONE), "ONE"}, + {std::to_string(SWITCH_TYPE_FLIGHT_MODE), "FMn"}, + {std::to_string(SWITCH_TYPE_TIMER_MODE), "Timer"}, + {std::to_string(SWITCH_TYPE_TELEMETRY), "TELEMETRY_STREAMING"}, + {std::to_string(SWITCH_TYPE_SENSOR), "Tnn"}, + {std::to_string(SWITCH_TYPE_ACT), "RADIO_ACTIVITY"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/rawswitch.h b/companion/src/firmwares/rawswitch.h index 762ff83ff..d108cf1d6 100644 --- a/companion/src/firmwares/rawswitch.h +++ b/companion/src/firmwares/rawswitch.h @@ -22,6 +22,7 @@ #include "boards.h" #include "constants.h" +#include "datahelpers.h" #include @@ -89,6 +90,7 @@ class RawSwitch { bool isSet() const { return type != SWITCH_TYPE_NONE || index != 0; } void clear() { type = SWITCH_TYPE_NONE; index = 0; } QStringList getSwitchList(Boards board) const; + static StringTagMappingTable getRawSwitchTypesLookupTable(); bool operator== ( const RawSwitch& other) const { return (this->type == other.type) && (this->index == other.index); From b20316e0d5962195c0d2f1244ae9c7345dc0311f Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 12:55:55 +1100 Subject: [PATCH 076/180] Switch type timer mode TODO --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index f4d07d777..967dafd13 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -63,6 +63,12 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) sw_str += std::to_string(sval + 1); break; + case SWITCH_TYPE_TIMER_MODE: + // TODO: + //sw_str += "Tmr"; + //sw_str += std::to_string(sval + 1); + break; + default: sw_str += getCurrentFirmware()->getRawSwitchTypesTag(sval); break; From 71b254924ea39e27bd0106992729e057748db6a1 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 13:03:12 +1100 Subject: [PATCH 077/180] RawSwitch timer mode appears to be depreciated --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 967dafd13..de83e26b0 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -64,9 +64,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; case SWITCH_TYPE_TIMER_MODE: - // TODO: - //sw_str += "Tmr"; - //sw_str += std::to_string(sval + 1); + // TODO: check as it appears to be depreciated as not in RawSwitch data model and not in radio yaml export break; default: @@ -137,7 +135,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } // TODO: SWITCH_TYPE_TIMER_MODE - //} else if (sw_str.substr(0, ?) == std::string("????")) { + // check as it appears to be depreciated as not in RawSwitch data model and not in radio yaml export } else { // types which do not use index From 0421774a68d0011b8d5e8294d5ac77fc04f7c0aa Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 20:48:14 +1100 Subject: [PATCH 078/180] Cpn add TX GPS source --- companion/src/datamodels/compounditemmodels.cpp | 2 +- companion/src/firmwares/edgetx/yaml_rawsource.cpp | 3 +-- companion/src/firmwares/opentx/opentxeeprom.cpp | 9 +++++---- companion/src/firmwares/rawsource.cpp | 8 ++++++-- companion/src/firmwares/rawsource.h | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index f4a135ee7..29dc9b8f5 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -118,7 +118,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, CPN_MAX_CYC); addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, firmware->getCapability(TrainerInputs)); addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, firmware->getCapability(Outputs)); - addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 5); + addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 6); addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, firmware->getCapability(Sensors) * 3); addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, firmware->getCapability(Gvars)); } diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index f0ffff324..868ab4776 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -44,11 +44,10 @@ const YamlLookupTable cycSourceLut = { const YamlLookupTable specialSourceLut = { { 0, "TX_VOLTAGE" }, { 1, "TX_TIME" }, - { 2, "ONE" }, + { 2, "TX_GPS" }, { 3, "TIMER1" }, { 4, "TIMER2" }, { 5, "TIMER3" }, - // TODO: { ???, "TX_GPS" }, }; std::string YamlRawSourceEncode(const RawSource& rhs) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 5017308cc..51402e931 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -384,10 +384,11 @@ class SourcesConversionTable: public ConversionTable { addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++); addConversion(RawSource(SOURCE_TYPE_SPECIAL, 0), val++); // BATT addConversion(RawSource(SOURCE_TYPE_SPECIAL, 1), val++); // TIME - val += 5; - addConversion(RawSource(SOURCE_TYPE_SPECIAL, 2), val++); // Timer1 - addConversion(RawSource(SOURCE_TYPE_SPECIAL, 3), val++); // Timer2 - addConversion(RawSource(SOURCE_TYPE_SPECIAL, 4), val++); // Timer3 + addConversion(RawSource(SOURCE_TYPE_SPECIAL, 2), val++); // GPS + val += 4; + addConversion(RawSource(SOURCE_TYPE_SPECIAL, 3), val++); // Timer1 + addConversion(RawSource(SOURCE_TYPE_SPECIAL, 4), val++); // Timer2 + addConversion(RawSource(SOURCE_TYPE_SPECIAL, 5), val++); // Timer3 for (int i=0; i 0); + return (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_TIMER1_IDX); } bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index a7d293173..25779ccd4 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -179,7 +179,7 @@ enum RawSourceType { }; constexpr int SOURCE_TYPE_STICK_THR_IDX { 3 }; // TODO is there a function to determine index? -constexpr int SOURCE_TYPE_SPECIAL_TIMER1_IDX { 2 }; // TODO temp const until Timers own source type +constexpr int SOURCE_TYPE_SPECIAL_TIMER1_IDX { 3 }; // TODO temp const until Timers own source type class RawSourceRange { From 0857c5d9ea4c701c4a6a14487e2f7c6db640b839 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 21:41:36 +1100 Subject: [PATCH 079/180] Reduce future maintenance of source type special --- .../src/datamodels/compounditemmodels.cpp | 2 +- .../src/firmwares/customfunctiondata.cpp | 4 ++-- .../src/firmwares/edgetx/yaml_rawsource.cpp | 10 +++++++--- .../src/firmwares/opentx/opentxeeprom.cpp | 10 +++------- companion/src/firmwares/rawsource.cpp | 13 ++++++++----- companion/src/firmwares/rawsource.h | 19 ++++++++++++++++++- 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/companion/src/datamodels/compounditemmodels.cpp b/companion/src/datamodels/compounditemmodels.cpp index 29dc9b8f5..7ee049d1f 100644 --- a/companion/src/datamodels/compounditemmodels.cpp +++ b/companion/src/datamodels/compounditemmodels.cpp @@ -118,7 +118,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, CPN_MAX_CYC); addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, firmware->getCapability(TrainerInputs)); addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, firmware->getCapability(Outputs)); - addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 6); + addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, SOURCE_TYPE_SPECIAL_COUNT); addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, firmware->getCapability(Sensors) * 3); addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, firmware->getCapability(Gvars)); } diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index f60f1c74a..293bdd6db 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -84,7 +84,7 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData else if (func == FuncReset) return tr("Reset"); else if (func >= FuncSetTimer1 && func <= FuncSetTimerLast) - return tr("Set %1").arg(RawSource(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_TIMER1_IDX + func - FuncSetTimer1).toString(model)); + return tr("Set %1").arg(RawSource(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_FIRST_TIMER + func - FuncSetTimer1).toString(model)); else if (func == FuncVario) return tr("Vario"); else if (func == FuncPlayPrompt) @@ -249,7 +249,7 @@ QString CustomFunctionData::resetToString(const int value, const ModelData * mod if (value < step) { if (value < firmware->getCapability(Timers)) - return RawSource(SOURCE_TYPE_SPECIAL, value + SOURCE_TYPE_SPECIAL_TIMER1_IDX).toString(model); + return RawSource(SOURCE_TYPE_SPECIAL, value + SOURCE_TYPE_SPECIAL_FIRST_TIMER).toString(model); else return QString(CPN_STR_UNKNOWN_ITEM); } diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 868ab4776..df72ec4fd 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -45,9 +45,13 @@ const YamlLookupTable specialSourceLut = { { 0, "TX_VOLTAGE" }, { 1, "TX_TIME" }, { 2, "TX_GPS" }, - { 3, "TIMER1" }, - { 4, "TIMER2" }, - { 5, "TIMER3" }, + { 3, "RESERVED1" }, + { 4, "RESERVED2" }, + { 5, "RESERVED3" }, + { 6, "RESERVED4" }, + { 7, "TIMER1" }, + { 8, "TIMER2" }, + { 9, "TIMER3" }, }; std::string YamlRawSourceEncode(const RawSource& rhs) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 51402e931..d07c0887c 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -184,6 +184,7 @@ inline int MAX_MOUSE_ANALOG_SOURCES(Board::Type board, int version) #define NUM_PPM_INPUTS(board, version) 16 #define ROTENC_COUNT(board, version) ((IS_STM32(board) && version >= 218) ? 0 : 1) #define MAX_AUX_TRIMS(board) ((IS_FAMILY_HORUS_OR_T16(board) && !IS_FLYSKY_NV14(board)) ? 2 : 0) +#define MAX_SOURCE_TYPE_SPECIAL(board, version) SOURCE_TYPE_SPECIAL_COUNT inline int switchIndex(int i, Board::Type board, unsigned int version) { @@ -382,13 +383,8 @@ class SourcesConversionTable: public ConversionTable { if (!(flags & FLAG_NOTELEMETRY)) { for (int i=0; i= SOURCE_TYPE_SPECIAL_TIMER1_IDX && index <= SOURCE_TYPE_SPECIAL_TIMER1_IDX + CPN_MAX_TIMERS - 1) { + if (index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER) { if (model) - result = model->timers[index - SOURCE_TYPE_SPECIAL_TIMER1_IDX].nameToString(index - SOURCE_TYPE_SPECIAL_TIMER1_IDX); + result = model->timers[index - SOURCE_TYPE_SPECIAL_FIRST_TIMER].nameToString(index - SOURCE_TYPE_SPECIAL_FIRST_TIMER); else - result = TimerData().nameToString(index - SOURCE_TYPE_SPECIAL_TIMER1_IDX); + result = TimerData().nameToString(index - SOURCE_TYPE_SPECIAL_FIRST_TIMER); } else result = CHECK_IN_ARRAY(special, index); @@ -293,7 +293,7 @@ bool RawSource::isSlider(int * sliderIndex, Board::Type board) const bool RawSource::isTimeBased(Board::Type board) const { - return (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_TIMER1_IDX); + return (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER); } bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const @@ -309,6 +309,9 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings if (type == SOURCE_TYPE_SWITCH && index >= b.getCapability(Board::Switches)) return false; + if (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED && index <= SOURCE_TYPE_SPECIAL_LAST_RESERVED) + return false; + if (model) { if (type == SOURCE_TYPE_VIRTUAL_INPUT && !model->isInputValid(index)) return false; diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index 25779ccd4..f5fbfbcd5 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -178,8 +178,25 @@ enum RawSourceType { MAX_SOURCE_TYPE }; +enum RawSourceTypeSpecial { + SOURCE_TYPE_SPECIAL_TX_BATT, + SOURCE_TYPE_SPECIAL_TX_TIME, + SOURCE_TYPE_SPECIAL_TX_GPS, + SOURCE_TYPE_SPECIAL_FIRST_RESERVED, + SOURCE_TYPE_SPECIAL_RESERVED1 = SOURCE_TYPE_SPECIAL_FIRST_RESERVED, + SOURCE_TYPE_SPECIAL_RESERVED2, + SOURCE_TYPE_SPECIAL_RESERVED3, + SOURCE_TYPE_SPECIAL_RESERVED4, + SOURCE_TYPE_SPECIAL_LAST_RESERVED = SOURCE_TYPE_SPECIAL_RESERVED4, + SOURCE_TYPE_SPECIAL_FIRST_TIMER, + SOURCE_TYPE_SPECIAL_TIMER1 = SOURCE_TYPE_SPECIAL_FIRST_TIMER, + SOURCE_TYPE_SPECIAL_TIMER2, + SOURCE_TYPE_SPECIAL_TIMER3, + SOURCE_TYPE_SPECIAL_LAST_TIMER = SOURCE_TYPE_SPECIAL_TIMER3, + SOURCE_TYPE_SPECIAL_COUNT +}; + constexpr int SOURCE_TYPE_STICK_THR_IDX { 3 }; // TODO is there a function to determine index? -constexpr int SOURCE_TYPE_SPECIAL_TIMER1_IDX { 3 }; // TODO temp const until Timers own source type class RawSourceRange { From 6f54fad526e68f34bd0c89c7e920643069e13530 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 21:42:18 +1100 Subject: [PATCH 080/180] Fix compiler warning --- companion/src/firmwares/edgetx/yaml_switchconfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 70218dc03..f8892d819 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -105,7 +105,7 @@ int YamlPotLookup::name2idx(const std::string& name) std::string YamlPotLookup::idx2name(unsigned int idx) { auto fw = getCurrentFirmware(); - int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + unsigned int pots = Boards::getCapability(fw->getBoard(), Board::Pots); if (idx >= pots) return std::string(); return fw->getAnalogInputTag(idx); @@ -131,7 +131,7 @@ std::string YamlSliderLookup::idx2name(unsigned int idx) { auto fw = getCurrentFirmware(); int pots = Boards::getCapability(fw->getBoard(), Board::Pots); - int sliders = Boards::getCapability(fw->getBoard(), Board::Sliders); + unsigned int sliders = Boards::getCapability(fw->getBoard(), Board::Sliders); if (idx >= sliders) return std::string(); return fw->getAnalogInputTag(idx + pots); From 4c92f9dbc95cdb0173f72acdd0f39330f9c2b017 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 22:31:58 +1100 Subject: [PATCH 081/180] Move special source lookup to firmware --- .../src/firmwares/edgetx/yaml_rawsource.cpp | 21 +++------------ companion/src/firmwares/eeprominterface.cpp | 26 +++++++++++++++++++ companion/src/firmwares/eeprominterface.h | 11 +++++++- companion/src/firmwares/rawsource.cpp | 21 +++++++++++++++ companion/src/firmwares/rawsource.h | 2 ++ 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index df72ec4fd..ba7ca7d10 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -41,19 +41,6 @@ const YamlLookupTable cycSourceLut = { // SOURCE_TYPE_MAX // { MIXSRC_MAX, "MAX" }, -const YamlLookupTable specialSourceLut = { - { 0, "TX_VOLTAGE" }, - { 1, "TX_TIME" }, - { 2, "TX_GPS" }, - { 3, "RESERVED1" }, - { 4, "RESERVED2" }, - { 5, "RESERVED3" }, - { 6, "RESERVED4" }, - { 7, "TIMER1" }, - { 8, "TIMER2" }, - { 9, "TIMER3" }, -}; - std::string YamlRawSourceEncode(const RawSource& rhs) { std::string src_str; @@ -105,7 +92,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_SPECIAL: - src_str = YAML::LookupValue(specialSourceLut, rhs.index); + src_str = getCurrentFirmware()->getRawSourceSpecialTypesTag(rhs.index); break; case SOURCE_TYPE_TELEMETRY: src_str = "tele("; @@ -255,10 +242,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str) rhs.index = conv.as(); } - conv = node >> specialSourceLut; - if (conv.IsScalar()) { + int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str()); + if (sp_idx >= 0) { rhs.type = SOURCE_TYPE_SPECIAL; - rhs.index = conv.as(); + rhs.index = sp_idx; } if (node.IsScalar() && node.as() == "MAX") { diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index e7f36875b..458a69dff 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -282,3 +282,29 @@ std::string Firmware::getRawSwitchTypesTag(unsigned int index) return std::string(); } + +int Firmware::getRawSourceSpecialTypesIndex(const char * tag) +{ + const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getRawSourceSpecialTypesTag(unsigned int index) +{ + const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 2632224d9..049e0ba12 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -294,7 +294,8 @@ class Firmware analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)), switchesLookupTable(Boards::getSwitchesLookupTable(board)), trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)), - rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()) + rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()), + rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()) { } @@ -423,6 +424,11 @@ class Firmware return &rawSwitchTypesLookupTable; } + const StringTagMappingTable* getRawSourceSpecialTypesLookupTable() + { + return &rawSourceSpecialTypesLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); int getSwitchesIndex(const char * tag); @@ -431,6 +437,8 @@ class Firmware std::string getTrimSwitchesTag(unsigned int index); int getRawSwitchTypesIndex(const char * tag); std::string getRawSwitchTypesTag(unsigned int index); + int getRawSourceSpecialTypesIndex(const char * tag); + std::string getRawSourceSpecialTypesTag(unsigned int index); protected: QString id; @@ -443,6 +451,7 @@ class Firmware const StringTagMappingTable switchesLookupTable; const StringTagMappingTable trimSwitchesLookupTable; const StringTagMappingTable rawSwitchTypesLookupTable; + const StringTagMappingTable rawSourceSpecialTypesLookupTable; QList languages; //QList ttslanguages; OptionsList opts; diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index 36844fab0..030ec3753 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -418,3 +418,24 @@ QStringList RawSource::getSwitchList(Boards board) const } return ret; } + +// static +StringTagMappingTable RawSource::getSpecialTypesLookupTable() +{ + StringTagMappingTable tbl; + +tbl.insert(tbl.end(), { + {std::to_string(SOURCE_TYPE_SPECIAL_TX_BATT), "TX_VOLTAGE"}, + {std::to_string(SOURCE_TYPE_SPECIAL_TX_TIME), "TX_TIME"}, + {std::to_string(SOURCE_TYPE_SPECIAL_TX_GPS), "TX_GPS"}, + {std::to_string(SOURCE_TYPE_SPECIAL_RESERVED1), "RESERVED1"}, + {std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "RESERVED2"}, + {std::to_string(SOURCE_TYPE_SPECIAL_RESERVED3), "RESERVED3"}, + {std::to_string(SOURCE_TYPE_SPECIAL_RESERVED4), "RESERVED4"}, + {std::to_string(SOURCE_TYPE_SPECIAL_TIMER1), "TIMER1"}, + {std::to_string(SOURCE_TYPE_SPECIAL_TIMER2), "TIMER2"}, + {std::to_string(SOURCE_TYPE_SPECIAL_TIMER3), "TIMER3"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index f5fbfbcd5..88339d514 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -23,6 +23,7 @@ #include "boards.h" #include "constants.h" +#include "datahelpers.h" #include @@ -274,6 +275,7 @@ class RawSource { void clear() { type = SOURCE_TYPE_NONE; index = 0; } QStringList getStickList(Boards board) const; QStringList getSwitchList(Boards board) const; + static StringTagMappingTable getSpecialTypesLookupTable(); bool operator == ( const RawSource & other) const { return (this->type == other.type) && (this->index == other.index); From ac9ce745bdc2f816f3693203a29beee3cfccf222 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 22:48:33 +1100 Subject: [PATCH 082/180] Move cyc source to firmware --- .../src/firmwares/edgetx/yaml_rawsource.cpp | 18 +++---------- companion/src/firmwares/eeprominterface.cpp | 26 +++++++++++++++++++ companion/src/firmwares/eeprominterface.h | 11 +++++++- companion/src/firmwares/rawsource.cpp | 14 ++++++++++ companion/src/firmwares/rawsource.h | 1 + 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index ba7ca7d10..21dccdf26 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -31,16 +31,6 @@ const YamlLookupTable trimSourceLut = { { 5, "TrimT6" }, }; -// SOURCE_TYPE_CYC -const YamlLookupTable cycSourceLut = { - { 0, "CYC1" }, - { 1, "CYC2" }, - { 2, "CYC3" }, -}; - -// SOURCE_TYPE_MAX - // { MIXSRC_MAX, "MAX" }, - std::string YamlRawSourceEncode(const RawSource& rhs) { std::string src_str; @@ -74,7 +64,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str += ")"; break; case SOURCE_TYPE_CYC: - src_str = YAML::LookupValue(cycSourceLut, rhs.index); + src_str = getCurrentFirmware()->getRawSourceCyclicTag(rhs.index); break; case SOURCE_TYPE_PPM: src_str += "tr("; @@ -236,10 +226,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str) rhs.index = conv.as(); } - conv = node >> cycSourceLut; - if (conv.IsScalar()) { + int cyc_idx = getCurrentFirmware()->getRawSourceCyclicIndex(src_str.c_str()); + if (cyc_idx >= 0) { rhs.type = SOURCE_TYPE_CYC; - rhs.index = conv.as(); + rhs.index = cyc_idx; } int sp_idx = getCurrentFirmware()->getRawSourceSpecialTypesIndex(src_str.c_str()); diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 458a69dff..56d039bbc 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -308,3 +308,29 @@ std::string Firmware::getRawSourceSpecialTypesTag(unsigned int index) return std::string(); } + +int Firmware::getRawSourceCyclicIndex(const char * tag) +{ + const StringTagMappingTable& lut = rawSourceCyclicLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getRawSourceCyclicTag(unsigned int index) +{ + const StringTagMappingTable& lut = rawSourceCyclicLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 049e0ba12..c61d921a5 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -295,7 +295,8 @@ class Firmware switchesLookupTable(Boards::getSwitchesLookupTable(board)), trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)), rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()), - rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()) + rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()), + rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable()) { } @@ -429,6 +430,11 @@ class Firmware return &rawSourceSpecialTypesLookupTable; } + const StringTagMappingTable* getRawSourceCyclicLookupTable() + { + return &rawSourceCyclicLookupTable; + } + int getAnalogInputIndex(const char * tag); std::string getAnalogInputTag(unsigned int index); int getSwitchesIndex(const char * tag); @@ -439,6 +445,8 @@ class Firmware std::string getRawSwitchTypesTag(unsigned int index); int getRawSourceSpecialTypesIndex(const char * tag); std::string getRawSourceSpecialTypesTag(unsigned int index); + int getRawSourceCyclicIndex(const char * tag); + std::string getRawSourceCyclicTag(unsigned int index); protected: QString id; @@ -452,6 +460,7 @@ class Firmware const StringTagMappingTable trimSwitchesLookupTable; const StringTagMappingTable rawSwitchTypesLookupTable; const StringTagMappingTable rawSourceSpecialTypesLookupTable; + const StringTagMappingTable rawSourceCyclicLookupTable; QList languages; //QList ttslanguages; OptionsList opts; diff --git a/companion/src/firmwares/rawsource.cpp b/companion/src/firmwares/rawsource.cpp index 030ec3753..b1ad52e30 100644 --- a/companion/src/firmwares/rawsource.cpp +++ b/companion/src/firmwares/rawsource.cpp @@ -439,3 +439,17 @@ tbl.insert(tbl.end(), { return tbl; } + +// static +StringTagMappingTable RawSource::getCyclicLookupTable() +{ + StringTagMappingTable tbl; + +tbl.insert(tbl.end(), { + {"0", "CYC1"}, + {"1", "CYC2"}, + {"2", "CYC3"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/rawsource.h b/companion/src/firmwares/rawsource.h index 88339d514..304024446 100644 --- a/companion/src/firmwares/rawsource.h +++ b/companion/src/firmwares/rawsource.h @@ -276,6 +276,7 @@ class RawSource { QStringList getStickList(Boards board) const; QStringList getSwitchList(Boards board) const; static StringTagMappingTable getSpecialTypesLookupTable(); + static StringTagMappingTable getCyclicLookupTable(); bool operator == ( const RawSource & other) const { return (this->type == other.type) && (this->index == other.index); From 19a9259d9672caa733ca65298e6166e4e44f808f Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 16 Dec 2021 23:04:54 +1100 Subject: [PATCH 083/180] Move trim sources to boards --- companion/src/firmwares/boards.cpp | 21 +++++++++++++++ companion/src/firmwares/boards.h | 1 + .../src/firmwares/edgetx/yaml_rawsource.cpp | 18 +++---------- companion/src/firmwares/eeprominterface.cpp | 27 +++++++++++++++++++ companion/src/firmwares/eeprominterface.h | 9 +++++++ 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 3c790fd7a..4332f32d8 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -784,3 +784,24 @@ StringTagMappingTable Boards::getTrimSwitchesLookupTable(Board::Type board) return tbl; } + +// static +StringTagMappingTable Boards::getTrimSourcesLookupTable(Board::Type board) +{ + StringTagMappingTable tbl; + + tbl.insert(tbl.end(), { + {std::to_string(TRIM_AXIS_LH), "TrimRud"}, + {std::to_string(TRIM_AXIS_LV), "TrimEle"}, + {std::to_string(TRIM_AXIS_RV), "TrimThr"}, + {std::to_string(TRIM_AXIS_RH), "TrimAil"}, + }); + + if (getCapability(board, Board::NumTrims) > 4) + tbl.insert(tbl.end(), { + {std::to_string(TRIM_AXIS_T5), "TrimT5"}, + {std::to_string(TRIM_AXIS_T6), "TrimT6"}, + }); + + return tbl; +} diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 1cf1fb353..f3a836963 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -215,6 +215,7 @@ class Boards static AbstractStaticItemModel * sliderTypeItemModel(); static AbstractStaticItemModel * switchTypeItemModel(); static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board); + static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board); protected: diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 21dccdf26..c8f02d794 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -21,16 +21,6 @@ #include "yaml_rawsource.h" #include "eeprominterface.h" -// SOURCE_TYPE_TRIM -const YamlLookupTable trimSourceLut = { - { 0, "TrimRud" }, - { 1, "TrimEle" }, - { 2, "TrimThr" }, - { 3, "TrimAil" }, - { 4, "TrimT5" }, - { 5, "TrimT6" }, -}; - std::string YamlRawSourceEncode(const RawSource& rhs) { std::string src_str; @@ -49,7 +39,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) src_str = getCurrentFirmware()->getAnalogInputTag(rhs.index); break; case SOURCE_TYPE_TRIM: - src_str = YAML::LookupValue(trimSourceLut, rhs.index); + src_str = getCurrentFirmware()->getTrimSourcesTag(rhs.index); break; case SOURCE_TYPE_MAX: src_str += "MAX"; @@ -220,10 +210,10 @@ RawSource YamlRawSourceDecode(const std::string& src_str) rhs.index = ana_idx; } - YAML::Node conv = node >> trimSourceLut; - if (conv.IsScalar()) { + int trm_idx = getCurrentFirmware()->getTrimSourcesIndex(src_str.c_str()); + if (trm_idx >= 0) { rhs.type = SOURCE_TYPE_TRIM; - rhs.index = conv.as(); + rhs.index = trm_idx; } int cyc_idx = getCurrentFirmware()->getRawSourceCyclicIndex(src_str.c_str()); diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 56d039bbc..4cd5f11fe 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -257,6 +257,33 @@ std::string Firmware::getTrimSwitchesTag(unsigned int index) return std::string(); } + +int Firmware::getTrimSourcesIndex(const char * tag) +{ + const StringTagMappingTable& lut = trimSourcesLookupTable; + + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string Firmware::getTrimSourcesTag(unsigned int index) +{ + const StringTagMappingTable& lut = trimSourcesLookupTable; + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} + int Firmware::getRawSwitchTypesIndex(const char * tag) { const StringTagMappingTable& lut = rawSwitchTypesLookupTable; diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index c61d921a5..9c9205e96 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -294,6 +294,7 @@ class Firmware analogInputNamesLookupTable(Boards::getAnalogNamesLookupTable(board)), switchesLookupTable(Boards::getSwitchesLookupTable(board)), trimSwitchesLookupTable(Boards::getTrimSwitchesLookupTable(board)), + trimSourcesLookupTable(Boards::getTrimSourcesLookupTable(board)), rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()), rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()), rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable()) @@ -420,6 +421,11 @@ class Firmware return &trimSwitchesLookupTable; } + const StringTagMappingTable* getTrimSourcesLookupTable() + { + return &trimSourcesLookupTable; + } + const StringTagMappingTable* getRawSwitchTypesLookupTable() { return &rawSwitchTypesLookupTable; @@ -441,6 +447,8 @@ class Firmware std::string getSwitchesTag(unsigned int index); int getTrimSwitchesIndex(const char * tag); std::string getTrimSwitchesTag(unsigned int index); + int getTrimSourcesIndex(const char * tag); + std::string getTrimSourcesTag(unsigned int index); int getRawSwitchTypesIndex(const char * tag); std::string getRawSwitchTypesTag(unsigned int index); int getRawSourceSpecialTypesIndex(const char * tag); @@ -458,6 +466,7 @@ class Firmware const StringTagMappingTable analogInputNamesLookupTable; const StringTagMappingTable switchesLookupTable; const StringTagMappingTable trimSwitchesLookupTable; + const StringTagMappingTable trimSourcesLookupTable; const StringTagMappingTable rawSwitchTypesLookupTable; const StringTagMappingTable rawSourceSpecialTypesLookupTable; const StringTagMappingTable rawSourceCyclicLookupTable; From 340b779c8b0bca7253f296a8954ebf5379788fac Mon Sep 17 00:00:00 2001 From: elecpower Date: Fri, 17 Dec 2021 16:46:40 +1100 Subject: [PATCH 084/180] String tag mapping housekeeping --- companion/src/firmwares/datahelpers.cpp | 23 +++ companion/src/firmwares/datahelpers.h | 16 +- .../src/firmwares/edgetx/yaml_calibdata.cpp | 1 - companion/src/firmwares/eeprominterface.cpp | 183 ------------------ companion/src/firmwares/eeprominterface.h | 54 +----- 5 files changed, 48 insertions(+), 229 deletions(-) diff --git a/companion/src/firmwares/datahelpers.cpp b/companion/src/firmwares/datahelpers.cpp index 8ae759a1b..a7003d75b 100644 --- a/companion/src/firmwares/datahelpers.cpp +++ b/companion/src/firmwares/datahelpers.cpp @@ -68,3 +68,26 @@ QString DataHelpers::timeToString(const int value, const unsigned int mask) result.append(QString("%1:%2").arg(minutes, 2, 10, QLatin1Char('0')).arg(seconds, 2, 10, QLatin1Char('0'))); return result; } + +int DataHelpers::getStringTagMappingIndex(const StringTagMappingTable& lut, const char * tag) +{ + auto it = + find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { + if (elmt.tag == tag) return true; + return false; + }); + + if (it != lut.end()) { + return it - lut.begin(); + } + + return -1; +} + +std::string DataHelpers::getStringTagMappingTag(const StringTagMappingTable& lut, unsigned int index) +{ + if (index < lut.size()) + return lut[index].tag; + + return std::string(); +} diff --git a/companion/src/firmwares/datahelpers.h b/companion/src/firmwares/datahelpers.h index 336616dbe..07d7609e0 100644 --- a/companion/src/firmwares/datahelpers.h +++ b/companion/src/firmwares/datahelpers.h @@ -49,6 +49,19 @@ struct StringTagMapping { typedef std::vector StringTagMappingTable; +#define STRINGTAGMAPPINGFUNCS_HELPER(tbl, name, index, tag) \ + inline int name##index (const char * tag) \ + { \ + return DataHelpers::getStringTagMappingIndex(tbl, tag); \ + } \ + \ + inline std::string name##tag (unsigned int index) \ + { \ + return DataHelpers::getStringTagMappingTag(tbl, index); \ + } + +#define STRINGTAGMAPPINGFUNCS(tbl, name) STRINGTAGMAPPINGFUNCS_HELPER(tbl, get##name, Index, Tag) + class FieldRange { public: @@ -92,5 +105,6 @@ namespace DataHelpers QString boolToString(const bool value, const BoolFormat format); QString getElementName(const QString & prefix, const unsigned int index, const char * name = 0, const bool padding = false); QString timeToString(const int value, const unsigned int mask); - + int getStringTagMappingIndex(const StringTagMappingTable& lut, const char * tag); + std::string getStringTagMappingTag(const StringTagMappingTable& lut, unsigned int index); } diff --git a/companion/src/firmwares/edgetx/yaml_calibdata.cpp b/companion/src/firmwares/edgetx/yaml_calibdata.cpp index 45f1fd407..32f0b2000 100644 --- a/companion/src/firmwares/edgetx/yaml_calibdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_calibdata.cpp @@ -68,7 +68,6 @@ Node convert::encode(const YamlCalibData& rhs) { Node node; int idx = 0; - // TODO: for efficiency construct once at an outer level possibly add to Firmware? const auto* calibIdxLut = getCurrentFirmware()->getAnalogIndexNamesLookupTable(); for (const auto& kv : *calibIdxLut) { node[kv.tag] = rhs.calib[idx++]; diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 4cd5f11fe..90272d0ad 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -178,186 +178,3 @@ void Firmware::addOptionsGroup(const OptionsGroup & options) { this->opts.append(options); } - -int Firmware::getAnalogInputIndex(const char * tag) -{ - const StringTagMappingTable& lut = analogInputNamesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getAnalogInputTag(unsigned int index) -{ - const StringTagMappingTable& lut = analogInputNamesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - -int Firmware::getSwitchesIndex(const char * tag) -{ - const StringTagMappingTable& lut = switchesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getSwitchesTag(unsigned int index) -{ - const StringTagMappingTable& lut = switchesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - -int Firmware::getTrimSwitchesIndex(const char * tag) -{ - const StringTagMappingTable& lut = trimSwitchesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getTrimSwitchesTag(unsigned int index) -{ - const StringTagMappingTable& lut = trimSwitchesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - - -int Firmware::getTrimSourcesIndex(const char * tag) -{ - const StringTagMappingTable& lut = trimSourcesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getTrimSourcesTag(unsigned int index) -{ - const StringTagMappingTable& lut = trimSourcesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - -int Firmware::getRawSwitchTypesIndex(const char * tag) -{ - const StringTagMappingTable& lut = rawSwitchTypesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getRawSwitchTypesTag(unsigned int index) -{ - const StringTagMappingTable& lut = rawSwitchTypesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - -int Firmware::getRawSourceSpecialTypesIndex(const char * tag) -{ - const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getRawSourceSpecialTypesTag(unsigned int index) -{ - const StringTagMappingTable& lut = rawSourceSpecialTypesLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} - -int Firmware::getRawSourceCyclicIndex(const char * tag) -{ - const StringTagMappingTable& lut = rawSourceCyclicLookupTable; - - auto it = - find_if(lut.begin(), lut.end(), [=](const StringTagMapping& elmt) { - if (elmt.tag == tag) return true; - return false; - }); - - if (it != lut.end()) { - return it - lut.begin(); - } - - return -1; -} - -std::string Firmware::getRawSourceCyclicTag(unsigned int index) -{ - const StringTagMappingTable& lut = rawSourceCyclicLookupTable; - if (index < lut.size()) - return lut[index].tag; - - return std::string(); -} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 9c9205e96..37945e73b 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -411,50 +411,13 @@ class Firmware return &analogInputNamesLookupTable; } - const StringTagMappingTable* getSwitchesLookupTable() - { - return &switchesLookupTable; - } - - const StringTagMappingTable* getTrimSwitchesLookupTable() - { - return &trimSwitchesLookupTable; - } - - const StringTagMappingTable* getTrimSourcesLookupTable() - { - return &trimSourcesLookupTable; - } - - const StringTagMappingTable* getRawSwitchTypesLookupTable() - { - return &rawSwitchTypesLookupTable; - } - - const StringTagMappingTable* getRawSourceSpecialTypesLookupTable() - { - return &rawSourceSpecialTypesLookupTable; - } - - const StringTagMappingTable* getRawSourceCyclicLookupTable() - { - return &rawSourceCyclicLookupTable; - } - - int getAnalogInputIndex(const char * tag); - std::string getAnalogInputTag(unsigned int index); - int getSwitchesIndex(const char * tag); - std::string getSwitchesTag(unsigned int index); - int getTrimSwitchesIndex(const char * tag); - std::string getTrimSwitchesTag(unsigned int index); - int getTrimSourcesIndex(const char * tag); - std::string getTrimSourcesTag(unsigned int index); - int getRawSwitchTypesIndex(const char * tag); - std::string getRawSwitchTypesTag(unsigned int index); - int getRawSourceSpecialTypesIndex(const char * tag); - std::string getRawSourceSpecialTypesTag(unsigned int index); - int getRawSourceCyclicIndex(const char * tag); - std::string getRawSourceCyclicTag(unsigned int index); + STRINGTAGMAPPINGFUNCS(analogInputNamesLookupTable, AnalogInput); + STRINGTAGMAPPINGFUNCS(switchesLookupTable, Switches); + STRINGTAGMAPPINGFUNCS(trimSwitchesLookupTable, TrimSwitches); + STRINGTAGMAPPINGFUNCS(trimSourcesLookupTable, TrimSources); + STRINGTAGMAPPINGFUNCS(rawSwitchTypesLookupTable, RawSwitchTypes); + STRINGTAGMAPPINGFUNCS(rawSourceSpecialTypesLookupTable, RawSourceSpecialTypes); + STRINGTAGMAPPINGFUNCS(rawSourceCyclicLookupTable, RawSourceCyclic); protected: QString id; @@ -463,6 +426,8 @@ class Firmware unsigned int variantBase; Firmware * base; EEPROMInterface * eepromInterface; + + // used by YAML encode and decode const StringTagMappingTable analogInputNamesLookupTable; const StringTagMappingTable switchesLookupTable; const StringTagMappingTable trimSwitchesLookupTable; @@ -470,6 +435,7 @@ class Firmware const StringTagMappingTable rawSwitchTypesLookupTable; const StringTagMappingTable rawSourceSpecialTypesLookupTable; const StringTagMappingTable rawSourceCyclicLookupTable; + QList languages; //QList ttslanguages; OptionsList opts; From d7ca02403fcc6c1838893685733c18a4b05f55de Mon Sep 17 00:00:00 2001 From: elecpower Date: Fri, 17 Dec 2021 17:23:45 +1100 Subject: [PATCH 085/180] Model gvars --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index ee983ccbc..7c82c0540 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -280,6 +280,32 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const GVarData& rhs) + { + Node node; + node["name"] = rhs.name; + node["min"] = rhs.min; + node["max"] = rhs.max; + node["popup"] = rhs.popup; + node["prec"] = rhs.prec; + node["unit"] = rhs.unit; + return node; + } + + static bool decode(const Node& node, GVarData& rhs) + { + node["name"] >> rhs.name; + node["min"] >> rhs.min; + node["max"] >> rhs.max; + node["popup"] >> rhs.popup; + node["prec"] >> rhs.prec; + node["unit"] >> rhs.unit; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -383,7 +409,13 @@ Node convert::encode(const ModelData& rhs) node["displayChecklist"] = (int)rhs.displayChecklist; - // gvarData[] + for (int i = 0; i < CPN_MAX_GVARS; i++) { + const GVarData& gv = rhs.gvarData[i]; + if (!gv.isEmpty()) { + node["gvars"][std::to_string(i)] = gv; + } + } + // mavlink ??? // telemetryProtocol ??? // frsky @@ -474,6 +506,7 @@ bool convert::decode(const Node& node, ModelData& rhs) node["displayChecklist"] >> rhs.displayChecklist; // gvarData[] + node["gvars"] >> rhs.gvarData; // mavlink ??? // telemetryProtocol ??? // frsky From 673ac5acbca153722c9bc08c715529a76444e98e Mon Sep 17 00:00:00 2001 From: elecpower Date: Fri, 17 Dec 2021 22:21:01 +1100 Subject: [PATCH 086/180] Temporarily hide custom screens config for color lcd radios --- companion/src/modeledit/modeledit.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/companion/src/modeledit/modeledit.cpp b/companion/src/modeledit/modeledit.cpp index 60ad7781f..c2f5b2c30 100644 --- a/companion/src/modeledit/modeledit.cpp +++ b/companion/src/modeledit/modeledit.cpp @@ -106,11 +106,12 @@ ModelEdit::ModelEdit(QWidget * parent, RadioData & radioData, int modelId, Firmw s1.report("Telemetry"); } - if (Boards::getCapability(firmware->getBoard(), Board::HasColorLcd)) { + // temporary hide + /*if (Boards::getCapability(firmware->getBoard(), Board::HasColorLcd)) { addTab(new ColorCustomScreensPanel(this, model, generalSettings, firmware, sharedItemModels), tr("Custom Screens")); s1.report("ColorLcd Custom Screens"); } - else if (firmware->getCapability(TelemetryCustomScreens)) { + else */if (firmware->getCapability(TelemetryCustomScreens)) { addTab(new TelemetryCustomScreensPanel(this, model, generalSettings, firmware, sharedItemModels), tr("Custom Screens")); s1.report("Telemetry Custom Screens"); } From dac2a9401bbb72dd3f95b8cdd191066d50301d16 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 18 Dec 2021 06:25:29 +1100 Subject: [PATCH 087/180] Add potswarningmode --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 7c82c0540..b96957770 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -63,6 +63,12 @@ static const YamlLookupTable swashTypeLut = { { 4, "TYPE_90" }, }; +static const YamlLookupTable potsWarningModeLut = { + { 0, "WARN_OFF" }, + { 1, "WARN_MANUAL" }, + { 2, "WARN_AUTO" }, +}; + struct YamlTrim { int mode = 0; int ref = 0; @@ -403,7 +409,7 @@ Node convert::encode(const ModelData& rhs) // switchWarningStates node["thrTrimSw"] = rhs.thrTrimSwitch; - // potsWarningMode + node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode; // potsWarnEnabled[] // potsWarnPosition[] @@ -499,13 +505,12 @@ bool convert::decode(const Node& node, ModelData& rhs) // switchWarningStates node["thrTrimSw"] >> rhs.thrTrimSwitch; - // potsWarningMode + node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode; // potsWarnEnabled[] // potsWarnPosition[] node["displayChecklist"] >> rhs.displayChecklist; - // gvarData[] node["gvars"] >> rhs.gvarData; // mavlink ??? // telemetryProtocol ??? From 9d81de1d29fab745bf2afb29ec2b4bd72de7601d Mon Sep 17 00:00:00 2001 From: elecpower Date: Sat, 18 Dec 2021 09:32:15 +1100 Subject: [PATCH 088/180] Add potswarnenable --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b96957770..1f64343dd 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -127,6 +127,30 @@ struct YamlThrTrace { } }; +struct YamlPotsWarnEnabled { + unsigned int value; + + YamlPotsWarnEnabled() = default; + + YamlPotsWarnEnabled(const bool * potsWarnEnabled) + { + value = 0; + + for (int i = 0; i < 8; i++) { + value |= (*(potsWarnEnabled + i) << (7 - i)); + } + } + + void toCpn(bool * potsWarnEnabled) + { + memset(potsWarnEnabled, 0, sizeof(bool) * (CPN_MAX_POTS + CPN_MAX_SLIDERS)); + + for (int i = 1; i <= 8; i++) { + *(potsWarnEnabled + (i - 1)) = (bool)((value >> (8 - i)) & 1); + } + } +}; + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -410,7 +434,10 @@ Node convert::encode(const ModelData& rhs) // switchWarningStates node["thrTrimSw"] = rhs.thrTrimSwitch; node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode; - // potsWarnEnabled[] + + YamlPotsWarnEnabled potsWarnEnabled(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]); + node["potsWarnEnabled"] = potsWarnEnabled.value; + // potsWarnPosition[] node["displayChecklist"] = (int)rhs.displayChecklist; @@ -506,7 +533,11 @@ bool convert::decode(const Node& node, ModelData& rhs) // switchWarningStates node["thrTrimSw"] >> rhs.thrTrimSwitch; node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode; - // potsWarnEnabled[] + + YamlPotsWarnEnabled potsWarnEnabled; + node["potsWarnEnabled"] >> potsWarnEnabled.value; + potsWarnEnabled.toCpn(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]); + // potsWarnPosition[] node["displayChecklist"] >> rhs.displayChecklist; From 940950372801ed73e3aaa408ba824d79a640b659 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 18 Dec 2021 10:52:56 +0100 Subject: [PATCH 089/180] Add sensor data / script data --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/edgetx/yaml_modeldata.cpp | 66 ++++++- .../src/firmwares/edgetx/yaml_sensordata.cpp | 184 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_sensordata.h | 31 +++ 4 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_sensordata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_sensordata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index f7eea5186..6c4f53ded 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -44,6 +44,7 @@ set(firmwares_SRCS edgetx/yaml_moduledata.cpp edgetx/yaml_logicalswitchdata.cpp edgetx/yaml_customfunctiondata.cpp + edgetx/yaml_sensordata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 1f64343dd..b76e1fd80 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -27,6 +27,7 @@ #include "yaml_moduledata.h" #include "yaml_logicalswitchdata.h" #include "yaml_customfunctiondata.h" +#include "yaml_sensordata.h" #include "modeldata.h" #include "output_data.h" @@ -336,6 +337,54 @@ struct convert { } }; +struct YamlScriptDataInput { int i; }; + +template <> +struct convert { + static Node encode(const YamlScriptDataInput& rhs) + { + Node node; + node["u"]["value"] = rhs.i; + return node; + } + static bool decode(const Node& node, YamlScriptDataInput& rhs) + { + node["u"]["value"] >> rhs.i; + return true; + } +}; + +template <> +struct convert { + static Node encode(const ScriptData& rhs) + { + Node node; + node["file"] = rhs.filename; + node["name"] = rhs.name; + + for (int i=0; i < 6; i++) { + node["inputs"][std::to_string(i)]["u"]["value"] = (int)rhs.inputs[i]; + } + + return node; + } + + static bool decode(const Node& node, ScriptData& rhs) + { + node["file"] >> rhs.filename; + node["name"] >> rhs.name; + + YamlScriptDataInput inputs[CPN_MAX_SCRIPT_INPUTS]; + node["inputs"] >> inputs; + + for (int i=0; i < CPN_MAX_SCRIPT_INPUTS; i++) { + rhs.inputs[i] = inputs[i].i; + } + + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -463,8 +512,17 @@ Node convert::encode(const ModelData& rhs) } } - // scriptData[] - // sensorData[] + for (int i=0; i 0) { + node["scriptData"][std::to_string(i)] = rhs.scriptData[i]; + } + } + + for (int i=0; i::decode(const Node& node, ModelData& rhs) node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; node["moduleData"] >> rhs.moduleData; - // scriptData[] - // sensorData[] + node["scriptData"] >> rhs.scriptData; + node["telemetrySensors"] >> rhs.sensorData; node["toplcdTimer"] >> rhs.toplcdTimer; diff --git a/companion/src/firmwares/edgetx/yaml_sensordata.cpp b/companion/src/firmwares/edgetx/yaml_sensordata.cpp new file mode 100644 index 000000000..d90b32554 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_sensordata.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_sensordata.h" + +static const YamlLookupTable sensorType = { + {SensorData::TELEM_TYPE_CUSTOM, "TYPE_CUSTOM"}, + {SensorData::TELEM_TYPE_CALCULATED, "TYPE_CALCULATED"}, +}; + +static const YamlLookupTable sensorFormula = { + {SensorData::TELEM_FORMULA_ADD, "FORMULA_ADD"}, + {SensorData::TELEM_FORMULA_AVERAGE, "FORMULA_AVERAGE"}, + {SensorData::TELEM_FORMULA_MIN, "FORMULA_MIN"}, + {SensorData::TELEM_FORMULA_MAX, "FORMULA_MAX"}, + {SensorData::TELEM_FORMULA_MULTIPLY, "FORMULA_MULTIPLY"}, + {SensorData::TELEM_FORMULA_TOTALIZE, "FORMULA_TOTALIZE"}, + {SensorData::TELEM_FORMULA_CELL, "FORMULA_CELL"}, + {SensorData::TELEM_FORMULA_CONSUMPTION, "FORMULA_CONSUMPTION"}, + {SensorData::TELEM_FORMULA_DIST, "FORMULA_DIST"}, +}; + +namespace YAML +{ +Node convert::encode(const SensorData& rhs) +{ + Node node; + node["type"] = LookupValue(sensorType, rhs.type); + + Node cfg; + if (rhs.type == SensorData::TELEM_TYPE_CUSTOM) { + node["id1"]["id"] = rhs.id; + node["subid"] = rhs.subid; + + unsigned int instance = rhs.instance; + if (instance != 0) { + instance = + ((instance - 1) & 0x1F) | (rhs.rxIdx << 5) | (rhs.moduleIdx << 7); + } + node["id2"]["instance"] = instance; + cfg["custom"]["ratio"] = rhs.ratio; + cfg["custom"]["offset"] = rhs.offset; + } else { + if (rhs.persistent) { + node["persistent"] = 1; + node["id1"]["persistentValue"] = rhs.persistentValue; + } + + node["id2"]["formula"] = LookupValue(sensorFormula, rhs.formula); + + switch (rhs.formula) { + case SensorData::TELEM_FORMULA_CELL: + cfg["cell"]["source"] = rhs.source; + cfg["cell"]["index"] = rhs.index; + break; + case SensorData::TELEM_FORMULA_ADD: + case SensorData::TELEM_FORMULA_AVERAGE: + case SensorData::TELEM_FORMULA_MULTIPLY: + case SensorData::TELEM_FORMULA_MIN: + case SensorData::TELEM_FORMULA_MAX: { + Node sources; + for (int i = 0; i < 4; i++) { + if (rhs.sources[i]) { + sources[std::to_string(i)]["val"] = rhs.sources[i]; + } + } + cfg["calc"]["sources"] = sources; + } break; + case SensorData::TELEM_FORMULA_DIST: + if (rhs.gps) { + cfg["dist"]["gps"] = rhs.gps; + } + if (rhs.alt) { + cfg["dist"]["alt"] = rhs.alt; + } + break; + case SensorData::TELEM_FORMULA_CONSUMPTION: + case SensorData::TELEM_FORMULA_TOTALIZE: + cfg["consumption"]["source"] = rhs.amps; + default: + break; + } + } + + node["label"] = rhs.label; + node["unit"] = rhs.unit; + node["prec"] = rhs.prec; + node["autoOffset"] = (int)rhs.autoOffset; + node["filter"] = (int)rhs.filter; + node["logs"] = (int)rhs.logs; + node["persistent"] = (int)rhs.persistent; + node["onlyPositive"] = (int)rhs.onlyPositive; + + if (cfg && cfg.IsMap()) { + node["cfg"] = cfg; + } + return node; +} + +bool convert::decode(const Node& node, SensorData& rhs) +{ + node["type"] >> sensorType >> rhs.type; + if (node["id1"]) { + Node id1 = node["id1"]; + id1["id"] >> rhs.id; + id1["persistentValue"] >> rhs.persistentValue; + } + node["subid"] >> rhs.subid; + if (node["id2"]) { + Node id2 = node["id2"]; + id2["instance"] >> rhs.instance; + id2["formula"] >> sensorFormula >> rhs.formula; + } + + if (rhs.type == SensorData::TELEM_TYPE_CUSTOM) { + rhs.rxIdx = (rhs.instance >> 5) & 0x03; // 2 bits Rx idx + rhs.moduleIdx = (rhs.instance >> 7) & 0x1; // 1 bit module idx + rhs.instance = (rhs.instance & 0x1F) + 1; // 5 bits instance + } + + node["label"] >> rhs.label; + node["unit"] >> rhs.unit; + node["prec"] >> rhs.prec; + node["autoOffset"] >> rhs.autoOffset; + node["filter"] >> rhs.filter; + node["logs"] >> rhs.logs; + node["persistent"] >> rhs.persistent; + node["onlyPositive"] >> rhs.onlyPositive; + + if (node["cfg"]) { + Node cfg = node["cfg"]; + if (cfg.IsMap()) { + if (cfg["custom"]) { + Node custom = cfg["custom"]; + if (custom.IsMap()) { + custom["ratio"] >> rhs.ratio; + custom["offset"] >> rhs.offset; + } + } else if (cfg["cell"]) { + Node cell = cfg["cell"]; + if (cell.IsMap()) { + cell["source"] >> rhs.source; + cell["index"] >> rhs.index; + } + } else if (cfg["calc"]) { + Node calc = cfg["calc"]; + if (calc.IsMap()) { + calc["sources"] >> rhs.sources; + } + } else if (cfg["consumption"]) { + Node consumption = cfg["consumption"]; + if (consumption.IsMap()) { + consumption["source"] >> rhs.amps; + } + } else if (cfg["dist"]) { + Node dist = cfg["dist"]; + if (dist.IsMap()) { + dist["gps"] >> rhs.gps; + dist["alt"] >> rhs.alt; + } + } + } + } + + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_sensordata.h b/companion/src/firmwares/edgetx/yaml_sensordata.h new file mode 100644 index 000000000..b914ba834 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_sensordata.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "sensordata.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const SensorData& rhs); + static bool decode(const Node& node, SensorData& rhs); +}; +} // namespace YAML From 2a1cc9719e92fc628bdd4ac172d841dd72a27cf0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 18 Dec 2021 17:16:35 +0100 Subject: [PATCH 090/180] Add screen / topbar data --- companion/src/firmwares/CMakeLists.txt | 1 + .../src/firmwares/customisation_data.cpp | 19 +++ companion/src/firmwares/customisation_data.h | 13 +- .../src/firmwares/edgetx/yaml_modeldata.cpp | 14 +- .../src/firmwares/edgetx/yaml_screendata.cpp | 129 ++++++++++++++++++ .../src/firmwares/edgetx/yaml_screendata.h | 72 ++++++++++ 6 files changed, 244 insertions(+), 4 deletions(-) create mode 100644 companion/src/firmwares/edgetx/yaml_screendata.cpp create mode 100644 companion/src/firmwares/edgetx/yaml_screendata.h diff --git a/companion/src/firmwares/CMakeLists.txt b/companion/src/firmwares/CMakeLists.txt index 6c4f53ded..870d14cde 100644 --- a/companion/src/firmwares/CMakeLists.txt +++ b/companion/src/firmwares/CMakeLists.txt @@ -45,6 +45,7 @@ set(firmwares_SRCS edgetx/yaml_logicalswitchdata.cpp edgetx/yaml_customfunctiondata.cpp edgetx/yaml_sensordata.cpp + edgetx/yaml_screendata.cpp datahelpers.cpp customisation_data.cpp ) diff --git a/companion/src/firmwares/customisation_data.cpp b/companion/src/firmwares/customisation_data.cpp index 34489aa59..5de5fb803 100644 --- a/companion/src/firmwares/customisation_data.cpp +++ b/companion/src/firmwares/customisation_data.cpp @@ -85,6 +85,25 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { } } +static const ZoneOptionValueTyped zero_widget_option = { + ZOV_Unsigned, {0} +}; + +bool ZoneOptionValueTyped::isEmpty() const +{ + return !memcmp((void*)this, &zero_widget_option, sizeof(zero_widget_option)); +} + +bool ZonePersistentData::isEmpty() const +{ + return strlen(widgetName) == 0; +} + +bool RadioLayout::CustomScreenData::isEmpty() const +{ + return strlen(layoutId) == 0; +} + void RadioTheme::init(const char* themeName, ThemeData& themeData) { memset(&themeData, 0, sizeof(ThemeData)); diff --git a/companion/src/firmwares/customisation_data.h b/companion/src/firmwares/customisation_data.h index baad3c828..457be6c0c 100644 --- a/companion/src/firmwares/customisation_data.h +++ b/companion/src/firmwares/customisation_data.h @@ -20,6 +20,7 @@ #pragma once #include "constants.h" +#include "rawsource.h" #include @@ -58,6 +59,8 @@ struct ZoneOptionValue // union in radio/src/datastructs.h int signedValue; unsigned int boolValue; char stringValue[LEN_ZONE_OPTION_STRING + 1]; + RawSource sourceValue; + unsigned int colorValue; }; enum ZoneOptionValueEnum { @@ -65,7 +68,9 @@ enum ZoneOptionValueEnum { ZOV_Signed, ZOV_Bool, ZOV_String, - ZOV_LAST = ZOV_String + ZOV_Source, + ZOV_Color, + ZOV_LAST = ZOV_Color }; struct ZoneOption @@ -93,6 +98,8 @@ struct ZoneOptionValueTyped { ZoneOptionValueEnum type; ZoneOptionValue value; + + bool isEmpty() const; }; struct WidgetPersistentData { @@ -102,6 +109,8 @@ struct WidgetPersistentData { struct ZonePersistentData { char widgetName[WIDGET_NAME_LEN + 1]; WidgetPersistentData widgetData; + + bool isEmpty() const; }; template @@ -141,6 +150,8 @@ class RadioLayout struct CustomScreenData { char layoutId[LAYOUT_ID_LEN + 1]; LayoutPersistentData layoutPersistentData; + + bool isEmpty() const; }; struct CustomScreens { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b76e1fd80..ec4af1e8c 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -28,6 +28,7 @@ #include "yaml_logicalswitchdata.h" #include "yaml_customfunctiondata.h" #include "yaml_sensordata.h" +#include "yaml_screendata.h" #include "modeldata.h" #include "output_data.h" @@ -526,9 +527,13 @@ Node convert::encode(const ModelData& rhs) node["toplcdTimer"] = rhs.toplcdTimer; - // B&W only - // customScreens - // topBarData + for (int i=0; i::decode(const Node& node, ModelData& rhs) // customScreens // topBarData + node["screenData"] >> rhs.customScreens.customScreenData; + node["topbarData"] >> rhs.topBarData; + node["view"] >> rhs.view; node["modelRegistrationID"] >> rhs.registrationId; diff --git a/companion/src/firmwares/edgetx/yaml_screendata.cpp b/companion/src/firmwares/edgetx/yaml_screendata.cpp new file mode 100644 index 000000000..ab26f4f49 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_screendata.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_screendata.h" +#include "yaml_rawsource.h" +#include "yaml_ops.h" + +static const YamlLookupTable zoneOptionValueEnum = { + {ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"}, + {ZOV_String, "String"}, {ZOV_Source, "Source"}, {ZOV_Color, "Color"}, +}; + +namespace YAML +{ +ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum); + +Node convert::encode(const ZoneOptionValueTyped& rhs) +{ + Node node, value; + node["type"] = rhs.type; + + switch (rhs.type) { + case ZOV_Unsigned: + value["unsignedValue"] = rhs.value.unsignedValue; + break; + case ZOV_Signed: + value["signedValue"] = rhs.value.signedValue; + break; + case ZOV_Bool: + value["boolValue"] = rhs.value.boolValue; + break; + case ZOV_Source: + value["sourceValue"] = rhs.value.sourceValue; + break; + case ZOV_Color: + value["colorValue"] = rhs.value.colorValue; + break; + default: + break; + } + node["value"] = value; + return node; +} + +bool convert::decode(const Node& node, + ZoneOptionValueTyped& rhs) +{ + node["type"] >> rhs.type; + if (node["value"]) { + Node value = node["value"]; + if (value.IsMap()) { + value["unsignedValue"] >> rhs.value.unsignedValue; + value["signedValue"] >> rhs.value.signedValue; + value["boolValue"] >> rhs.value.boolValue; + value["stringValue"] >> rhs.value.stringValue; + value["sourceValue"] >> rhs.value.sourceValue; + value["colorValue"] >> rhs.value.colorValue; + } + } + return true; +} + +template <> +struct convert { + static Node encode(const WidgetPersistentData& rhs) + { + Node node; + for (int i=0; i> rhs.options; + return true; + } +}; + +Node convert::encode(const ZonePersistentData& rhs) +{ + Node node; + node["widgetName"] = rhs.widgetName; + node["widgetData"] = rhs.widgetData; + return node; +} + +bool convert::decode(const Node& node, ZonePersistentData& rhs) +{ + node["widgetName"] >> rhs.widgetName; + node["widgetData"] >> rhs.widgetData; + return true; +} + +Node convert::encode(const ScreenData& rhs) +{ + Node node; + node["LayoutId"] = rhs.layoutId; + node["layoutData"] = rhs.layoutPersistentData; + return node; +} + +bool convert::decode(const Node& node, ScreenData& rhs) +{ + node["LayoutId"] >> rhs.layoutId; + node["layoutData"] >> rhs.layoutPersistentData; + return true; +} +} // namespace YAML diff --git a/companion/src/firmwares/edgetx/yaml_screendata.h b/companion/src/firmwares/edgetx/yaml_screendata.h new file mode 100644 index 000000000..81349e588 --- /dev/null +++ b/companion/src/firmwares/edgetx/yaml_screendata.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "yaml_ops.h" +#include "customisation_data.h" + +namespace YAML +{ +template <> +struct convert { + static Node encode(const ZonePersistentData& rhs); + static bool decode(const Node& node, ZonePersistentData& rhs); +}; + +template <> +struct convert { + static Node encode(const ZoneOptionValueTyped& rhs); + static bool decode(const Node& node, ZoneOptionValueTyped& rhs); +}; + +template +struct convert > { + typedef WidgetsContainerPersistentData PersistentData; + static Node encode(const PersistentData& rhs) + { + Node node; + for (int i=0; i 0) { + node["zones"][std::to_string(i)] = rhs.zones[i]; + } + } + for(int i=0; i> rhs.zones; + node["options"] >> rhs.options; + return true; + } +}; + +typedef RadioLayout::CustomScreenData ScreenData; + +template <> +struct convert { + static Node encode(const ScreenData& rhs); + static bool decode(const Node& node, ScreenData& rhs); +}; +} // namespace YAML From a4ad8154eb997cc0018c874f08844edbb89eb407 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 18 Dec 2021 17:26:04 +0100 Subject: [PATCH 091/180] Add function switches --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index ec4af1e8c..e758eeaf6 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -538,6 +538,20 @@ Node convert::encode(const ModelData& rhs) node["view"] = rhs.view; node["modelRegistrationID"] = rhs.registrationId; + if (getCurrentFirmware()->getCapability(FunctionSwitches)) { + node["functionSwitchConfig"] = rhs.functionSwitchConfig; + node["functionSwitchGroup"] = rhs.functionSwitchGroup; + node["functionSwitchStartConfig"] = rhs.functionSwitchStartConfig; + node["functionSwitchLogicalState"] = rhs.functionSwitchLogicalState; + + for (int i = 0; i < CPN_MAX_FUNCTION_SWITCHES; i++) { + if (strlen(rhs.functionSwitchNames[i]) > 0) { + node["functionSwitchNames"][std::to_string(i)] = + rhs.functionSwitchNames[i]; + } + } + } + return node; } @@ -627,6 +641,12 @@ bool convert::decode(const Node& node, ModelData& rhs) node["view"] >> rhs.view; node["modelRegistrationID"] >> rhs.registrationId; + node["functionSwitchConfig"] >> rhs.functionSwitchConfig; + node["functionSwitchGroup"] >> rhs.functionSwitchGroup; + node["functionSwitchStartConfig"] >> rhs.functionSwitchStartConfig; + node["functionSwitchLogicalState"] >> rhs.functionSwitchLogicalState; + node["functionSwitchNames"] >> rhs.functionSwitchNames; + return true; } From ce841f9b11f9bc1b50d4321346edfda9ab799dce Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 07:55:56 +1100 Subject: [PATCH 092/180] Housekeeping --- companion/src/firmwares/eeprominterface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index 37945e73b..b91d7262e 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -166,7 +166,6 @@ enum Capability { HasTelemetryBaudrate, TopBarZones, FunctionSwitches, - Has, HasModelsList, HasFlySkyGimbals }; From 2dedf63138612f1500e8cb2bb8286062344ddd08 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 08:08:57 +1100 Subject: [PATCH 093/180] Rename merged code opentx refs to edgetx --- companion/src/firmwares/opentx/opentxinterface.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 4a9f7ea44..c1be0e465 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -990,6 +990,7 @@ EepromLoadErrors OpenTxEepromInterface::checkVersion(unsigned int version) // ALL: YAML storage // X10PCB: add pots EXT3 and EXT4 (conversion required as shifts slider settings in multiple fields) // RM TX16S: add Flysky gimbals firmware build option and repurpose EXT3 and EXT4 if selected + // ??: add source TX GPS break; default: @@ -1394,7 +1395,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T-Pro board */ - firmware = new OpenTxFirmware("opentx-tpro", QCoreApplication::translate("Firmware", "Jumper T-Pro"), BOARD_JUMPER_TPRO); + firmware = new OpenTxFirmware("edgetx-tpro", QCoreApplication::translate("Firmware", "Jumper T-Pro"), BOARD_JUMPER_TPRO); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1423,7 +1424,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Radiomaster Zorro board */ - firmware = new OpenTxFirmware("opentx-zorro", QCoreApplication::translate("Firmware", "Radiomaster Zorro"), Board::BOARD_RADIOMASTER_ZORRO); + firmware = new OpenTxFirmware("edgetx-zorro", QCoreApplication::translate("Firmware", "Radiomaster Zorro"), Board::BOARD_RADIOMASTER_ZORRO); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); From bc115319a5a005ccb8cbe470bf7156a04ba4490c Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 08:43:40 +1100 Subject: [PATCH 094/180] Add potsWarnPosition --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index e758eeaf6..5ab51add8 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -366,7 +366,7 @@ struct convert { for (int i=0; i < 6; i++) { node["inputs"][std::to_string(i)]["u"]["value"] = (int)rhs.inputs[i]; } - + return node; } @@ -381,7 +381,7 @@ struct convert { for (int i=0; i < CPN_MAX_SCRIPT_INPUTS; i++) { rhs.inputs[i] = inputs[i].i; } - + return true; } }; @@ -488,7 +488,10 @@ Node convert::encode(const ModelData& rhs) YamlPotsWarnEnabled potsWarnEnabled(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]); node["potsWarnEnabled"] = potsWarnEnabled.value; - // potsWarnPosition[] + for (int i = 0; i < CPN_MAX_POTS + CPN_MAX_SLIDERS; i++) { + if (rhs.potsWarnPosition[i] != 0) + node["potsWarnPosition"][std::to_string(i)]["val"] = rhs.potsWarnPosition[i]; + } node["displayChecklist"] = (int)rhs.displayChecklist; @@ -615,7 +618,7 @@ bool convert::decode(const Node& node, ModelData& rhs) node["potsWarnEnabled"] >> potsWarnEnabled.value; potsWarnEnabled.toCpn(&rhs.potsWarnEnabled[CPN_MAX_POTS + CPN_MAX_SLIDERS]); - // potsWarnPosition[] + node["potsWarnPosition"] >> rhs.potsWarnPosition; node["displayChecklist"] >> rhs.displayChecklist; @@ -633,8 +636,6 @@ bool convert::decode(const Node& node, ModelData& rhs) node["toplcdTimer"] >> rhs.toplcdTimer; - // customScreens - // topBarData node["screenData"] >> rhs.customScreens.customScreenData; node["topbarData"] >> rhs.topBarData; From 3482723805277f2c13308ae3835363b354bc8b18 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 14:22:53 +1100 Subject: [PATCH 095/180] Add switchWarningState --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 103 +++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 5ab51add8..9ad08f83a 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -153,6 +153,99 @@ struct YamlPotsWarnEnabled { } }; +// modeldata: uint64_t switchWarningStates +// Yaml switchWarningState: AuBuEuFuG-IuJu +struct YamlSwitchWarningState { + std::string src_str; + + YamlSwitchWarningState() = default; + + YamlSwitchWarningState(uint64_t cpn_value, unsigned int switchWarningEnable) + { + uint64_t states = cpn_value; + + for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) { + if (!(switchWarningEnable & (1 << i))) { + std::string tag = getCurrentFirmware()->getSwitchesTag(i); + const char *sw = tag.data(); + + if (tag.size() >= 2 && sw[0] == 'S') { + char val[2]; + val[0] = sw[1]; + + uint64_t value = (i == 0 ? states & 0x3 : states & 0x1); + + if (value == 0) + val[1] = 'u'; + else if (value == 1) + val[1] = '-'; + else + val[1] = 'd'; + + src_str.append(val); + } + } + + states >>= (i == 0 ? 2 : 1); + } + } + + uint64_t toCpn() + { + uint64_t states = 0; + + for (unsigned int i = 0; i < src_str.size() / 2; i++) { + const char* val = src_str.substr(i * 2, 2).c_str(); + if (val[0] >= 'A' && val[0] <= 'Z' && ( + val[1] == 'u' || val[1] == '-' || val[1] == 'd')) { + + int shift = 0; + uint64_t mask; + + char sw[2]; + sw[0] = 'S'; + sw[1] = val[0]; + + int index = getCurrentFirmware()->getSwitchesIndex(sw); + + if (index > -1) { + + if (IS_HORUS_OR_TARANIS(getCurrentFirmware()->getBoard())) { + shift = index * 2; + mask = 0x03ull << shift; + } + else { + if (index == 0) { + mask = 0x03; + } + else { + shift = index + 1; + mask = 0x01ull << shift; + } + } + + states &= ~mask; + + uint64_t value; + + if (val[1] == 'u') + value = 0; + else if (val[1] == '-') + value = 1; + else + value = 2; + + if (value) { + states |= ((uint64_t)value << shift); + } + } + } + } + + return states; + } +}; + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -481,7 +574,10 @@ Node convert::encode(const ModelData& rhs) YamlThrTrace thrTrace(rhs.thrTraceSrc); node["thrTraceSrc"] = thrTrace.src; - // switchWarningStates + YamlSwitchWarningState switchWarningState(rhs.switchWarningStates, rhs.switchWarningEnable); + node["switchWarningState"] = switchWarningState.src_str; + + node["thrTrimSw"] = rhs.thrTrimSwitch; node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode; @@ -610,7 +706,10 @@ bool convert::decode(const Node& node, ModelData& rhs) node["thrTraceSrc"] >> thrTrace.src; rhs.thrTraceSrc = thrTrace.toCpn(); - // switchWarningStates + YamlSwitchWarningState switchWarningState; + node["switchWarningState"] >> switchWarningState.src_str; + rhs.switchWarningStates = switchWarningState.toCpn(); + node["thrTrimSw"] >> rhs.thrTrimSwitch; node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode; From 707e8e83bf63a2b62c71554bf825a50657ebd1d8 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 14:35:03 +1100 Subject: [PATCH 096/180] Add telemetryProtocol --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 9ad08f83a..7036e289c 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -577,7 +577,6 @@ Node convert::encode(const ModelData& rhs) YamlSwitchWarningState switchWarningState(rhs.switchWarningStates, rhs.switchWarningEnable); node["switchWarningState"] = switchWarningState.src_str; - node["thrTrimSw"] = rhs.thrTrimSwitch; node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode; @@ -599,7 +598,9 @@ Node convert::encode(const ModelData& rhs) } // mavlink ??? - // telemetryProtocol ??? + + node["telemetryProtocol"] = rhs.telemetryProtocol; + // frsky // rssiSource // rssiAlarms @@ -722,8 +723,11 @@ bool convert::decode(const Node& node, ModelData& rhs) node["displayChecklist"] >> rhs.displayChecklist; node["gvars"] >> rhs.gvarData; + // mavlink ??? - // telemetryProtocol ??? + + node["telemetryProtocol"] >> rhs.telemetryProtocol; + // frsky // rssiSource // rssiAlarms From 788f26381427dacf27118ffb00c73b15aa94f829 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 14:55:16 +1100 Subject: [PATCH 097/180] Add rssiAlarms --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 7036e289c..f83133228 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -479,6 +479,26 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const RSSIAlarmData& rhs) + { + Node node; + node["disabled"] = rhs.disabled; + node["warning"] = rhs.warning; + node["critical"] = rhs.critical; + return node; + } + + static bool decode(const Node& node, RSSIAlarmData& rhs) + { + node["disabled"] >> rhs.disabled; + node["warning"] >> rhs.warning; + node["critical"] >> rhs.critical; + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -602,8 +622,10 @@ Node convert::encode(const ModelData& rhs) node["telemetryProtocol"] = rhs.telemetryProtocol; // frsky + // rssiSource - // rssiAlarms + + node["rssiAlarms"] = rhs.rssiAlarms; node["trainerMode"] = trainerModeLut << rhs.trainerMode; @@ -729,8 +751,10 @@ bool convert::decode(const Node& node, ModelData& rhs) node["telemetryProtocol"] >> rhs.telemetryProtocol; // frsky + // rssiSource - // rssiAlarms + + node["rssiAlarms"] >> rhs.rssiAlarms; node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; node["moduleData"] >> rhs.moduleData; From eafc0d419300f57ab15da638af1dddb2c6a235e8 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 20:11:34 +1100 Subject: [PATCH 098/180] Add rssiSource and fix rssiAlarms --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index f83133228..e738fa9c5 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -246,6 +246,27 @@ struct YamlSwitchWarningState { } }; +struct YamlRssiSource { + std::string src_str; + + YamlRssiSource() = default; + + YamlRssiSource(unsigned int cpn_value) + { + if (cpn_value == 0) + src_str.append("none"); + else + src_str.append(std::to_string(cpn_value)); + } + + unsigned int toCpn() + { + if (src_str.find("none") == std::string::npos) + return std::stoul(src_str); + return 0; + } +}; + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -485,8 +506,8 @@ struct convert { { Node node; node["disabled"] = rhs.disabled; - node["warning"] = rhs.warning; - node["critical"] = rhs.critical; + node["warning"] = rhs.warning - 45; + node["critical"] = rhs.critical - 42; return node; } @@ -494,7 +515,9 @@ struct convert { { node["disabled"] >> rhs.disabled; node["warning"] >> rhs.warning; + rhs.warning += 45; node["critical"] >> rhs.critical; + rhs.critical += 42; return true; } }; @@ -623,7 +646,8 @@ Node convert::encode(const ModelData& rhs) // frsky - // rssiSource + YamlRssiSource rssiSource(rhs.rssiSource); + node["rssiSource"] = rssiSource.src_str; node["rssiAlarms"] = rhs.rssiAlarms; @@ -752,7 +776,9 @@ bool convert::decode(const Node& node, ModelData& rhs) // frsky - // rssiSource + YamlRssiSource rssiSource; + node["rssiSource"] >> rssiSource.src_str; + rhs.rssiSource = rssiSource.toCpn(); node["rssiAlarms"] >> rhs.rssiAlarms; From 51f66a9e79db0562bca3f1401393e268070fd0a9 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 19 Dec 2021 09:16:30 +0100 Subject: [PATCH 099/180] modelID and small fixes --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index e738fa9c5..cafcebdf9 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -195,7 +195,7 @@ struct YamlSwitchWarningState { uint64_t states = 0; for (unsigned int i = 0; i < src_str.size() / 2; i++) { - const char* val = src_str.substr(i * 2, 2).c_str(); + auto val = src_str.substr(i * 2, 2); if (val[0] >= 'A' && val[0] <= 'Z' && ( val[1] == 'u' || val[1] == '-' || val[1] == 'd')) { @@ -505,7 +505,7 @@ struct convert { static Node encode(const RSSIAlarmData& rhs) { Node node; - node["disabled"] = rhs.disabled; + node["disabled"] = (int)rhs.disabled; node["warning"] = rhs.warning - 45; node["critical"] = rhs.critical - 42; return node; @@ -525,9 +525,18 @@ struct convert { Node convert::encode(const ModelData& rhs) { Node node; - node["header"]["name"] = rhs.name; - node["header"]["bitmap"] = rhs.bitmap; - // TODO: modelId + auto board = getCurrentBoard(); + + Node header; + header["name"] = rhs.name; + header["bitmap"] = rhs.bitmap; + + for (int i=0; i::encode(const ModelData& rhs) } } - node["toplcdTimer"] = rhs.toplcdTimer; + if (IS_TARANIS_X9E(board)) { + node["toplcdTimer"] = rhs.toplcdTimer; + } - for (int i=0; igetCapability(FunctionSwitches)) { @@ -707,11 +720,16 @@ bool convert::decode(const Node& node, ModelData& rhs) if (node["header"]) { const auto& header = node["header"]; - if (!header.IsMap()) return false; + if (header.IsMap()) { + header["name"] >> rhs.name; + header["bitmap"] >> rhs.bitmap; - header["name"] >> rhs.name; - header["bitmap"] >> rhs.bitmap; - // TODO: modelId + unsigned int modelIds[CPN_MAX_MODULES]; + header["modelId"] >> modelIds; + for (int i=0; i Date: Sun, 19 Dec 2021 10:54:56 +0100 Subject: [PATCH 100/180] Add various telemetry sources and screens --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 196 +++++++++++++++++- companion/src/firmwares/edgetx/yaml_ops.h | 19 +- 2 files changed, 195 insertions(+), 20 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index cafcebdf9..58abcaddc 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -369,12 +369,12 @@ struct convert { for (int i=0; i::encode(yt); + node["trim"] = encode_array(yt); node["swtch"] = rhs.swtch; node["name"] = rhs.name; node["fadeIn"] = rhs.fadeIn; node["fadeOut"] = rhs.fadeOut; - node["gvars"] = convert_array::encode(rhs.gvars); + node["gvars"] = encode_array(rhs.gvars); return node; } @@ -522,6 +522,130 @@ struct convert { } }; +struct YamlTelemSource { + unsigned int src = 0; + YamlTelemSource() = default; + YamlTelemSource(const unsigned int src) : src(src) {} +}; + +template <> +struct convert { + static Node encode(const YamlTelemSource& rhs) + { + if (rhs.src == 0) + return Node("none"); + return Node(rhs.src - 1); + } + + static bool decode(const Node& node, YamlTelemSource& rhs) + { + if (node && node.IsScalar()) { + std::string str = node.Scalar(); + if (str == "none") { + rhs.src = 0; + } else { + rhs.src = std::stoi(str) + 1; + } + } + return true; + } +}; + +template <> +struct convert { + static Node encode(const FrSkyBarData& rhs) + { + Node node; + if (rhs.source.isSet()) { + node["source"] = rhs.source; + node["barMin"] = rhs.barMin; + node["barMax"] = rhs.barMax; + } + return node; + } + + static bool decode(const Node& node, FrSkyBarData& rhs) + { + node["source"] >> rhs.source; + node["barMin"] >> rhs.barMin; + node["barMax"] >> rhs.barMax; + return true; + } +}; + +template <> +struct convert { + static Node encode(const FrSkyLineData& rhs) + { + Node node, sources; + sources = encode_array(rhs.source); + if (sources && sources.IsMap()) { + node["sources"] = sources; + } + return node; + } + + static bool decode(const Node& node, FrSkyLineData& rhs) + { + node["sources"] >> rhs.source; + return true; + } +}; + +static const YamlLookupTable screenTypeLut = { + {TELEMETRY_SCREEN_NONE, "NONE"}, + {TELEMETRY_SCREEN_NUMBERS, "VALUES"}, + {TELEMETRY_SCREEN_BARS, "BARS"}, + {TELEMETRY_SCREEN_SCRIPT, "SCRIPT"}, +}; + +template <> +struct convert { + static Node encode(const FrSkyScreenData& rhs) + { + Node node; + node["type"] = LookupValue(screenTypeLut, rhs.type); + switch(rhs.type) { + case TELEMETRY_SCREEN_NONE: + break; + case TELEMETRY_SCREEN_NUMBERS: + node["lines"] = encode_array(rhs.body.lines); + break; + case TELEMETRY_SCREEN_BARS: + node["bars"] = encode_array(rhs.body.bars); + break; + case TELEMETRY_SCREEN_SCRIPT: + node["script"]["file"] = rhs.body.script.filename; + break; + } + return node; + } + + static bool decode(const Node& node, FrSkyScreenData& rhs) + { + node["type"] >> screenTypeLut >> rhs.type; + switch(rhs.type) { + case TELEMETRY_SCREEN_NONE: + return true; + case TELEMETRY_SCREEN_NUMBERS: + node["lines"] >> rhs.body.lines; + break; + case TELEMETRY_SCREEN_BARS: + node["bars"] >> rhs.body.bars; + break; + case TELEMETRY_SCREEN_SCRIPT: + if (node["script"]) { + const auto& script = node["script"]; + if (script && script.IsMap()) { + script["file"] >> rhs.body.script.filename; + } + } + break; + } + return true; + } +}; + Node convert::encode(const ModelData& rhs) { Node node; @@ -653,13 +777,36 @@ Node convert::encode(const ModelData& rhs) node["telemetryProtocol"] = rhs.telemetryProtocol; - // frsky + if (!IS_FAMILY_HORUS_OR_T16(board)) { + Node screens; + for (int i=0; i<4; i++) { + const auto& scr = rhs.frsky.screens[i]; + if (scr.type != TELEMETRY_SCREEN_NONE) { + screens[std::to_string(i)] = rhs.frsky.screens[i]; + } + } + if (screens.IsMap()) { + node["screens"] = screens; + } + } - YamlRssiSource rssiSource(rhs.rssiSource); - node["rssiSource"] = rssiSource.src_str; + Node vario; + vario["source"] = YamlTelemSource{rhs.frsky.varioSource}; + vario["centerSilent"] = (int)rhs.frsky.varioCenterSilent; + vario["centerMax"] = rhs.frsky.varioCenterMax; + vario["centerMin"] = rhs.frsky.varioCenterMin; + vario["min"] = rhs.frsky.varioMin; + vario["max"] = rhs.frsky.varioMax; + + node["varioData"] = vario; + node["rssiSource"] = YamlTelemSource(rhs.rssiSource); + + if (IS_TARANIS_X9(getCurrentBoard())) { + node["voltsSource"] = YamlTelemSource(rhs.frsky.voltsSource); + node["altitudeSource"] = YamlTelemSource(rhs.frsky.altitudeSource); + } node["rssiAlarms"] = rhs.rssiAlarms; - node["trainerMode"] = trainerModeLut << rhs.trainerMode; for (int i=0; i::decode(const Node& node, ModelData& rhs) node["telemetryProtocol"] >> rhs.telemetryProtocol; // frsky + if (node["screens"]) { + node["screens"] >> rhs.frsky.screens; + } - YamlRssiSource rssiSource; - node["rssiSource"] >> rssiSource.src_str; - rhs.rssiSource = rssiSource.toCpn(); + if (node["varioData"]) { + const auto& vario = node["varioData"]; + + YamlTelemSource varioSrc; + vario["source"] >> varioSrc; + rhs.frsky.varioSource = varioSrc.src; + + vario["centerSilent"] >> rhs.frsky.varioCenterSilent; + vario["centerMax"] >> rhs.frsky.varioCenterMax; + vario["centerMin"] >> rhs.frsky.varioCenterMin; + vario["min"] >> rhs.frsky.varioMin; + vario["max"] >> rhs.frsky.varioMax; + } + + if (node["rssiSource"]) { + YamlTelemSource rssiSource; + node["rssiSource"] >> rssiSource; + rhs.rssiSource = rssiSource.src; + } + + if (node["voltsSource"]) { + YamlTelemSource voltsSource; + node["voltsSource"] >> voltsSource; + rhs.frsky.voltsSource = voltsSource.src; + } + + if (node["altitudeSource"]) { + YamlTelemSource altitudeSource; + node["altitudeSource"] >> altitudeSource; + rhs.frsky.altitudeSource = altitudeSource.src; + } node["rssiAlarms"] >> rhs.rssiAlarms; diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 09d2f9783..f6ca8c6fc 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -122,19 +122,16 @@ std::string LookupValue(const YamlLookupTable& lut, const int& value); Node operator << (const YamlLookupTable& lut, const int& value); template -struct convert_array +Node encode_array(const T (&rhs)[N]) { - static YAML::Node encode(const T (&rhs)[N]) - { - Node node; - for (size_t i=0; i struct convert_enum From d3e619cec4fb507aa70a72bbe8af4ada0cf95816 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 19 Dec 2021 11:41:34 +0100 Subject: [PATCH 101/180] Removed unused YamlRssiSource --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 58abcaddc..d271a172e 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -246,27 +246,6 @@ struct YamlSwitchWarningState { } }; -struct YamlRssiSource { - std::string src_str; - - YamlRssiSource() = default; - - YamlRssiSource(unsigned int cpn_value) - { - if (cpn_value == 0) - src_str.append("none"); - else - src_str.append(std::to_string(cpn_value)); - } - - unsigned int toCpn() - { - if (src_str.find("none") == std::string::npos) - return std::stoul(src_str); - return 0; - } -}; - namespace YAML { Node convert::encode(const TimerData& rhs) From 3809c1d0ff8445ec7763df9a4fa0c0fc9fcdc506 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 22:29:55 +1100 Subject: [PATCH 102/180] Fix YamlSwitchWarningState --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index d271a172e..97dcb6087 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -170,7 +170,7 @@ struct YamlSwitchWarningState { const char *sw = tag.data(); if (tag.size() >= 2 && sw[0] == 'S') { - char val[2]; + char val[3]; val[0] = sw[1]; uint64_t value = (i == 0 ? states & 0x3 : states & 0x1); @@ -181,6 +181,7 @@ struct YamlSwitchWarningState { val[1] = '-'; else val[1] = 'd'; + val[2] = '\0'; src_str.append(val); } @@ -202,9 +203,10 @@ struct YamlSwitchWarningState { int shift = 0; uint64_t mask; - char sw[2]; + char sw[3]; sw[0] = 'S'; sw[1] = val[0]; + sw[2] = '\0'; int index = getCurrentFirmware()->getSwitchesIndex(sw); @@ -934,9 +936,9 @@ bool convert::decode(const Node& node, ModelData& rhs) vario["centerMax"] >> rhs.frsky.varioCenterMax; vario["centerMin"] >> rhs.frsky.varioCenterMin; vario["min"] >> rhs.frsky.varioMin; - vario["max"] >> rhs.frsky.varioMax; + vario["max"] >> rhs.frsky.varioMax; } - + if (node["rssiSource"]) { YamlTelemSource rssiSource; node["rssiSource"] >> rssiSource; From 427be5165ce9b87ccbdb8ac74fb61c8eac2678f0 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 23:23:13 +1100 Subject: [PATCH 103/180] Remove testing safeguard for saving etx format --- companion/src/storage/categorized.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index b057c56df..ae13a3b43 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -225,7 +225,7 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) setError(tr("Can't extract RADIO/radio.yml")); return false; } - + if (!loadRadioSettingsFromYaml(radioData.generalSettings, radioSettingsBuffer)) { setError(tr("Can't load RADIO/radio.yml")); return false; @@ -256,7 +256,7 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) QString filename = "MODELS/" + QString::fromStdString(mc.first); if (!loadFile(modelBuffer, filename)) { setError(tr("Can't extract ") + filename); - return false; + return false; } // Please note: @@ -269,7 +269,7 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) if (!loadModelFromYaml(model,modelBuffer)) { setError(tr("Can't load ") + filename); - return false; + return false; } model.used = true; @@ -295,7 +295,7 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) } bool hasCategories = getCurrentFirmware()->getCapability(HasModelCategories); - + EtxModelfiles modelFiles; for (const auto& model : radioData.models) { @@ -329,6 +329,5 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) } } - // force error to avoid overwriting the archive... - return false; + return true; } From 0200e1eaa78897ed5fb481378875cd6bb7659f63 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 19 Dec 2021 23:36:32 +1100 Subject: [PATCH 104/180] Fix timer mode drop down list --- companion/src/modeledit/setup.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index f12d83a74..1c9248814 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -1171,6 +1171,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge panelItemModels->registerItemModel(TimerData::countdownBeepItemModel()); panelItemModels->registerItemModel(TimerData::countdownStartItemModel()); panelItemModels->registerItemModel(TimerData::persistentItemModel()); + panelItemModels->registerItemModel(TimerData::modeItemModel()); panelFilteredModels->registerItemModel(new FilteredItemModel(ModelData::trainerModeItemModel(generalSettings, firmware)), FIM_TRAINERMODE); Board::Type board = firmware->getBoard(); From 1ec3113a856b5bc9f6b4cf4b59aa781c10806c39 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 19 Dec 2021 12:34:50 +0100 Subject: [PATCH 105/180] Fixed outputting timers, flight modes, mixers and limits --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 76 ++++++++++++------- companion/src/firmwares/timerdata.cpp | 7 +- companion/src/firmwares/timerdata.h | 2 +- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 97dcb6087..cb684e378 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -80,6 +80,8 @@ struct YamlTrim { YamlTrim(int mode, int ref, int value): mode(mode), ref(ref), value(value) {} + + bool isEmpty() { return !mode && !ref && !value; } }; struct YamlThrTrace { @@ -340,25 +342,46 @@ struct convert { } }; -template <> -struct convert { - static Node encode(const FlightModeData& rhs) - { +Node EncodeFMData(const FlightModeData& rhs, int phaseIdx) +{ Node node; - // TODO: use max number of trims for radio instead - YamlTrim yt[CPN_MAX_TRIMS]; - for (int i=0; i 0) { + node["swtch"] = rhs.swtch; } - node["trim"] = encode_array(yt); - node["swtch"] = rhs.swtch; node["name"] = rhs.name; node["fadeIn"] = rhs.fadeIn; node["fadeOut"] = rhs.fadeOut; - node["gvars"] = encode_array(rhs.gvars); - return node; - } + Node gvars; + for (size_t i=0; i +struct convert { static bool decode(const Node& node, FlightModeData& rhs) { YamlTrim trims[CPN_MAX_TRIMS]; @@ -638,15 +661,19 @@ Node convert::encode(const ModelData& rhs) for (int i=0; i::encode(const ModelData& rhs) node["throttleReversed"] = (int)rhs.throttleReversed; for (int i = 0; i < CPN_MAX_FLIGHT_MODES; i++) { - Node fmNode; - fmNode = rhs.flightModeData[i]; - node["flightModeData"].push_back(fmNode); + if (!rhs.flightModeData[i].isEmpty(i)) { + node["flightModeData"][std::to_string(i)] = + EncodeFMData(rhs.flightModeData[i], i); + } } for (int i = 0; i < CPN_MAX_MIXERS; i++) { const MixData& mix = rhs.mixData[i]; if (!mix.isEmpty()) { - Node mixNode; - mixNode = mix; - node["mixData"].push_back(mixNode); + node["mixData"].push_back(Node(mix)); } } for (int i = 0; i < CPN_MAX_CHNOUT; i++) { const LimitData& limit = rhs.limitData[i]; if (!limit.isEmpty()) { - Node limitNode; - limitNode = limit; - node["limitData"].push_back(limitNode); + node["limitData"].push_back(Node(limit)); } } @@ -772,7 +796,7 @@ Node convert::encode(const ModelData& rhs) } Node vario; - vario["source"] = YamlTelemSource{rhs.frsky.varioSource}; + vario["source"] = YamlTelemSource(rhs.frsky.varioSource); vario["centerSilent"] = (int)rhs.frsky.varioCenterSilent; vario["centerMax"] = rhs.frsky.varioCenterMax; vario["centerMin"] = rhs.frsky.varioCenterMin; diff --git a/companion/src/firmwares/timerdata.cpp b/companion/src/firmwares/timerdata.cpp index 676b3b3c4..abde9046f 100644 --- a/companion/src/firmwares/timerdata.cpp +++ b/companion/src/firmwares/timerdata.cpp @@ -35,9 +35,12 @@ void TimerData::clear() swtch = RawSwitch(SWITCH_TYPE_NONE); } -bool TimerData::isEmpty() +bool TimerData::isEmpty() const { - return (swtch == RawSwitch(SWITCH_TYPE_NONE, 0) && mode == TIMERMODE_OFF && name[0] == '\0' && minuteBeep == 0 && countdownBeep == COUNTDOWNBEEP_SILENT && val == 0 && persistent == 0 /*&& pvalue == 0*/); + return (swtch == RawSwitch(SWITCH_TYPE_NONE, 0) && mode == TIMERMODE_OFF && + name[0] == '\0' && minuteBeep == 0 && + countdownBeep == COUNTDOWNBEEP_SILENT && val == 0 && + persistent == 0 /*&& pvalue == 0*/); } bool TimerData::isModeOff() diff --git a/companion/src/firmwares/timerdata.h b/companion/src/firmwares/timerdata.h index 42d008664..78bcec716 100644 --- a/companion/src/firmwares/timerdata.h +++ b/companion/src/firmwares/timerdata.h @@ -88,7 +88,7 @@ class TimerData { void convert(RadioDataConversionState & cstate); void clear(); - bool isEmpty(); + bool isEmpty() const; bool isModeOff(); QString nameToString(int index) const; QString countdownBeepToString() const; From 3e8913b06a970f6e64ec492681327991731bb6e0 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 20 Dec 2021 22:25:21 +1100 Subject: [PATCH 106/180] Fix switches on bin import --- companion/src/firmwares/opentx/opentxeeprom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index d07c0887c..423f5050c 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -119,6 +119,8 @@ inline int MAX_XPOTS(Board::Type board, int version) { if (version <= 218 && IS_FAMILY_HORUS_OR_T16(board)) return 3; + if (version <= 220 && (IS_HORUS_X10(board) || IS_FAMILY_T16(board))) + return 5; if (IS_FAMILY_T12(board)) return 2; return Boards::getCapability(board, Board::MultiposPots); From 832b1820ddb1ad171019c307b8e4d718d528dc31 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 20 Dec 2021 22:32:07 +1100 Subject: [PATCH 107/180] Remove poc include --- companion/src/storage/yaml.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/companion/src/storage/yaml.cpp b/companion/src/storage/yaml.cpp index 9be4b5ef0..d404f9acd 100644 --- a/companion/src/storage/yaml.cpp +++ b/companion/src/storage/yaml.cpp @@ -19,7 +19,6 @@ */ #include "yaml.h" -#include "../../../radio/src/storage/yaml/yaml_tree_walker.h" // just to confirm valid compiler path #include #include From ae8b55ae80db41ef74b44d5b0f17a118b8ea6f64 Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 20 Dec 2021 22:56:56 +1100 Subject: [PATCH 108/180] Fix adjustRTC encode --- companion/src/firmwares/edgetx/yaml_generalsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index ec1ee53d2..99335d272 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -109,7 +109,7 @@ Node convert::encode(const GeneralSettings& rhs) node["hapticMode"] = rhs.hapticMode; node["stickMode"] = rhs.stickMode; node["timezone"] = rhs.timezone; - node["adjustRTC"] = rhs.adjustRTC; + node["adjustRTC"] = (int)rhs.adjustRTC; node["inactivityTimer"] = rhs.inactivityTimer; node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? node["splashMode"] = rhs.splashMode; // TODO: B&W only From 28fbbfa515b1e56a25b98e96d672352408b593af Mon Sep 17 00:00:00 2001 From: elecpower Date: Mon, 20 Dec 2021 23:33:14 +1100 Subject: [PATCH 109/180] Fix error when no curve points node --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index cb684e378..3430a897e 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -376,7 +376,7 @@ Node EncodeFMData(const FlightModeData& rhs, int phaseIdx) if (gvars && gvars.IsMap()) { node["gvars"] = gvars; } - + return node; } @@ -908,7 +908,8 @@ bool convert::decode(const Node& node, ModelData& rhs) node["expoData"] >> rhs.expoData; node["curves"] >> rhs.curves; - YamlReadCurvePoints(node["points"], rhs.curves); + if (node["points"]) + YamlReadCurvePoints(node["points"], rhs.curves); node["logicalSw"] >> rhs.logicalSw; node["customFn"] >> rhs.customFn; From 44146f1e4f718f7b2f8410463b91ea8e2fc82c61 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 22 Dec 2021 07:41:48 +1100 Subject: [PATCH 110/180] Fix decode rawswitch and more encode bools --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 6 +++--- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 3430a897e..6bcf0d191 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -288,10 +288,10 @@ struct convert { Node node; node["min"] = rhs.min; node["max"] = rhs.max; - node["revert"] = rhs.revert; + node["revert"] = (int)rhs.revert; node["offset"] = rhs.offset; node["ppmCenter"] = rhs.ppmCenter; - node["symetrical"] = rhs.symetrical; + node["symetrical"] = (int)rhs.symetrical; node["failsafe"] = rhs.failsafe; node["name"] = rhs.name; node["curve"] = rhs.curve; @@ -438,7 +438,7 @@ struct convert { node["name"] = rhs.name; node["min"] = rhs.min; node["max"] = rhs.max; - node["popup"] = rhs.popup; + node["popup"] = (int)rhs.popup; node["prec"] = rhs.prec; node["unit"] = rhs.unit; return node; diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index de83e26b0..970b4dbd2 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -79,21 +79,25 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) RawSwitch rhs; // constructor sets to SWITCH_TYPE_NONE const char* val = sw_str.data(); size_t val_len = sw_str.size(); + std::string sw_str_tmp = sw_str; bool neg = false; if (val_len > 0 && val[0] == '!') { neg = true; val++; val_len--; + sw_str_tmp = sw_str.substr(1); } int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); + // TODO: validate all expected numeric chars are numeric not just first + if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { + if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + std::stoi(sw_str_tmp.substr(1, val_len - 1)) - 1); } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && @@ -111,14 +115,14 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { + if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { rhs = RawSwitch(SWITCH_TYPE_SENSOR, - std::stoi(sw_str.substr(1, val_len - 1)) - 1); + std::stoi(sw_str_tmp.substr(1, val_len - 1)) - 1); } - } else if (sw_str.substr(0, 4) == std::string("Trim")) { + } else if (sw_str_tmp.substr(0, 4) == std::string("Trim")) { - int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str.c_str()); + int tsw_idx = getCurrentFirmware()->getTrimSwitchesIndex(sw_str_tmp.c_str()); if (tsw_idx >= 0) { rhs.type = SWITCH_TYPE_TRIM; rhs.index = tsw_idx; @@ -128,7 +132,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) (val[1] >= 'A' && val[1] <= 'Z') && (val[2] >= '0' && val[2] <= '2')) { - int sw_idx = getCurrentFirmware()->getSwitchesIndex(sw_str.substr(0, 2).c_str()); + int sw_idx = getCurrentFirmware()->getSwitchesIndex(sw_str_tmp.substr(0, 2).c_str()); if (sw_idx >= 0) { rhs.type = SWITCH_TYPE_SWITCH; rhs.index = sw_idx * 3 + val[2] - '0'; @@ -139,7 +143,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else { // types which do not use index - int sw_type = getCurrentFirmware()->getRawSwitchTypesIndex(sw_str.c_str()); + int sw_type = getCurrentFirmware()->getRawSwitchTypesIndex(sw_str_tmp.c_str()); if (sw_type >= 0) { rhs.type = (RawSwitchType)sw_type; rhs.index = 0; From 5d8947f19f57b3eb372a811d417a58d6d0aa4f28 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 22 Dec 2021 17:20:10 +1100 Subject: [PATCH 111/180] Fix grouping models by category --- companion/src/storage/categorized.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index ae13a3b43..7f9a52ce2 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -263,15 +263,16 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) // ModelData() use memset to clear everything to 0 // auto& model = radioData.models[modelIdx]; - model.category = mc.second; - model.modelIndex = modelIdx; - strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); if (!loadModelFromYaml(model,modelBuffer)) { setError(tr("Can't load ") + filename); return false; } + model.category = mc.second; + model.modelIndex = modelIdx; + strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); + model.used = true; modelIdx++; } From 26ecb10288e80355fe5f6380464207f39f09ff73 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 22 Dec 2021 12:40:58 +0100 Subject: [PATCH 112/180] Fixed switches index --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 970b4dbd2..4ae567841 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -135,7 +135,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) int sw_idx = getCurrentFirmware()->getSwitchesIndex(sw_str_tmp.substr(0, 2).c_str()); if (sw_idx >= 0) { rhs.type = SWITCH_TYPE_SWITCH; - rhs.index = sw_idx * 3 + val[2] - '0'; + rhs.index = sw_idx * 3 + (val[2] - '0' + 1); } // TODO: SWITCH_TYPE_TIMER_MODE From 9057a6b7f19c1681bdedf7a2e7d069f4416985bc Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 22 Dec 2021 12:50:00 +0100 Subject: [PATCH 113/180] Default to YAML for write format --- companion/src/storage/categorized.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 7f9a52ce2..05540bbb0 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -25,20 +25,28 @@ bool CategorizedStorageFormat::load(RadioData & radioData) { - if (getStorageType(filename) == STORAGE_TYPE_ETX || - (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX)) + StorageType st = getStorageType(filename); + if (st == STORAGE_TYPE_UNKNOWN) { + st = probeFormat(); + } + if (st == STORAGE_TYPE_ETX || st == STORAGE_TYPE_YML) { return loadYaml(radioData); - else + } else { return loadBin(radioData); + } } bool CategorizedStorageFormat::write(const RadioData & radioData) { - if (getStorageType(filename) == STORAGE_TYPE_ETX || - (getStorageType(filename) == STORAGE_TYPE_UNKNOWN && probeFormat() == STORAGE_TYPE_ETX)) + StorageType st = getStorageType(filename); + if (st == STORAGE_TYPE_UNKNOWN) { + st = probeFormat(); + } + if (st == STORAGE_TYPE_ETX || st == STORAGE_TYPE_UNKNOWN) { return writeYaml(radioData); - else + } else { return writeBin(radioData); + } } StorageType CategorizedStorageFormat::probeFormat() From 47a3d343b5cbb2c2c6528091634d133090d31678 Mon Sep 17 00:00:00 2001 From: elecpower Date: Wed, 22 Dec 2021 23:00:17 +1100 Subject: [PATCH 114/180] Fix custom functions decode of func --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 4f9db6a41..654a00201 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -61,7 +61,7 @@ static const YamlLookupTable customFnLut = { { FuncBacklight, "BACKLIGHT" }, { FuncScreenshot, "SCREENSHOT" }, { FuncRacingMode, "RACING_MODE" }, - { FuncDisableTouch, "DISABLE_TOUCH" }, + { FuncDisableTouch, "DISABLE_TOUCH" }, }; static const YamlLookupTable trainerLut = { @@ -218,7 +218,7 @@ Node convert::encode(const CustomFunctionData& rhs) if (!def.empty()) { node["def"] = def; } - + return node; } @@ -228,13 +228,13 @@ bool convert::decode(const Node& node, node["swtch"] >> rhs.swtch; int func = 0; - node["func"] >> func; + node["func"] >> customFnLut >> func; rhs.func = (AssignFunc)func; std::string def_str; node["def"] >> def_str; std::stringstream def(def_str); - + switch(rhs.func) { case FuncOverrideCH1: { int ch=0; @@ -254,7 +254,7 @@ bool convert::decode(const Node& node, case FuncPlayPrompt: case FuncPlayScript: case FuncBackgroundMusic: - strncpy(rhs.paramarm, def.str().c_str(), sizeof(rhs.paramarm)-1); + strncpy(rhs.paramarm, def.str().c_str(), sizeof(rhs.paramarm)-1); // TODO fix eg def: engarm,1x break; case FuncReset: { try { @@ -327,7 +327,7 @@ bool convert::decode(const Node& node, rhs.repeatParam = std::stoi(repeat); } } - + return true; } } // namespace YAML From 7a526a17860fbe6a75bce29f8217608f8123e02a Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 23 Dec 2021 06:33:28 +1100 Subject: [PATCH 115/180] Fix custom func decode play_x --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 654a00201..73da42dcc 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -253,9 +253,11 @@ bool convert::decode(const Node& node, break; case FuncPlayPrompt: case FuncPlayScript: - case FuncBackgroundMusic: - strncpy(rhs.paramarm, def.str().c_str(), sizeof(rhs.paramarm)-1); // TODO fix eg def: engarm,1x - break; + case FuncBackgroundMusic: { + std::string file_str; + getline(def, file_str, ','); + strncpy(rhs.paramarm, file_str.c_str(), sizeof(rhs.paramarm)-1); + } break; case FuncReset: { try { def >> rhs.param; From 340e7627d53b2764d16551d7a2c0f238cd6406a4 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 23 Dec 2021 07:09:05 +1100 Subject: [PATCH 116/180] Fix custom func logs and sounds list --- .../edgetx/yaml_customfunctiondata.cpp | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 73da42dcc..226e6abb7 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -78,18 +78,18 @@ static const YamlLookupTable soundLut = { { 1, "Bp2" }, { 2, "Bp3" }, { 3, "Wrn1" }, - { 5, "Wrn2" }, - { 6, "Chee" }, - { 7, "Rata" }, - { 8, "Tick" }, - { 9, "Sirn" }, - { 10, "Ring" }, - { 11, "SciF" }, - { 12, "Robt" }, - { 13, "Chrp" }, - { 14, "Tada" }, - { 15, "Crck" }, - { 16, "Alrm" }, + { 4, "Wrn2" }, + { 5, "Chee" }, + { 6, "Rata" }, + { 7, "Tick" }, + { 8, "Sirn" }, + { 9, "Ring" }, + { 10, "SciF" }, + { 11, "Robt" }, + { 12, "Chrp" }, + { 13, "Tada" }, + { 14, "Crck" }, + { 15, "Alrm" }, }; static const YamlLookupTable resetLut = { @@ -193,6 +193,9 @@ Node convert::encode(const CustomFunctionData& rhs) case FuncBindInternalModule: { def += LookupValue(moduleLut, p1); } break; + case FuncLogs: + def += std::to_string(rhs.param); + break; default: break; } @@ -310,6 +313,11 @@ bool convert::decode(const Node& node, Node(mod) >> moduleLut >> module; rhs.func = (AssignFunc)((int)rhs.func + module); } break; + case FuncLogs: { + int param = 0; + def >> param; + rhs.param = param; + } break; default: break; } From 62028ffccec1f89fcf66ddf43076afb9e33f9563 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 23 Dec 2021 08:52:13 +1100 Subject: [PATCH 117/180] Fix custom func reset --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 226e6abb7..2153f8803 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -97,7 +97,7 @@ static const YamlLookupTable resetLut = { { 1, "Tmr2" }, { 2, "Tmr3" }, { 3, "All" }, - { 5, "Tele" }, + { 4, "Tele" }, }; static const YamlLookupTable gvarModeLut = { @@ -262,12 +262,13 @@ bool convert::decode(const Node& node, strncpy(rhs.paramarm, file_str.c_str(), sizeof(rhs.paramarm)-1); } break; case FuncReset: { + std::string rst_str; + getline(def, rst_str, ','); try { - def >> rhs.param; - rhs.param += 5; // + FUNC_RESET_PARAM_FIRST_TELEM + rhs.param = std::stoi(rst_str); // TODO: check this works for radio generated if not then encode and here will need fixing break; } catch(...) {} - Node(def.str()) >> resetLut >> rhs.param; + Node(rst_str.c_str()) >> resetLut >> rhs.param; } break; case FuncSetTimer1: { // + timer # From 00b6e4faca07a99851a312f71d4507d730a6cbe0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 23 Dec 2021 09:13:55 +0100 Subject: [PATCH 118/180] Fixed FuncReset --- companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 2153f8803..d115457c3 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -163,7 +163,7 @@ Node convert::encode(const CustomFunctionData& rhs) case FuncReset: def += LookupValue(resetLut, rhs.param); if (def.empty()) { - def += std::to_string(rhs.param); + def += std::to_string(rhs.param - resetLut.size()); } break; case FuncSetTimer1: { @@ -265,7 +265,8 @@ bool convert::decode(const Node& node, std::string rst_str; getline(def, rst_str, ','); try { - rhs.param = std::stoi(rst_str); // TODO: check this works for radio generated if not then encode and here will need fixing + rhs.param = std::stoi(rst_str); + rhs.param += resetLut.size(); break; } catch(...) {} Node(rst_str.c_str()) >> resetLut >> rhs.param; From 2659abf21661ffca70c0f6739c193c941fac66e6 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 23 Dec 2021 09:14:58 +0100 Subject: [PATCH 119/180] Fixed screen data --- .../src/firmwares/customisation_data.cpp | 35 ++++++++++++++++--- companion/src/firmwares/customisation_data.h | 11 ++++++ .../src/firmwares/edgetx/yaml_rawsource.cpp | 1 + .../src/firmwares/edgetx/yaml_screendata.cpp | 26 +++++++++++--- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/companion/src/firmwares/customisation_data.cpp b/companion/src/firmwares/customisation_data.cpp index 5de5fb803..fb9e1fed3 100644 --- a/companion/src/firmwares/customisation_data.cpp +++ b/companion/src/firmwares/customisation_data.cpp @@ -27,6 +27,26 @@ #define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF) #define RED RADIO_RGB(229, 32, 30) +ZoneOptionValue::ZoneOptionValue() +{ + memset((void*)this, 0, sizeof(ZoneOptionValue)); +} + +ZoneOptionValueTyped::ZoneOptionValueTyped() +{ + memset((void*)this, 0, sizeof(ZoneOptionValueTyped)); +} + +WidgetPersistentData::WidgetPersistentData() +{ + memset((void*)this, 0, sizeof(WidgetPersistentData)); +} + +ZonePersistentData::ZonePersistentData() +{ + memset((void*)this, 0, sizeof(ZonePersistentData)); +} + inline void setZoneOptionValue(ZoneOptionValue& zov, bool value) { zov.boolValue = value; @@ -61,9 +81,13 @@ inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type) return ZOV_Bool; case ZoneOption::Color: + return ZOV_Color; + + case ZoneOption::Source: + return ZOV_Source; + case ZoneOption::Timer: case ZoneOption::Switch: - case ZoneOption::Source: case ZoneOption::TextSize: default: return ZOV_Unsigned; @@ -85,9 +109,7 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { } } -static const ZoneOptionValueTyped zero_widget_option = { - ZOV_Unsigned, {0} -}; +static const ZoneOptionValueTyped zero_widget_option = {}; bool ZoneOptionValueTyped::isEmpty() const { @@ -99,6 +121,11 @@ bool ZonePersistentData::isEmpty() const return strlen(widgetName) == 0; } +RadioLayout::CustomScreenData::CustomScreenData() +{ + memset((void*)this, 0, sizeof(RadioLayout::CustomScreenData)); +} + bool RadioLayout::CustomScreenData::isEmpty() const { return strlen(layoutId) == 0; diff --git a/companion/src/firmwares/customisation_data.h b/companion/src/firmwares/customisation_data.h index 457be6c0c..b2d5bf72d 100644 --- a/companion/src/firmwares/customisation_data.h +++ b/companion/src/firmwares/customisation_data.h @@ -61,6 +61,8 @@ struct ZoneOptionValue // union in radio/src/datastructs.h char stringValue[LEN_ZONE_OPTION_STRING + 1]; RawSource sourceValue; unsigned int colorValue; + + ZoneOptionValue(); }; enum ZoneOptionValueEnum { @@ -99,17 +101,21 @@ struct ZoneOptionValueTyped ZoneOptionValueEnum type; ZoneOptionValue value; + ZoneOptionValueTyped(); bool isEmpty() const; }; struct WidgetPersistentData { ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS]; + + WidgetPersistentData(); }; struct ZonePersistentData { char widgetName[WIDGET_NAME_LEN + 1]; WidgetPersistentData widgetData; + ZonePersistentData(); bool isEmpty() const; }; @@ -117,6 +123,10 @@ template struct WidgetsContainerPersistentData { ZonePersistentData zones[N]; ZoneOptionValueTyped options[O]; + + WidgetsContainerPersistentData() { + memset((void*)this, 0, sizeof(WidgetsContainerPersistentData)); + } }; typedef WidgetsContainerPersistentData @@ -151,6 +161,7 @@ class RadioLayout char layoutId[LAYOUT_ID_LEN + 1]; LayoutPersistentData layoutPersistentData; + CustomScreenData(); bool isEmpty() const; }; diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index c8f02d794..d700c712b 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -87,6 +87,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) break; } src_str += std::to_string(rhs.index / 3); + src_str += ")"; break; default: src_str = "NONE"; diff --git a/companion/src/firmwares/edgetx/yaml_screendata.cpp b/companion/src/firmwares/edgetx/yaml_screendata.cpp index ab26f4f49..d4d8c2852 100644 --- a/companion/src/firmwares/edgetx/yaml_screendata.cpp +++ b/companion/src/firmwares/edgetx/yaml_screendata.cpp @@ -22,11 +22,23 @@ #include "yaml_rawsource.h" #include "yaml_ops.h" +#include +#include + static const YamlLookupTable zoneOptionValueEnum = { {ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"}, {ZOV_String, "String"}, {ZOV_Source, "Source"}, {ZOV_Color, "Color"}, }; +std::string color_to_hex( unsigned int i ) +{ + std::stringstream stream; + stream << "0x" + << std::setfill ('0') << std::setw(6) + << std::hex << i; + return stream.str(); +} + namespace YAML { ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum); @@ -47,10 +59,10 @@ Node convert::encode(const ZoneOptionValueTyped& rhs) value["boolValue"] = rhs.value.boolValue; break; case ZOV_Source: - value["sourceValue"] = rhs.value.sourceValue; + value["source"] = rhs.value.sourceValue; break; case ZOV_Color: - value["colorValue"] = rhs.value.colorValue; + value["color"] = color_to_hex(rhs.value.colorValue); break; default: break; @@ -70,8 +82,8 @@ bool convert::decode(const Node& node, value["signedValue"] >> rhs.value.signedValue; value["boolValue"] >> rhs.value.boolValue; value["stringValue"] >> rhs.value.stringValue; - value["sourceValue"] >> rhs.value.sourceValue; - value["colorValue"] >> rhs.value.colorValue; + value["source"] >> rhs.value.sourceValue; + value["color"] >> rhs.value.colorValue; } } return true; @@ -84,7 +96,11 @@ struct convert { Node node; for (int i=0; i Date: Thu, 23 Dec 2021 10:43:22 +0100 Subject: [PATCH 120/180] Fixed switch, pot & sliders config --- .../src/firmwares/edgetx/yaml_switchconfig.cpp | 16 +++++++++++++--- .../src/firmwares/edgetx/yaml_switchconfig.h | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index f8892d819..7ba57903a 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -96,6 +96,10 @@ int YamlPotLookup::name2idx(const std::string& name) int idx = fw->getAnalogInputIndex(name.c_str()); if (idx < 0) return idx; + int sticks = Boards::getCapability(fw->getBoard(), Board::Sticks); + if (idx < sticks) return -1; + idx -= sticks; + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); if (idx >= pots) return -1; @@ -108,7 +112,8 @@ std::string YamlPotLookup::idx2name(unsigned int idx) unsigned int pots = Boards::getCapability(fw->getBoard(), Board::Pots); if (idx >= pots) return std::string(); - return fw->getAnalogInputTag(idx); + unsigned int sticks = Boards::getCapability(fw->getBoard(), Board::Sticks); + return fw->getAnalogInputTag(idx + sticks); } int YamlSliderLookup::name2idx(const std::string& name) @@ -117,6 +122,10 @@ int YamlSliderLookup::name2idx(const std::string& name) int idx = fw->getAnalogInputIndex(name.c_str()); if (idx < 0) return idx; + int sticks = Boards::getCapability(fw->getBoard(), Board::Sticks); + if (idx < sticks) return -1; + idx -= sticks; + int pots = Boards::getCapability(fw->getBoard(), Board::Pots); if (idx < pots) return -1; idx -= pots; @@ -130,9 +139,10 @@ int YamlSliderLookup::name2idx(const std::string& name) std::string YamlSliderLookup::idx2name(unsigned int idx) { auto fw = getCurrentFirmware(); - int pots = Boards::getCapability(fw->getBoard(), Board::Pots); unsigned int sliders = Boards::getCapability(fw->getBoard(), Board::Sliders); if (idx >= sliders) return std::string(); - return fw->getAnalogInputTag(idx + pots); + unsigned int sticks = Boards::getCapability(fw->getBoard(), Board::Sticks); + unsigned int pots = Boards::getCapability(fw->getBoard(), Board::Pots); + return fw->getAnalogInputTag(idx + pots + sticks); } diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.h b/companion/src/firmwares/edgetx/yaml_switchconfig.h index 37e3e5fd3..c5240e4e4 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.h +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.h @@ -110,7 +110,7 @@ struct convert > { Node node; for (unsigned int i=0; i > { Node node; for (unsigned int i=0; i Date: Thu, 23 Dec 2021 10:43:51 +0100 Subject: [PATCH 121/180] Remove some more empty attributes --- .../firmwares/edgetx/yaml_generalsettings.cpp | 27 ++++++++++++++++--- .../src/firmwares/edgetx/yaml_modeldata.cpp | 4 ++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 99335d272..fe1e96aea 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -151,10 +151,29 @@ Node convert::encode(const GeneralSettings& rhs) } } - node["sticksConfig"] = YamlStickConfig(rhs.stickName); - node["switchConfig"] = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); - node["potsConfig"] = YamlPotConfig(rhs.potName, rhs.potConfig); - node["slidersConfig"] = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); + Node sticksConfig; + sticksConfig = YamlStickConfig(rhs.stickName); + if (sticksConfig && sticksConfig.IsMap()) { + node["sticksConfig"] = sticksConfig; + } + + Node switchConfig; + switchConfig = YamlSwitchConfig(rhs.switchName, rhs.switchConfig); + if (switchConfig && switchConfig.IsMap()) { + node["switchConfig"] = switchConfig; + } + + Node potsConfig; + potsConfig = YamlPotConfig(rhs.potName, rhs.potConfig); + if (potsConfig && potsConfig.IsMap()) { + node["potsConfig"] = potsConfig; + } + + Node slidersConfig; + slidersConfig = YamlSliderConfig(rhs.sliderName, rhs.sliderConfig); + if (slidersConfig && slidersConfig.IsMap()) { + node["slidersConfig"] = slidersConfig; + } // Color lcd theme settings are not used in EdgeTx // RadioTheme::ThemeData themeData; diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 6bcf0d191..723f9c2e4 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -719,7 +719,9 @@ Node convert::encode(const ModelData& rhs) } for (auto input : inputs) { - node["inputNames"][std::to_string(input)]["val"] = rhs.inputNames[input]; + if (rhs.inputNames[input][0]) { + node["inputNames"][std::to_string(input)]["val"] = rhs.inputNames[input]; + } } for (int i = 0; i < CPN_MAX_CURVES; i++) { From 56ceaebeb8a0f5e2eabf9b82ff3e6a95f008fa6d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 23 Dec 2021 11:02:03 +0100 Subject: [PATCH 122/180] Use proper switch lookup --- .../firmwares/edgetx/yaml_switchconfig.cpp | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 7ba57903a..75b0e05af 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -69,25 +69,20 @@ std::string YamlStickLookup::idx2name(unsigned int idx) int YamlSwitchLookup::name2idx(const std::string& name) { - // TODO: replace this with a real lookup of available switches - if (name.size() == 2 - && name[0] == 'S' - && (name[1] >= 'A' && name[1] <= 'J')) { + auto fw = getCurrentFirmware(); + int idx = fw->getSwitchesIndex(name.c_str()); + if (idx < 0) return -1; - return name[1] - 'A'; - } - - return -1; + return idx; } std::string YamlSwitchLookup::idx2name(unsigned int idx) { - // TODO: replace this with a real lookup of available switches - if (idx < 10) { - return std::string("S") + (char)('A' + idx); - } + auto fw = getCurrentFirmware(); + unsigned int switches = Boards::getCapability(fw->getBoard(), Board::Switches); + if (idx >= switches) return std::string(); - return std::string(); + return fw->getSwitchesTag(idx); } int YamlPotLookup::name2idx(const std::string& name) From a0bc0fd2e12d98dd0764a075fb415f344de2adb4 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 24 Dec 2021 10:09:46 +0100 Subject: [PATCH 123/180] Use temporary SD card path for all radios using SD card storage --- companion/src/simulation/simulatorwidget.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/companion/src/simulation/simulatorwidget.cpp b/companion/src/simulation/simulatorwidget.cpp index 365cb57d4..406e2bdbe 100644 --- a/companion/src/simulation/simulatorwidget.cpp +++ b/companion/src/simulation/simulatorwidget.cpp @@ -294,17 +294,20 @@ bool SimulatorWidget::setRadioData(RadioData * radioData) saveTempRadioData = (flags & SIMULATOR_FLAGS_STANDALONE); - if (IS_FAMILY_HORUS_OR_T16(m_board)) + // All radios use SD card data path from 2.6.0 on + bool hasSdCard = Boards::getCapability(m_board, Board::HasSDCard); + if (hasSdCard) ret = useTempDataPath(true); if (ret) { - if (radioDataPath.isEmpty()) { + if (!hasSdCard) { startupData.fill(0, Boards::getEEpromSize(m_board)); - if (firmware->getEEpromInterface()->save((uint8_t *)startupData.data(), *radioData, 0, firmware->getCapability(SimulatorVariant)) <= 0) { + if (firmware->getEEpromInterface()->save( + (uint8_t *)startupData.data(), *radioData, 0, + firmware->getCapability(SimulatorVariant)) <= 0) { ret = false; } - } - else { + } else { ret = saveRadioData(radioData, radioDataPath); } } From f4257c0c2ab41d2ffbb6682f411951724b6ad58a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 24 Dec 2021 10:33:16 +0100 Subject: [PATCH 124/180] Fix simulated SD card path redirection --- radio/src/targets/simu/simufatfs.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/radio/src/targets/simu/simufatfs.cpp b/radio/src/targets/simu/simufatfs.cpp index 92d2ac27e..5598217b0 100644 --- a/radio/src/targets/simu/simufatfs.cpp +++ b/radio/src/targets/simu/simufatfs.cpp @@ -124,23 +124,20 @@ bool redirectToSettingsDirectory(const std::string & path) * model (*.bin) files in /MODELS directory */ if (!simuSettingsDirectory.empty()) { -#if defined(COLORLCD) - if (path == RADIO_MODELSLIST_PATH || path == RADIO_SETTINGS_PATH -#if defined(SDCARD_YAML) - || path == MODELSLIST_YAML_PATH || path == RADIO_SETTINGS_YAML_PATH -#endif - ) { +#if defined(SDCARD_RAW) || defined(SDCARD_YAML) + if (path == MODELS_PATH || path == RADIO_PATH) return true; + #if !defined(EEPROM_RLC) + if (path == RADIO_MODELSLIST_PATH || path == RADIO_SETTINGS_PATH) return true; - } -#endif - if (startsWith(path, "/MODELS") - && (endsWith(path, MODELS_EXT) -#if defined(SDCARD_YAML) - || endsWith(path, YAML_EXT) -#endif - )) { + if (startsWith(path, MODELS_PATH) && endsWith(path, MODELS_EXT)) return true; - } + #endif +#endif +#if defined(SDCARD_YAML) + if (path == MODELSLIST_YAML_PATH || path == RADIO_SETTINGS_YAML_PATH) + return true; + if (startsWith(path, MODELS_PATH) && endsWith(path, YAML_EXT)) return true; +#endif } return false; } From 9f348b513e6fcd0990cfc2273385b55887ec8058 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 24 Dec 2021 10:59:12 +0100 Subject: [PATCH 125/180] Fix writing model files for radios without categories --- companion/src/storage/categorized.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 05540bbb0..3f89b431f 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -319,7 +319,8 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) modelFilename = QString("MODELS/%1").arg(model.filename); modelFiles.push_back({ std::string(model.filename), model.category }); } else { - modelFilename = QString("MODELS/model%1").arg(model.modelIndex, 2, QLatin1Char('0')); + modelFilename = QString("MODELS/model%1.yml") + .arg(model.modelIndex, 2, 10, QLatin1Char('0')); } QByteArray modelData; From c2c23c43d96cb2a507be0c801d21e89a0b9c5c27 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 09:40:47 +0100 Subject: [PATCH 126/180] Fix parsing last line without CRLF/LF. Check EOF at the end of the buffer. --- radio/src/storage/modelslist.cpp | 1 + radio/src/storage/sdcard_yaml.cpp | 1 + radio/src/storage/yaml/yaml_parser.cpp | 6 ++++++ radio/src/storage/yaml/yaml_parser.h | 3 +++ 4 files changed, 11 insertions(+) diff --git a/radio/src/storage/modelslist.cpp b/radio/src/storage/modelslist.cpp index b3c3f87e0..f4c609114 100644 --- a/radio/src/storage/modelslist.cpp +++ b/radio/src/storage/modelslist.cpp @@ -381,6 +381,7 @@ bool ModelsList::loadYaml() if (bytes_read == 0) break; + if (f_eof(&file)) yp.set_eof(); if (yp.parse(line, bytes_read) != YamlParser::CONTINUE_PARSING) break; } diff --git a/radio/src/storage/sdcard_yaml.cpp b/radio/src/storage/sdcard_yaml.cpp index 55e6f22cf..bbc28cddc 100644 --- a/radio/src/storage/sdcard_yaml.cpp +++ b/radio/src/storage/sdcard_yaml.cpp @@ -58,6 +58,7 @@ const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, vo if (bytes_read == 0) break; + if (f_eof(&file)) yp.set_eof(); if (yp.parse(buffer, bytes_read) != YamlParser::CONTINUE_PARSING) break; } diff --git a/radio/src/storage/yaml/yaml_parser.cpp b/radio/src/storage/yaml/yaml_parser.cpp index 743760ce8..682151353 100644 --- a/radio/src/storage/yaml/yaml_parser.cpp +++ b/radio/src/storage/yaml/yaml_parser.cpp @@ -40,6 +40,7 @@ void YamlParser::init(const YamlParserCalls* parser_calls, void* parser_ctx) calls = parser_calls; ctx = parser_ctx; reset(); + eof = false; } void YamlParser::reset() @@ -311,6 +312,11 @@ YamlParser::parse(const char* buffer, unsigned int size) c++; } // for each char + if ((state == ps_Val) && eof && node_found) { + // TODO: trim spaces at the end? + calls->set_attr(ctx, scratch_buf, scratch_len); + } + return CONTINUE_PARSING; } diff --git a/radio/src/storage/yaml/yaml_parser.h b/radio/src/storage/yaml/yaml_parser.h index bc62dbe7d..15b4b4907 100644 --- a/radio/src/storage/yaml/yaml_parser.h +++ b/radio/src/storage/yaml/yaml_parser.h @@ -73,6 +73,7 @@ class YamlParser uint8_t scratch_len; bool node_found; + bool eof; // tree iterator state const YamlParserCalls* calls; @@ -98,6 +99,8 @@ public: void init(const YamlParserCalls* parser_calls, void* parser_ctx); YamlResult parse(const char* buffer, unsigned int size); + + void set_eof() { eof = true; } }; #endif From 7e8e5bf55447213515d830f42c9025235e1f780a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 10:20:06 +0100 Subject: [PATCH 127/180] Fixed metadata in models.yml --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 13 ++++++++----- companion/src/firmwares/edgetx/edgetxinterface.h | 9 +++++++-- companion/src/storage/categorized.cpp | 11 ++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 7c5b88dc8..878757294 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -65,7 +65,9 @@ bool loadModelsListFromYaml(std::vector& categories, for (const auto& model : models) { std::string filename; model["filename"] >> filename; - modelFiles.push_back({ filename, categories.size()-1 }); + std::string name; + model["name"] >> name; + modelFiles.push_back({filename, name, (int)categories.size() - 1}); } } } @@ -124,14 +126,15 @@ bool writeModelsListToYaml(const std::vector& categories, for (const auto& modelFile: modelFiles) { YAML::Node cat_attrs; - cat_attrs["filename"] = modelFile.first; + cat_attrs["filename"] = modelFile.filename; + cat_attrs["name"] = modelFile.name; - if (modelFile.second >= (int)categories.size()) { + if (modelFile.category >= (int)categories.size()) { return false; } - const std::string cat_name = categories[modelFile.second].name; - node[modelFile.second][cat_name].push_back(cat_attrs); + const std::string cat_name = categories[modelFile.category].name; + node[modelFile.category][cat_name].push_back(cat_attrs); } writeYamlToByteArray(node, data); diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index e82771562..60b69119d 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -29,8 +29,13 @@ constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 }; -typedef std::pair EtxModelfileCategoryPair; -typedef std::list EtxModelfiles; +struct EtxModelMetadata { + std::string filename; + std::string name; + int category; +}; + +typedef std::list EtxModelfiles; bool loadModelsListFromYaml(std::vector& categories, EtxModelfiles& modelFiles, diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 3f89b431f..58e7c7ba0 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -258,10 +258,10 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) int modelIdx = 0; for (const auto& mc : modelFiles) { - qDebug() << "Filename: " << mc.first.c_str() << " / Category: " << mc.second; + qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category; QByteArray modelBuffer; - QString filename = "MODELS/" + QString::fromStdString(mc.first); + QString filename = "MODELS/" + QString::fromStdString(mc.filename); if (!loadFile(modelBuffer, filename)) { setError(tr("Can't extract ") + filename); return false; @@ -277,9 +277,9 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) return false; } - model.category = mc.second; + model.category = mc.category; model.modelIndex = modelIdx; - strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1); + strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1); model.used = true; modelIdx++; @@ -317,7 +317,8 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) QString modelFilename; if (hasCategories) { modelFilename = QString("MODELS/%1").arg(model.filename); - modelFiles.push_back({ std::string(model.filename), model.category }); + modelFiles.push_back({std::string(model.filename), + std::string(model.name), model.category}); } else { modelFilename = QString("MODELS/model%1.yml") .arg(model.modelIndex, 2, 10, QLatin1Char('0')); From e56e769d279744177b9074aad759cd0f6bdc2ecf Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 12:10:57 +0100 Subject: [PATCH 128/180] Patch `.bin` filename to `.yml` --- .../src/firmwares/edgetx/edgetxinterface.cpp | 15 +++++++++++++++ companion/src/firmwares/edgetx/edgetxinterface.h | 2 ++ .../src/firmwares/edgetx/yaml_generalsettings.cpp | 2 +- companion/src/storage/categorized.cpp | 8 +++++--- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 878757294..d5a90de1f 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -158,3 +158,18 @@ bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data) writeYamlToByteArray(node, data); return true; } + +std::string patchFilenameToYaml(const std::string& str) +{ + constexpr const char MODELS_EXT[] = ".bin"; + constexpr const char YAML_EXT[] = ".yml"; + constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1; + + // patch file extension + auto const dot_pos = str.find_last_of('.'); + if ((dot_pos != std::string::npos) && (str.substr(dot_pos) == MODELS_EXT)) { + std::string tmp = str; + return tmp.replace(dot_pos, bin_len, YAML_EXT); + } + return str; +} diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index 60b69119d..4512ccd8d 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -50,3 +50,5 @@ bool writeModelsListToYaml(const std::vector& categories, bool writeModelToYaml(const ModelData& model, QByteArray& data); bool writeRadioSettingsToYaml(const GeneralSettings& settings, QByteArray& data); + +std::string patchFilenameToYaml(const std::string& str); diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index fe1e96aea..d824414f9 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -88,7 +88,7 @@ Node convert::encode(const GeneralSettings& rhs) node["calib"] = calib; node["currModel"] = rhs.currModelIndex; - node["currModelFilename"] = rhs.currModelFilename; + node["currModelFilename"] = patchFilenameToYaml(rhs.currModelFilename); node["contrast"] = rhs.contrast; node["vBatWarn"] = rhs.vBatWarn; node["txVoltageCalibration"] = rhs.txVoltageCalibration; diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 58e7c7ba0..e6aef817a 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -316,9 +316,11 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) QString modelFilename; if (hasCategories) { - modelFilename = QString("MODELS/%1").arg(model.filename); - modelFiles.push_back({std::string(model.filename), - std::string(model.name), model.category}); + std::string ymlFilename = patchFilenameToYaml(model.filename); + modelFilename = + QString("MODELS/%1").arg(QString::fromStdString(ymlFilename)); + modelFiles.push_back( + {ymlFilename, std::string(model.name), model.category}); } else { modelFilename = QString("MODELS/model%1.yml") .arg(model.modelIndex, 2, 10, QLatin1Char('0')); From 1a7e5e3b2b3c25bca30e173156236de42161d604 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 14:24:26 +0100 Subject: [PATCH 129/180] Fixed setting bit-field members in random order --- radio/src/storage/yaml/yaml_bits.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/storage/yaml/yaml_bits.cpp b/radio/src/storage/yaml/yaml_bits.cpp index fc77bb98d..17c87bcf8 100644 --- a/radio/src/storage/yaml/yaml_bits.cpp +++ b/radio/src/storage/yaml/yaml_bits.cpp @@ -32,7 +32,7 @@ void yaml_put_bits(uint8_t* dst, uint32_t i, uint32_t bit_ofs, uint32_t bits) if (bit_ofs) { - *dst &= MASK_LOWER(bit_ofs); + *dst &= ~((MASK_LOWER(bits) << bit_ofs) & 0xFF); *(dst++) |= (i << bit_ofs) & 0xFF; if (bits <= 8 - bit_ofs) From a9e1e7d18ede3b32b37aad9c3085502d9ebc3ea2 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 14:25:00 +0100 Subject: [PATCH 130/180] Filter out empty topbar data --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 723f9c2e4..fda413f16 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -845,7 +845,11 @@ Node convert::encode(const ModelData& rhs) node["screenData"][std::to_string(i)] = csd; } } - node["topbarData"] = rhs.topBarData; + Node topbarData; + topbarData = rhs.topBarData; + if (topbarData && topbarData.IsMap()) { + node["topbarData"] = topbarData; + } node["view"] = rhs.view; } From 282ba2bd5a65e3c4eef26bd3d6d494c8134d5e72 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 16:33:47 +0100 Subject: [PATCH 131/180] Fixed switch warnings --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 119 +++++++++--------- 1 file changed, 57 insertions(+), 62 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index fda413f16..6a6bf0490 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -158,7 +158,12 @@ struct YamlPotsWarnEnabled { // modeldata: uint64_t switchWarningStates // Yaml switchWarningState: AuBuEuFuG-IuJu struct YamlSwitchWarningState { + + static constexpr size_t MASK_LEN = 2; + static constexpr size_t MASK = (1 << MASK_LEN) - 1; + std::string src_str; + uint64_t enabled; YamlSwitchWarningState() = default; @@ -166,84 +171,73 @@ struct YamlSwitchWarningState { { uint64_t states = cpn_value; + std::stringstream ss; for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) { + //TODO: exclude 2-pos toggle from switch warnings if (!(switchWarningEnable & (1 << i))) { std::string tag = getCurrentFirmware()->getSwitchesTag(i); const char *sw = tag.data(); if (tag.size() >= 2 && sw[0] == 'S') { - char val[3]; - val[0] = sw[1]; - - uint64_t value = (i == 0 ? states & 0x3 : states & 0x1); - - if (value == 0) - val[1] = 'u'; - else if (value == 1) - val[1] = '-'; - else - val[1] = 'd'; - val[2] = '\0'; - - src_str.append(val); + ss << sw[1]; + switch(states & MASK) { + case 0: + ss << 'u'; + break; + case 1: + ss << '-'; + break; + case 2: + ss << 'd'; + break; + } } } - - states >>= (i == 0 ? 2 : 1); + states >>= MASK_LEN; } + + ss >> src_str; } uint64_t toCpn() { uint64_t states = 0; + enabled = 0; - for (unsigned int i = 0; i < src_str.size() / 2; i++) { - auto val = src_str.substr(i * 2, 2); - if (val[0] >= 'A' && val[0] <= 'Z' && ( - val[1] == 'u' || val[1] == '-' || val[1] == 'd')) { - - int shift = 0; - uint64_t mask; - - char sw[3]; - sw[0] = 'S'; - sw[1] = val[0]; - sw[2] = '\0'; - - int index = getCurrentFirmware()->getSwitchesIndex(sw); - - if (index > -1) { - - if (IS_HORUS_OR_TARANIS(getCurrentFirmware()->getBoard())) { - shift = index * 2; - mask = 0x03ull << shift; - } - else { - if (index == 0) { - mask = 0x03; - } - else { - shift = index + 1; - mask = 0x01ull << shift; - } - } - - states &= ~mask; - - uint64_t value; - - if (val[1] == 'u') - value = 0; - else if (val[1] == '-') - value = 1; - else - value = 2; - - if (value) { - states |= ((uint64_t)value << shift); - } - } + std::stringstream ss(src_str); + while (!ss.eof()) { + auto c = ss.get(); + if (c < 'A' && c > 'Z') { + ss.ignore(); + continue; } + + std::string sw = std::string("S") + (char)c; + int index = getCurrentFirmware()->getSwitchesIndex(sw.c_str()); + if (index < 0) { + ss.ignore(); + continue; + } + + auto s = ss.get(); + + int value = 0; + switch(s) { + case 'u': + value = 0; + break; + case '-': + value = 1; + break; + case 'd': + value = 2; + break; + default: + continue; + } + + states |= ((uint64_t)value << (index * MASK_LEN)); + enabled |= (1 << index); } return states; @@ -933,6 +927,7 @@ bool convert::decode(const Node& node, ModelData& rhs) YamlSwitchWarningState switchWarningState; node["switchWarningState"] >> switchWarningState.src_str; rhs.switchWarningStates = switchWarningState.toCpn(); + rhs.switchWarningEnable = ~switchWarningState.enabled; node["thrTrimSw"] >> rhs.thrTrimSwitch; node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode; From 0c88f4e52b077956f3ad9d88038122619e03cb57 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 25 Dec 2021 19:09:24 +0100 Subject: [PATCH 132/180] Small fixes --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 19 +++++++++++-------- .../src/firmwares/edgetx/yaml_moduledata.cpp | 14 +++++++++----- companion/src/firmwares/edgetx/yaml_ops.h | 7 ++++++- companion/src/modeledit/setup.cpp | 1 + 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 6a6bf0490..d4623f0b4 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -163,18 +163,19 @@ struct YamlSwitchWarningState { static constexpr size_t MASK = (1 << MASK_LEN) - 1; std::string src_str; - uint64_t enabled; + unsigned int enabled; YamlSwitchWarningState() = default; YamlSwitchWarningState(uint64_t cpn_value, unsigned int switchWarningEnable) + : enabled(~switchWarningEnable) { uint64_t states = cpn_value; std::stringstream ss; for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) { //TODO: exclude 2-pos toggle from switch warnings - if (!(switchWarningEnable & (1 << i))) { + if (enabled & (1 << i)) { std::string tag = getCurrentFirmware()->getSwitchesTag(i); const char *sw = tag.data(); @@ -870,17 +871,15 @@ bool convert::decode(const Node& node, ModelData& rhs) { if (!node.IsMap()) return false; + unsigned int modelIds[CPN_MAX_MODULES]; + memset(modelIds, 0, sizeof(modelIds)); + if (node["header"]) { const auto& header = node["header"]; if (header.IsMap()) { header["name"] >> rhs.name; header["bitmap"] >> rhs.bitmap; - - unsigned int modelIds[CPN_MAX_MODULES]; header["modelId"] >> modelIds; - for (int i=0; i::decode(const Node& node, ModelData& rhs) } node["rssiAlarms"] >> rhs.rssiAlarms; - node["trainerMode"] >> trainerModeLut >> rhs.trainerMode; + node["moduleData"] >> rhs.moduleData; + for (int i=0; i> rhs.scriptData; node["telemetrySensors"] >> rhs.sensorData; diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.cpp b/companion/src/firmwares/edgetx/yaml_moduledata.cpp index 55d41058f..2089ee683 100644 --- a/companion/src/firmwares/edgetx/yaml_moduledata.cpp +++ b/companion/src/firmwares/edgetx/yaml_moduledata.cpp @@ -188,6 +188,9 @@ void convertEtxProtocolToMulti(int *protocol, int *subprotocol) } } +static int exportPpmDelay(int delay) { return (delay - 300) / 50; } +static int importPpmDelay(int delay) { return 300 + 50 * delay; } + namespace YAML { Node convert::encode(const ModuleData& rhs) @@ -284,9 +287,9 @@ Node convert::encode(const ModuleData& rhs) // TODO: afhds3, flysky default: { Node ppm; - ppm["delay"] = rhs.ppm.delay; - ppm["pulsePol"] = rhs.ppm.pulsePol; - ppm["outputType"] = rhs.ppm.outputType; + ppm["delay"] = exportPpmDelay(rhs.ppm.delay); + ppm["pulsePol"] = (int)rhs.ppm.pulsePol; + ppm["outputType"] = (int)rhs.ppm.outputType; ppm["frameLength"] = rhs.ppm.frameLength; mod["ppm"] = ppm; } break; @@ -347,10 +350,11 @@ bool convert::decode(const Node& node, ModuleData& rhs) node["failsafeMode"] >> failsafeLut >> rhs.failsafeMode; if (node["mod"]) { - Node mod = node["mod"]; + const Node& mod = node["mod"]; if (mod["ppm"]) { - Node ppm = mod["ppm"]; + const Node& ppm = mod["ppm"]; ppm["delay"] >> rhs.ppm.delay; + rhs.ppm.delay = importPpmDelay(rhs.ppm.delay); ppm["pulsePol"] >> rhs.ppm.pulsePol; ppm["outputType"] >> rhs.ppm.outputType; ppm["frameLength"] >> rhs.ppm.frameLength; diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index f6ca8c6fc..52a40ab65 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -102,7 +102,12 @@ void operator>>(const YAML::Node& node, T (&value)[N]) int idx = std::stoi(elmt.first.Scalar()); if (idx < 0 || idx >= (int)N) return; - elmt.second >> value[idx]; + if (elmt.second.IsMap() && (elmt.second.size() == 1) && + elmt.second["val"]) { + elmt.second["val"] >> value[idx]; + } else { + elmt.second >> value[idx]; + } } catch (...) { return; } diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 1c9248814..c611aa1f5 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -1321,6 +1321,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge Board::SwitchInfo switchInfo = Boards::getSwitchInfo(board, i); switchInfo.config = Board::SwitchType(generalSettings.switchConfig[i]); if (switchInfo.config == Board::SWITCH_NOT_AVAILABLE || switchInfo.config == Board::SWITCH_TOGGLE) { + model.switchWarningEnable |= (1 << i); continue; } RawSource src(RawSourceType::SOURCE_TYPE_SWITCH, i); From 03a6e9edc8227295bca0f609d29f67df612d03dd Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 26 Dec 2021 16:40:32 +1100 Subject: [PATCH 133/180] Bump Companion settings version to force upgrade of profiles --- companion/src/storage/appdata.cpp | 2 +- companion/src/storage/appdata.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index cd5c129e4..f529c780c 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -427,7 +427,7 @@ void AppData::convertSettings(QSettings & settings) << fmtHex(CPN_SETTINGS_VERSION) << " (" << fmtHex(currMajMin) << "). Removing unused: " << removeUnused; // firmwares renamed from opentx-* to edgetx-* at 2.6 - if (savedMajMin < 0x206) { + if (savedMajMin <= 0x207) { // Note: change merged post 2.6 rc 1 and version bumped to 2.7 the Nightly users also require upgrade qInfo().noquote() << "Converting profiles"; static const QString profileFwTypePath = QStringLiteral("Profiles/profile%1/fwType"); for (int i = 0; i < MAX_PROFILES; i++) { diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 3afa1dc77..9741aa96d 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -40,7 +40,7 @@ //! CPN_SETTINGS_REVISION is used to track settings changes independently of EdgeTX version. It should be reset to zero whenever settings are migrated to new COMPANY or PRODUCT. //! \note !! Increment this value if properties are removed or refactored. It will trigger a conversion/cleanup of any stored settings. \sa AppData::convertSettings() -#define CPN_SETTINGS_REVISION 0 +#define CPN_SETTINGS_REVISION 1 // Note: bumped to ensure 2.7 Nightly version users also get upgraded //! CPN_SETTINGS_VERSION is used for settings data version tracking. #define CPN_SETTINGS_VERSION ((VERSION_NUMBER << 8) | CPN_SETTINGS_REVISION) From 38e6748e142773db7e0c0ec270ea9622584734c0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 10:03:40 +0100 Subject: [PATCH 134/180] Rename test files to .otx as they still use binary format --- radio/src/tests/CMakeLists.txt | 2 +- .../tests/{model_23_x10.etx => model_23_x10.otx} | Bin .../tests/{model_23_x12s.etx => model_23_x12s.otx} | Bin .../{model_25_tx16s.etx => model_25_tx16s.otx} | Bin 4 files changed, 1 insertion(+), 1 deletion(-) rename radio/src/tests/{model_23_x10.etx => model_23_x10.otx} (100%) rename radio/src/tests/{model_23_x12s.etx => model_23_x12s.otx} (100%) rename radio/src/tests/{model_25_tx16s.etx => model_25_tx16s.otx} (100%) diff --git a/radio/src/tests/CMakeLists.txt b/radio/src/tests/CMakeLists.txt index 7d07d6ff1..b56549908 100644 --- a/radio/src/tests/CMakeLists.txt +++ b/radio/src/tests/CMakeLists.txt @@ -19,7 +19,7 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND) foreach(model_file ${EXTRACT_MODEL_FILES}) add_custom_command( - DEPENDS ${TESTS_PATH}/${model_file}.etx + DEPENDS ${TESTS_PATH}/${model_file}.otx OUTPUT ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.etx >/dev/null WORKING_DIRECTORY ${TESTS_BUILD_PATH} diff --git a/radio/src/tests/model_23_x10.etx b/radio/src/tests/model_23_x10.otx similarity index 100% rename from radio/src/tests/model_23_x10.etx rename to radio/src/tests/model_23_x10.otx diff --git a/radio/src/tests/model_23_x12s.etx b/radio/src/tests/model_23_x12s.otx similarity index 100% rename from radio/src/tests/model_23_x12s.etx rename to radio/src/tests/model_23_x12s.otx diff --git a/radio/src/tests/model_25_tx16s.etx b/radio/src/tests/model_25_tx16s.otx similarity index 100% rename from radio/src/tests/model_25_tx16s.etx rename to radio/src/tests/model_25_tx16s.otx From bf41080b57c70d9462079047837d2f2ab6b09b49 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 12:04:01 +0100 Subject: [PATCH 135/180] Fix YAML radio format: outputs GVAR support and small fixes --- radio/src/dataconstants.h | 5 ++--- radio/src/datastructs_private.h | 6 +++--- .../conversions/yaml/yaml_datastructs_nv14.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_t12.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_t8.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_tlite.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_tx12.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x10.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x12s.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x7.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x9d.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x9e.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x9lite.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_x9lites.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_xlite.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_xlites.cpp | 6 +++--- .../conversions/yaml/yaml_datastructs_zorro.cpp | 11 ++++++----- radio/src/storage/yaml/yaml_datastructs_nv14.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_t12.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_t8.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_tlite.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_tpro.cpp | 13 +++++++------ radio/src/storage/yaml/yaml_datastructs_tx12.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x10.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x12s.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x7.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x9d.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x9e.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x9lite.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_x9lites.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_xlite.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_xlites.cpp | 6 +++--- radio/src/storage/yaml/yaml_datastructs_zorro.cpp | 13 +++++++------ 33 files changed, 109 insertions(+), 107 deletions(-) diff --git a/radio/src/dataconstants.h b/radio/src/dataconstants.h index 356fc20f8..e24a035c6 100644 --- a/radio/src/dataconstants.h +++ b/radio/src/dataconstants.h @@ -240,10 +240,9 @@ enum TrainerMode { #endif enum UartModes { -#if defined(CLI) || defined(DEBUG) - UART_MODE_DEBUG, -#else UART_MODE_NONE, +#if defined(CLI) || defined(DEBUG) + UART_MODE_DEBUG SKIP = UART_MODE_NONE, #endif UART_MODE_TELEMETRY_MIRROR, UART_MODE_TELEMETRY, diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index 99775f4d7..27dbb47e8 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -111,10 +111,10 @@ PACK(struct ExpoData { */ PACK(struct LimitData { - int32_t min:11; - int32_t max:11; + int32_t min:11 CUST(in_read_weight,in_write_weight); + int32_t max:11 CUST(in_read_weight,in_write_weight); int32_t ppmCenter:10; // TODO can be reduced to 8 bits - int16_t offset:11; + int16_t offset:11 CUST(in_read_weight,in_write_weight); uint16_t symetrical:1; uint16_t revert:1; uint16_t spare:3 SKIP; diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index 254c4a604..4936c811a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -490,10 +490,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp index 9aec3504d..d065a249e 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp index 4d7211cb3..43b07da31 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp index 4d7211cb3..43b07da31 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp index 255ff3dec..09608077f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index c19cf30ab..0e95111d0 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -507,10 +507,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index e9080a1eb..1e0fd3c3c 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -507,10 +507,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp index 4d7211cb3..43b07da31 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp index 65038c815..5445b5043 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp @@ -463,10 +463,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp index be3b6c6cb..ae5bf6bda 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp @@ -502,10 +502,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp index 63cf15877..a8ea493b9 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp @@ -440,10 +440,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp index 7acca6e5c..1cda4c30a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp @@ -450,10 +450,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp index e0f1a8c2f..6ced4bee2 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp @@ -447,10 +447,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp index 5a8978845..424cdee76 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp @@ -451,10 +451,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp index 37ab5895d..f3eedf17f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -441,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -454,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), @@ -476,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index d3ad55534..1f82453b4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -489,10 +489,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index 70afcd933..ac75e20f6 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index 726868e50..0724e41b4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index 726868e50..0724e41b4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index 6966b1ff8..7a2170a79 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -336,6 +336,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -372,7 +373,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), @@ -447,7 +448,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -460,10 +461,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), @@ -482,7 +483,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 4e3d7af25..4adc3b16f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index f0b84b3b7..71343a40c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -510,10 +510,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 06356a794..f5de5f1cf 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -508,10 +508,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index 726868e50..0724e41b4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -455,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index b50050d00..aab9477a0 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -463,10 +463,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 87cd0815f..fb382c0b9 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -502,10 +502,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 6d3d90d78..9609d2638 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -440,10 +440,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 97b3feed3..09070865c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -450,10 +450,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index 58bbb5417..24e913aed 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -447,10 +447,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 1b69f0491..c3a35cd86 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -451,10 +451,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp index b4d09d03a..fbd0b0c19 100644 --- a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp @@ -328,6 +328,7 @@ static const struct YamlNode struct_string_24[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "version", 8 ), + YAML_CUSTOM("board",nullptr,w_board), YAML_PADDING( 16 ), YAML_ARRAY("calib", 48, 6, struct_CalibData, NULL), YAML_PADDING( 16 ), @@ -364,7 +365,7 @@ static const struct YamlNode struct_RadioData[] = { YAML_SIGNED_CUST( "beepLength", 3, r_5pos, w_5pos ), YAML_SIGNED_CUST( "hapticStrength", 3, r_5pos, w_5pos ), YAML_UNSIGNED( "gpsFormat", 1 ), - YAML_UNSIGNED( "unexpectedShutdown", 1 ), + YAML_PADDING( 1 ), YAML_UNSIGNED_CUST( "speakerPitch", 8, r_spPitch, w_spPitch ), YAML_SIGNED_CUST( "speakerVolume", 8, r_vol, w_vol ), YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ), @@ -441,7 +442,7 @@ static const struct YamlNode struct_MixData[] = { YAML_UNSIGNED( "mixWarn", 2 ), YAML_ENUM("mltpx", 2, enum_MixerMultiplex), YAML_PADDING( 1 ), - YAML_SIGNED( "offset", 14 ), + YAML_SIGNED_CUST( "offset", 14, in_read_weight, in_write_weight ), YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ), YAML_UNSIGNED_CUST( "flightModes", 9, r_flightModes, w_flightModes ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), @@ -454,10 +455,10 @@ static const struct YamlNode struct_MixData[] = { }; static const struct YamlNode struct_LimitData[] = { YAML_IDX, - YAML_SIGNED( "min", 11 ), - YAML_SIGNED( "max", 11 ), + YAML_SIGNED_CUST( "min", 11, in_read_weight, in_write_weight ), + YAML_SIGNED_CUST( "max", 11, in_read_weight, in_write_weight ), YAML_SIGNED( "ppmCenter", 10 ), - YAML_SIGNED( "offset", 11 ), + YAML_SIGNED_CUST( "offset", 11, in_read_weight, in_write_weight ), YAML_UNSIGNED( "symetrical", 1 ), YAML_UNSIGNED( "revert", 1 ), YAML_PADDING( 3 ), @@ -476,7 +477,7 @@ static const struct YamlNode struct_ExpoData[] = { YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ), YAML_PADDING( 1 ), YAML_STRING("name", 6), - YAML_SIGNED( "offset", 8 ), + YAML_SIGNED_CUST( "offset", 8, in_read_weight, in_write_weight ), YAML_STRUCT("curve", 16, struct_CurveRef, NULL), YAML_END }; From c8cd009ea28425bdec5281a98450f9b4323f105a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 12:04:53 +0100 Subject: [PATCH 136/180] Fix output encoding/decoding --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index d4623f0b4..5965bda03 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -281,10 +281,10 @@ struct convert { static Node encode(const LimitData& rhs) { Node node; - node["min"] = rhs.min; - node["max"] = rhs.max; + node["min"] = YamlWriteMixWeight(rhs.min); + node["max"] = YamlWriteMixWeight(rhs.max); node["revert"] = (int)rhs.revert; - node["offset"] = rhs.offset; + node["offset"] = YamlWriteMixWeight(rhs.offset); node["ppmCenter"] = rhs.ppmCenter; node["symetrical"] = (int)rhs.symetrical; node["failsafe"] = rhs.failsafe; @@ -295,10 +295,16 @@ struct convert { static bool decode(const Node& node, LimitData& rhs) { - node["min"] >> rhs.min; - node["max"] >> rhs.max; + if (node["min"]) { + rhs.min = YamlReadMixWeight(node["min"]); + } + if (node["max"]) { + rhs.max = YamlReadMixWeight(node["max"]); + } + if (node["offset"]) { + rhs.offset = YamlReadMixWeight(node["offset"]); + } node["revert"] >> rhs.revert; - node["offset"] >> rhs.offset; node["ppmCenter"] >> rhs.ppmCenter; node["symetrical"] >> rhs.symetrical; node["failsafe"] >> rhs.failsafe; @@ -698,7 +704,7 @@ Node convert::encode(const ModelData& rhs) for (int i = 0; i < CPN_MAX_CHNOUT; i++) { const LimitData& limit = rhs.limitData[i]; if (!limit.isEmpty()) { - node["limitData"].push_back(Node(limit)); + node["limitData"][std::to_string(i)] = limit; } } From 7a66c3413afadc68b8f3eff264e740d5fd2aefb5 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 14:53:49 +0100 Subject: [PATCH 137/180] Fixed YAML GVAR based values --- .../conversions/yaml/yaml_datastructs_funcs.cpp | 10 +++++----- radio/src/storage/yaml/yaml_datastructs_funcs.cpp | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index 5a8951c25..d4c0ccf60 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -23,7 +23,6 @@ #include "datastructs_220.h" #include "myeeprom_220.h" -#define GVAR_SMALL 128 #define VOLUME_LEVEL_DEF 12 bool w_board(void* user, uint8_t* data, uint32_t bitoffs, @@ -38,12 +37,13 @@ bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque) { int32_t sval = yaml_to_signed(val, node->size); + int32_t gvar = (node->size > 8 ? GV1_LARGE : GV1_SMALL); - if (sval > GVAR_SMALL - 11 && sval < GVAR_SMALL - 1) { - char n = GVAR_SMALL - sval + '0'; + if (sval >= gvar - 10 && sval <= gvar) { + char n = gvar - sval + '0'; return wf(opaque, "-GV", 3) && wf(opaque, &n, 1); - } else if (sval < -GVAR_SMALL + 11 && sval > -GVAR_SMALL + 1) { - char n = val - GVAR_SMALL + '1'; + } else if (sval <= -gvar + 10 && sval >= -gvar) { + char n = val - gvar + '1'; return wf(opaque, "GV", 2) && wf(opaque, &n, 1); } diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 5d4922497..567745ec7 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -143,10 +143,10 @@ static bool w_board(void* user, uint8_t* data, uint32_t bitoffs, return yaml_conv_220::w_board(user, data, bitoffs, wf, opaque); } -#define GVAR_SMALL 128 - static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t val_len) { + int gvar = (node->size > 8 ? GV1_LARGE : GV1_SMALL); + if ((val_len == 4) && (val[0] == '-') && (val[1] == 'G') @@ -154,8 +154,8 @@ static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t va && (val[3] >= '1') && (val[3] <= '9')) { - TRACE("%.*s -> %i\n", val_len, val, GVAR_SMALL - (val[3] - '0')); - return GVAR_SMALL - (val[3] - '0'); // -GVx => 128 - x + TRACE("%.*s -> %i\n", val_len, val, gvar - (val[3] - '0')); + return gvar - (val[3] - '0'); // -GVx => 128 - x } if ((val_len == 3) @@ -164,8 +164,8 @@ static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t va && (val[2] >= '1') && (val[2] <= '9')) { - TRACE("%.*s -> %i\n", val_len, val, -GVAR_SMALL + (val[2] - '1')); - return -GVAR_SMALL + (val[2] - '1'); // GVx => -128 + (x-1) + TRACE("%.*s -> %i\n", val_len, val, -gvar + (val[2] - '1')); + return -gvar + (val[2] - '1'); // GVx => -128 + (x-1) } return (uint32_t)yaml_str2int(val, val_len); From 9f9c3aba01e9ae62798b04329b8c6eb585178836 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 14:54:59 +0100 Subject: [PATCH 138/180] Add curve ref gvar support --- radio/src/datastructs_private.h | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp | 2 +- radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_nv14.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_t12.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_t8.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_tlite.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_tpro.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_tx12.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x10.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x12s.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x7.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x9d.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x9e.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x9lite.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_x9lites.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_xlite.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_xlites.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_zorro.cpp | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index 27dbb47e8..f2cd1fc32 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -65,7 +65,7 @@ PACK(struct CurveRef { uint8_t type; - int8_t value; + int8_t value CUST(in_read_weight,in_write_weight); }); PACK(struct MixData { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index 4936c811a..1b12702e3 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -466,7 +466,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp index d065a249e..5d02e2cd7 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t12.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp index 43b07da31..3b7452e96 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_t8.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp index 43b07da31..3b7452e96 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tlite.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp index 09608077f..366acd3da 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_tx12.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index 0e95111d0..db2bd42cb 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -483,7 +483,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index 1e0fd3c3c..41e00722f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -483,7 +483,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp index 43b07da31..3b7452e96 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x7.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp index 5445b5043..5241e7d00 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9d.cpp @@ -439,7 +439,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp index ae5bf6bda..aeaed279f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9e.cpp @@ -478,7 +478,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp index a8ea493b9..d65fb41ac 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lite.cpp @@ -416,7 +416,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp index 1cda4c30a..903bf0b7f 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x9lites.cpp @@ -426,7 +426,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp index 6ced4bee2..f42f55783 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlite.cpp @@ -423,7 +423,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp index 424cdee76..fc0febc7d 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_xlites.cpp @@ -427,7 +427,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp index f3eedf17f..4a655962a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_zorro.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 1f82453b4..48572ca88 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -465,7 +465,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index ac75e20f6..a0da3fdaf 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index 0724e41b4..70ae1f57e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index 0724e41b4..70ae1f57e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index 7a2170a79..30485f8c3 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -437,7 +437,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 4adc3b16f..731f46515 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 71343a40c..2db86eb85 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -486,7 +486,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index f5de5f1cf..40b01a388 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -484,7 +484,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index 0724e41b4..70ae1f57e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index aab9477a0..baa86f46d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -439,7 +439,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index fb382c0b9..927510ceb 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -478,7 +478,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 9609d2638..ad3a9be0e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -416,7 +416,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 09070865c..24fac20a7 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -426,7 +426,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index 24e913aed..3478f6852 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -423,7 +423,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index c3a35cd86..a9a7479bb 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -427,7 +427,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp index fbd0b0c19..476bb6093 100644 --- a/radio/src/storage/yaml/yaml_datastructs_zorro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_zorro.cpp @@ -431,7 +431,7 @@ static const struct YamlNode struct_TimerData[] = { }; static const struct YamlNode struct_CurveRef[] = { YAML_UNSIGNED( "type", 8 ), - YAML_SIGNED( "value", 8 ), + YAML_SIGNED_CUST( "value", 8, in_read_weight, in_write_weight ), YAML_END }; static const struct YamlNode struct_MixData[] = { From ef86a76dd65764152fb778560daf3d8cad8f73e9 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 15:20:18 +0100 Subject: [PATCH 139/180] Fixed GVAR curve ref --- companion/src/firmwares/edgetx/yaml_mixdata.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index 979539228..dc34a9fa6 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -125,7 +125,7 @@ Node convert::encode(const CurveReference& rhs) { Node node; node["type"] = (int)rhs.type; - node["value"] = rhs.value; + node["value"] = YamlWriteMixWeight(rhs.value); return node; } @@ -135,8 +135,9 @@ bool convert::decode(const Node& node, CurveReference& rhs) int type = 0; node["type"] >> type; rhs.type = (CurveReference::CurveRefType)type; - - node["value"] >> rhs.value; + if (node["value"]) { + rhs.value = YamlReadMixWeight(node["value"]); + } return true; } From c95bb666023d8d1b7561f096fce186f25be5aee8 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 26 Dec 2021 16:00:53 +0100 Subject: [PATCH 140/180] Fixed test file unzipping --- radio/src/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/tests/CMakeLists.txt b/radio/src/tests/CMakeLists.txt index b56549908..4417696c3 100644 --- a/radio/src/tests/CMakeLists.txt +++ b/radio/src/tests/CMakeLists.txt @@ -21,7 +21,7 @@ if(GTEST_INCDIR AND GTEST_SRCDIR AND Qt5Widgets_FOUND) add_custom_command( DEPENDS ${TESTS_PATH}/${model_file}.otx OUTPUT ${TESTS_BUILD_PATH}/${model_file}/RADIO/radio.bin - COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.etx >/dev/null + COMMAND mkdir -p ${model_file} && cd ${model_file} && unzip -o -q -DD ${TESTS_PATH}/${model_file}.otx >/dev/null WORKING_DIRECTORY ${TESTS_BUILD_PATH} ) add_custom_target(${model_file}_files From 64287e5654b21663f0396ce36f59909eb87f7a4a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 27 Dec 2021 00:00:14 +0100 Subject: [PATCH 141/180] Fixed flight modes' and logical switches' indexes --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 4ae567841..686736e6e 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -40,7 +40,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) case SWITCH_TYPE_VIRTUAL: sw_str += "L"; - sw_str += std::to_string(sval + 1); + sw_str += std::to_string(sval); break; case SWITCH_TYPE_MULTIPOS_POT: @@ -55,7 +55,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) case SWITCH_TYPE_FLIGHT_MODE: sw_str += "FM"; - sw_str += std::to_string(sval); + sw_str += std::to_string(sval - 1); break; case SWITCH_TYPE_SENSOR: @@ -97,7 +97,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str_tmp.substr(1, val_len - 1)) - 1); + std::stoi(sw_str_tmp.substr(1, val_len - 1))); } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && @@ -110,7 +110,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len == 3 && val[0] == 'F' && val[1] == 'M' && (val[2] >= '0' && val[2] <= '9')) { - rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0'); + rhs = RawSwitch(SWITCH_TYPE_FLIGHT_MODE, val[2] - '0' + 1); } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { From af00d03640428c009e26af029ddcddeb6464852f Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 27 Dec 2021 09:07:02 +0100 Subject: [PATCH 142/180] Fixed special switches and play value, volume & backlight custom functions --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 12 ++++++++++++ companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index d115457c3..010095551 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -171,6 +171,11 @@ Node convert::encode(const CustomFunctionData& rhs) def += ","; def += std::to_string(rhs.param); } break; + case FuncPlayValue: + case FuncVolume: + case FuncBacklight: { + def += YamlRawSourceEncode(RawSource(rhs.param)); + } break; case FuncAdjustGV1: { // + GV # def += std::to_string(p1); @@ -280,6 +285,13 @@ bool convert::decode(const Node& node, rhs.func = (AssignFunc)((int)rhs.func + tmr); def >> rhs.param; } break; + case FuncPlayValue: + case FuncVolume: + case FuncBacklight: { + std::string src_str; + getline(def, src_str, ','); + rhs.param = YamlRawSourceDecode(src_str).toValue(); + } break; case FuncAdjustGV1: { // + GV # int gvar_idx=0; diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 686736e6e..0d1ee3c89 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -68,7 +68,7 @@ std::string YamlRawSwitchEncode(const RawSwitch& rhs) break; default: - sw_str += getCurrentFirmware()->getRawSwitchTypesTag(sval); + sw_str += getCurrentFirmware()->getRawSwitchTypesTag(rhs.type); break; } return sw_str; From 36aaa8d555a7336d2f925caa7355b881f4389b6c Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 09:00:57 +0100 Subject: [PATCH 143/180] Fix GVAR output --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 5965bda03..b834d0ebe 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -371,7 +371,7 @@ Node EncodeFMData(const FlightModeData& rhs, int phaseIdx) Node gvars; for (size_t i=0; i Date: Tue, 28 Dec 2021 09:23:48 +0100 Subject: [PATCH 144/180] Fixed output min/max --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b834d0ebe..f2d7d07bb 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -276,15 +276,53 @@ bool convert::decode(const Node& node, TimerData& rhs) return true; } +static int32_t YamlReadLimitValue(const YAML::Node& node, int32_t shift = 0) +{ + std::string val = node.as(); + if ((val.size() >= 4) + && (val[0] == '-') + && (val[1] == 'G') + && (val[2] == 'V') + && (val[3] >= '1') + && (val[3] <= '9')) { + + return -10000 - std::stoi(val.substr(3)); + } + + if ((val.size() >= 3) + && (val[0] == 'G') + && (val[1] == 'V') + && (val[2] >= '1') + && (val[2] <= '9')) { + + return 10000 + std::stoi(val.substr(2)); + } + + return std::stoi(val) + shift; +} + +static std::string YamlWriteLimitValue(int32_t sval, int32_t shift = 0) +{ + if (sval < -10000) { + int n = -sval - 10000; + return std::string("-GV") + std::to_string(n); + } else if (sval > 10000) { + int n = sval - 10000; + return std::string("GV") + std::to_string(n); + } + + return std::to_string(sval - shift); +} + template <> struct convert { static Node encode(const LimitData& rhs) { Node node; - node["min"] = YamlWriteMixWeight(rhs.min); - node["max"] = YamlWriteMixWeight(rhs.max); + node["min"] = YamlWriteLimitValue(rhs.min, -1000); + node["max"] = YamlWriteLimitValue(rhs.max, 1000); node["revert"] = (int)rhs.revert; - node["offset"] = YamlWriteMixWeight(rhs.offset); + node["offset"] = YamlWriteLimitValue(rhs.offset); node["ppmCenter"] = rhs.ppmCenter; node["symetrical"] = (int)rhs.symetrical; node["failsafe"] = rhs.failsafe; @@ -296,13 +334,13 @@ struct convert { static bool decode(const Node& node, LimitData& rhs) { if (node["min"]) { - rhs.min = YamlReadMixWeight(node["min"]); + rhs.min = YamlReadLimitValue(node["min"], -1000); } if (node["max"]) { - rhs.max = YamlReadMixWeight(node["max"]); + rhs.max = YamlReadLimitValue(node["max"], 1000); } if (node["offset"]) { - rhs.offset = YamlReadMixWeight(node["offset"]); + rhs.offset = YamlReadLimitValue(node["offset"]); } node["revert"] >> rhs.revert; node["ppmCenter"] >> rhs.ppmCenter; From 7b2d7158ffa247d0934f1359fea626f920689c7f Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 09:35:59 +0100 Subject: [PATCH 145/180] Fixed curve reference in outputs --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index f2d7d07bb..8c7b91423 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -327,7 +327,7 @@ struct convert { node["symetrical"] = (int)rhs.symetrical; node["failsafe"] = rhs.failsafe; node["name"] = rhs.name; - node["curve"] = rhs.curve; + node["curve"] = rhs.curve.value; return node; } @@ -347,7 +347,7 @@ struct convert { node["symetrical"] >> rhs.symetrical; node["failsafe"] >> rhs.failsafe; node["name"] >> rhs.name; - node["curve"] >> rhs.curve; + node["curve"] >> rhs.curve.value; return true; } }; From b4a64189b7fbf46f4acbd6b5c3fa6ab801abc5c3 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 09:51:59 +0100 Subject: [PATCH 146/180] Fixed custom functions "play sound" and trainer. --- .../firmwares/edgetx/yaml_customfunctiondata.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 010095551..8fcf1a113 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -153,7 +153,7 @@ Node convert::encode(const CustomFunctionData& rhs) def += LookupValue(trainerLut, p1); break; case FuncPlaySound: - def += std::to_string(rhs.param); + def += LookupValue(soundLut, rhs.param); break; case FuncPlayPrompt: case FuncPlayScript: @@ -252,13 +252,17 @@ bool convert::decode(const Node& node, def >> rhs.param; } break; case FuncTrainer: { + std::string value_str; + getline(def, value_str, ','); int value=0; - Node(def.str()) >> trainerLut >> value; + Node(value_str) >> trainerLut >> value; rhs.func = (AssignFunc)((int)rhs.func + value); } break; - case FuncPlaySound: - Node(def.str()) >> soundLut >> rhs.param; - break; + case FuncPlaySound: { + std::string snd; + getline(def, snd, ','); + Node(snd) >> soundLut >> rhs.param; + } break; case FuncPlayPrompt: case FuncPlayScript: case FuncBackgroundMusic: { From 0190b1e19da705eb2de5ee7540fec09575f638cc Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 12:16:45 +0100 Subject: [PATCH 147/180] Fixed reading flight mode data (gvars) --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 42 +++++++++++-------- .../src/firmwares/edgetx/yaml_modeldata.h | 5 +++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 8c7b91423..4cc939147 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -245,6 +245,14 @@ struct YamlSwitchWarningState { } }; +template <> +void operator >> (const YAML::Node& node, FlightModeData& value) +{ + if (node && !node.IsNull()) { + YAML::convert::decode(node, value); + } +} + namespace YAML { Node convert::encode(const TimerData& rhs) @@ -419,25 +427,23 @@ Node EncodeFMData(const FlightModeData& rhs, int phaseIdx) return node; } -template <> -struct convert { - static bool decode(const Node& node, FlightModeData& rhs) - { - YamlTrim trims[CPN_MAX_TRIMS]; - node["trim"] >> trims; - for (size_t i=0; i> rhs.swtch; - node["name"] >> rhs.name; - node["fadeIn"] >> rhs.fadeIn; - node["fadeOut"] >> rhs.fadeOut; - node["gvars"] >> rhs.gvars; - return true; +bool convert::decode(const Node& node, + FlightModeData& rhs) +{ + YamlTrim trims[CPN_MAX_TRIMS]; + node["trim"] >> trims; + for (size_t i = 0; i < CPN_MAX_TRIMS; i++) { + rhs.trimMode[i] = trims[i].mode; + rhs.trimRef[i] = trims[i].ref; + rhs.trim[i] = trims[i].value; } -}; + node["swtch"] >> rhs.swtch; + node["name"] >> rhs.name; + node["fadeIn"] >> rhs.fadeIn; + node["fadeOut"] >> rhs.fadeOut; + node["gvars"] >> rhs.gvars; + return true; +} template <> struct convert { diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.h b/companion/src/firmwares/edgetx/yaml_modeldata.h index 25b05a471..c3355c113 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.h +++ b/companion/src/firmwares/edgetx/yaml_modeldata.h @@ -29,6 +29,11 @@ struct convert { static bool decode(const Node& node, TimerData& rhs); }; +template <> +struct convert { + static bool decode(const Node& node, FlightModeData& rhs); +}; + template <> struct convert { static Node encode(const ModelData& rhs); From a90d89ece69a90a08962fd856b0c691b386c82ce Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 14:01:31 +0100 Subject: [PATCH 148/180] Remove escaping in negated switches (yaml-cpp does not seem to do it) --- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index 0d1ee3c89..bea8f11c4 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -81,12 +81,18 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) size_t val_len = sw_str.size(); std::string sw_str_tmp = sw_str; + // yaml-cpp does not escape this + if (val_len > 0 && val[0] == '\\') { + val++; val_len--; + sw_str_tmp = sw_str_tmp.substr(1); + } + bool neg = false; if (val_len > 0 && val[0] == '!') { neg = true; val++; val_len--; - sw_str_tmp = sw_str.substr(1); + sw_str_tmp = sw_str_tmp.substr(1); } int multiposcnt = Boards::getCapability(getCurrentBoard(), Board::MultiposPotsPositions); From c9ba1a632bbcf1b77d1a0c0c55aa33cfbf4044bf Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 28 Dec 2021 14:48:55 +0100 Subject: [PATCH 149/180] Fixed custom function repeat param (!1x) --- companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 8fcf1a113..4975a207b 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -216,7 +216,7 @@ Node convert::encode(const CustomFunctionData& rhs) } if (rhs.repeatParam == 0) { def += "1x"; - } else if (rhs.repeatParam == 0xFF) { + } else if (rhs.repeatParam == -1) { def += "!1x"; } else { def += std::to_string(rhs.repeatParam); @@ -350,7 +350,7 @@ bool convert::decode(const Node& node, if (repeat == "1x") { rhs.repeatParam = 0; } else if (repeat == "!1x") { - rhs.repeatParam = 0xFF; + rhs.repeatParam = -1; } else { rhs.repeatParam = std::stoi(repeat); } From f965707bdd5c60901e1ff20855d72797708ed91f Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 29 Dec 2021 12:45:30 +0100 Subject: [PATCH 150/180] Fixed write format detection --- companion/src/storage/categorized.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index e6aef817a..63f98ffa7 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -42,7 +42,8 @@ bool CategorizedStorageFormat::write(const RadioData & radioData) if (st == STORAGE_TYPE_UNKNOWN) { st = probeFormat(); } - if (st == STORAGE_TYPE_ETX || st == STORAGE_TYPE_UNKNOWN) { + if (st == STORAGE_TYPE_ETX || st == STORAGE_TYPE_YML || + st == STORAGE_TYPE_UNKNOWN) { return writeYaml(radioData); } else { return writeBin(radioData); From e64f57768aa927d40e3d20b30c15024fa1b1b57c Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 30 Dec 2021 07:43:41 +1100 Subject: [PATCH 151/180] Add board flavour --- .../firmwares/edgetx/yaml_generalsettings.cpp | 51 +++++--- companion/src/firmwares/eeprominterface.cpp | 6 + companion/src/firmwares/eeprominterface.h | 9 ++ .../src/firmwares/opentx/opentxinterface.cpp | 111 +++++++++--------- companion/src/mdichild.cpp | 1 + companion/src/storage/categorized.cpp | 3 +- 6 files changed, 111 insertions(+), 70 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index d824414f9..e51cc5b2f 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -27,6 +27,8 @@ #include "eeprominterface.h" #include "edgetxinterface.h" +#include + const YamlLookupTable beeperModeLut = { { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, { GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" }, @@ -81,9 +83,11 @@ Node convert::encode(const GeneralSettings& rhs) { Node node; + std::string board = getCurrentFirmware()->getFlavour().toStdString(); + node["board"] = board; + node["version"] = CPN_CURRENT_SETTINGS_VERSION; - // Radio calib YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); node["calib"] = calib; @@ -198,21 +202,40 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // qDebug() << QString::fromStdString(n.first.Scalar()); // } - // TODO: check board string and fetch Board instance - std::string board; - node["board"] >> board; - // TODO: we should be able to fetch the board based on 'board' - // auto fw = getCurrentFirmware(); - // if (fw) { - // qDebug() << "FW Id: " << fw->getId(); - // if (fw->getId() != ("edgetx-" + radioData.generalSettings.board)) { - // throw std::runtime_error("Wrong board"); - // } - // } - node["version"] >> rhs.version; - // Radio calib + // Decoding uses profile firmare therefore all conversions are performed on the fly + // So set board to firmware board + // However we should alert users that conversions may have occured + // 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 + + rhs.variant = Board::BOARD_UNKNOWN; + + std::string flavour; + node["board"] >> flavour; + + auto fw = getCurrentFirmware(); + auto msfw = Firmware::getFirmwareForFlavour(QString(flavour.c_str())); + + if (flavour.empty()) { + qDebug() << "Warning: Settings file does not contain board flavour! Default firmware board will be used"; + flavour = msfw->getFlavour().toStdString(); + } + + qDebug() << "Settings version:" << rhs.version << "File flavour:" << flavour.c_str() << "Firmware flavour:" << fw->getFlavour(); + + if (fw->getFlavour().toStdString() != flavour) { + QString prmpt = QCoreApplication::translate("YamlGeneralSettings", "File board (%1) does not match current profile board (%2), models and settings will be converted where possible.\n\nDo you wish to continue?").arg(Boards::getBoardName(msfw->getBoard())).arg(Boards::getBoardName(fw->getBoard())); + + if (QMessageBox::question(NULL, CPN_STR_APP_NAME, prmpt, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) { + // TODO: this triggers an error in the calling code so we need a graceful way to handle + return false; + } + } + + rhs.variant = fw->getBoard(); + YamlCalibData calib; node["calib"] >> calib; calib.copy(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos); diff --git a/companion/src/firmwares/eeprominterface.cpp b/companion/src/firmwares/eeprominterface.cpp index 90272d0ad..7cefd6d7e 100644 --- a/companion/src/firmwares/eeprominterface.cpp +++ b/companion/src/firmwares/eeprominterface.cpp @@ -178,3 +178,9 @@ void Firmware::addOptionsGroup(const OptionsGroup & options) { this->opts.append(options); } + +QString Firmware::getFlavour() +{ + QStringList strl = id.split("-"); + return strl.count() >= 2 ? strl.at(1) : QString(); +} diff --git a/companion/src/firmwares/eeprominterface.h b/companion/src/firmwares/eeprominterface.h index b91d7262e..77a9ce783 100644 --- a/companion/src/firmwares/eeprominterface.h +++ b/companion/src/firmwares/eeprominterface.h @@ -262,6 +262,8 @@ enum EepromLoadErrors { NUM_ERRORS }; +constexpr char FIRMWARE_ID_PREFIX[] = { "edgetx-" }; + class Firmware { Q_DECLARE_TR_FUNCTIONS(Firmware) @@ -405,6 +407,13 @@ class Firmware currentVariant = value; } + QString getFlavour(); + + static Firmware * getFirmwareForFlavour(const QString & flavour) + { + return getFirmwareForId(FIRMWARE_ID_PREFIX + flavour); + } + const StringTagMappingTable* getAnalogIndexNamesLookupTable() { return &analogInputNamesLookupTable; diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index c1be0e465..97ea8ddbc 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -59,59 +59,59 @@ const char * OpenTxEepromInterface::getName() { switch (board) { case BOARD_JUMPER_T12: - return "OpenTX for Jumper T12"; + return "EdgeTX for Jumper T12"; case BOARD_JUMPER_TLITE: - return "OpenTX for Jumper T-Lite"; + return "EdgeTX for Jumper T-Lite"; case BOARD_JUMPER_TPRO: - return "OpenTX for Jumper T-Pro"; + return "EdgeTX for Jumper T-Pro"; case BOARD_JUMPER_T16: - return "OpenTX for Jumper T16"; + return "EdgeTX for Jumper T16"; case BOARD_JUMPER_T18: - return "OpenTX for Jumper T18"; + return "EdgeTX for Jumper T18"; case BOARD_RADIOMASTER_TX16S: - return "OpenTX for Radiomaster TX16S"; + return "EdgeTX for Radiomaster TX16S"; case BOARD_RADIOMASTER_TX12: - return "OpenTX for Radiomaster TX12"; + return "EdgeTX for Radiomaster TX12"; case BOARD_RADIOMASTER_ZORRO: - return "OpenTX for Radiomaster Zorro"; + return "EdgeTX for Radiomaster Zorro"; case BOARD_RADIOMASTER_T8: - return "OpenTX for Radiomaster T8"; + return "EdgeTX for Radiomaster T8"; case BOARD_TARANIS_X9D: - return "OpenTX for FrSky Taranis X9D"; + return "EdgeTX for FrSky Taranis X9D"; case BOARD_TARANIS_X9DP: - return "OpenTX for FrSky Taranis X9D+"; + return "EdgeTX for FrSky Taranis X9D+"; case BOARD_TARANIS_X9DP_2019: - return "OpenTX for FrSky Taranis X9D+ 2019"; + return "EdgeTX for FrSky Taranis X9D+ 2019"; case BOARD_TARANIS_X9E: - return "OpenTX for FrSky Taranis X9E"; + return "EdgeTX for FrSky Taranis X9E"; case BOARD_TARANIS_X7: - return "OpenTX for FrSky Taranis X7"; + return "EdgeTX for FrSky Taranis X7"; case BOARD_TARANIS_X7_ACCESS: - return "OpenTX for FrSky Taranis X7 Access"; + return "EdgeTX for FrSky Taranis X7 Access"; case BOARD_TARANIS_X9LITES: - return "OpenTX for FrSky Taranis X9-Lite S"; + return "EdgeTX for FrSky Taranis X9-Lite S"; case BOARD_TARANIS_X9LITE: - return "OpenTX for FrSky Taranis X9-Lite"; + return "EdgeTX for FrSky Taranis X9-Lite"; case BOARD_TARANIS_XLITE: - return "OpenTX for FrSky Taranis X-Lite"; + return "EdgeTX for FrSky Taranis X-Lite"; case BOARD_TARANIS_XLITES: - return "OpenTX for FrSky Taranis X-Lite S/Pro"; + return "EdgeTX for FrSky Taranis X-Lite S/Pro"; case BOARD_SKY9X: - return "OpenTX for Sky9x board / 9X"; + return "EdgeTX for Sky9x board / 9X"; case BOARD_9XRPRO: - return "OpenTX for 9XR-PRO"; + return "EdgeTX for 9XR-PRO"; case BOARD_AR9X: - return "OpenTX for ar9x board / 9X"; + return "EdgeTX for ar9x board / 9X"; case BOARD_HORUS_X12S: - return "OpenTX for FrSky Horus"; + return "EdgeTX for FrSky Horus"; case BOARD_X10: - return "OpenTX for FrSky X10"; + return "EdgeTX for FrSky X10"; case BOARD_X10_EXPRESS: - return "OpenTX for FrSky X10 Express"; + return "EdgeTX for FrSky X10 Express"; case BOARD_FLYSKY_NV14: - return "OpenTX for FlySky NV14"; + return "EdgeTX for FlySky NV14"; default: - return "OpenTX for an unknown board"; + return "Board is unknown to EdgeTX"; } } @@ -1280,25 +1280,28 @@ void addOpenTxArm9xOptions(OpenTxFirmware * firmware, bool dblkeys = true) addOpenTxRfOptions(firmware, FLEX); } +// TODO: refactoring OpenTxFirmware constructor - need to check if used elsewhere and how +#define FIRMWAREID(flavour) std::string(FIRMWARE_ID_PREFIX).append(flavour).c_str() + void registerOpenTxFirmwares() { OpenTxFirmware * firmware; /* FrSky Taranis X9D+ board */ - firmware = new OpenTxFirmware("edgetx-x9d+", Firmware::tr("FrSky Taranis X9D+"), BOARD_TARANIS_X9DP); + firmware = new OpenTxFirmware(FIRMWAREID("x9d+"), Firmware::tr("FrSky Taranis X9D+"), BOARD_TARANIS_X9DP); firmware->addOption("noras", Firmware::tr("Disable RAS (SWR)")); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX + AFHDS3); /* FrSky Taranis X9D+ 2019 board */ - firmware = new OpenTxFirmware("edgetx-x9d+2019", Firmware::tr("FrSky Taranis X9D+ 2019"), BOARD_TARANIS_X9DP_2019); + firmware = new OpenTxFirmware(FIRMWAREID("x9d+2019"), Firmware::tr("FrSky Taranis X9D+ 2019"), BOARD_TARANIS_X9DP_2019); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky Taranis X9D board */ - firmware = new OpenTxFirmware("edgetx-x9d", Firmware::tr("FrSky Taranis X9D"), BOARD_TARANIS_X9D); + firmware = new OpenTxFirmware(FIRMWAREID("x9d"), Firmware::tr("FrSky Taranis X9D"), BOARD_TARANIS_X9D); firmware->addOption("noras", Firmware::tr("Disable RAS (SWR)")); firmware->addOption("haptic", Firmware::tr("Haptic module installed")); addOpenTxTaranisOptions(firmware); @@ -1306,7 +1309,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX + AFHDS3); /* FrSky Taranis X9E board */ - firmware = new OpenTxFirmware("edgetx-x9e", Firmware::tr("FrSky Taranis X9E"), BOARD_TARANIS_X9E); + firmware = new OpenTxFirmware(FIRMWAREID("x9e"), Firmware::tr("FrSky Taranis X9E"), BOARD_TARANIS_X9E); firmware->addOption("shutdownconfirm", Firmware::tr("Confirmation before radio shutdown")); firmware->addOption("horussticks", Firmware::tr("Horus gimbals installed (Hall sensors)")); addOpenTxTaranisOptions(firmware); @@ -1314,44 +1317,44 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X9-Lite board */ - firmware = new OpenTxFirmware("edgetx-x9lite", Firmware::tr("FrSky Taranis X9-Lite"), BOARD_TARANIS_X9LITE); + firmware = new OpenTxFirmware(FIRMWAREID("x9lite"), Firmware::tr("FrSky Taranis X9-Lite"), BOARD_TARANIS_X9LITE); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X9-LiteS board */ - firmware = new OpenTxFirmware("edgetx-x9lites", Firmware::tr("FrSky Taranis X9-Lite S"), BOARD_TARANIS_X9LITES); + firmware = new OpenTxFirmware(FIRMWAREID("x9lites"), Firmware::tr("FrSky Taranis X9-Lite S"), BOARD_TARANIS_X9LITES); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X7 board */ - firmware = new OpenTxFirmware("edgetx-x7", Firmware::tr("FrSky Taranis X7 / X7S"), BOARD_TARANIS_X7); + firmware = new OpenTxFirmware(FIRMWAREID("x7"), Firmware::tr("FrSky Taranis X7 / X7S"), BOARD_TARANIS_X7); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X7 Access board */ - firmware = new OpenTxFirmware("edgetx-x7access", Firmware::tr("FrSky Taranis X7 / X7S Access"), BOARD_TARANIS_X7_ACCESS); + firmware = new OpenTxFirmware(FIRMWAREID("x7access"), Firmware::tr("FrSky Taranis X7 / X7S Access"), BOARD_TARANIS_X7_ACCESS); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X-Lite S/PRO board */ - firmware = new OpenTxFirmware("edgetx-xlites", Firmware::tr("FrSky Taranis X-Lite S/PRO"), BOARD_TARANIS_XLITES); + firmware = new OpenTxFirmware(FIRMWAREID("xlites"), Firmware::tr("FrSky Taranis X-Lite S/PRO"), BOARD_TARANIS_XLITES); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X-Lite board */ - firmware = new OpenTxFirmware("edgetx-xlite", Firmware::tr("FrSky Taranis X-Lite"), BOARD_TARANIS_XLITE); + firmware = new OpenTxFirmware(FIRMWAREID("xlite"), Firmware::tr("FrSky Taranis X-Lite"), BOARD_TARANIS_XLITE); // firmware->addOption("stdr9m", Firmware::tr("Use JR-sized R9M module")); addOpenTxTaranisOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X10 board */ - firmware = new OpenTxFirmware("edgetx-x10", Firmware::tr("FrSky Horus X10 / X10S"), BOARD_X10); + firmware = new OpenTxFirmware(FIRMWAREID("x10"), Firmware::tr("FrSky Horus X10 / X10S"), BOARD_X10); addOpenTxFrskyOptions(firmware); firmware->addOption("internalaccess", Firmware::tr("Support for ACCESS internal module replacement")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1359,13 +1362,13 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* FrSky X10 Express board */ - firmware = new OpenTxFirmware("edgetx-x10express", Firmware::tr("FrSky Horus X10 Express / X10S Express"), BOARD_X10_EXPRESS); + firmware = new OpenTxFirmware(FIRMWAREID("x10express"), Firmware::tr("FrSky Horus X10 Express / X10S Express"), BOARD_X10_EXPRESS); addOpenTxFrskyOptions(firmware); registerOpenTxFirmware(firmware); addOpenTxRfOptions(firmware, FLEX); /* FrSky X12 (Horus) board */ - firmware = new OpenTxFirmware("edgetx-x12s", Firmware::tr("FrSky Horus X12S"), BOARD_HORUS_X12S); + firmware = new OpenTxFirmware(FIRMWAREID("x12s"), Firmware::tr("FrSky Horus X12S"), BOARD_HORUS_X12S); addOpenTxFrskyOptions(firmware); firmware->addOption("internalaccess", Firmware::tr("Support for ACCESS internal module replacement")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1374,7 +1377,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, EU + FLEX); /* Jumper T12 board */ - firmware = new OpenTxFirmware("edgetx-t12", QCoreApplication::translate("Firmware", "Jumper T12 / T12 Pro"), BOARD_JUMPER_T12); + firmware = new OpenTxFirmware(FIRMWAREID("t12"), QCoreApplication::translate("Firmware", "Jumper T12 / T12 Pro"), BOARD_JUMPER_T12); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1385,7 +1388,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T-Lite board */ - firmware = new OpenTxFirmware("edgetx-tlite", QCoreApplication::translate("Firmware", "Jumper T-Lite"), BOARD_JUMPER_TLITE); + firmware = new OpenTxFirmware(FIRMWAREID("tlite"), QCoreApplication::translate("Firmware", "Jumper T-Lite"), BOARD_JUMPER_TLITE); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1395,7 +1398,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T-Pro board */ - firmware = new OpenTxFirmware("edgetx-tpro", QCoreApplication::translate("Firmware", "Jumper T-Pro"), BOARD_JUMPER_TPRO); + firmware = new OpenTxFirmware(FIRMWAREID("tpro"), QCoreApplication::translate("Firmware", "Jumper T-Pro"), BOARD_JUMPER_TPRO); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1405,7 +1408,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Jumper T16 board */ - firmware = new OpenTxFirmware("edgetx-t16", Firmware::tr("Jumper T16 / T16+ / T16 Pro"), BOARD_JUMPER_T16); + firmware = new OpenTxFirmware(FIRMWAREID("t16"), Firmware::tr("Jumper T16 / T16+ / T16 Pro"), BOARD_JUMPER_T16); addOpenTxFrskyOptions(firmware); firmware->addOption("internalmulti", Firmware::tr("Support for MULTI internal module")); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); @@ -1414,7 +1417,7 @@ void registerOpenTxFirmwares() registerOpenTxFirmware(firmware); /* Radiomaster TX12 board */ - firmware = new OpenTxFirmware("edgetx-tx12", QCoreApplication::translate("Firmware", "Radiomaster TX12"), BOARD_RADIOMASTER_TX12); + firmware = new OpenTxFirmware(FIRMWAREID("tx12"), QCoreApplication::translate("Firmware", "Radiomaster TX12"), BOARD_RADIOMASTER_TX12); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1424,7 +1427,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* Radiomaster Zorro board */ - firmware = new OpenTxFirmware("edgetx-zorro", QCoreApplication::translate("Firmware", "Radiomaster Zorro"), Board::BOARD_RADIOMASTER_ZORRO); + firmware = new OpenTxFirmware(FIRMWAREID("zorro"), QCoreApplication::translate("Firmware", "Radiomaster Zorro"), Board::BOARD_RADIOMASTER_ZORRO); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1435,7 +1438,7 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX + AFHDS3); /* Radiomaster T8 board */ - firmware = new OpenTxFirmware("edgetx-t8", QCoreApplication::translate("Firmware", "Radiomaster T8"), BOARD_RADIOMASTER_T8); + firmware = new OpenTxFirmware(FIRMWAREID("t8"), QCoreApplication::translate("Firmware", "Radiomaster T8"), BOARD_RADIOMASTER_T8); addOpenTxCommonOptions(firmware); firmware->addOption("noheli", Firmware::tr("Disable HELI menu and cyclic mix support")); firmware->addOption("nogvars", Firmware::tr("Disable Global variables")); @@ -1446,7 +1449,7 @@ void registerOpenTxFirmwares() firmware->addOption("bindkey", Firmware::tr("Allow bind using bind key")); /* Radiomaster TX16S board */ - firmware = new OpenTxFirmware("edgetx-tx16s", Firmware::tr("Radiomaster TX16S / SE / Hall / Masterfire"), BOARD_RADIOMASTER_TX16S); + firmware = new OpenTxFirmware(FIRMWAREID("tx16s"), Firmware::tr("Radiomaster TX16S / SE / Hall / Masterfire"), BOARD_RADIOMASTER_TX16S); addOpenTxFrskyOptions(firmware); addOpenTxRfOptions(firmware, FLEX); static const Firmware::Option opt_bt("bluetooth", Firmware::tr("Support for bluetooth module")); @@ -1457,7 +1460,7 @@ void registerOpenTxFirmwares() registerOpenTxFirmware(firmware); /* Jumper T18 board */ - firmware = new OpenTxFirmware("edgetx-t18", Firmware::tr("Jumper T18"), BOARD_JUMPER_T18); + firmware = new OpenTxFirmware(FIRMWAREID("t18"), Firmware::tr("Jumper T18"), BOARD_JUMPER_T18); addOpenTxFrskyOptions(firmware); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); firmware->addOption("externalaccessmod", Firmware::tr("Support hardware mod: R9M ACCESS")); @@ -1465,30 +1468,30 @@ void registerOpenTxFirmwares() addOpenTxRfOptions(firmware, FLEX); /* FlySky NV14 board */ - firmware = new OpenTxFirmware("edgetx-nv14", QCoreApplication::translate("Firmware", "FlySky NV14"), BOARD_FLYSKY_NV14); + firmware = new OpenTxFirmware(FIRMWAREID("nv14"), QCoreApplication::translate("Firmware", "FlySky NV14"), BOARD_FLYSKY_NV14); addOpenTxFrskyOptions(firmware); firmware->addOption("bluetooth", Firmware::tr("Support for bluetooth module")); addOpenTxRfOptions(firmware, FLEX + AFHDS3); registerOpenTxFirmware(firmware); /* 9XR-Pro */ - firmware = new OpenTxFirmware("edgetx-9xrpro", Firmware::tr("Turnigy 9XR-PRO"), BOARD_9XRPRO); + firmware = new OpenTxFirmware(FIRMWAREID("9xrpro"), Firmware::tr("Turnigy 9XR-PRO"), BOARD_9XRPRO); addOpenTxArm9xOptions(firmware, false); registerOpenTxFirmware(firmware, true); /* ar9x board */ - firmware = new OpenTxFirmware("edgetx-ar9x", Firmware::tr("9X with AR9X board"), BOARD_AR9X); + firmware = new OpenTxFirmware(FIRMWAREID("ar9x"), Firmware::tr("9X with AR9X board"), BOARD_AR9X); addOpenTxArm9xOptions(firmware, true); //firmware->addOption("rtc", Firmware::tr("Optional RTC added")); //firmware->addOption("volume", Firmware::tr("i2c volume control added")); registerOpenTxFirmware(firmware, true); /* Sky9x board */ - firmware = new OpenTxFirmware("edgetx-sky9x", Firmware::tr("9X with Sky9x board"), BOARD_SKY9X); + firmware = new OpenTxFirmware(FIRMWAREID("sky9x"), Firmware::tr("9X with Sky9x board"), BOARD_SKY9X); addOpenTxArm9xOptions(firmware); registerOpenTxFirmware(firmware, true); - Firmware::setDefaultVariant(Firmware::getFirmwareForId("edgetx-tx16s")); + Firmware::setDefaultVariant(Firmware::getFirmwareForFlavour("tx16s")); Firmware::setCurrentVariant(Firmware::getDefaultVariant()); } diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index e1d59e041..4e4d36ebd 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1345,6 +1345,7 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile) setCurrentFile(filename); } + // For etx files this will never be true as any conversion occurs when parsing file if (!Boards::isBoardCompatible(storage.getBoard(), getCurrentBoard())) { if (!convertStorage(storage.getBoard(), getCurrentBoard(), true)) return false; diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 63f98ffa7..b5745d51f 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -240,8 +240,7 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) return false; } - // TODO: provide a simple text mapping - board = Board::BOARD_RADIOMASTER_TX16S; + board = (Board::Type)radioData.generalSettings.variant; // get models QByteArray modelslistBuffer; From 7648dfc54433b3c8917439999416984b4bfa211a Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 30 Dec 2021 08:19:06 +1100 Subject: [PATCH 152/180] Do not prompt to use previous version settings when newer version --- companion/src/companion.cpp | 22 ++++++++-------------- companion/src/storage/appdata.cpp | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/companion/src/companion.cpp b/companion/src/companion.cpp index 7a431b8f4..5059d93ff 100644 --- a/companion/src/companion.cpp +++ b/companion/src/companion.cpp @@ -69,28 +69,22 @@ void checkSettingsImport(bool force = false) if (!found && !force) return; - const QString impFileBtn = QCoreApplication::translate("Companion", "Import from File"); - const QString impPrevBtn = QCoreApplication::translate("Companion", "Import from v%1").arg(previousVersion); - const QString impNoneBtn = QCoreApplication::translate("Companion", "Do not import"); - QString msg; if (previousVersion.isEmpty()) { + const QString impFileBtn = QCoreApplication::translate("Companion", "Import from File"); + const QString impNoneBtn = QCoreApplication::translate("Companion", "Do not import"); + if (found) msg = QCoreApplication::translate("Companion", "We have found possible Companion settings backup file(s).\nDo you want to import settings from a file?"); else msg = QCoreApplication::translate("Companion", "Import settings from a file, or start with current values."); + + const int ret = QMessageBox::question(nullptr, CPN_STR_APP_NAME, msg, impNoneBtn, impFileBtn, 0, 0); + + if (!ret) + return; } else { - msg = QCoreApplication::translate("Companion", "We have found existing settings for Companion version: %1.\nDo you want to import them?\n\n" \ - "If you have a settings backup file, you may import that instead.").arg(previousVersion); - } - - const int ret = QMessageBox::question(nullptr, CPN_STR_APP_NAME, msg, impNoneBtn, impFileBtn, (previousVersion.isEmpty() ? QString() : impPrevBtn), 0, 0); - if (!ret) - return; - - // Import from previous version - if (ret == 2) { if (!g.importSettings(previousVersion)) { // very unlikely, but just in case of unexpected error, restart the import importError(); diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index f529c780c..34a5aea6e 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -471,7 +471,7 @@ void AppData::clearUnusedSettings(QSettings & settings) bool AppData::findPreviousVersionSettings(QString * version) const { // TODO need a more dynamic method since ETX moves so quickly - static const QStringList versList({QStringLiteral("2.5"), QStringLiteral("2.4")}); + static const QStringList versList({QStringLiteral("2.6"), QStringLiteral("2.5"), QStringLiteral("2.4")}); for (const QString &ver : versList) { const QString prod("Companion " % ver); From 3eb55af2286871092a6b7cf5d3f9ba1ec1c09421 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 11:35:39 +0100 Subject: [PATCH 153/180] Do not init points to identity function to avoid issues with radio firmware --- companion/src/firmwares/curvedata.cpp | 12 ------------ companion/src/firmwares/opentx/opentxeeprom.cpp | 4 ---- 2 files changed, 16 deletions(-) diff --git a/companion/src/firmwares/curvedata.cpp b/companion/src/firmwares/curvedata.cpp index 3843fb77b..904863a3d 100644 --- a/companion/src/firmwares/curvedata.cpp +++ b/companion/src/firmwares/curvedata.cpp @@ -30,18 +30,6 @@ void CurveData::clear(int count) { memset(reinterpret_cast(this), 0, sizeof(CurveData)); this->count = count; - - int incr = 200 / (count - 1); - - // points[0].x must be -100 - for (int i = 0; i < count; i++) { - if (i < count - 1) - points[i].x = -100 + incr * i; - else - points[i].x = 100; // points[last].x must be +100 do not risk a rounding issue using incr - - points[i].y = points[i].x; - } } bool CurveData::isEmpty() const diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 423f5050c..9e186e095 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -1280,10 +1280,6 @@ class CurvesField: public TransformedField { curve->points[j].x = *cur++; curve->points[curve->count-1].x = +100; } - else { - for (int j=0; jcount; j++) - curve->points[j].x = -100 + (200*i) / (curve->count-1); - } qCDebug(eepromImport) << QString("imported curve: %3 points").arg(curve->count); } } From 79181d1484af5ecdc8a7d8037a123ccc74fca559 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 12:09:04 +0100 Subject: [PATCH 154/180] Add model files loading for B&W radios --- .../src/firmwares/edgetx/edgetxinterface.cpp | 7 +- .../src/firmwares/edgetx/edgetxinterface.h | 1 + companion/src/storage/categorized.cpp | 86 +++++++++++-------- companion/src/storage/categorized.h | 3 + companion/src/storage/etx.cpp | 15 ++++ companion/src/storage/etx.h | 1 + companion/src/storage/otx.h | 1 + companion/src/storage/sdcard.cpp | 10 +++ companion/src/storage/sdcard.h | 1 + 9 files changed, 85 insertions(+), 40 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index d5a90de1f..49e205107 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -52,6 +52,7 @@ bool loadModelsListFromYaml(std::vector& categories, YAML::Node node = loadYamlFromByteArray(data); if (!node.IsSequence()) return false; + int modelIdx = 0; for (const auto& cat : node) { if (!cat.IsMap()) continue; @@ -63,11 +64,11 @@ bool loadModelsListFromYaml(std::vector& categories, if (!models.IsSequence()) continue; for (const auto& model : models) { - std::string filename; + std::string filename, name; model["filename"] >> filename; - std::string name; model["name"] >> name; - modelFiles.push_back({filename, name, (int)categories.size() - 1}); + modelFiles.push_back( + {filename, name, (int)categories.size() - 1, modelIdx++}); } } } diff --git a/companion/src/firmwares/edgetx/edgetxinterface.h b/companion/src/firmwares/edgetx/edgetxinterface.h index 4512ccd8d..55b374ac9 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.h +++ b/companion/src/firmwares/edgetx/edgetxinterface.h @@ -33,6 +33,7 @@ struct EtxModelMetadata { std::string filename; std::string name; int category; + int modelIdx; }; typedef std::list EtxModelfiles; diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index b5745d51f..7eb8af901 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -23,6 +23,8 @@ #include "firmwares/edgetx/edgetxinterface.h" #include "miniz.c" // Can only be included once! +#include + bool CategorizedStorageFormat::load(RadioData & radioData) { StorageType st = getStorageType(filename); @@ -243,50 +245,63 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) board = (Board::Type)radioData.generalSettings.variant; // get models + EtxModelfiles modelFiles; + QByteArray modelslistBuffer; if (loadFile(modelslistBuffer, "MODELS/models.yml")) { - // List< { filename, category index } > - EtxModelfiles modelFiles; if (!loadModelsListFromYaml(radioData.categories, modelFiles, modelslistBuffer)) { setError(tr("Can't load MODELS/models.yml")); return false; } - - radioData.models.resize(modelFiles.size()); - - int modelIdx = 0; - for (const auto& mc : modelFiles) { - qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category; - - QByteArray modelBuffer; - QString filename = "MODELS/" + QString::fromStdString(mc.filename); - if (!loadFile(modelBuffer, filename)) { - setError(tr("Can't extract ") + filename); - return false; - } - - // Please note: - // ModelData() use memset to clear everything to 0 - // - auto& model = radioData.models[modelIdx]; - - if (!loadModelFromYaml(model,modelBuffer)) { - setError(tr("Can't load ") + filename); - return false; - } - - model.category = mc.category; - model.modelIndex = modelIdx; - strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1); - - model.used = true; - modelIdx++; - } - } else { // fetch "MODELS/modelXX.yml" + std::list filelist; + if (!getFileList(filelist)) { + setError(tr("Can't list files")); + return false; + } + + const std::regex yml_regex("MODELS/(model([0-9]+)\\.yml)"); + for(const auto& f : filelist) { + std::smatch match; + if (std::regex_match(f, match, yml_regex)) { + if (match.size() == 3) { + std::ssub_match modelFile = match[1]; + std::ssub_match modelIdx = match[2]; + modelFiles.push_back({ modelFile.str(), "", 0, std::stoi(modelIdx.str()) }); + } + } + } + } + + radioData.models.resize(modelFiles.size()); + for (const auto& mc : modelFiles) { + qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category; + + QByteArray modelBuffer; + QString filename = "MODELS/" + QString::fromStdString(mc.filename); + if (!loadFile(modelBuffer, filename)) { + setError(tr("Can't extract ") + filename); + return false; + } + + // Please note: + // ModelData() use memset to clear everything to 0 + // + auto& model = radioData.models[mc.modelIdx]; + + if (!loadModelFromYaml(model,modelBuffer)) { + setError(tr("Can't load ") + filename); + return false; + } + + model.category = mc.category; + model.modelIndex = mc.modelIdx; + strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1); + + model.used = true; } return true; @@ -308,12 +323,9 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData) EtxModelfiles modelFiles; for (const auto& model : radioData.models) { - qDebug() << "Model index: " << model.modelIndex; if (model.isEmpty()) continue; - // TODO: verify '.yml' (in case we moved from '.bin') - QString modelFilename; if (hasCategories) { std::string ymlFilename = patchFilenameToYaml(model.filename); diff --git a/companion/src/storage/categorized.h b/companion/src/storage/categorized.h index df9f069c9..c14769d27 100644 --- a/companion/src/storage/categorized.h +++ b/companion/src/storage/categorized.h @@ -24,6 +24,8 @@ #include "storage.h" #include +#include +#include class CategorizedStorageFormat : public StorageFormat { @@ -41,6 +43,7 @@ class CategorizedStorageFormat : public StorageFormat protected: virtual bool loadFile(QByteArray & fileData, const QString & fileName) = 0; virtual bool writeFile(const QByteArray & fileData, const QString & fileName) = 0; + virtual bool getFileList(std::list& filelist) = 0; virtual bool loadBin(RadioData & radioData); virtual bool writeBin(const RadioData & radioData); diff --git a/companion/src/storage/etx.cpp b/companion/src/storage/etx.cpp index 051bf8391..8ec2085ef 100644 --- a/companion/src/storage/etx.cpp +++ b/companion/src/storage/etx.cpp @@ -113,3 +113,18 @@ bool EtxFormat::writeFile(const QByteArray & filedata, const QString & filename) return true; } + +bool EtxFormat::getFileList(std::list& filelist) +{ + int count = (int)mz_zip_reader_get_num_files(&zip_archive); + if (count == 0) return false; + + mz_zip_archive_file_stat file_stat; + for (int i=0; i& filelist); mz_zip_archive zip_archive; }; diff --git a/companion/src/storage/otx.h b/companion/src/storage/otx.h index da4923488..37739074c 100644 --- a/companion/src/storage/otx.h +++ b/companion/src/storage/otx.h @@ -46,6 +46,7 @@ class OtxFormat : public CategorizedStorageFormat protected: virtual bool loadFile(QByteArray & fileData, const QString & fileName); virtual bool writeFile(const QByteArray & fileData, const QString & fileName); + virtual bool getFileList(std::list& filelist) { return false; } mz_zip_archive zip_archive; }; diff --git a/companion/src/storage/sdcard.cpp b/companion/src/storage/sdcard.cpp index 248f23615..3ac02f1fd 100644 --- a/companion/src/storage/sdcard.cpp +++ b/companion/src/storage/sdcard.cpp @@ -57,6 +57,16 @@ bool SdcardFormat::writeFile(const QByteArray & data, const QString & filename) return true; } +bool SdcardFormat::getFileList(std::list& filelist) +{ + QDir dir(filename); + QStringList ql = dir.entryList(); + for (const auto& str : ql) { + filelist.push_back(str.toStdString()); + } + return true; +} + bool SdcardStorageFactory::probe(const QString & path) { return QDir(path).exists(); diff --git a/companion/src/storage/sdcard.h b/companion/src/storage/sdcard.h index 1d7d813d2..cc6230a9b 100644 --- a/companion/src/storage/sdcard.h +++ b/companion/src/storage/sdcard.h @@ -41,6 +41,7 @@ class SdcardFormat : public CategorizedStorageFormat protected: virtual bool loadFile(QByteArray & fileData, const QString & fileName); virtual bool writeFile(const QByteArray & fileData, const QString & fileName); + virtual bool getFileList(std::list& filelist); }; class SdcardStorageFactory : public DefaultStorageFactory From 56283915390cbdfe2be2e4ef6ccec913d200b8c4 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 13:36:22 +0100 Subject: [PATCH 155/180] Allow yaml-cpp exception to be caught in the loader and set as error This allows for better debugging: the exception shows where in the file the error has occurred. --- .../src/firmwares/edgetx/edgetxinterface.cpp | 10 ---------- companion/src/firmwares/edgetx/yaml_ops.h | 20 +++++++++---------- companion/src/storage/categorized.cpp | 20 +++++++++++++------ 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 49e205107..709c06c6e 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -83,20 +83,14 @@ bool loadModelsListFromYaml(std::vector& categories, bool loadModelFromYaml(ModelData& model, const QByteArray& data) { - try { YAML::Node node = loadYamlFromByteArray(data); node >> model; - } catch (const std::runtime_error& e) { - qDebug() << "YAML::ParserException: " << e.what(); - return false; - } return true; } bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data) { - try { YAML::Node node = loadYamlFromByteArray(data); node >> settings; if (settings.version < CPN_CURRENT_SETTINGS_VERSION) { @@ -107,10 +101,6 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data QMessageBox::critical(NULL, CPN_STR_APP_NAME, QCoreApplication::translate("EdgeTXInterface", "Companion does not support settings version %1!").arg(settings.version)); return false; } - } catch (const std::runtime_error& e) { - qDebug() << "YAML::ParserException: " << e.what(); - return false; - } return true; } diff --git a/companion/src/firmwares/edgetx/yaml_ops.h b/companion/src/firmwares/edgetx/yaml_ops.h index 52a40ab65..539db8b96 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.h +++ b/companion/src/firmwares/edgetx/yaml_ops.h @@ -98,18 +98,18 @@ void operator>>(const YAML::Node& node, T (&value)[N]) if (!node) return; if (node.IsMap()) { for (const auto& elmt : node) { + int idx = -1; try { - int idx = std::stoi(elmt.first.Scalar()); - if (idx < 0 || idx >= (int)N) return; - - if (elmt.second.IsMap() && (elmt.second.size() == 1) && - elmt.second["val"]) { - elmt.second["val"] >> value[idx]; - } else { - elmt.second >> value[idx]; - } + idx = std::stoi(elmt.first.Scalar()); } catch (...) { - return; + } + if (idx < 0 || idx >= (int)N) continue; + + if (elmt.second.IsMap() && (elmt.second.size() == 1) && + elmt.second["val"]) { + elmt.second["val"] >> value[idx]; + } else { + elmt.second >> value[idx]; } } } else if (node.IsSequence()) { diff --git a/companion/src/storage/categorized.cpp b/companion/src/storage/categorized.cpp index 7eb8af901..4c3caf7c2 100644 --- a/companion/src/storage/categorized.cpp +++ b/companion/src/storage/categorized.cpp @@ -237,8 +237,13 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) return false; } - if (!loadRadioSettingsFromYaml(radioData.generalSettings, radioSettingsBuffer)) { - setError(tr("Can't load RADIO/radio.yml")); + try { + if (!loadRadioSettingsFromYaml(radioData.generalSettings, radioSettingsBuffer)) { + setError(tr("Can't load RADIO/radio.yml")); + return false; + } + } catch(const std::runtime_error& e) { + setError(tr("Can't load RADIO/radio.yml") + ":\n" + QString(e.what())); return false; } @@ -249,8 +254,6 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) QByteArray modelslistBuffer; if (loadFile(modelslistBuffer, "MODELS/models.yml")) { - - if (!loadModelsListFromYaml(radioData.categories, modelFiles, modelslistBuffer)) { setError(tr("Can't load MODELS/models.yml")); return false; @@ -292,8 +295,13 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData) // auto& model = radioData.models[mc.modelIdx]; - if (!loadModelFromYaml(model,modelBuffer)) { - setError(tr("Can't load ") + filename); + try { + if (!loadModelFromYaml(model,modelBuffer)) { + setError(tr("Can't load ") + filename); + return false; + } + } catch(const std::runtime_error& e) { + setError(tr("Can't load ") + filename + ":\n" + QString(e.what())); return false; } From 6cfecb7ddb2e5e3ad53f1a4e91183a25b36f48ac Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 13:42:35 +0100 Subject: [PATCH 156/180] Fix output for empty params in custom functions (like "Play track") --- .../src/firmwares/edgetx/yaml_customfunctiondata.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp index 4975a207b..22d59f191 100644 --- a/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp +++ b/companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp @@ -142,6 +142,7 @@ Node convert::encode(const CustomFunctionData& rhs) } node["func"] = LookupValue(customFnLut, fn); + bool add_comma = true; std::string def; switch(fn) { case FuncOverrideCH1: @@ -202,16 +203,17 @@ Node convert::encode(const CustomFunctionData& rhs) def += std::to_string(rhs.param); break; default: + add_comma = false; break; } if (fnHasEnable(rhs.func)) { - if (!def.empty()) { + if (add_comma) { def += ","; } def += std::to_string((int)rhs.enabled); } else if(fnHasRepeat(rhs.func)) { - if (!def.empty()) { + if (add_comma) { def += ","; } if (rhs.repeatParam == 0) { @@ -352,7 +354,9 @@ bool convert::decode(const Node& node, } else if (repeat == "!1x") { rhs.repeatParam = -1; } else { - rhs.repeatParam = std::stoi(repeat); + try { + rhs.repeatParam = std::stoi(repeat); + } catch(...) {} } } From b097593e7300e8b7e9f5b160738fd3d36edbdeb2 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 30 Dec 2021 15:11:13 +0100 Subject: [PATCH 157/180] Fix reading models from B&W radio --- companion/src/mainwindow.cpp | 2 +- companion/src/storage/sdcard.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 973cc372a..085b1b3fe 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -907,7 +907,7 @@ void MainWindow::readSettings() { Board::Type board = getCurrentBoard(); QString tempFile; - if (IS_FAMILY_HORUS_OR_T16(board)) + if (Boards::getCapability(board, Board::HasSDCard)) tempFile = generateProcessUniqueTempFileName("temp.etx"); else tempFile = generateProcessUniqueTempFileName("temp.bin"); diff --git a/companion/src/storage/sdcard.cpp b/companion/src/storage/sdcard.cpp index 3ac02f1fd..c58c4bf84 100644 --- a/companion/src/storage/sdcard.cpp +++ b/companion/src/storage/sdcard.cpp @@ -60,9 +60,11 @@ bool SdcardFormat::writeFile(const QByteArray & data, const QString & filename) bool SdcardFormat::getFileList(std::list& filelist) { QDir dir(filename); + if (!dir.cd("MODELS")) return false; + QStringList ql = dir.entryList(); for (const auto& str : ql) { - filelist.push_back(str.toStdString()); + filelist.push_back("MODELS/" + str.toStdString()); } return true; } From f56b462d54752d09778e0cc17b0743354c44f929 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 31 Dec 2021 10:48:53 +0100 Subject: [PATCH 158/180] Do not set varioSource to an arbitrary value. --- companion/src/firmwares/telem_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/telem_data.cpp b/companion/src/firmwares/telem_data.cpp index 99743c7e2..07513c087 100644 --- a/companion/src/firmwares/telem_data.cpp +++ b/companion/src/firmwares/telem_data.cpp @@ -65,7 +65,7 @@ void FrSkyData::clear() fasOffset = 0; for (int i=0; i<4; i++) screens[i].clear(); - varioSource = 2/*VARIO*/; + varioSource = 0; blades = 2; } From 9f6038c4e7d590744fd77b13bdf0482e4bd8e346 Mon Sep 17 00:00:00 2001 From: rotorman Date: Fri, 31 Dec 2021 12:47:32 +0100 Subject: [PATCH 159/180] Enable building under MSYS2 --- companion/src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 901d26436..35bfd2968 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -199,6 +199,9 @@ add_subdirectory(thirdparty/qcustomplot) add_subdirectory(thirdparty/maxlibqt/src/widgets) set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Enable testing" FORCE) +set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Enable parse tools" FORCE) +set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Enable contrib stuff in library" FORCE) +set(YAML_CPP_INSTALL OFF CACHE BOOL "Enable generation of install target" FORCE) add_subdirectory(thirdparty/yaml-cpp) ############# Companion ############### From 4a1c44a553c60052b0594e4ecaf8d5050d9b7736 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 31 Dec 2021 14:16:44 +0100 Subject: [PATCH 160/180] Do not try to parse the model list if it's empty --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 709c06c6e..f1f1a0c91 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -48,6 +48,9 @@ bool loadModelsListFromYaml(std::vector& categories, EtxModelfiles& modelFiles, const QByteArray& data) { + if (data.size() == 0) + return true; + try { YAML::Node node = loadYamlFromByteArray(data); if (!node.IsSequence()) return false; From 0f6c2b0cba286b93c04b5d0f6c62afca69c7c3b5 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 31 Dec 2021 14:28:40 +0100 Subject: [PATCH 161/180] Fix GCC warning. --- companion/src/firmwares/radiodata.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/companion/src/firmwares/radiodata.h b/companion/src/firmwares/radiodata.h index d289f1846..7b5caa9b6 100644 --- a/companion/src/firmwares/radiodata.h +++ b/companion/src/firmwares/radiodata.h @@ -12,7 +12,8 @@ class RadioDataConversionState; class CategoryData { public: CategoryData(const char * name) { - strncpy(this->name, name, sizeof(CategoryData::name)); + memset(this->name, 0, sizeof(CategoryData::name)); + strncpy(this->name, name, sizeof(CategoryData::name)-1); } char name[15+1]; }; From ede80e2ebd731a70be4eed8edb93d84e5930a5a4 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 31 Dec 2021 17:24:12 +0100 Subject: [PATCH 162/180] Fix backlight delay --- companion/src/firmwares/edgetx/yaml_generalsettings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index e51cc5b2f..431e5e461 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -117,6 +117,7 @@ Node convert::encode(const GeneralSettings& rhs) node["inactivityTimer"] = rhs.inactivityTimer; node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? node["splashMode"] = rhs.splashMode; // TODO: B&W only + node["lightAutoOff"] = rhs.backlightDelay; node["templateSetup"] = rhs.templateSetup; node["hapticLength"] = rhs.hapticLength + 2; node["speakerPitch"] = rhs.speakerPitch * 15; @@ -266,6 +267,7 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) node["inactivityTimer"] >> rhs.inactivityTimer; node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? node["splashMode"] >> rhs.splashMode; // TODO: B&W only + node["lightAutoOff"] >> rhs.backlightDelay; node["templateSetup"] >> rhs.templateSetup; node["hapticLength"] >> ioffset_int(rhs.hapticLength, 2); node["speakerPitch"] >> ifactor(rhs.speakerPitch, 15); From 8e69976dbb9dba519e7c4e43004dcc087948c520 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 31 Dec 2021 18:41:40 +0100 Subject: [PATCH 163/180] Skip calibration data for invalid analogs --- radio/src/storage/yaml/yaml_datastructs_funcs.cpp | 5 +++++ radio/src/storage/yaml/yaml_tree_walker.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 567745ec7..26adf40bf 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -463,6 +463,11 @@ static uint32_t r_calib(void* user, const char* val, uint8_t val_len) uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len); if (sw >= MIXSRC_Rud) return sw - MIXSRC_Rud; + // detect invalid values + if (val_len == 0 || (val[0] < '0') || (val[0] > '9')) { + return -1; + } + return (uint32_t)yaml_str2int(val, val_len); } diff --git a/radio/src/storage/yaml/yaml_tree_walker.cpp b/radio/src/storage/yaml/yaml_tree_walker.cpp index b2e900327..7f2c806da 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.cpp +++ b/radio/src/storage/yaml/yaml_tree_walker.cpp @@ -301,7 +301,7 @@ bool YamlTreeWalker::toParent() bool YamlTreeWalker::toChild() { const struct YamlNode* attr = getAttr(); - if (!attr + if (!attr || isIdxInvalid() || (attr->type != YDT_ARRAY && attr->type != YDT_UNION && !isArrayElmt())) { From 25ee9369cf3b6a1747d728b3ba10f6f8b9c0f426 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 11:36:29 +0100 Subject: [PATCH 164/180] Do not convert node to string if not a scalar --- companion/src/firmwares/edgetx/yaml_ops.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_ops.cpp b/companion/src/firmwares/edgetx/yaml_ops.cpp index ed7983fb3..c89aaea89 100644 --- a/companion/src/firmwares/edgetx/yaml_ops.cpp +++ b/companion/src/firmwares/edgetx/yaml_ops.cpp @@ -22,7 +22,7 @@ YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut) { - if (node) { + if (node && node.IsScalar()) { std::string str = node.as(); const auto& it = find_if(lut.begin(), lut.end(), [=](const YamlLookupTableElmt& elmt) { From e18219f53be9d6d075030f3da5654e8d4093ef43 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 11:39:17 +0100 Subject: [PATCH 165/180] backlightMode ON is -4 Seems the field is read as a signed 3 bit integer from `.otx`. --- companion/src/firmwares/edgetx/yaml_generalsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 431e5e461..6eb7b6a51 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -100,7 +100,7 @@ Node convert::encode(const GeneralSettings& rhs) node["vBatMin"] = rhs.vBatMin + 90; node["vBatMax"] = rhs.vBatMax + 120; - node["backlightMode"] = backlightModeLut << rhs.backlightMode; + node["backlightMode"] = backlightModeLut << std::abs(rhs.backlightMode); node["trainer"] = rhs.trainer; node["view"] = rhs.view; node["fai"] = (int)rhs.fai; From 7ef56c5d60fd872df29b0c2b27a1cc3b3744c2a1 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 11:57:56 +0100 Subject: [PATCH 166/180] Throw proper YAML exception instead of std::invalid_argument --- .../src/firmwares/edgetx/yaml_mixdata.cpp | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_mixdata.cpp b/companion/src/firmwares/edgetx/yaml_mixdata.cpp index dc34a9fa6..5b53bf762 100644 --- a/companion/src/firmwares/edgetx/yaml_mixdata.cpp +++ b/companion/src/firmwares/edgetx/yaml_mixdata.cpp @@ -23,27 +23,6 @@ #include "yaml_rawsource.h" #include "curvereference.h" -// static const YamlLookupTable timerModeLut = { -// {TimerData::TIMERMODE_OFF, "OFF"}, -// {TimerData::TIMERMODE_ON, "ON"}, -// {TimerData::TIMERMODE_START, "START"}, -// {TimerData::TIMERMODE_THR, "THR"}, -// {TimerData::TIMERMODE_THR_REL, "THR_REL"}, -// {TimerData::TIMERMODE_THR_START, "THR_START"}, -// }; - -// static const YamlLookupTable trainerModeLut = { -// { TRAINER_MODE_OFF, "OFF" }, -// { TRAINER_MODE_MASTER_JACK, "MASTER_TRAINER_JACK" }, -// { TRAINER_MODE_SLAVE_JACK, "SLAVE" }, -// { TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE, "MASTER_SBUS_EXT" }, -// { TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE, "MASTER_CPPM_EXT" }, -// { TRAINER_MODE_MASTER_BATTERY_COMPARTMENT, "MASTER_BATT_COMP" }, -// { TRAINER_MODE_MASTER_BLUETOOTH, "MASTER_BT" }, -// { TRAINER_MODE_SLAVE_BLUETOOTH, "SLAVE_BT" }, -// { TRAINER_MODE_MULTI, "MASTER_MULTI" }, -// }; - static const YamlLookupTable mixMultiplexLut = { { MLTPX_ADD, "ADD" }, { MLTPX_MUL, "MUL" }, @@ -75,7 +54,11 @@ int32_t YamlReadMixWeight(const YAML::Node& node) return 10000 + std::stoi(val.substr(2)); } - return std::stoi(val); + try { + return std::stoi(val); + } catch(...) { + throw YAML::TypedBadConversion(node.Mark()); + } } std::string YamlWriteMixWeight(int32_t sval) From eb1e3078c8f2f5c2e4d5f593facad9e1be029755 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 12:35:29 +0100 Subject: [PATCH 167/180] Fix index for negative GVARs --- radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp | 2 +- radio/src/storage/yaml/yaml_datastructs_funcs.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index d4c0ccf60..6d66fcf45 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -40,7 +40,7 @@ bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, int32_t gvar = (node->size > 8 ? GV1_LARGE : GV1_SMALL); if (sval >= gvar - 10 && sval <= gvar) { - char n = gvar - sval + '0'; + char n = gvar - sval + '1'; return wf(opaque, "-GV", 3) && wf(opaque, &n, 1); } else if (sval <= -gvar + 10 && sval >= -gvar) { char n = val - gvar + '1'; diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 26adf40bf..b51017eaf 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -155,7 +155,7 @@ static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t va && (val[3] <= '9')) { TRACE("%.*s -> %i\n", val_len, val, gvar - (val[3] - '0')); - return gvar - (val[3] - '0'); // -GVx => 128 - x + return gvar - (val[3] - '1'); // -GVx => 128 - x } if ((val_len == 3) From 85a184f15e3f3a03698b2d90686a62b83ecc5247 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 12:51:56 +0100 Subject: [PATCH 168/180] Catch all exceptions thrown by std::stoi() --- .../src/firmwares/edgetx/yaml_modeldata.cpp | 10 ++++++++-- .../src/firmwares/edgetx/yaml_moduledata.cpp | 18 ++++++++++-------- .../src/firmwares/edgetx/yaml_rawsource.cpp | 7 ++++--- .../src/firmwares/edgetx/yaml_rawswitch.cpp | 13 +++++++------ .../src/firmwares/edgetx/yaml_switchconfig.cpp | 10 ++++++---- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 4cc939147..45e5f8a4b 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -306,7 +306,11 @@ static int32_t YamlReadLimitValue(const YAML::Node& node, int32_t shift = 0) return 10000 + std::stoi(val.substr(2)); } - return std::stoi(val) + shift; + try { + return std::stoi(val) + shift; + } catch(...) { + throw YAML::TypedBadConversion(node.Mark()); + } } static std::string YamlWriteLimitValue(int32_t sval, int32_t shift = 0) @@ -593,7 +597,9 @@ struct convert { if (str == "none") { rhs.src = 0; } else { - rhs.src = std::stoi(str) + 1; + try { + rhs.src = std::stoi(str) + 1; + } catch(...) {} } } return true; diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.cpp b/companion/src/firmwares/edgetx/yaml_moduledata.cpp index 2089ee683..a6c84d8d5 100644 --- a/companion/src/firmwares/edgetx/yaml_moduledata.cpp +++ b/companion/src/firmwares/edgetx/yaml_moduledata.cpp @@ -333,14 +333,16 @@ bool convert::decode(const Node& node, ModuleData& rhs) subType >> st_str; if (!st_str.empty()) { size_t pos = 0; - int rfProtocol = std::stoi(st_str, &pos); - st_str = st_str.substr(pos + 1); - int rfSubType = std::stoi(st_str); - convertMultiProtocolToEtx(&rfProtocol, &rfSubType); - if (rfProtocol > 0) { - rhs.multi.rfProtocol = rfProtocol - 1; - rhs.subType = rfSubType; - } + try { + int rfProtocol = std::stoi(st_str, &pos); + st_str = st_str.substr(pos + 1); + int rfSubType = std::stoi(st_str); + convertMultiProtocolToEtx(&rfProtocol, &rfSubType); + if (rfProtocol > 0) { + rhs.multi.rfProtocol = rfProtocol - 1; + rhs.subType = rfSubType; + } + } catch(...) {} } } break; } diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index d700c712b..4d8e98cfd 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -102,12 +102,13 @@ RawSource YamlRawSourceDecode(const std::string& src_str) const char* val = src_str.data(); size_t val_len = src_str.size(); - if (val_len > 0 && val[0] == 'I') { + if (val_len > 1 && val[0] == 'I' + && (val[1] >= '0') && (val[1] <= '9')) { int idx = std::stoi(src_str.substr(1)); - if (idx < CPN_MAX_INPUTS) + if (idx < CPN_MAX_INPUTS) { rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, idx); - + } } else if (val_len >= 2 && val[0] == 'S' && val[1] >= 'A' diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index bea8f11c4..34ae49321 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -101,9 +101,9 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { - rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str_tmp.substr(1, val_len - 1))); + int sw_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1)); + if (sw_idx < CPN_MAX_LOGICAL_SWITCHES) { + rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, sw_idx); } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && @@ -121,9 +121,10 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { - rhs = RawSwitch(SWITCH_TYPE_SENSOR, - std::stoi(sw_str_tmp.substr(1, val_len - 1)) - 1); + // starts at T1 + int sensor_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1)); + if ((sensor_idx > 0) && (sensor_idx < CPN_MAX_SENSORS)) { + rhs = RawSwitch(SWITCH_TYPE_SENSOR, sensor_idx - 1); } } else if (sw_str_tmp.substr(0, 4) == std::string("Trim")) { diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 75b0e05af..7ab997c55 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -50,10 +50,12 @@ const YamlLookupTable sliderConfigLut = { int YamlStickLookup::name2idx(const std::string& name) { - int idx = std::stoi(name); - if (idx < 4) { - return idx; - } + try { + int idx = std::stoi(name); + if (idx < 4) { + return idx; + } + } catch(...) {} return -1; } From d7190493d598e51de5a56f44a3b28aebcc913aa8 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 00:23:27 +1100 Subject: [PATCH 169/180] Add Internal Module to companion --- companion/src/firmwares/boards.cpp | 3 + companion/src/firmwares/boards.h | 5 +- companion/src/firmwares/generalsettings.h | 1 + companion/src/firmwares/moduledata.cpp | 279 +++++++++++++++++++++- companion/src/firmwares/moduledata.h | 38 ++- companion/src/generaledit/hardware.cpp | 28 ++- companion/src/modeledit/setup.cpp | 19 +- companion/src/modeledit/setup_module.ui | 2 +- 8 files changed, 348 insertions(+), 27 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 4332f32d8..0378b95c7 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -489,6 +489,9 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) case HasSDCard: return IS_STM32(board); + case HasInternalModuleSupport: + return (IS_STM32(board) && !IS_TARANIS_SMALL(board)); + default: return 0; } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index f3a836963..844ea7502 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -147,7 +147,8 @@ namespace Board { HasRTC, HasColorLcd, NumFunctionSwitches, - HasSDCard + HasSDCard, + HasInternalModuleSupport }; struct SwitchInfo @@ -211,9 +212,11 @@ class Boards static QString potTypeToString(int value); static QString sliderTypeToString(int value); static QString switchTypeToString(int value); + static QString intModuleTypeToString(int value); static AbstractStaticItemModel * potTypeItemModel(); static AbstractStaticItemModel * sliderTypeItemModel(); static AbstractStaticItemModel * switchTypeItemModel(); + static AbstractStaticItemModel * intModuleTypeItemModel(); static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board); static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board); diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index f7115cc46..bf334c63a 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -161,6 +161,7 @@ class GeneralSettings { int vBatMin; int vBatMax; int backlightMode; + unsigned int internalModule; // Introducted in EdgeTX 2.6 yaml only TrainerData trainer; unsigned int view; // main screen view // TODO enum bool disableThrottleWarning; diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 37bf5be4c..5b2a84192 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -23,6 +23,12 @@ #include "multiprotocols.h" #include "afhds3.h" #include "radiodataconversionstate.h" +#include "compounditemmodels.h" +#include "generalsettings.h" +#include "datahelpers.h" + +#include +#include void ModuleData::convert(RadioDataConversionState & cstate) { @@ -149,7 +155,7 @@ QString ModuleData::indexToString(int index, Firmware * fw) } // static -QString ModuleData::protocolToString(unsigned protocol) +QString ModuleData::protocolToString(unsigned int protocol) { static const char * strings[] = { "OFF", @@ -262,3 +268,274 @@ int ModuleData::getMaxChannelCount() } return 8; } + +/* + If Companion did not combine the /radio/src/datastructs type and sub-type fields + this would be so much cleaner and, modules and protocols generally easier to maintain + Another case for refactoring ModuleData as a whole! +*/ + +// static +int ModuleData::getTypeFromProtocol(unsigned int protocol) +{ + const QVector>ProtocolTypeTable = { + + { PULSES_OFF, MODULE_TYPE_NONE }, + { PULSES_PPM, MODULE_TYPE_PPM }, + + { PULSES_PXX_XJT_X16, MODULE_TYPE_XJT_PXX1 }, + { PULSES_PXX_XJT_D8, MODULE_TYPE_XJT_PXX1 }, + { PULSES_PXX_XJT_LR12, MODULE_TYPE_XJT_PXX1 }, + + { PULSES_ACCESS_ISRM, MODULE_TYPE_ISRM_PXX2 }, + { PULSES_ACCST_ISRM_D16, MODULE_TYPE_ISRM_PXX2 }, + + { PULSES_LP45, MODULE_TYPE_DSM2 }, + { PULSES_DSM2, MODULE_TYPE_DSM2 }, + { PULSES_DSMX, MODULE_TYPE_DSM2 }, + + { PULSES_CROSSFIRE, MODULE_TYPE_CROSSFIRE }, + { PULSES_MULTIMODULE, MODULE_TYPE_MULTIMODULE }, + { PULSES_PXX_R9M, MODULE_TYPE_R9M_PXX1 }, + { PULSES_ACCESS_R9M, MODULE_TYPE_R9M_PXX2 }, + { PULSES_PXX_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX1 }, + { PULSES_ACCESS_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX2 }, + { PULSES_GHOST, MODULE_TYPE_GHOST }, + { PULSES_ACCESS_R9M_LITE_PRO, MODULE_TYPE_R9M_LITE_PRO_PXX2 }, + { PULSES_SBUS, MODULE_TYPE_SBUS }, + + { PULSES_XJT_LITE_X16, MODULE_TYPE_XJT_LITE_PXX2 }, + { PULSES_XJT_LITE_D8, MODULE_TYPE_XJT_LITE_PXX2 }, + { PULSES_XJT_LITE_LR12, MODULE_TYPE_XJT_LITE_PXX2 }, + + { PULSES_AFHDS3, MODULE_TYPE_FLYSKY } + }; + + QPairelmt; + + foreach (elmt, ProtocolTypeTable) { + if (elmt.first == (int)protocol) + return elmt.second; + } + + return -1; +} + +// static +int ModuleData::getSubTypeFromProtocol(unsigned int protocol) +{ + if (protocol == PULSES_ACCST_ISRM_D16 || protocol == PULSES_ACCESS_ISRM) + return protocol - PULSES_ACCESS_ISRM; + else if (protocol >= PULSES_PXX_XJT_X16 && protocol <= PULSES_PXX_XJT_LR12) + return protocol - PULSES_PXX_XJT_X16; + else + return 0; +} + +// static +QString ModuleData::typeToString(int type) +{ + static const char * strings[] = { + "OFF", + "PPM", + "FrSky XJT", + "ISRM", + "DSM2", + "TBS Crossfire", + "DIY Multiprotocol Module", + "FrSky R9M", + "FrSky R9M ACCESS", + "FrSky R9MLite", + "FrSky R9ML ACCESS", + "ImmersionRC Ghost", + "FrSky R9MLP ACCESS", + "SBUS output at VBat", + "FrSky XJT Lite", + "FlySky" + }; + + return CHECK_IN_ARRAY(strings, type); +} + +// static +bool ModuleData::isInternalModuleAvailable(int moduleType) +{ + if (moduleType == MODULE_TYPE_NONE) + return true; + + Firmware *fw = getCurrentFirmware(); + Board::Type board = fw->getBoard(); + QString id = fw->getId(); + + if (!Boards::getCapability(board, Board::HasInternalModuleSupport)) + return false; + + //=================================== + // TODO: this is not finished!!!!!!! + //=================================== + + switch(moduleType) { + case MODULE_TYPE_MULTIMODULE: + return id.contains("internalmulti") || IS_RADIOMASTER_TX16S(board) || IS_JUMPER_T18(board) || IS_RADIOMASTER_TX12(board) || IS_JUMPER_TLITE(board); + break; + case MODULE_TYPE_CROSSFIRE: + break; + case MODULE_TYPE_XJT_PXX1: + if(IS_TARANIS(board)) + return true; + break; + case MODULE_TYPE_ISRM_PXX2: + if(IS_ACCESS_RADIO(board, id)) + return true; + break; + case MODULE_TYPE_PPM: + break; + case MODULE_TYPE_FLYSKY: + if (IS_FLYSKY_NV14(board)) + return true; + break; + default: + return false; + } + + return false; +} + +// static +AbstractStaticItemModel * ModuleData::internalModuleItemModel() +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.internalmodule"); + + for (int i = 0; i < MODULE_TYPE_COUNT; i++) { + mdl->appendToItemList(typeToString(i), i, isInternalModuleAvailable(i)); + } + + mdl->loadItemList(); + return mdl; +} + +// static +bool ModuleData::isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & settings) +{ + if (protocol == PULSES_OFF) + return true; + + Firmware *fw = getCurrentFirmware(); + Board::Type board = fw->getBoard(); + + if (moduleidx == 0 && Boards::getCapability(board, Board::HasInternalModuleSupport)) + return (int)settings.internalModule == getTypeFromProtocol(protocol); + + QString id = fw->getId(); + + if (IS_HORUS_OR_TARANIS(board)) { + switch (moduleidx) { + case 1: + switch (protocol) { + case PULSES_OFF: + case PULSES_PPM: + return true; + case PULSES_PXX_XJT_X16: + case PULSES_PXX_XJT_D8: + case PULSES_PXX_XJT_LR12: + return !(IS_TARANIS_XLITES(board) || IS_TARANIS_X9LITE(board)); + case PULSES_PXX_R9M: + case PULSES_LP45: + case PULSES_DSM2: + case PULSES_DSMX: + case PULSES_SBUS: + case PULSES_MULTIMODULE: + case PULSES_CROSSFIRE: + case PULSES_AFHDS3: + case PULSES_GHOST: + return true; + case PULSES_ACCESS_R9M: + return IS_ACCESS_RADIO(board, id) || (IS_FAMILY_HORUS_OR_T16(board) && id.contains("externalaccessmod")); + case PULSES_PXX_R9M_LITE: + case PULSES_ACCESS_R9M_LITE: + case PULSES_ACCESS_R9M_LITE_PRO: + case PULSES_XJT_LITE_X16: + case PULSES_XJT_LITE_D8: + case PULSES_XJT_LITE_LR12: + return (IS_TARANIS_XLITE(board) || IS_TARANIS_X9LITE(board) || IS_JUMPER_TLITE(board)); + default: + return false; + } + + case -1: + switch (protocol) { + case PULSES_PPM: + return true; + default: + return false; + } + + default: + return false; + } + } + else if (IS_SKY9X(board)) { + switch (moduleidx) { + case 0: + switch (protocol) { + case PULSES_PPM: + case PULSES_PXX_XJT_X16: + case PULSES_PXX_XJT_D8: + case PULSES_PXX_XJT_LR12: + case PULSES_PXX_R9M: + case PULSES_LP45: + case PULSES_DSM2: + case PULSES_DSMX: + case PULSES_SBUS: + case PULSES_MULTIMODULE: + return true; + default: + return false; + } + break; + case 1: + switch (protocol) { + case PULSES_PPM: + return true; + default: + return false; + } + break; + default: + return false; + } + } + else { + switch (protocol) { + case PULSES_PPM: + case PULSES_DSMX: + case PULSES_LP45: + case PULSES_DSM2: + // case PULSES_PXX_DJT: // Unavailable for now + case PULSES_PPM16: + case PULSES_PPMSIM: + return true; + default: + return false; + } + } + + return false; // to avoid compiler warning +} + +// static +AbstractStaticItemModel * ModuleData::protocolItemModel(GeneralSettings & settings) +{ + AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); + mdl->setName("moduledata.protocol"); + + for (int i = 0; i <= 1; i++) { + for (unsigned int j = 0; j < PULSES_PROTOCOL_LAST; j++) { + mdl->appendToItemList(protocolToString(j), j, isProtocolAvailable(i, j, settings), 0, i + 1/*flag cannot be 0*/); + } + } + + mdl->loadItemList(); + return mdl; +} diff --git a/companion/src/firmwares/moduledata.h b/companion/src/firmwares/moduledata.h index 04e936758..49dc594c8 100644 --- a/companion/src/firmwares/moduledata.h +++ b/companion/src/firmwares/moduledata.h @@ -18,8 +18,7 @@ * GNU General Public License for more details. */ -#ifndef MODULEDATA_H -#define MODULEDATA_H +#pragma once #include "constants.h" @@ -27,6 +26,30 @@ class Firmware; class RadioDataConversionState; +class AbstractStaticItemModel; +class GeneralSettings; + +// from radio/src/pulses/module_constants.h +enum ModuleType { + MODULE_TYPE_NONE = 0, + MODULE_TYPE_PPM, + MODULE_TYPE_XJT_PXX1, + MODULE_TYPE_ISRM_PXX2, + MODULE_TYPE_DSM2, + MODULE_TYPE_CROSSFIRE, + MODULE_TYPE_MULTIMODULE, + MODULE_TYPE_R9M_PXX1, // R9M + MODULE_TYPE_R9M_PXX2, // R9M ACCESS + MODULE_TYPE_R9M_LITE_PXX1, //R9MLite + MODULE_TYPE_R9M_LITE_PXX2, //R9MLP + MODULE_TYPE_GHOST, // Replaces MODULE_TYPE_R9M_LITE_PRO_PXX1 which doesn't exist + MODULE_TYPE_R9M_LITE_PRO_PXX2, + MODULE_TYPE_SBUS, + MODULE_TYPE_XJT_LITE_PXX2, + MODULE_TYPE_FLYSKY, //no more protocols possible because of 4 bits value + MODULE_TYPE_COUNT, + MODULE_TYPE_MAX = MODULE_TYPE_COUNT - 1 +}; enum PulsesProtocol { PULSES_OFF, @@ -219,10 +242,15 @@ class ModuleData { QString subTypeToString(int type = -1) const; QString powerValueToString(Firmware * fw) const; static QString indexToString(int index, Firmware * fw); - static QString protocolToString(unsigned protocol); + static QString protocolToString(unsigned int protocol); static QStringList powerValueStrings(enum PulsesProtocol protocol, int subType, Firmware * fw); bool hasFailsafes(Firmware * fw) const; int getMaxChannelCount(); + static int getTypeFromProtocol(unsigned int protocol); + static int getSubTypeFromProtocol(unsigned int protocol); + static QString typeToString(int type); + static bool isInternalModuleAvailable(int type); + static AbstractStaticItemModel * internalModuleItemModel(); + static bool isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & settings); + static AbstractStaticItemModel * protocolItemModel(GeneralSettings & settings); }; - -#endif // MODULEDATA_H diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 69a2a6de4..95e4d1284 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -33,6 +33,7 @@ constexpr char FIM_SWITCHTYPE2POS[] {"Switch Type 2 Pos"}; constexpr char FIM_SWITCHTYPE3POS[] {"Switch Type 3 Pos"}; +constexpr char FIM_INTERNALMODULES[] {"Internal Modules"}; HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * sharedItemModels): GeneralPanel(parent, generalSettings, firmware), @@ -52,6 +53,9 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings int auxmodelid = editorItemModels->registerItemModel(GeneralSettings::auxSerialModeItemModel()); int baudmodelid = editorItemModels->registerItemModel(GeneralSettings::telemetryBaudrateItemModel()); + id = editorItemModels->registerItemModel(ModuleData::internalModuleItemModel()); + tabFilteredModels->registerItemModel(new FilteredItemModel(editorItemModels->getItemModel(id)), FIM_INTERNALMODULES); + grid = new QGridLayout(this); int count; int row = 0; @@ -127,6 +131,22 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings addParams(row, antennaMode); } + if (Boards::getCapability(board, Board::HasInternalModuleSupport)) { + addLabel(tr("Internal module"), row, 0); + AutoComboBox *internalModule = new AutoComboBox(this); + internalModule->setModel(tabFilteredModels->getItemModel(FIM_INTERNALMODULES)); + internalModule->setField(generalSettings.internalModule, this); + addParams(row, internalModule); + } + + if (firmware->getCapability(HasTelemetryBaudrate)) { + addLabel(tr("Maximum Baud"), row, 0); + AutoComboBox *maxBaudRate = new AutoComboBox(this); + maxBaudRate->setModel(editorItemModels->getItemModel(baudmodelid)); + maxBaudRate->setField(generalSettings.telemetryBaudrate, this); + addParams(row, maxBaudRate); + } + if (firmware->getCapability(HasAuxSerialMode)) { QString lbl = "Serial Port"; if (IS_RADIOMASTER_TX16S(board)) @@ -163,14 +183,6 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings addParams(row, sportPower); } - if (firmware->getCapability(HasTelemetryBaudrate)) { - addLabel(tr("Maximum Baud"), row, 0); - AutoComboBox *maxBaudRate = new AutoComboBox(this); - maxBaudRate->setModel(editorItemModels->getItemModel(baudmodelid)); - maxBaudRate->setField(generalSettings.telemetryBaudrate, this); - addParams(row, maxBaudRate); - } - if (firmware->getCapability(HastxCurrentCalibration)) { addLabel(tr("Current Offset"), row, 0); AutoSpinBox *txCurrentCalibration = new AutoSpinBox(this); diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index c611aa1f5..b838fc4b0 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -237,14 +237,12 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul ui->trainerMode->hide(); } - // The protocols available on this board - for (unsigned int i = 0; i < PULSES_PROTOCOL_LAST; i++) { - if (firmware->isAvailable((PulsesProtocol) i, moduleIdx)) { - ui->protocol->addItem(ModuleData::protocolToString(i), i); - if (i == module.protocol) - ui->protocol->setCurrentIndex(ui->protocol->count() - 1); - } + if (panelFilteredItemModels && moduleIdx >= 0) { + int id = panelFilteredItemModels->registerItemModel(new FilteredItemModel(ModuleData::protocolItemModel(generalSettings), moduleIdx + 1/*flag cannot be 0*/), QString("Module Protocol %1").arg(moduleIdx)); + ui->protocol->setModel(panelFilteredItemModels->getItemModel(id)); + ui->protocol->setField(module.protocol, this); } + for (int i = 0; i <= MODULE_SUBTYPE_MULTI_LAST; i++) { if (i == MODULE_SUBTYPE_MULTI_SCANNER) continue; @@ -266,7 +264,7 @@ ModulePanel::ModulePanel(QWidget * parent, ModelData & model, ModuleData & modul update(); - connect(ui->protocol, static_cast(&QComboBox::currentIndexChanged), this, &ModulePanel::onProtocolChanged); + connect(ui->protocol, &AutoComboBox::currentDataChanged, this, &ModulePanel::onProtocolChanged); connect(ui->multiSubType, static_cast(&QComboBox::currentIndexChanged), this, &ModulePanel::onSubTypeChanged); connect(ui->multiProtocol, static_cast(&QComboBox::currentIndexChanged), this, &ModulePanel::onMultiProtocolChanged); connect(this, &ModulePanel::channelsRangeChanged, this, &ModulePanel::setupFailsafes); @@ -662,8 +660,7 @@ void ModulePanel::update() void ModulePanel::onProtocolChanged(int index) { - if (!lock && module.protocol != ui->protocol->itemData(index).toUInt()) { - module.protocol = ui->protocol->itemData(index).toInt(); + if (!lock) { module.channelsCount = module.getMaxChannelCount(); update(); emit updateItemModels(); @@ -1391,7 +1388,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge // ui->functionSwitchesLayout->hide(); for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) { - modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i); + modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i, panelFilteredModels); ui->modulesLayout->addWidget(modules[i]); connect(modules[i], &ModulePanel::modified, this, &SetupPanel::modified); connect(modules[i], &ModulePanel::updateItemModels, this, &SetupPanel::onModuleUpdateItemModels); diff --git a/companion/src/modeledit/setup_module.ui b/companion/src/modeledit/setup_module.ui index f78bd2772..4689f6a8d 100644 --- a/companion/src/modeledit/setup_module.ui +++ b/companion/src/modeledit/setup_module.ui @@ -805,7 +805,7 @@ - + 0 From a719b2429fed26d4b7e099be3458d74ad71f5737 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 16:28:43 +0100 Subject: [PATCH 170/180] Fixed condition for supported internal module feature --- companion/src/firmwares/boards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 0378b95c7..55790b85a 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -490,7 +490,7 @@ int Boards::getCapability(Board::Type board, Board::Capability capability) return IS_STM32(board); case HasInternalModuleSupport: - return (IS_STM32(board) && !IS_TARANIS_SMALL(board)); + return (IS_STM32(board) && !IS_TARANIS_X9(board)); default: return 0; From 1c823120e4d126200c9d055b36fef308f478c7ce Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 16:29:58 +0100 Subject: [PATCH 171/180] Use a list of supported internal modules rather than a module by module test --- companion/src/firmwares/boards.cpp | 62 ++++++++++++++++++++++++++ companion/src/firmwares/boards.h | 23 ++++++++-- companion/src/firmwares/moduledata.cpp | 5 ++- 3 files changed, 84 insertions(+), 6 deletions(-) diff --git a/companion/src/firmwares/boards.cpp b/companion/src/firmwares/boards.cpp index 55790b85a..cf508533b 100644 --- a/companion/src/firmwares/boards.cpp +++ b/companion/src/firmwares/boards.cpp @@ -21,6 +21,7 @@ #include "boards.h" #include "macros.h" #include "compounditemmodels.h" +#include "moduledata.h" // TODO remove all those constants // Update: These are now all only used within this class. @@ -808,3 +809,64 @@ StringTagMappingTable Boards::getTrimSourcesLookupTable(Board::Type board) return tbl; } + +QList Boards::getSupportedInternalModules(Board::Type board) +{ + QList modules; + if (IS_TARANIS_X9DP_2019(board) || IS_TARANIS_X7_ACCESS(board)) { + modules = {MODULE_TYPE_ISRM_PXX2}; + } else if (IS_FLYSKY_NV14(board)) { + modules = {MODULE_TYPE_FLYSKY}; + } else if (IS_FAMILY_HORUS_OR_T16(board) || IS_FAMILY_T12(board) + || (IS_TARANIS_SMALL(board) && IS_ACCESS_RADIO(board))) { + modules.append({ + MODULE_TYPE_XJT_PXX1, + MODULE_TYPE_ISRM_PXX2, + MODULE_TYPE_CROSSFIRE, + MODULE_TYPE_MULTIMODULE, + }); + } else if (IS_TARANIS(board)) { + modules = {MODULE_TYPE_XJT_PXX1}; + } + + return modules; +} + +ModuleType Boards::getDefaultInternalModules(Board::Type board) +{ + switch(board) { + case BOARD_TARANIS_X7: + case BOARD_TARANIS_X9D: + case BOARD_TARANIS_X9DP: + case BOARD_TARANIS_X9E: + case BOARD_HORUS_X12S: + case BOARD_X10: + case BOARD_TARANIS_XLITE: + return MODULE_TYPE_XJT_PXX1; + + case BOARD_TARANIS_X7_ACCESS: + case BOARD_TARANIS_X9DP_2019: + case BOARD_X10_EXPRESS: + case BOARD_TARANIS_XLITES: + case BOARD_TARANIS_X9LITE: + case BOARD_TARANIS_X9LITES: + return MODULE_TYPE_ISRM_PXX2; + + case BOARD_JUMPER_T12: + case BOARD_JUMPER_T16: + case BOARD_RADIOMASTER_TX16S: + case BOARD_JUMPER_T18: + case BOARD_RADIOMASTER_TX12: + case BOARD_RADIOMASTER_T8: + case BOARD_JUMPER_TLITE: + case BOARD_RADIOMASTER_ZORRO: + case BOARD_JUMPER_TPRO: + return MODULE_TYPE_MULTIMODULE; + + case BOARD_FLYSKY_NV14: + return MODULE_TYPE_FLYSKY; + + default: + return MODULE_TYPE_NONE; + } +} diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index 844ea7502..07b8b572a 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -20,6 +20,7 @@ #pragma once #include "datahelpers.h" +#include "moduledata.h" #include #include @@ -219,7 +220,9 @@ class Boards static AbstractStaticItemModel * intModuleTypeItemModel(); static StringTagMappingTable getTrimSwitchesLookupTable(Board::Type board); static StringTagMappingTable getTrimSourcesLookupTable(Board::Type board); - + static QList getSupportedInternalModules(Board::Type board); + static ModuleType getDefaultInternalModules(Board::Type board); + protected: Board::Type m_boardType; @@ -291,7 +294,12 @@ inline bool IS_FAMILY_T16(Board::Type board) inline bool IS_FAMILY_T12(Board::Type board) { - return board == Board::BOARD_JUMPER_T12 || board == Board::BOARD_RADIOMASTER_TX12 || board == Board::BOARD_RADIOMASTER_ZORRO || board == Board::BOARD_RADIOMASTER_T8 || board == Board::BOARD_JUMPER_TLITE; + return board == Board::BOARD_JUMPER_T12 || + board == Board::BOARD_RADIOMASTER_TX12 || + board == Board::BOARD_RADIOMASTER_ZORRO || + board == Board::BOARD_RADIOMASTER_T8 || + board == Board::BOARD_JUMPER_TLITE || + board == Board::BOARD_JUMPER_TPRO; } inline bool IS_FLYSKY_NV14(Board::Type board) @@ -409,10 +417,17 @@ inline bool IS_TARANIS_X9DP_2019(Board::Type board) return (board == Board::BOARD_TARANIS_X9DP_2019); } +inline bool IS_ACCESS_RADIO(Board::Type board) +{ + return IS_TARANIS_XLITES(board) || IS_TARANIS_X9LITE(board) || + board == Board::BOARD_TARANIS_X9DP_2019 || + board == Board::BOARD_X10_EXPRESS || IS_TARANIS_X7_ACCESS(board); +} + inline bool IS_ACCESS_RADIO(Board::Type board, const QString & id) { - return (IS_TARANIS_XLITES(board) || IS_TARANIS_X9LITE(board) || board == Board::BOARD_TARANIS_X9DP_2019 || board == Board::BOARD_X10_EXPRESS || IS_TARANIS_X7_ACCESS(board) || - (IS_FAMILY_HORUS_OR_T16(board) && id.contains("internalaccess"))); + return IS_ACCESS_RADIO(board) || + (IS_FAMILY_HORUS_OR_T16(board) && id.contains("internalaccess")); } inline bool HAS_EEPROM_YAML(Board::Type board) diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 5b2a84192..940e2eb73 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -407,8 +407,9 @@ AbstractStaticItemModel * ModuleData::internalModuleItemModel() AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); mdl->setName("moduledata.internalmodule"); - for (int i = 0; i < MODULE_TYPE_COUNT; i++) { - mdl->appendToItemList(typeToString(i), i, isInternalModuleAvailable(i)); + auto modules = Boards::getSupportedInternalModules(getCurrentBoard()); + for(auto mod : modules) { + mdl->appendToItemList(typeToString(mod), mod); } mdl->loadItemList(); From 8a936af8f41b5b337f0ce22ae73fdb0bd25a108a Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 16:30:17 +0100 Subject: [PATCH 172/180] Add YAML support for internal module setting --- .../firmwares/edgetx/yaml_generalsettings.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 6eb7b6a51..d5c5ddaea 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -23,6 +23,7 @@ #include "yaml_trainerdata.h" #include "yaml_calibdata.h" #include "yaml_switchconfig.h" +#include "yaml_moduledata.h" #include "eeprominterface.h" #include "edgetxinterface.h" @@ -74,6 +75,25 @@ const YamlLookupTable antennaModeLut = { { GeneralSettings::ANTENNA_MODE_INTERNAL_EXTERNAL, "MODE_INTERNAL_EXTERNAL" }, }; +const YamlLookupTable internalModuleLut = { + { MODULE_TYPE_NONE, "TYPE_NONE" }, + { MODULE_TYPE_PPM, "TYPE_PPM" }, + { MODULE_TYPE_XJT_PXX1, "TYPE_XJT_PXX1" }, + { MODULE_TYPE_ISRM_PXX2, "TYPE_ISRM_PXX2" }, + { MODULE_TYPE_DSM2, "TYPE_DSM2" }, + { MODULE_TYPE_CROSSFIRE, "TYPE_CROSSFIRE" }, + { MODULE_TYPE_MULTIMODULE, "TYPE_MULTIMODULE" }, + { MODULE_TYPE_R9M_PXX1, "TYPE_R9M_PXX1" }, + { MODULE_TYPE_R9M_PXX2, "TYPE_R9M_PXX2" }, + { MODULE_TYPE_R9M_LITE_PXX1, "TYPE_R9M_LITE_PXX1" }, + { MODULE_TYPE_R9M_LITE_PXX2, "TYPE_R9M_LITE_PXX2" }, + { MODULE_TYPE_GHOST, "TYPE_GHOST" }, + { MODULE_TYPE_R9M_LITE_PRO_PXX2, "TYPE_R9M_LITE_PRO_PXX2" }, + { MODULE_TYPE_SBUS, "TYPE_SBUS" }, + { MODULE_TYPE_XJT_LITE_PXX2, "TYPE_XJT_LITE_PXX2" }, + { MODULE_TYPE_FLYSKY, "TYPE_FLYSKY" }, +}; + namespace YAML { @@ -116,6 +136,7 @@ Node convert::encode(const GeneralSettings& rhs) node["adjustRTC"] = (int)rhs.adjustRTC; node["inactivityTimer"] = rhs.inactivityTimer; node["telemetryBaudrate"] = rhs.telemetryBaudrate; // TODO: conversion??? + node["internalModule"] = LookupValue(internalModuleLut, rhs.internalModule); node["splashMode"] = rhs.splashMode; // TODO: B&W only node["lightAutoOff"] = rhs.backlightDelay; node["templateSetup"] = rhs.templateSetup; @@ -266,6 +287,13 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) node["adjustRTC"] >> rhs.adjustRTC; node["inactivityTimer"] >> rhs.inactivityTimer; node["telemetryBaudrate"] >> rhs.telemetryBaudrate; // TODO: conversion??? + + if (node["internalModule"]) { + node["internalModule"] >> internalModuleLut >> rhs.internalModule; + } else { + rhs.internalModule = Boards::getDefaultInternalModules(fw->getBoard()); + } + node["splashMode"] >> rhs.splashMode; // TODO: B&W only node["lightAutoOff"] >> rhs.backlightDelay; node["templateSetup"] >> rhs.templateSetup; From 5495eac12afcaa4ddd0511deacc29d85256dc23c Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 1 Jan 2022 16:36:51 +0100 Subject: [PATCH 173/180] Set default internal module in general settings --- companion/src/firmwares/generalsettings.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index c5b09e76f..c7b307a14 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -245,6 +245,9 @@ GeneralSettings::GeneralSettings() } } + // TODO: add a preset in the radio profile + internalModule = Boards::getDefaultInternalModules(board); + const char * themeName = IS_FLYSKY_NV14(board) ? "FlySky" : "EdgeTX"; RadioTheme::init(themeName, themeData); } From 5f5d3a4e1a0f9ca9c4bbd82c9a8d1db179c941cb Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 07:25:05 +1100 Subject: [PATCH 174/180] Mirror module type description --- companion/src/firmwares/moduledata.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 940e2eb73..520d0e9c1 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -338,20 +338,20 @@ QString ModuleData::typeToString(int type) static const char * strings[] = { "OFF", "PPM", - "FrSky XJT", + "XJT", "ISRM", "DSM2", - "TBS Crossfire", - "DIY Multiprotocol Module", - "FrSky R9M", - "FrSky R9M ACCESS", - "FrSky R9MLite", - "FrSky R9ML ACCESS", - "ImmersionRC Ghost", - "FrSky R9MLP ACCESS", - "SBUS output at VBat", - "FrSky XJT Lite", - "FlySky" + "CRSF", + "MULTI", + "R9M", + "R9M ACCESS", + "R9MLite", + "R9ML ACCESS", + "GHST", + "R9MLP ACCESS", + "SBUS", + "XJT Lite", + "FLYSKY" }; return CHECK_IN_ARRAY(strings, type); From 926dfdd035de8ab8d95d5438cf62a7b7e4a38131 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 07:37:36 +1100 Subject: [PATCH 175/180] Remove unused code --- companion/src/firmwares/moduledata.cpp | 91 +++++++------------------- companion/src/firmwares/moduledata.h | 1 - 2 files changed, 24 insertions(+), 68 deletions(-) diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 520d0e9c1..5c191e464 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -278,37 +278,39 @@ int ModuleData::getMaxChannelCount() // static int ModuleData::getTypeFromProtocol(unsigned int protocol) { + // must be kept in sync with opentxeeprom.h ProtocolsConversionTable + const QVector>ProtocolTypeTable = { - { PULSES_OFF, MODULE_TYPE_NONE }, - { PULSES_PPM, MODULE_TYPE_PPM }, + { PULSES_OFF, MODULE_TYPE_NONE }, + { PULSES_PPM, MODULE_TYPE_PPM }, - { PULSES_PXX_XJT_X16, MODULE_TYPE_XJT_PXX1 }, - { PULSES_PXX_XJT_D8, MODULE_TYPE_XJT_PXX1 }, - { PULSES_PXX_XJT_LR12, MODULE_TYPE_XJT_PXX1 }, + { PULSES_PXX_XJT_X16, MODULE_TYPE_XJT_PXX1 }, + { PULSES_PXX_XJT_D8, MODULE_TYPE_XJT_PXX1 }, + { PULSES_PXX_XJT_LR12, MODULE_TYPE_XJT_PXX1 }, - { PULSES_ACCESS_ISRM, MODULE_TYPE_ISRM_PXX2 }, - { PULSES_ACCST_ISRM_D16, MODULE_TYPE_ISRM_PXX2 }, + { PULSES_ACCESS_ISRM, MODULE_TYPE_ISRM_PXX2 }, + { PULSES_ACCST_ISRM_D16, MODULE_TYPE_ISRM_PXX2 }, - { PULSES_LP45, MODULE_TYPE_DSM2 }, - { PULSES_DSM2, MODULE_TYPE_DSM2 }, - { PULSES_DSMX, MODULE_TYPE_DSM2 }, + { PULSES_LP45, MODULE_TYPE_DSM2 }, + { PULSES_DSM2, MODULE_TYPE_DSM2 }, + { PULSES_DSMX, MODULE_TYPE_DSM2 }, - { PULSES_CROSSFIRE, MODULE_TYPE_CROSSFIRE }, - { PULSES_MULTIMODULE, MODULE_TYPE_MULTIMODULE }, - { PULSES_PXX_R9M, MODULE_TYPE_R9M_PXX1 }, - { PULSES_ACCESS_R9M, MODULE_TYPE_R9M_PXX2 }, - { PULSES_PXX_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX1 }, - { PULSES_ACCESS_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX2 }, - { PULSES_GHOST, MODULE_TYPE_GHOST }, + { PULSES_CROSSFIRE, MODULE_TYPE_CROSSFIRE }, + { PULSES_MULTIMODULE, MODULE_TYPE_MULTIMODULE }, + { PULSES_PXX_R9M, MODULE_TYPE_R9M_PXX1 }, + { PULSES_ACCESS_R9M, MODULE_TYPE_R9M_PXX2 }, + { PULSES_PXX_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX1 }, + { PULSES_ACCESS_R9M_LITE, MODULE_TYPE_R9M_LITE_PXX2 }, + { PULSES_GHOST, MODULE_TYPE_GHOST }, { PULSES_ACCESS_R9M_LITE_PRO, MODULE_TYPE_R9M_LITE_PRO_PXX2 }, - { PULSES_SBUS, MODULE_TYPE_SBUS }, + { PULSES_SBUS, MODULE_TYPE_SBUS }, - { PULSES_XJT_LITE_X16, MODULE_TYPE_XJT_LITE_PXX2 }, - { PULSES_XJT_LITE_D8, MODULE_TYPE_XJT_LITE_PXX2 }, - { PULSES_XJT_LITE_LR12, MODULE_TYPE_XJT_LITE_PXX2 }, + { PULSES_XJT_LITE_X16, MODULE_TYPE_XJT_LITE_PXX2 }, + { PULSES_XJT_LITE_D8, MODULE_TYPE_XJT_LITE_PXX2 }, + { PULSES_XJT_LITE_LR12, MODULE_TYPE_XJT_LITE_PXX2 }, - { PULSES_AFHDS3, MODULE_TYPE_FLYSKY } + { PULSES_AFHDS3, MODULE_TYPE_FLYSKY } }; QPairelmt; @@ -357,51 +359,6 @@ QString ModuleData::typeToString(int type) return CHECK_IN_ARRAY(strings, type); } -// static -bool ModuleData::isInternalModuleAvailable(int moduleType) -{ - if (moduleType == MODULE_TYPE_NONE) - return true; - - Firmware *fw = getCurrentFirmware(); - Board::Type board = fw->getBoard(); - QString id = fw->getId(); - - if (!Boards::getCapability(board, Board::HasInternalModuleSupport)) - return false; - - //=================================== - // TODO: this is not finished!!!!!!! - //=================================== - - switch(moduleType) { - case MODULE_TYPE_MULTIMODULE: - return id.contains("internalmulti") || IS_RADIOMASTER_TX16S(board) || IS_JUMPER_T18(board) || IS_RADIOMASTER_TX12(board) || IS_JUMPER_TLITE(board); - break; - case MODULE_TYPE_CROSSFIRE: - break; - case MODULE_TYPE_XJT_PXX1: - if(IS_TARANIS(board)) - return true; - break; - case MODULE_TYPE_ISRM_PXX2: - if(IS_ACCESS_RADIO(board, id)) - return true; - break; - case MODULE_TYPE_PPM: - break; - case MODULE_TYPE_FLYSKY: - if (IS_FLYSKY_NV14(board)) - return true; - break; - default: - return false; - } - - return false; -} - -// static AbstractStaticItemModel * ModuleData::internalModuleItemModel() { AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); diff --git a/companion/src/firmwares/moduledata.h b/companion/src/firmwares/moduledata.h index 49dc594c8..af0ff5a70 100644 --- a/companion/src/firmwares/moduledata.h +++ b/companion/src/firmwares/moduledata.h @@ -249,7 +249,6 @@ class ModuleData { static int getTypeFromProtocol(unsigned int protocol); static int getSubTypeFromProtocol(unsigned int protocol); static QString typeToString(int type); - static bool isInternalModuleAvailable(int type); static AbstractStaticItemModel * internalModuleItemModel(); static bool isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & settings); static AbstractStaticItemModel * protocolItemModel(GeneralSettings & settings); From 592f173a94e907dc58a9296711f8ca9c9bd2e550 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 07:58:28 +1100 Subject: [PATCH 176/180] Some more generic protocol names --- companion/src/firmwares/moduledata.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 5c191e464..167fc83e1 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -165,8 +165,8 @@ QString ModuleData::protocolToString(unsigned int protocol) "LP45", "DSM2", "DSMX", "PPM16", "PPMsim", "FrSky XJT (D16)", "FrSky XJT (D8)", "FrSky XJT (LR12)", "FrSky DJT", - "TBS Crossfire", - "DIY Multiprotocol Module", + "Crossfire", + "Multi", "FrSky R9M", "FrSky R9M Lite", "FrSky R9M Lite Pro", @@ -177,7 +177,7 @@ QString ModuleData::protocolToString(unsigned int protocol) "FrSky ACCESS R9M Lite Pro", "FrSky XJT lite (D16)", "FrSky XJT lite (D8)", "FrSky XJT lite (LR12)", "AFHDS3", - "ImmersionRC Ghost" + "Ghost" }; return CHECK_IN_ARRAY(strings, protocol); From e728560a45801567d9bd4527593c6bdda7ec097a Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 08:54:48 +1100 Subject: [PATCH 177/180] Add default internal module to radio profile --- companion/src/apppreferencesdialog.cpp | 7 + companion/src/apppreferencesdialog.ui | 736 +++++++++++++------------ companion/src/storage/appdata.h | 1 + 3 files changed, 381 insertions(+), 363 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 99f0bb90f..2a676e667 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -28,6 +28,10 @@ #include "joystick.h" #include "joystickdialog.h" #endif +#include "moduledata.h" +#include "compounditemmodels.h" + +#include AppPreferencesDialog::AppPreferencesDialog(QWidget * parent) : QDialog(parent), @@ -97,6 +101,7 @@ void AppPreferencesDialog::accept() g.jsSupport(false); g.jsCtrl(0); } + profile.defaultInternalModule(ui->defaultInternalModuleCB->currentData().toInt()); profile.channelOrder(ui->channelorderCB->currentIndex()); profile.defaultMode(ui->stickmodeCB->currentIndex()); profile.renameFwFiles(ui->renameFirmware->isChecked()); @@ -256,6 +261,8 @@ void AppPreferencesDialog::initSettings() } #endif // Profile Tab Inits + ui->defaultInternalModuleCB->setModel(ModuleData::internalModuleItemModel()); + ui->defaultInternalModuleCB->setCurrentIndex(ui->defaultInternalModuleCB->findData(profile.defaultInternalModule())); ui->channelorderCB->setCurrentIndex(profile.channelOrder()); ui->stickmodeCB->setCurrentIndex(profile.defaultMode()); ui->renameFirmware->setChecked(profile.renameFwFiles()); diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index a3156efa3..888d6d1c6 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -51,178 +51,21 @@ Radio Profile - - - + + + - - 0 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 5 - - - 4 - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 6 - - - - - - 0 - 0 - - - - - 75 - true - - - - Splash Screen - - - - - - - true - - - true - - - - - - - Select Image - - - - - - - - 0 - 0 - - - - - 128 - 64 - - - - - 212 - 64 - - - - QFrame::StyledPanel - - - QFrame::Plain - - - 1 - - - - - - true - - - - - - - Clear Image - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - - - - + 0 0 - Offer to write FW to Tx after download + Default Stick Mode - - - - - 0 - 0 - - - - Qt::Horizontal - - - - + @@ -358,88 +201,27 @@ - - - - true + + + + If set it will override the application general setting + + + false - - - - - 0 - 0 - - - - Build Options - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - + + 0 0 - - Append version number to FW file name - - - - - Select Folder - - - - - - - - 0 - 0 - - - - - 75 - true - - - - Profile Name - - - - - - - - - - - 0 - 0 - - - - The profile specific folder, if set, will override general Backup folder - - - Backup folder - - - - + true @@ -455,39 +237,17 @@ - - - - - 0 - 0 - - - - - 75 - true - + + + + The profile specific folder, if set, will override general Backup folder - Other Settings + Select Folder - - - - - 0 - 0 - - - - Default Stick Mode - - - - + @@ -541,61 +301,61 @@ Mode 4: - - - - - 0 - 0 - + + + + true - Default Channel Order - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - if set, will override general backup enable - - - Enable automatic backup before writing firmware - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - If set it will override the application general setting + false + + + + + + + true + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Profile Name + + + + + + + + 0 + 0 + + + + Append version number to FW file name + + + @@ -612,16 +372,6 @@ Mode 4: - - - - The profile specific folder, if set, will override general Backup folder - - - Select Folder - - - @@ -635,6 +385,136 @@ Mode 4: + + + + + 0 + 0 + + + + The profile specific folder, if set, will override general Backup folder + + + Backup folder + + + + + + + + 0 + 0 + + + + Default Channel Order + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Default Int. Module + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Offer to write FW to Tx after download + + + + + + + + 0 + 0 + + + + Build Options + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + Menu Language + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Select Folder + + + + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + @@ -658,58 +538,188 @@ Mode 4: - - - - - 0 - 0 - - - - Menu Language - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - true - - - - - - false - - - - - - - Qt::Vertical - - - - 20 - 5 - - - - - - + + 0 0 + + if set, will override general backup enable + + + Enable automatic backup before writing firmware + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + + 0 + 0 + + + + + 75 + true + + + + Splash Screen + + + + + + + true + + + true + + + + + + + Select Image + + + + + + + + 0 + 0 + + + + + 128 + 64 + + + + + 212 + 64 + + + + QFrame::StyledPanel + + + QFrame::Plain + + + 1 + + + + + + true + + + + + + + Clear Image + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 5 + + + 4 + + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Other Settings + + + + + + diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 9741aa96d..53ffb71d9 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -380,6 +380,7 @@ class Profile: public CompStoreObj PROPERTYSTR(sdPath) PROPERTYSTR(pBackupDir) + PROPERTY (int, defaultInternalModule, 0) PROPERTY4(int, channelOrder, "default_channel_order", 0) PROPERTY4(int, defaultMode, "default_mode", 1) PROPERTY (int, volumeGain, 10) From 2797f7d9764ada1b35b0cca2c20680daccf9118a Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 09:00:01 +1100 Subject: [PATCH 178/180] Use profile default internal module for new radio files --- companion/src/firmwares/generalsettings.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index c7b307a14..729c57b93 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -245,9 +245,8 @@ GeneralSettings::GeneralSettings() } } - // TODO: add a preset in the radio profile - internalModule = Boards::getDefaultInternalModules(board); - + internalModule = g.profile[g.sessionId()].defaultInternalModule(); + const char * themeName = IS_FLYSKY_NV14(board) ? "FlySky" : "EdgeTX"; RadioTheme::init(themeName, themeData); } From 417c7f12472d89de971a21fe6b6afebd66d53462 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 09:11:36 +1100 Subject: [PATCH 179/180] Prompt to check all models when harwdare setting changed --- companion/src/generaledit/hardware.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 95e4d1284..c084607b4 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -137,6 +137,10 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings internalModule->setModel(tabFilteredModels->getItemModel(FIM_INTERNALMODULES)); internalModule->setField(generalSettings.internalModule, this); addParams(row, internalModule); + connect(internalModule, &AutoComboBox::currentDataChanged, this, [=] () { + QMessageBox::warning(this, CPN_STR_APP_NAME, + tr("ALERT: Check each model's internal module protocol to ensure it is compatible!")); + }); } if (firmware->getCapability(HasTelemetryBaudrate)) { From 2a13dba41199965c7082b60fcb2be5ff86dacf68 Mon Sep 17 00:00:00 2001 From: elecpower Date: Sun, 2 Jan 2022 11:19:04 +1100 Subject: [PATCH 180/180] Set default internal module in profile --- companion/src/apppreferencesdialog.cpp | 6 ++++++ companion/src/firmwares/moduledata.cpp | 5 ++--- companion/src/firmwares/moduledata.h | 2 +- companion/src/mainwindow.cpp | 6 ++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 2a676e667..a89082cb2 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -460,6 +460,12 @@ void AppPreferencesDialog::on_clearImageButton_clicked() void AppPreferencesDialog::onBaseFirmwareChanged() { populateFirmwareOptions(getBaseFirmware()); + + Firmware *newfw = getFirmwareVariant(); + Profile & profile = g.currentProfile(); + profile.defaultInternalModule(Boards::getDefaultInternalModules(newfw->getBoard())); + ui->defaultInternalModuleCB->setModel(ModuleData::internalModuleItemModel(newfw->getBoard())); + ui->defaultInternalModuleCB->setCurrentIndex(ui->defaultInternalModuleCB->findData(profile.defaultInternalModule())); } Firmware *AppPreferencesDialog::getBaseFirmware() const diff --git a/companion/src/firmwares/moduledata.cpp b/companion/src/firmwares/moduledata.cpp index 167fc83e1..25bb5aec9 100644 --- a/companion/src/firmwares/moduledata.cpp +++ b/companion/src/firmwares/moduledata.cpp @@ -25,7 +25,6 @@ #include "radiodataconversionstate.h" #include "compounditemmodels.h" #include "generalsettings.h" -#include "datahelpers.h" #include #include @@ -359,12 +358,12 @@ QString ModuleData::typeToString(int type) return CHECK_IN_ARRAY(strings, type); } -AbstractStaticItemModel * ModuleData::internalModuleItemModel() +AbstractStaticItemModel * ModuleData::internalModuleItemModel(int board) { AbstractStaticItemModel * mdl = new AbstractStaticItemModel(); mdl->setName("moduledata.internalmodule"); - auto modules = Boards::getSupportedInternalModules(getCurrentBoard()); + auto modules = Boards::getSupportedInternalModules(board == Board::BOARD_UNKNOWN ? getCurrentBoard() : (Board::Type)board); for(auto mod : modules) { mdl->appendToItemList(typeToString(mod), mod); } diff --git a/companion/src/firmwares/moduledata.h b/companion/src/firmwares/moduledata.h index af0ff5a70..b1606f0d5 100644 --- a/companion/src/firmwares/moduledata.h +++ b/companion/src/firmwares/moduledata.h @@ -249,7 +249,7 @@ class ModuleData { static int getTypeFromProtocol(unsigned int protocol); static int getSubTypeFromProtocol(unsigned int protocol); static QString typeToString(int type); - static AbstractStaticItemModel * internalModuleItemModel(); + static AbstractStaticItemModel * internalModuleItemModel(int board = -1); static bool isProtocolAvailable(int moduleidx, unsigned int protocol, GeneralSettings & settings); static AbstractStaticItemModel * protocolItemModel(GeneralSettings & settings); }; diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 085b1b3fe..dab9309e1 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -1626,9 +1626,11 @@ int MainWindow::newProfile(bool loadProfile) if (i == MAX_PROFILES) //Failed to find free slot return -1; + Firmware *newfw = Firmware::getDefaultVariant(); g.profile[i].init(); - g.profile[i].name(tr("New Radio")); - g.profile[i].fwType(Firmware::getDefaultVariant()->getId()); + g.profile[i].name("New Radio"); + g.profile[i].fwType(newfw->getId()); + g.profile[i].defaultInternalModule(Boards::getDefaultInternalModules(newfw->getBoard())); if (loadProfile) { if (loadProfileId(i))