From 57aafeb0627c6e7c3a8e110f0451499a96bac448 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 24 Jan 2017 20:08:48 +0100 Subject: [PATCH] [Companion] Refactoring - fixes the X9E=>X7 conversion segfault --- companion/src/CMakeLists.txt | 1 + companion/src/boards.cpp | 97 ++++++++++++++++ companion/src/boards.h | 106 ++++++++++++++++++ companion/src/constants.h | 17 --- companion/src/eepromimportexport.h | 2 - companion/src/eeprominterface.cpp | 42 ++----- companion/src/eeprominterface.h | 43 ------- .../src/firmwares/opentx/opentxeeprom.cpp | 12 +- .../src/firmwares/opentx/opentxinterface.cpp | 45 -------- .../src/firmwares/opentx/opentxinterface.h | 2 - companion/src/generaledit/hardware.cpp | 23 ++-- companion/src/helpers.cpp | 4 +- companion/src/macros.h | 26 +++++ companion/src/modeledit/setup.cpp | 14 +-- companion/src/radiodata.h | 22 +--- companion/src/simulation/simulatordialog.cpp | 12 +- companion/src/simulation/simulatorinterface.h | 1 + .../src/simulation/widgets/radioknobwidget.h | 15 +-- .../simulation/widgets/radioswitchwidget.h | 13 +-- 19 files changed, 289 insertions(+), 208 deletions(-) create mode 100644 companion/src/boards.cpp create mode 100644 companion/src/boards.h create mode 100644 companion/src/macros.h diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 66dd94f2f..32e5c47fd 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -112,6 +112,7 @@ add_subdirectory(thirdparty/qxtcommandoptions) ############# Common lib ############### set(common_SRCS + boards.cpp eeprominterface.cpp radiodata.cpp firmwares/er9x/er9xeeprom.cpp diff --git a/companion/src/boards.cpp b/companion/src/boards.cpp new file mode 100644 index 000000000..00db08bbb --- /dev/null +++ b/companion/src/boards.cpp @@ -0,0 +1,97 @@ +/* + * 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 "boards.h" +#include "macros.h" + +int getEEpromSize(BoardEnum board) +{ + switch (board) { + case BOARD_STOCK: + return EESIZE_STOCK; + case BOARD_M128: + return EESIZE_M128; + case BOARD_MEGA2560: + case BOARD_GRUVIN9X: + return EESIZE_GRUVIN9X; + case BOARD_SKY9X: + return EESIZE_SKY9X; + case BOARD_9XRPRO: + case BOARD_AR9X: + return EESIZE_9XRPRO; + case BOARD_TARANIS_X7: + case BOARD_TARANIS_X9D: + case BOARD_TARANIS_X9DP: + case BOARD_TARANIS_X9E: + case BOARD_FLAMENCO: + return EESIZE_TARANIS; + default: + return 0; // unlimited + } +} + +SwitchInfo getSwitchInfo(BoardEnum board, unsigned index) +{ + if (IS_TARANIS_X7(board)) { + const SwitchInfo switches[] = {{SWITCH_3POS, "SA"}, + {SWITCH_3POS, "SB"}, + {SWITCH_3POS, "SC"}, + {SWITCH_3POS, "SD"}, + {SWITCH_2POS, "SF"}, + {SWITCH_TOGGLE, "SH"}}; + if (index < DIM(switches)) + return switches[index]; + } + else if (IS_HORUS_OR_TARANIS(board)) { + const SwitchInfo switches[] = {{SWITCH_3POS, "SA"}, + {SWITCH_3POS, "SB"}, + {SWITCH_3POS, "SC"}, + {SWITCH_3POS, "SD"}, + {SWITCH_3POS, "SE"}, + {SWITCH_2POS, "SF"}, + {SWITCH_3POS, "SG"}, + {SWITCH_TOGGLE, "SH"}, + {SWITCH_3POS, "SI"}, + {SWITCH_3POS, "SJ"}, + {SWITCH_3POS, "SK"}, + {SWITCH_3POS, "SL"}, + {SWITCH_3POS, "SM"}, + {SWITCH_3POS, "SN"}, + {SWITCH_3POS, "SO"}, + {SWITCH_3POS, "SP"}, + {SWITCH_3POS, "SQ"}, + {SWITCH_3POS, "SR"}}; + if (index < DIM(switches)) + return switches[index]; + } + else { + const SwitchInfo switches[] = {{SWITCH_2POS, "THR"}, + {SWITCH_2POS, "RUD"}, + {SWITCH_2POS, "ELE"}, + {SWITCH_3POS, "3POS"}, + {SWITCH_2POS, "AIL"}, + {SWITCH_2POS, "GEA"}, + {SWITCH_TOGGLE, "TRN"}}; + if (index < DIM(switches)) + return switches[index]; + } + + return {SWITCH_NOT_AVAILABLE, "???"}; +} \ No newline at end of file diff --git a/companion/src/boards.h b/companion/src/boards.h new file mode 100644 index 000000000..2c94f1170 --- /dev/null +++ b/companion/src/boards.h @@ -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. + */ + +#ifndef _BOARDS_H_ +#define _BOARDS_H_ + +// TODO create a Board class with all these functions + +enum BoardEnum { + BOARD_STOCK, + BOARD_M128, + BOARD_MEGA2560, + BOARD_GRUVIN9X, + BOARD_SKY9X, + BOARD_9XRPRO, + BOARD_AR9X, + BOARD_TARANIS_X7, + BOARD_TARANIS_X9D, + BOARD_TARANIS_X9DP, + BOARD_TARANIS_X9E, + BOARD_FLAMENCO, + BOARD_HORUS, + BOARD_UNKNOWN = -1 +}; + +enum PotConfig { + POT_NONE, + POT_WITH_DETENT, + POT_MULTIPOS_SWITCH, + POT_WITHOUT_DETENT +}; + +enum SliderConfig { + SLIDER_NONE, + SLIDER_WITH_DETENT +}; + +enum SwitchConfig { + SWITCH_NOT_AVAILABLE, + SWITCH_TOGGLE, + SWITCH_2POS, + SWITCH_3POS +}; + +struct SwitchInfo { + SwitchConfig config; + const char * name; +}; + +// TODO remove all those constants +#define EESIZE_STOCK 2048 +#define EESIZE_M128 4096 +#define EESIZE_GRUVIN9X 4096 +#define EESIZE_TARANIS (32*1024) +#define EESIZE_SKY9X (128*4096) +#define EESIZE_9XRPRO (128*4096) +#define EESIZE_MAX EESIZE_9XRPRO + +// TODO remove all those constants +#define FSIZE_STOCK (64*1024) +#define FSIZE_M128 (128*1024) +#define FSIZE_GRUVIN9X (256*1024) +#define FSIZE_TARANIS (512*1024) +#define FSIZE_SKY9X (256*1024) +#define FSIZE_9XRPRO (512*1024) +#define FSIZE_HORUS (2048*1024) +#define FSIZE_MAX FSIZE_HORUS + +int getEEpromSize(BoardEnum board); +SwitchInfo getSwitchInfo(BoardEnum board, unsigned index); + +#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128) +#define IS_STOCK(board) (board==BOARD_STOCK) +#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560) +#define IS_SKY9X(board) (board==BOARD_SKY9X || board==BOARD_9XRPRO || board==BOARD_AR9X) +#define IS_9XRPRO(board) (board==BOARD_9XRPRO) +#define IS_TARANIS_X7(board) (board==BOARD_TARANIS_X7) +#define IS_TARANIS_X9(board) (board==BOARD_TARANIS_X9D || board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E) +#define IS_TARANIS_PLUS(board) (board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E) +#define IS_TARANIS_X9E(board) (board==BOARD_TARANIS_X9E) +#define IS_TARANIS(board) (IS_TARANIS_X9(board) || IS_TARANIS_X7(board)) +#define IS_HORUS(board) (board==BOARD_HORUS) +#define IS_HORUS_OR_TARANIS(board) (IS_HORUS(board) || IS_TARANIS(board)) +#define IS_FLAMENCO(board) (board==BOARD_FLAMENCO) +#define IS_STM32(board) (IS_TARANIS(board) || IS_HORUS(board) || IS_FLAMENCO(board)) +#define IS_ARM(board) (IS_STM32(board) || IS_SKY9X(board)) +#define HAS_LARGE_LCD(board) (IS_HORUS(board) || (IS_TARANIS(board) && !IS_TARANIS_X7(board))) + +#endif // _BOARDS_H_ diff --git a/companion/src/constants.h b/companion/src/constants.h index 1b36b416c..55638d5db 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -21,23 +21,6 @@ #ifndef _CONSTANTS_H_ #define _CONSTANTS_H_ -enum BoardEnum { - BOARD_STOCK, - BOARD_M128, - BOARD_MEGA2560, - BOARD_GRUVIN9X, - BOARD_SKY9X, - BOARD_9XRPRO, - BOARD_AR9X, - BOARD_TARANIS_X7, - BOARD_TARANIS_X9D, - BOARD_TARANIS_X9DP, - BOARD_TARANIS_X9E, - BOARD_FLAMENCO, - BOARD_HORUS, - BOARD_UNKNOWN = -1 -}; - #define CPN_MAX_MODELS 60 #define CPN_MAX_TIMERS 3 #define CPN_MAX_FLIGHT_MODES 9 diff --git a/companion/src/eepromimportexport.h b/companion/src/eepromimportexport.h index 6555e1d22..3886a1eab 100644 --- a/companion/src/eepromimportexport.h +++ b/companion/src/eepromimportexport.h @@ -24,8 +24,6 @@ #include "customdebug.h" #include -#define DIM(arr) (sizeof((arr))/sizeof((arr)[0])) - class DataField { public: DataField(const char *name=""): diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 2996150f8..cd4b9a169 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -27,6 +27,7 @@ #include "helpers.h" #include "wizarddata.h" #include "firmwareinterface.h" +#include "macros.h" #include #include #include @@ -36,32 +37,6 @@ std::list EEPROMWarnings; -int getEEpromSize(BoardEnum board) -{ - switch (board) { - case BOARD_STOCK: - return EESIZE_STOCK; - case BOARD_M128: - return EESIZE_M128; - case BOARD_MEGA2560: - case BOARD_GRUVIN9X: - return EESIZE_GRUVIN9X; - case BOARD_SKY9X: - return EESIZE_SKY9X; - case BOARD_9XRPRO: - case BOARD_AR9X: - return EESIZE_9XRPRO; - case BOARD_TARANIS_X7: - case BOARD_TARANIS_X9D: - case BOARD_TARANIS_X9DP: - case BOARD_TARANIS_X9E: - case BOARD_FLAMENCO: - return EESIZE_TARANIS; - default: - return 0; // unlimited - } -} - const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second is relevant channel out 1,2,3,4 , 1,2,4,3 , 1,3,2,4 , 1,3,4,2 , 1,4,2,3 , 1,4,3,2, 2,1,3,4 , 2,1,4,3 , 2,3,1,4 , 2,3,4,1 , 2,4,1,3 , 2,4,3,1, @@ -575,7 +550,7 @@ QString RawSource::toString(const ModelData * model) const case SOURCE_TYPE_MAX: return QObject::tr("MAX"); case SOURCE_TYPE_SWITCH: - return getCurrentFirmware()->getSwitch(index).name; + return getSwitchInfo(getCurrentBoard(), index).name; case SOURCE_TYPE_CUSTOM_SWITCH: return QObject::tr("L%1").arg(index+1); case SOURCE_TYPE_CYC: @@ -617,8 +592,12 @@ bool RawSource::isSlider() const index < CPN_MAX_STICKS+getCurrentFirmware()->getCapability(Pots)+getCurrentFirmware()->getCapability(Sliders)); } -QString RawSwitch::toString() const +QString RawSwitch::toString(BoardEnum board) const { + if (board == BOARD_UNKNOWN) { + board = getCurrentBoard(); + } + static const QString switches9X[] = { QString("THR"), QString("RUD"), QString("ELE"), QString("ID0"), QString("ID1"), QString("ID2"), @@ -655,14 +634,13 @@ QString RawSwitch::toString() const return QString("!") + RawSwitch(type, -index).toString(); } else { - BoardEnum board = getCurrentBoard(); switch(type) { case SWITCH_TYPE_SWITCH: if (IS_HORUS_OR_TARANIS(board)) { div_t qr = div(index-1, 3); - Firmware::Switch sw = getCurrentFirmware()->getSwitch(qr.quot); + SwitchInfo switchInfo = getSwitchInfo(board, qr.quot); const char * positions[] = { ARROW_UP, "-", ARROW_DOWN }; - return QString(sw.name) + QString(positions[qr.rem]); + return QString(switchInfo.name) + QString(positions[qr.rem]); } else { return CHECK_IN_ARRAY(switches9X, index - 1); @@ -1097,7 +1075,7 @@ GeneralSettings::GeneralSettings() BoardEnum board = firmware->getBoard(); for (int i=0; igetCapability(FactoryInstalledSwitches); i++) { - switchConfig[i] = firmware->getSwitch(i).type; + switchConfig[i] = getSwitchInfo(board, i).config; } if (IS_HORUS(board)) { diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 5ba348219..511d5b125 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -29,40 +29,6 @@ #include #include -#define EESIZE_STOCK 2048 -#define EESIZE_M128 4096 -#define EESIZE_GRUVIN9X 4096 -#define EESIZE_TARANIS (32*1024) -#define EESIZE_SKY9X (128*4096) -#define EESIZE_9XRPRO (128*4096) -#define EESIZE_MAX EESIZE_9XRPRO - -#define FSIZE_STOCK (64*1024) -#define FSIZE_M128 (128*1024) -#define FSIZE_GRUVIN9X (256*1024) -#define FSIZE_TARANIS (512*1024) -#define FSIZE_SKY9X (256*1024) -#define FSIZE_9XRPRO (512*1024) -#define FSIZE_HORUS (2048*1024) -#define FSIZE_MAX FSIZE_HORUS - -#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128) -#define IS_STOCK(board) (board==BOARD_STOCK) -#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560) -#define IS_SKY9X(board) (board==BOARD_SKY9X || board==BOARD_9XRPRO || board==BOARD_AR9X) -#define IS_9XRPRO(board) (board==BOARD_9XRPRO) -#define IS_TARANIS_X7(board) (board==BOARD_TARANIS_X7) -#define IS_TARANIS_X9(board) (board==BOARD_TARANIS_X9D || board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E) -#define IS_TARANIS_PLUS(board) (board==BOARD_TARANIS_X9DP || board==BOARD_TARANIS_X9E) -#define IS_TARANIS_X9E(board) (board==BOARD_TARANIS_X9E) -#define IS_TARANIS(board) (IS_TARANIS_X9(board) || IS_TARANIS_X7(board)) -#define IS_HORUS(board) (board==BOARD_HORUS) -#define IS_HORUS_OR_TARANIS(board) (IS_HORUS(board) || IS_TARANIS(board)) -#define IS_FLAMENCO(board) (board==BOARD_FLAMENCO) -#define IS_STM32(board) (IS_TARANIS(board) || IS_HORUS(board) || IS_FLAMENCO(board)) -#define IS_ARM(board) (IS_STM32(board) || IS_SKY9X(board)) -#define HAS_LARGE_LCD(board) (IS_HORUS(board) || (IS_TARANIS(board) && board != BOARD_TARANIS_X7)) - QString RotaryEncoderString(int index); const uint8_t modn12x3[4][4]= { @@ -217,8 +183,6 @@ class EEPROMInterface }; -int getEEpromSize(BoardEnum board); - extern std::list EEPROMWarnings; /* EEPROM string conversion functions */ @@ -364,13 +328,6 @@ class Firmware { virtual int getCapability(Capability) = 0; - struct Switch { - GeneralSettings::SwitchConfig type; - const char * name; - }; - - virtual Switch getSwitch(unsigned int index) = 0; - virtual QString getAnalogInputName(unsigned int index) = 0; virtual QTime getMaxTimerStart() = 0; diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index e7adcf4f1..570db6931 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -416,9 +416,10 @@ class SwitchField: public ConversionField< SignedField > { public: SwitchField(RawSwitch & sw, BoardEnum board, unsigned int version, unsigned long flags=0): ConversionField< SignedField >(_switch, SwitchesConversionTable::getInstance(board, version, flags), QObject::tr("Switch").toLatin1(), - QObject::tr("Switch ").toLatin1()+ sw.toString()+ QObject::tr(" cannot be exported on this board!").toLatin1()), + QObject::tr("Switch ").toLatin1()+ sw.toString(board) + QObject::tr(" cannot be exported on this board!").toLatin1()), sw(sw), - _switch(0) + _switch(0), + board(board) { } @@ -436,12 +437,13 @@ class SwitchField: public ConversionField< SignedField > { { ConversionField< SignedField >::afterImport(); sw = RawSwitch(_switch); - eepromImportDebug() << QString("imported %1: %2").arg(ConversionField< SignedField >::internalField.getName()).arg(sw.toString()); + eepromImportDebug() << QString("imported %1: %2").arg(ConversionField< SignedField >::internalField.getName()).arg(sw.toString(board)); } protected: RawSwitch & sw; int _switch; + BoardEnum board; }; class TelemetrySourcesConversionTable: public ConversionTable { @@ -3814,7 +3816,7 @@ void OpenTxGeneralData::beforeExport() void OpenTxGeneralData::afterImport() { if (IS_TARANIS(board) && version < 217) { - generalData.potConfig[0] = GeneralSettings::POT_WITH_DETENT; - generalData.potConfig[1] = GeneralSettings::POT_WITH_DETENT; + generalData.potConfig[0] = POT_WITH_DETENT; + generalData.potConfig[1] = POT_WITH_DETENT; } } diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index efcaf790c..b1cd7d1ce 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -818,51 +818,6 @@ QString OpenTxFirmware::getAnalogInputName(unsigned int index) } } -Firmware::Switch OpenTxFirmware::getSwitch(unsigned int index) -{ - typedef GeneralSettings::SwitchConfig sc; - if (board == BOARD_TARANIS_X7) { - const Switch switches[] = {{sc::SWITCH_3POS, "SA"}, - {sc::SWITCH_3POS, "SB"}, - {sc::SWITCH_3POS, "SC"}, - {sc::SWITCH_3POS, "SD"}, - {sc::SWITCH_2POS, "SF"}, - {sc::SWITCH_TOGGLE, "SH"}}; - return switches[index]; - } - else if (IS_HORUS_OR_TARANIS(board)) { - const Switch switches[] = {{sc::SWITCH_3POS, "SA"}, - {sc::SWITCH_3POS, "SB"}, - {sc::SWITCH_3POS, "SC"}, - {sc::SWITCH_3POS, "SD"}, - {sc::SWITCH_3POS, "SE"}, - {sc::SWITCH_2POS, "SF"}, - {sc::SWITCH_3POS, "SG"}, - {sc::SWITCH_TOGGLE, "SH"}, - {sc::SWITCH_3POS, "SI"}, - {sc::SWITCH_3POS, "SJ"}, - {sc::SWITCH_3POS, "SK"}, - {sc::SWITCH_3POS, "SL"}, - {sc::SWITCH_3POS, "SM"}, - {sc::SWITCH_3POS, "SN"}, - {sc::SWITCH_3POS, "SO"}, - {sc::SWITCH_3POS, "SP"}, - {sc::SWITCH_3POS, "SQ"}, - {sc::SWITCH_3POS, "SR"}}; - return switches[index]; - } - else { - const Switch switches[] = {{sc::SWITCH_2POS, "THR"}, - {sc::SWITCH_2POS, "RUD"}, - {sc::SWITCH_2POS, "ELE"}, - {sc::SWITCH_3POS, "3POS"}, - {sc::SWITCH_2POS, "AIL"}, - {sc::SWITCH_2POS, "GEA"}, - {sc::SWITCH_TOGGLE, "TRN"}}; - return switches[index]; - } -} - QTime OpenTxFirmware::getMaxTimerStart() { if (IS_HORUS_OR_TARANIS(board)) diff --git a/companion/src/firmwares/opentx/opentxinterface.h b/companion/src/firmwares/opentx/opentxinterface.h index 978a51d1b..d892fb326 100644 --- a/companion/src/firmwares/opentx/opentxinterface.h +++ b/companion/src/firmwares/opentx/opentxinterface.h @@ -131,8 +131,6 @@ class OpenTxFirmware: public Firmware virtual int getCapability(Capability); - virtual Switch getSwitch(unsigned int index); - virtual QString getAnalogInputName(unsigned int index); virtual QTime getMaxTimerStart(); diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 4418c00bc..87e5dbcf1 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -24,11 +24,12 @@ void HardwarePanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true) { if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Switches)) { - type->addItem(tr("None"), GeneralSettings::SWITCH_NONE); - type->addItem(tr("2 Positions Toggle"), GeneralSettings::SWITCH_TOGGLE); - type->addItem(tr("2 Positions"), GeneralSettings::SWITCH_2POS); - if (threePos) - type->addItem(tr("3 Positions"), GeneralSettings::SWITCH_3POS); + type->addItem(tr("None"), SWITCH_NONE); + type->addItem(tr("2 Positions Toggle"), SWITCH_TOGGLE); + type->addItem(tr("2 Positions"), SWITCH_2POS); + if (threePos) { + type->addItem(tr("3 Positions"), SWITCH_3POS); + } name->setField(generalSettings.switchName[index], 3, this); type->setField(generalSettings.switchConfig[index], this); } @@ -43,10 +44,10 @@ void HardwarePanel::setupPotConfig(int index, QLabel *label, AutoLineEdit *name, { if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Pots)) { label->setText(RawSource(SOURCE_TYPE_STICK, CPN_MAX_STICKS+index).toString()); - type->addItem(tr("None"), GeneralSettings::POT_NONE); - type->addItem(tr("Pot with detent"), GeneralSettings::POT_WITH_DETENT); - type->addItem(tr("Multipos switch"), GeneralSettings::POT_MULTIPOS_SWITCH); - type->addItem(tr("Pot without detent"), GeneralSettings::POT_WITHOUT_DETENT); + type->addItem(tr("None"), POT_NONE); + type->addItem(tr("Pot with detent"), POT_WITH_DETENT); + type->addItem(tr("Multipos switch"), POT_MULTIPOS_SWITCH); + type->addItem(tr("Pot without detent"), POT_WITHOUT_DETENT); name->setField(generalSettings.potName[index], 3, this); type->setField(generalSettings.potConfig[index], this); } @@ -61,8 +62,8 @@ void HardwarePanel::setupSliderConfig(int index, QLabel *label, AutoLineEdit *na { if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Sliders)) { label->setText(RawSource(SOURCE_TYPE_STICK, CPN_MAX_STICKS+firmware->getCapability(Pots)+index).toString()); - type->addItem(tr("None"), GeneralSettings::SLIDER_NONE); - type->addItem(tr("Slider with detent"), GeneralSettings::SLIDER_WITH_DETENT); + type->addItem(tr("None"), SLIDER_NONE); + type->addItem(tr("Slider with detent"), SLIDER_WITH_DETENT); name->setField(generalSettings.sliderName[index], 3, this); type->setField(generalSettings.sliderConfig[index], this); } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index d81d52ae4..bb474af33 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -413,7 +413,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin } for (int i=getCurrentFirmware()->getCapability(MultiposPots)-1; i>=0; i--) { - if (generalSettings.potConfig[i] == GeneralSettings::POT_MULTIPOS_SWITCH) { + if (generalSettings.potConfig[i] == POT_MULTIPOS_SWITCH) { for (int j=-getCurrentFirmware()->getCapability(MultiposPotsPositions); j<0; j++) { item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, -i*getCurrentFirmware()->getCapability(MultiposPotsPositions)+j); b->addItem(item.toString(), item.toValue()); @@ -454,7 +454,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, const GeneralSettin } for (int i=0; igetCapability(MultiposPots); i++) { - if (generalSettings.potConfig[i] == GeneralSettings::POT_MULTIPOS_SWITCH) { + if (generalSettings.potConfig[i] == POT_MULTIPOS_SWITCH) { for (int j=1; j<=getCurrentFirmware()->getCapability(MultiposPotsPositions); j++) { item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i*getCurrentFirmware()->getCapability(MultiposPotsPositions)+j); b->addItem(item.toString(), item.toValue()); diff --git a/companion/src/macros.h b/companion/src/macros.h new file mode 100644 index 000000000..7ff39a753 --- /dev/null +++ b/companion/src/macros.h @@ -0,0 +1,26 @@ +/* + * 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 _MACROS_H_ +#define _MACROS_H_ + +#define DIM(arr) (sizeof((arr))/sizeof((arr)[0])) + +#endif // _MACROS_H_ \ No newline at end of file diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index b281d710e..067761094 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -709,11 +709,11 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge // Startup switches warnings for (int i=0; igetCapability(Switches); i++) { - Firmware::Switch sw = firmware->getSwitch(i); + SwitchInfo switchInfo = getSwitchInfo(board, i); if (IS_HORUS_OR_TARANIS(board)) { - sw.type = GeneralSettings::SwitchConfig(generalSettings.switchConfig[i]); + switchInfo.config = SwitchConfig(generalSettings.switchConfig[i]); } - if (sw.type == GeneralSettings::SWITCH_NONE || sw.type == GeneralSettings::SWITCH_TOGGLE) { + if (switchInfo.config == SWITCH_NOT_AVAILABLE || switchInfo.config == SWITCH_TOGGLE) { continue; } QLabel * label = new QLabel(this); @@ -729,8 +729,8 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge slider->setSingleStep(1); slider->setPageStep(1); slider->setTickInterval(1); - label->setText(sw.name); - slider->setMaximum(sw.type == GeneralSettings::SWITCH_3POS ? 2 : 1); + label->setText(switchInfo.name); + slider->setMaximum(switchInfo.config == SWITCH_3POS ? 2 : 1); cb->setProperty("index", i); ui->switchesStartupLayout->addWidget(label, 0, i+1); ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter); @@ -960,7 +960,7 @@ void SetupPanel::updateStartupSwitches() bool enabled = !(model->switchWarningEnable & (1 << index)); if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { value = (switchStates >> 2*index) & 0x03; - if (generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS && value == 2) { + if (generalSettings.switchConfig[index] != SWITCH_3POS && value == 2) { value = 1; } } @@ -999,7 +999,7 @@ void SetupPanel::startupSwitchEdited(int value) model->switchWarningStates &= ~mask; - if (IS_HORUS_OR_TARANIS(firmware->getBoard()) && generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS) { + if (IS_HORUS_OR_TARANIS(firmware->getBoard()) && generalSettings.switchConfig[index] != SWITCH_3POS) { if (value == 1) { value = 2; } diff --git a/companion/src/radiodata.h b/companion/src/radiodata.h index 83123785a..17df24fa0 100644 --- a/companion/src/radiodata.h +++ b/companion/src/radiodata.h @@ -1,6 +1,7 @@ #ifndef _RADIODATA_H_ #define _RADIODATA_H_ +#include "boards.h" #include "constants.h" #include #include @@ -289,7 +290,7 @@ class RawSwitch { return index >= 0 ? (type * 256 + index) : -(type * 256 - index); } - QString toString() const; + QString toString(BoardEnum board = BOARD_UNKNOWN) const; bool operator== ( const RawSwitch& other) { return (this->type == other.type) && (this->index == other.index); @@ -1128,25 +1129,6 @@ class GeneralSettings { BEEPER_ALL = 1 }; - enum PotConfig { - POT_NONE, - POT_WITH_DETENT, - POT_MULTIPOS_SWITCH, - POT_WITHOUT_DETENT - }; - - enum SliderConfig { - SLIDER_NONE, - SLIDER_WITH_DETENT - }; - - enum SwitchConfig { - SWITCH_NONE, - SWITCH_TOGGLE, - SWITCH_2POS, - SWITCH_3POS - }; - GeneralSettings(); void convert(BoardEnum before, BoardEnum after); diff --git a/companion/src/simulation/simulatordialog.cpp b/companion/src/simulation/simulatordialog.cpp index 52ba61a7b..43e4b7d67 100644 --- a/companion/src/simulation/simulatordialog.cpp +++ b/companion/src/simulation/simulatordialog.cpp @@ -334,17 +334,17 @@ void SimulatorDialog::setupRadioWidgets() // Now set up new widgets. // switches - Firmware::Switch swinfo; + SwitchInfo switchInfo; // FIXME : CPN_MAX_SWITCHES == 32 but GeneralSettings::switchConfig[18] !! for (i = 0; i < firmware->getCapability(Capability(Switches)) && i < 18 /*CPN_MAX_SWITCHES*/; ++i) { - if (radioSettings.switchConfig[i] == GeneralSettings::SWITCH_NONE) + if (radioSettings.switchConfig[i] == SWITCH_NONE) continue; if ((wname = QString(radioSettings.switchName[i])).isEmpty()) { - swinfo = firmware->getSwitch(i); - wname = QString(swinfo.name); + switchInfo = getSwitchInfo(board, i); + wname = QString(switchInfo.name); } - RadioSwitchWidget * sw = new RadioSwitchWidget(GeneralSettings::SwitchConfig(radioSettings.switchConfig[i]), wname, 0, ui->radioWidgetsHT); + RadioSwitchWidget * sw = new RadioSwitchWidget(SwitchConfig(radioSettings.switchConfig[i]), wname, 0, ui->radioWidgetsHT); sw->setIndex(i); ui->radioWidgetsHTLayout->addWidget(sw); switches.append(sw); @@ -361,7 +361,7 @@ void SimulatorDialog::setupRadioWidgets() if ((wname = QString(radioSettings.potName[i])).isEmpty()) wname = firmware->getAnalogInputName(4 + aIdx + i); - RadioKnobWidget * pot = new RadioKnobWidget(GeneralSettings::PotConfig(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT); + RadioKnobWidget * pot = new RadioKnobWidget(PotConfig(radioSettings.potConfig[i]), wname, 0, ui->radioWidgetsHT); pot->setIndex(aIdx + i); // FIXME : total hack here -- this needs to follow the exception in radio/src/mixer.cpp:evalInputs() if (i == 0 && IS_TARANIS(board) && !IS_TARANIS_X7(board)) diff --git a/companion/src/simulation/simulatorinterface.h b/companion/src/simulation/simulatorinterface.h index 5f1c20451..9f84557ec 100644 --- a/companion/src/simulation/simulatorinterface.h +++ b/companion/src/simulation/simulatorinterface.h @@ -21,6 +21,7 @@ #ifndef _SIMULATORINTERFACE_H_ #define _SIMULATORINTERFACE_H_ +#include "boards.h" #include "constants.h" #include #include diff --git a/companion/src/simulation/widgets/radioknobwidget.h b/companion/src/simulation/widgets/radioknobwidget.h index 6d3c5821f..b7637dc0a 100644 --- a/companion/src/simulation/widgets/radioknobwidget.h +++ b/companion/src/simulation/widgets/radioknobwidget.h @@ -35,15 +35,13 @@ class RadioKnobWidget : public RadioWidget public: - using potType_t = GeneralSettings::PotConfig; - - explicit RadioKnobWidget(potType_t type = potType_t::POT_WITH_DETENT, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + explicit RadioKnobWidget(PotConfig type = POT_WITH_DETENT, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : RadioWidget(parent, f), m_potType(type) { init(); } - explicit RadioKnobWidget(potType_t type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + explicit RadioKnobWidget(PotConfig type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : RadioWidget(labelText, value, parent, f), m_potType(type) { @@ -65,20 +63,19 @@ class RadioKnobWidget : public RadioWidget private: - potType_t m_potType; + PotConfig m_potType; class KnobWidget : public QDial { friend class RadioKnobWidget; - using potType_t = RadioKnobWidget::potType_t; public: - explicit KnobWidget(potType_t type, QWidget * parent = 0): + explicit KnobWidget(PotConfig type, QWidget * parent = 0): QDial(parent), m_type(type), - m_positions(type == potType_t::POT_MULTIPOS_SWITCH ? 5 : 0) + m_positions(type == POT_MULTIPOS_SWITCH ? 5 : 0) { setToolTip(tr("Right-double-click to reset to center.")); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -117,7 +114,7 @@ class RadioKnobWidget : public RadioWidget QDial::mousePressEvent(event); } - potType_t m_type; + PotConfig m_type; quint8 m_positions; }; diff --git a/companion/src/simulation/widgets/radioswitchwidget.h b/companion/src/simulation/widgets/radioswitchwidget.h index e4a6da625..929bd1eb5 100644 --- a/companion/src/simulation/widgets/radioswitchwidget.h +++ b/companion/src/simulation/widgets/radioswitchwidget.h @@ -32,17 +32,16 @@ class RadioSwitchWidget : public RadioWidget Q_OBJECT public: - typedef GeneralSettings::SwitchConfig swType_t; - explicit RadioSwitchWidget(swType_t type = swType_t::SWITCH_3POS, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + explicit RadioSwitchWidget(SwitchConfig type = SWITCH_3POS, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : RadioWidget(parent, f), - swType(type) + switchConfig(type) { init(); } - explicit RadioSwitchWidget(swType_t type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : + explicit RadioSwitchWidget(SwitchConfig type, const QString &labelText, int value = 0, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) : RadioWidget(labelText, value, parent, f), - swType(type) + switchConfig(type) { init(); } @@ -59,7 +58,7 @@ class RadioSwitchWidget : public RadioWidget sl->setInvertedControls(true); sl->setTickPosition(QSlider::TicksBothSides); sl->setPageStep(1); - sl->setMinimum((swType == swType_t::SWITCH_3POS ? -1 : 0)); + sl->setMinimum((switchConfig == SWITCH_3POS ? -1 : 0)); sl->setMaximum(1); sl->setTickInterval(1); sl->setValue(m_value); @@ -71,7 +70,7 @@ class RadioSwitchWidget : public RadioWidget } private: - swType_t swType; + SwitchConfig switchConfig; };