From f5b398b32ce0b0cdfb4258d40dae55622625e8b2 Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 9 Dec 2021 23:05:14 +1100 Subject: [PATCH] Add function switches to model print and compare --- companion/src/firmwares/modeldata.cpp | 16 ++++----- companion/src/firmwares/modeldata.h | 8 ++--- companion/src/multimodelprinter.cpp | 52 +++++++++++++++++++++++++++ companion/src/multimodelprinter.h | 1 + 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/companion/src/firmwares/modeldata.cpp b/companion/src/firmwares/modeldata.cpp index 2fd3c9ce4..64e8879d6 100644 --- a/companion/src/firmwares/modeldata.cpp +++ b/companion/src/firmwares/modeldata.cpp @@ -1654,16 +1654,16 @@ AbstractStaticItemModel * ModelData::trainerModeItemModel(const GeneralSettings return mdl; } -QString ModelData::funcSwitchConfigToString(unsigned int index) const +QString ModelData::funcSwitchConfigToString(const int index) const { if (index < CPN_MAX_FUNCTION_SWITCHES) - return funcSwitchConfigToString((functionSwitchConfig >> (2 * index)) & 0x03); + return funcSwitchConfigToString(index, (int)(functionSwitchConfig >> (2 * index)) & 0x03); else return CPN_STR_UNKNOWN_ITEM; } // static -QString ModelData::funcSwitchConfigToString(int value) +QString ModelData::funcSwitchConfigToString(const int index, const int value) { switch (value) { case FUNC_SWITCH_CONFIG_NONE: @@ -1684,23 +1684,23 @@ AbstractStaticItemModel * ModelData::funcSwitchConfigItemModel() mdl->setName(AIM_MODELDATA_FUNCSWITCHCONFIG); for (int i = FUNC_SWITCH_CONFIG_FIRST; i <= FUNC_SWITCH_CONFIG_LAST; i++) { - mdl->appendToItemList(funcSwitchConfigToString(i), i); + mdl->appendToItemList(funcSwitchConfigToString(0, i), i); } mdl->loadItemList(); return mdl; } -QString ModelData::funcSwitchStartToString(unsigned int index) const +QString ModelData::funcSwitchStartToString(const int index) const { if (index < CPN_MAX_FUNCTION_SWITCHES) - return funcSwitchStartToString((functionSwitchStartConfig >> (2 * index)) & 0x03); + return funcSwitchStartToString(index, (int)(functionSwitchStartConfig >> (2 * index)) & 0x03); else return CPN_STR_UNKNOWN_ITEM; } // static -QString ModelData::funcSwitchStartToString(int value) +QString ModelData::funcSwitchStartToString(const int index, const int value) { switch (value) { case FUNC_SWITCH_START_INACTIVE: @@ -1721,7 +1721,7 @@ AbstractStaticItemModel * ModelData::funcSwitchStartItemModel() mdl->setName(AIM_MODELDATA_FUNCSWITCHSTART); for (int i = FUNC_SWITCH_START_FIRST; i <= FUNC_SWITCH_START_LAST; i++) { - mdl->appendToItemList(funcSwitchStartToString(i), i); + mdl->appendToItemList(funcSwitchStartToString(0, i), i); } mdl->loadItemList(); diff --git a/companion/src/firmwares/modeldata.h b/companion/src/firmwares/modeldata.h index 2be1a7ff4..6a1443c12 100644 --- a/companion/src/firmwares/modeldata.h +++ b/companion/src/firmwares/modeldata.h @@ -286,11 +286,11 @@ class ModelData { static QString trainerModeToString(const int value); static bool isTrainerModeAvailable(const GeneralSettings & generalSettings, const Firmware * firmware, const int value); static AbstractStaticItemModel * trainerModeItemModel(const GeneralSettings & generalSettings, const Firmware * firmware); - QString funcSwitchConfigToString(unsigned int index) const; - static QString funcSwitchConfigToString(const int value); + QString funcSwitchConfigToString(const int index) const; + static QString funcSwitchConfigToString(const int index, const int value); static AbstractStaticItemModel * funcSwitchConfigItemModel(); - QString funcSwitchStartToString(unsigned int index) const; - static QString funcSwitchStartToString(const int value); + QString funcSwitchStartToString(const int index) const; + static QString funcSwitchStartToString(const int index, const int value); static AbstractStaticItemModel * funcSwitchStartItemModel(); protected: diff --git a/companion/src/multimodelprinter.cpp b/companion/src/multimodelprinter.cpp index 1cf0140e3..8c38776e5 100644 --- a/companion/src/multimodelprinter.cpp +++ b/companion/src/multimodelprinter.cpp @@ -277,6 +277,9 @@ QString MultiModelPrinter::print(QTextDocument * document) if (firmware->getCapability(Timers)) { str.append(printTimers()); } + if (Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches)) { + str.append(printFunctionSwitches()); + } str.append(printModules()); if (firmware->getCapability(Heli)) str.append(printHeliSetup()); @@ -938,3 +941,52 @@ QString MultiModelPrinter::printChecklist() } return str; } + +QString MultiModelPrinter::printFunctionSwitches() +{ + QString str; + MultiColumns columns(modelPrinterMap.size()); + columns.appendSectionTableStart(); + + int numFS = Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches); + int colwidth = 80 / numFS; + + QStringList headings = { tr("Function Switches") }; + for (int i = 0; i < numFS; i++) { + headings << tr("Switch %1").arg(i + 1); + } + columns.appendRowHeader(headings); + + columns.appendRowStart(tr("Name"), 20); + + for (int i = 0; i < numFS; i++) { + COMPARECELLWIDTH(model->functionSwitchNames[i], colwidth); + } + + columns.appendRowEnd(); + columns.appendRowStart(tr("Type"), 20); + + for (int i = 0; i < numFS; i++) { + COMPARECELLWIDTH(model->funcSwitchConfigToString((unsigned int)i), colwidth); + } + + columns.appendRowEnd(); + columns.appendRowStart(tr("Start"), 20); + + for (int i = 0; i < numFS; i++) { + COMPARECELLWIDTH(model->funcSwitchStartToString((unsigned int)i), colwidth); + } + + columns.appendRowEnd(); + columns.appendRowStart(tr("Group"), 20); + + for (int i = 0; i < numFS; i++) { + COMPARECELLWIDTH((model->functionSwitchGroup >> (2 * i)) & 0x03, colwidth); + } + + columns.appendRowEnd(); + + columns.appendTableEnd(); + str.append(columns.print()); + return str; +} diff --git a/companion/src/multimodelprinter.h b/companion/src/multimodelprinter.h index 4214bc45b..8cc48642c 100644 --- a/companion/src/multimodelprinter.h +++ b/companion/src/multimodelprinter.h @@ -95,6 +95,7 @@ class MultiModelPrinter: public QObject QString printTelemetryScreens(); QString printGlobalFunctions(); QString printChecklist(); + QString printFunctionSwitches(); }; #endif // _MULTIMODELPRINTER_H_