diff --git a/companion/src/boards.cpp b/companion/src/boards.cpp index d5d885b6a..2214e4c1d 100644 --- a/companion/src/boards.cpp +++ b/companion/src/boards.cpp @@ -211,6 +211,11 @@ const int Boards::getCapability(Board::Type board, Board::Capability capability) return 8; else return 7; + case SwitchPositions: + if (IS_HORUS_OR_TARANIS(board)) + return getCapability(board, Switches) * 3; + else + return 9; case NumTrims: if (IS_HORUS(board)) return 6; diff --git a/companion/src/boards.h b/companion/src/boards.h index d399b7a09..ce9e15695 100644 --- a/companion/src/boards.h +++ b/companion/src/boards.h @@ -111,6 +111,7 @@ namespace Board { Sliders, MouseAnalogs, Switches, + SwitchPositions, FactoryInstalledSwitches, NumTrims, NumTrimSwitches diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index ae8bad2bc..05cfb4c0d 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -134,27 +134,6 @@ int TimToVal(float value) return (temp-129); } -QString getSignedStr(int value) -{ - return value > 0 ? QString("+%1").arg(value) : QString("%1").arg(value); -} - -QString getGVarString(int16_t val, bool sign) -{ - if (val >= -10000 && val <= 10000) { - if (sign) - return QString("%1%").arg(getSignedStr(val)); - else - return QString("%1%").arg(val); - } - else { - if (val<0) - return QObject::tr("-GV%1").arg(-val-10000); - else - return QObject::tr("GV%1").arg(val-10000); - } -} - void SensorData::updateUnit() { if (type == TELEM_TYPE_CALCULATED) { @@ -494,17 +473,6 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting return result; } -QString RotaryEncoderString(int index) -{ - static const QString rotary[] = { QObject::tr("REa"), QObject::tr("REb") }; - return CHECK_IN_ARRAY(rotary, index); -} - - -/* - * RawSource - */ - QString RawSource::toString(const ModelData * model, const GeneralSettings * const generalSettings) const { static const QString trims[] = { @@ -530,6 +498,8 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con QObject::tr("ACC"), QObject::tr("GPS Time"), }; + static const QString rotary[] = { QObject::tr("REa"), QObject::tr("REb") }; + if (index<0) { return QObject::tr("----"); } @@ -539,8 +509,8 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con switch (type) { case SOURCE_TYPE_VIRTUAL_INPUT: result = QObject::tr("[I%1]").arg(index+1); - if (model) - result += QString(model->inputNames[index]); + if (model && model->inputNames[index][0]) + result.append(":" + QString(model->inputNames[index]).trimmed()); return result; case SOURCE_TYPE_LUA_OUTPUT: @@ -562,7 +532,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con case SOURCE_TYPE_TRIM: return CHECK_IN_ARRAY(trims, index); case SOURCE_TYPE_ROTARY_ENCODER: - return RotaryEncoderString(index); + return CHECK_IN_ARRAY(rotary, index); case SOURCE_TYPE_MAX: return QObject::tr("MAX"); @@ -574,7 +544,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con return result; case SOURCE_TYPE_CUSTOM_SWITCH: - return QObject::tr("L%1").arg(index+1); + return QObject::tr("LSw%1").arg(index+1, 2, 10, QChar('0')); case SOURCE_TYPE_CYC: return QObject::tr("CYC%1").arg(index+1); @@ -583,7 +553,10 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con return QObject::tr("TR%1").arg(index+1); case SOURCE_TYPE_CH: - return QObject::tr("CH%1").arg(index+1); + result = QObject::tr("CH%1").arg(index+1, 2, 10, QChar('0')); + if (getCurrentFirmware()->getCapability(ChannelsName) && model && model->limitData[index].name[0]) + result.append(":" + QString(model->limitData[index].name).trimmed()); + return result; case SOURCE_TYPE_SPECIAL: return CHECK_IN_ARRAY(special, index); @@ -601,7 +574,10 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con } case SOURCE_TYPE_GVAR: - return QObject::tr("GV%1").arg(index+1); + result = QObject::tr("GV%1").arg(index+1); + if (getCurrentFirmware()->getCapability(GvarsName) && model && model->gvars_names[index][0]) + result.append(":" + QString(model->gvars_names[index]).trimmed()); + return result; default: return QObject::tr("----"); @@ -706,7 +682,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen } case SWITCH_TYPE_VIRTUAL: - return QObject::tr("L%1").arg(index); + return QObject::tr("LSw%1").arg(index, 2, 10, QChar('0')); case SWITCH_TYPE_MULTIPOS_POT: if (!getCurrentFirmware()->getCapability(MultiposPotsPositions)) @@ -753,23 +729,48 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen * CurveReference */ -QString CurveReference::toString() const +QString CurveReference::toString(const ModelData * model, bool verbose) const { if (value == 0) { return "----"; } - else { - switch(type) { - case CURVE_REF_DIFF: - return QObject::tr("Diff(%1)").arg(getGVarString(value)); - case CURVE_REF_EXPO: - return QObject::tr("Expo(%1)").arg(getGVarString(value)); - case CURVE_REF_FUNC: - return QObject::tr("Function(%1)").arg(QString("x>0" "x<0" "|x|" "f>0" "f<0" "|f|").mid(3*(value-1), 3)); - default: - return QString(value > 0 ? QObject::tr("Curve(%1)") : QObject::tr("!Curve(%1)")).arg(abs(value)); - } + + QString ret; + unsigned idx = abs(value) - 1; + + switch(type) { + case CURVE_REF_DIFF: + ret = QObject::tr("Diff(%1)").arg(Helpers::getAdjustmentString(value, model)); + break; + + case CURVE_REF_EXPO: + ret = QObject::tr("Expo(%1)").arg(Helpers::getAdjustmentString(value, model)); + break; + + case CURVE_REF_FUNC: + ret = QString("x>0" "x<0" "|x|" "f>0" "f<0" "|f|").mid(3*(value-1), 3); + if (verbose) + ret = QObject::tr("Function(%1)").arg(ret); + break; + + default: + if (model) + ret = model->curves[idx].nameToString(idx); + else + ret = CurveData().nameToString(idx); + if (verbose) + ret = QObject::tr("Curve(%1)").arg(ret); + if (value < 0) + ret.prepend(CPN_STR_SW_INDICATOR_REV); + break; } + + return ret; +} + +bool LogicalSwitchData::isEmpty() const +{ + return (func == 0); } CSFunctionFamily LogicalSwitchData::getFunctionFamily() const @@ -856,10 +857,15 @@ void CustomFunctionData::clear() } } -QString CustomFunctionData::funcToString() const +bool CustomFunctionData::isEmpty() const +{ + return (swtch.type == SWITCH_TYPE_NONE); +} + +QString CustomFunctionData::funcToString(const ModelData * model) const { if (func >= FuncOverrideCH1 && func <= FuncOverrideCH32) - return QObject::tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString()); + return QObject::tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString(model)); else if (func == FuncTrainer) return QObject::tr("Trainer"); else if (func == FuncTrainerRUD) @@ -903,7 +909,7 @@ QString CustomFunctionData::funcToString() const else if (func == FuncBackgroundMusicPause) return QObject::tr("Background Music Pause"); else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) - return QObject::tr("Adjust GV%1").arg(func-FuncAdjustGV1+1); + return QObject::tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR, func-FuncAdjustGV1).toString(model)); else if (func == FuncSetFailsafeInternalModule) return QObject::tr("SetFailsafe Int. Module"); else if (func == FuncSetFailsafeExternalModule) @@ -1078,6 +1084,14 @@ bool CurveData::isEmpty() const return true; } +QString CurveData::nameToString(const int idx) const +{ + QString ret = QCoreApplication::translate("CurveData", "CV%1").arg(idx+1, 2, 10, QChar('0')); + if (name[0]) + ret.append(":" + QString(name).trimmed()); + return ret; +} + QString LimitData::minToString() const { return QString::number((qreal)min/10); @@ -1504,11 +1518,6 @@ void ModelData::clearMixes() mixData[i].clear(); } -RadioData::RadioData() -{ - models.resize(getCurrentFirmware()->getCapability(Models)); -} - void ModelData::clear() { memset(this, 0, sizeof(ModelData)); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 1857cf410..0674f29dc 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -30,8 +30,6 @@ #include #include -QString RotaryEncoderString(int index); - const uint8_t modn12x3[4][4]= { {1, 2, 3, 4}, {1, 3, 2, 4}, @@ -52,7 +50,6 @@ enum Capability { VoicesMaxLength, MultiLangVoice, ModelImage, - SwitchesPositions, CustomFunctions, SafetyChannelCustomFunction, LogicalSwitches, @@ -187,9 +184,6 @@ void getEEPROMString(char *dst, const char *src, int size); float ValToTim(int value); int TimToVal(float value); -QString getSignedStr(int value); -QString getGVarString(int16_t val, bool sign=false); - inline int applyStickMode(int stick, unsigned int mode) { if (mode == 0 || mode > 4) { diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 874cf46d3..c5e6bebf3 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -489,11 +489,6 @@ int OpenTxFirmware::getCapability(::Capability capability) return 0; case PermTimers: return (IS_2560(board) || IS_ARM(board)); - case SwitchesPositions: - if (IS_HORUS_OR_TARANIS(board)) - return getBoardCapability(board, Board::Switches) * 3; - else - return 9; case CustomFunctions: if (IS_ARM(board)) return 64; diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index db714a8da..3851e2a0c 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -21,7 +21,7 @@ #include "hardware.h" #include "ui_hardware.h" -void HardwarePanel::setupSwitchType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type, bool threePos = true) +void HardwarePanel::setupSwitchType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type, bool threePos) { Board::Type board = getCurrentBoard(); if (IS_STM32(board) && index < getBoardCapability(board, Board::Switches)) { @@ -92,7 +92,7 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings ui(new Ui::Hardware) { ui->setupUi(this); - + Board::Type board = firmware->getBoard(); if (IS_STM32(board)) { @@ -163,7 +163,7 @@ HardwarePanel::HardwarePanel(QWidget * parent, GeneralSettings & generalSettings ui->bluetoothEnable->hide(); ui->bluetoothName->hide(); } - + if (IS_HORUS_OR_TARANIS(board)) { ui->filterEnable->setChecked(!generalSettings.jitterFilter); } diff --git a/companion/src/generaledit/hardware.h b/companion/src/generaledit/hardware.h index a067e4431..af7a2237a 100644 --- a/companion/src/generaledit/hardware.h +++ b/companion/src/generaledit/hardware.h @@ -56,7 +56,7 @@ class HardwarePanel : public GeneralPanel protected: void setupPotType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type); void setupSliderType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type); - void setupSwitchType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type, bool threePos); + void setupSwitchType(int index, QLabel * label, AutoLineEdit * name, AutoComboBox * type, bool threePos = true); private: Ui::Hardware *ui; diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 68afcc79d..a566b2d93 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -225,7 +225,7 @@ void CurveGroup::update() lastType = curve.type; curveValueCB->clear(); for (int i=0; i<=6/*TODO constant*/; i++) { - curveValueCB->addItem(CurveReference(CurveReference::CURVE_REF_FUNC, i).toString()); + curveValueCB->addItem(CurveReference(CurveReference::CURVE_REF_FUNC, i).toString(&model, false)); } } curveValueCB->setCurrentIndex(curve.value); @@ -237,7 +237,7 @@ void CurveGroup::update() lastType = curve.type; curveValueCB->clear(); for (int i= ((flags & HIDE_NEGATIVE_CURVES) ? 0 : -numcurves); i<=numcurves; i++) { - curveValueCB->addItem(CurveReference(CurveReference::CURVE_REF_CUSTOM, i).toString(), i); + curveValueCB->addItem(CurveReference(CurveReference::CURVE_REF_CUSTOM, i).toString(&model, false), i); if (i == curve.value) { curveValueCB->setCurrentIndex(curveValueCB->count() - 1); } @@ -324,38 +324,43 @@ void CurveGroup::valuesChanged() void Helpers::populateGVCB(QComboBox & b, int value, const ModelData & model) { - bool selected = false; + int count = getCurrentFirmware()->getCapability(Gvars); b.clear(); - int count = getCurrentFirmware()->getCapability(Gvars); for (int i=-count; i<=-1; i++) { int16_t gval = (int16_t)(-10000+i); - if (strlen(model.gvars_names[-i-1]) > 0) - b.addItem(QObject::tr("-GV%1 (%2)").arg(-i).arg(model.gvars_names[-i-1]), gval); - else - b.addItem(QObject::tr("-GV%1").arg(-i), gval); - if (value == gval) { - b.setCurrentIndex(b.count()-1); - selected = true; - } + b.addItem("-" + RawSource(SOURCE_TYPE_GVAR, abs(i)-1).toString(&model), gval); } for (int i=1; i<=count; i++) { int16_t gval = (int16_t)(10000+i); - if (strlen(model.gvars_names[i-1]) > 0) - b.addItem(QObject::tr("GV%1 (%2)").arg(i).arg(model.gvars_names[i-1]), gval); - else - b.addItem(QObject::tr("GV%1").arg(i), gval); - if (value == gval) { - b.setCurrentIndex(b.count()-1); - selected = true; - } + b.addItem(RawSource(SOURCE_TYPE_GVAR, i-1).toString(&model), gval); } - if (!selected) { + b.setCurrentIndex(b.findData(value)); + if (b.currentIndex() == -1) b.setCurrentIndex(count); +} + +// Returns Diff/Expo/Weight/Offset adjustment value as either a percentage or a global variable name. +QString Helpers::getAdjustmentString(int16_t val, const ModelData * model, bool sign) +{ + QString ret; + if (val >= -10000 && val <= 10000) { + ret = "%1%"; + if (sign && val > 0) + ret.prepend("+"); + ret = ret.arg(val); } + else { + ret = RawSource(SOURCE_TYPE_GVAR, abs(val) - 10001).toString(model); + if (val < 0) + ret.prepend("-"); + else if (sign) + ret.prepend("+"); + } + return ret; } void Helpers::populateGvarUseCB(QComboBox * b, unsigned int phase) @@ -368,29 +373,6 @@ void Helpers::populateGvarUseCB(QComboBox * b, unsigned int phase) } } -void Helpers::populateGvSourceCB(QComboBox * b, int value) -{ - QString strings[] = { QObject::tr("---"), QObject::tr("Rud Trim"), QObject::tr("Ele Trim"), QObject::tr("Thr Trim"), QObject::tr("Ail Trim"), QObject::tr("Rot Enc"), QObject::tr("Rud"), QObject::tr("Ele"), QObject::tr("Thr"), QObject::tr("Ail"), QObject::tr("P1"), QObject::tr("P2"), QObject::tr("P3")}; - b->clear(); - for (int i=0; i<= 12; i++) { - b->addItem(strings[i]); - } - b->setCurrentIndex(value); -} - -void Helpers::populatePhasesCB(QComboBox * b, int value) -{ - for (int i=-getCurrentFirmware()->getCapability(FlightModes); i<=getCurrentFirmware()->getCapability(FlightModes); i++) { - if (i < 0) - b->addItem(QObject::tr("!Flight mode %1").arg(-i-1), i); - else if (i > 0) - b->addItem(QObject::tr("Flight mode %1").arg(i-1), i); - else - b->addItem(QObject::tr("----"), 0); - } - b->setCurrentIndex(value + getCurrentFirmware()->getCapability(FlightModes)); -} - void Helpers::populateFileComboBox(QComboBox * b, const QSet & set, const QString & current) { b->clear(); @@ -456,21 +438,22 @@ void Helpers::addRawSwitchItems(QStandardItemModel * itemModel, const RawSwitchT QStandardItemModel * Helpers::getRawSwitchItemModel(const GeneralSettings * const generalSettings, SwitchContext context) { QStandardItemModel * itemModel = new QStandardItemModel(); - Board::Type board = getCurrentBoard(); + Boards board = Boards(getCurrentBoard()); + Board::Type btype = board.getBoardType(); Firmware * fw = getCurrentFirmware(); // Descending switch direction: NOT (!) switches - if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(board)) { + if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) { addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes), generalSettings); } if (context != GlobalFunctionsContext) { addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches), generalSettings); } addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders), generalSettings); - addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, -getBoardCapability(board, Board::NumTrimSwitches), generalSettings); + addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches), generalSettings); addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, -(fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions)), generalSettings); - addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, -fw->getCapability(SwitchesPositions), generalSettings); + addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions), generalSettings); // Ascending switch direction (including zero) @@ -481,14 +464,14 @@ QStandardItemModel * Helpers::getRawSwitchItemModel(const GeneralSettings * cons addRawSwitchItems(itemModel, SWITCH_TYPE_NONE, 1); } - addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, fw->getCapability(SwitchesPositions), generalSettings); + addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions), generalSettings); addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions), generalSettings); - addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, getBoardCapability(board, Board::NumTrimSwitches), generalSettings); + addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches), generalSettings); addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings); if (context != GlobalFunctionsContext) { addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches), generalSettings); } - if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(board)) { + if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) { addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes), generalSettings); } if (context == SpecialFunctionsContext || context == GlobalFunctionsContext) { @@ -530,7 +513,7 @@ void Helpers::addRawSourceItems(QStandardItemModel * itemModel, const RawSourceT QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const model, unsigned int flags) { QStandardItemModel * itemModel = new QStandardItemModel(); - Board::Type board = getCurrentBoard(); + Boards board = Boards(getCurrentBoard()); Firmware * fw = getCurrentFirmware(); if (flags & POPULATE_NONE) { @@ -548,13 +531,13 @@ QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * cons } if (flags & POPULATE_SOURCES) { - int totalSources = CPN_MAX_STICKS + getBoardCapability(board, Board::Pots) + getBoardCapability(board, Board::Sliders) + getBoardCapability(board, Board::MouseAnalogs); + int totalSources = CPN_MAX_STICKS + board.getCapability(Board::Pots) + board.getCapability(Board::Sliders) + board.getCapability(Board::MouseAnalogs); addRawSourceItems(itemModel, SOURCE_TYPE_STICK, totalSources, generalSettings, model); addRawSourceItems(itemModel, SOURCE_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings, model); } if (flags & POPULATE_TRIMS) { - addRawSourceItems(itemModel, SOURCE_TYPE_TRIM, getBoardCapability(board, Board::NumTrims), generalSettings, model); + addRawSourceItems(itemModel, SOURCE_TYPE_TRIM, board.getCapability(Board::NumTrims), generalSettings, model); } if (flags & POPULATE_SOURCES) { @@ -562,7 +545,7 @@ QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * cons } if (flags & POPULATE_SWITCHES) { - addRawSourceItems(itemModel, SOURCE_TYPE_SWITCH, getBoardCapability(board, Board::Switches), generalSettings, model); + addRawSourceItems(itemModel, SOURCE_TYPE_SWITCH, board.getCapability(Board::Switches), generalSettings, model); addRawSourceItems(itemModel, SOURCE_TYPE_CUSTOM_SWITCH, fw->getCapability(LogicalSwitches), generalSettings, model); } @@ -573,7 +556,7 @@ QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * cons } if (flags & POPULATE_TELEMETRY) { - if (IS_ARM(board)) { + if (IS_ARM(board.getBoardType())) { addRawSourceItems(itemModel, SOURCE_TYPE_SPECIAL, 5, generalSettings, model); if (model) { @@ -593,7 +576,7 @@ QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * cons exclude << TELEMETRY_SOURCE_TX_TIME; if (!fw->getCapability(SportTelemetry)) exclude << TELEMETRY_SOURCE_SWR; - if (!IS_ARM(board)) + if (!IS_ARM(board.getBoardType())) exclude << TELEMETRY_SOURCE_TIMER3; int count = ((flags & POPULATE_TELEMETRYEXT) ? TELEMETRY_SOURCES_STATUS_COUNT : TELEMETRY_SOURCES_COUNT); addRawSourceItems(itemModel, SOURCE_TYPE_TELEMETRY, count, generalSettings, model, 0, exclude); diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 24e2375b2..ebfe970ff 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -146,9 +146,8 @@ namespace Helpers QStandardItemModel * getRawSourceItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const model = NULL, unsigned int flags = 0); void populateGvarUseCB(QComboBox *b, unsigned int phase); - void populateGvSourceCB(QComboBox *b, int value); - void populatePhasesCB(QComboBox *b, int value); void populateGVCB(QComboBox & b, int value, const ModelData & model); + QString getAdjustmentString(int16_t val, const ModelData * model = NULL, bool sign = false); void populateFileComboBox(QComboBox * b, const QSet & set, const QString & current); void getFileComboBoxValue(QComboBox * b, char * dest, int length); diff --git a/companion/src/modeledit/channels.cpp b/companion/src/modeledit/channels.cpp index 1cdfd5376..8fe25b010 100644 --- a/companion/src/modeledit/channels.cpp +++ b/companion/src/modeledit/channels.cpp @@ -156,7 +156,7 @@ Channels::Channels(QWidget * parent, ModelData & model, GeneralSettings & genera curveCB->setProperty("index", i); int numcurves = firmware->getCapability(NumCurves); for (int j=-numcurves; j<=numcurves; j++) { - curveCB->addItem(CurveReference(CurveReference::CURVE_REF_CUSTOM, j).toString(), j); + curveCB->addItem(CurveReference(CurveReference::CURVE_REF_CUSTOM, j).toString(&model, false), j); } curveCB->setCurrentIndex(model.limitData[i].curve.value+numcurves); connect(curveCB, SIGNAL(currentIndexChanged(int)), this, SLOT(curveEdited())); diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index 514ea01d0..07576ff96 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -337,6 +337,7 @@ void CustomFunctionsPanel::playMusic() #define CUSTOM_FUNCTION_REPEAT (1<<7) #define CUSTOM_FUNCTION_PLAY (1<<8) #define CUSTOM_FUNCTION_BL_COLOR (1<<9) +#define CUSTOM_FUNCTION_SHOW_FUNC (1<<10) void CustomFunctionsPanel::customFunctionEdited() { @@ -357,7 +358,7 @@ void CustomFunctionsPanel::functionEdited() RawSwitch swtch = functions[index].swtch; functions[index].clear(); functions[index].swtch = swtch; - functions[index].func = (AssignFunc)fswtchFunc[index]->itemData(fswtchFunc[index]->currentIndex()).toInt(); + functions[index].func = (AssignFunc)fswtchFunc[index]->currentData().toInt(); refreshCustomFunction(index); emit modified(); lock = false; @@ -382,7 +383,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) cfn.adjustMode = (AssignFunc)fswtchGVmode[i]->currentIndex(); } - if (cfn.swtch.toValue()) { + if (!cfn.isEmpty()) { + widgetsMask |= CUSTOM_FUNCTION_SHOW_FUNC; if (func>=FuncOverrideCH1 && func<=FuncOverrideCH32) { if (model) { @@ -395,7 +397,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) cfn.param = fswtchParam[i]->value(); } fswtchParam[i]->setValue(cfn.param); - widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM + CUSTOM_FUNCTION_ENABLE; + widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_ENABLE; } } else if (func==FuncLogs) { @@ -456,7 +458,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) if (modified) cfn.param = fswtchParamT[i]->currentData().toInt(); populateFuncParamCB(fswtchParamT[i], func, cfn.param); - widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM + CUSTOM_FUNCTION_ENABLE; + widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE; } else if (func==FuncPlaySound || func==FuncPlayHaptic || func==FuncPlayValue || func==FuncPlayPrompt || func==FuncPlayBoth || func==FuncBackgroundMusic) { if (func != FuncBackgroundMusic) { @@ -467,7 +469,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) if (modified) cfn.param = fswtchParamT[i]->currentData().toInt(); populateFuncParamCB(fswtchParamT[i], func, cfn.param); - widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM + CUSTOM_FUNCTION_REPEAT; + widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_REPEAT; } else if (func==FuncPlayPrompt || func==FuncPlayBoth) { if (firmware->getCapability(VoicesAsNumbers)) { @@ -475,10 +477,10 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) fswtchParam[i]->setSingleStep(1); fswtchParam[i]->setMinimum(0); if (func==FuncPlayPrompt) { - widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM + CUSTOM_FUNCTION_REPEAT + CUSTOM_FUNCTION_GV_TOOGLE; + widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_REPEAT | CUSTOM_FUNCTION_GV_TOOGLE; } else { - widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM + CUSTOM_FUNCTION_REPEAT; + widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_REPEAT; fswtchParamGV[i]->setChecked(false); } fswtchParam[i]->setMaximum(func==FuncPlayBoth ? 254 : 255); @@ -563,7 +565,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) } - fswtchFunc[i]->setVisible(cfn.swtch.toValue()); + fswtchFunc[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SHOW_FUNC); fswtchParam[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_NUMERIC_PARAM); fswtchParamTime[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_TIME_PARAM); fswtchParamGV[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_GV_TOOGLE); @@ -678,7 +680,7 @@ void CustomFunctionsPanel::populateFuncCB(QComboBox *b, unsigned int value) // b->model()->setData(index, v, Qt::UserRole - 1); } else { - b->addItem(CustomFunctionData(AssignFunc(i)).funcToString(), i); + b->addItem(CustomFunctionData(AssignFunc(i)).funcToString(model), i); if (i == value) { b->setCurrentIndex(b->count()-1); } diff --git a/companion/src/modeledit/logicalswitches.cpp b/companion/src/modeledit/logicalswitches.cpp index c60616633..60b535549 100644 --- a/companion/src/modeledit/logicalswitches.cpp +++ b/companion/src/modeledit/logicalswitches.cpp @@ -468,7 +468,7 @@ void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b, const RawSwitch & v b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); - for (int i=1; i<=firmware->getCapability(SwitchesPositions); i++) { + for (int i=1; i <= Boards::getCapability(firmware->getBoard(), Board::SwitchPositions); i++) { item = RawSwitch(SWITCH_TYPE_SWITCH, i); b->addItem(item.toString(), item.toValue()); if (item == value) b->setCurrentIndex(b->count()-1); diff --git a/companion/src/modeledit/mixes.cpp b/companion/src/modeledit/mixes.cpp index 08427b4f8..26a8399c9 100644 --- a/companion/src/modeledit/mixes.cpp +++ b/companion/src/modeledit/mixes.cpp @@ -140,7 +140,7 @@ QString MixesPanel::getMixerText(int dest, bool * new_ch) QString str; bool newChannel = false; if (dest < 0) { - str = modelPrinter.printMixerName(-dest); + str = modelPrinter.printChannelName(abs(dest)-1); //highlight channel if needed if (-dest == (int)highlightedSource) { str = "" + str + ""; @@ -150,7 +150,7 @@ QString MixesPanel::getMixerText(int dest, bool * new_ch) else { MixData & mix = model->mixData[dest]; //mix->destCh from 1 to 32 - str = modelPrinter.printMixerName(mix.destCh); + str = modelPrinter.printChannelName(mix.destCh-1); if ((dest == 0) || (model->mixData[dest-1].destCh != mix.destCh)) { newChannel = true; diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index ec27a331f..64aee0af8 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -1104,7 +1104,7 @@ void SetupPanel::populateThrottleSourceCB() ui->throttleSource->addItem(firmware->getAnalogInputName(4+i), i); } for (int i=0; igetCapability(Outputs); i++) { - ui->throttleSource->addItem(ModelPrinter::printChannelName(i)); + ui->throttleSource->addItem(RawSource(SOURCE_TYPE_CH, i).toString(model, &generalSettings)); } ui->throttleSource->setCurrentIndex(model->thrTraceSrc); lock = false; diff --git a/companion/src/modelprinter.cpp b/companion/src/modelprinter.cpp index 79d26dbd0..b7e0a1e95 100644 --- a/companion/src/modelprinter.cpp +++ b/companion/src/modelprinter.cpp @@ -76,18 +76,12 @@ QString ModelPrinter::printEEpromSize() QString ModelPrinter::printChannelName(int idx) { - return tr("CH%1").arg(idx+1, 2, 10, QChar('0')); -} - -QString ModelPrinter::printOutputName(int idx) -{ - QString name = QString(model.limitData[idx].name).trimmed(); - if (firmware->getCapability(ChannelsName) > 0 && !name.isEmpty()) { - return name; - } - else { - return ""; + QString str = RawSource(SOURCE_TYPE_CH, idx).toString(&model, &generalSettings); + if (firmware->getCapability(ChannelsName)) { + str = str.leftJustified(firmware->getCapability(ChannelsName) + 5, ' ', false); } + str.append(' '); + return str.toHtmlEscaped(); } QString ModelPrinter::printTrimIncrementMode() @@ -368,9 +362,9 @@ QString ModelPrinter::printInputLine(const ExpoData & input) str += input.srcRaw.toString(&model, &generalSettings).toHtmlEscaped(); } - str += " " + tr("Weight").toHtmlEscaped() + QString("(%1)").arg(getGVarString(input.weight,true).toHtmlEscaped()); + str += " " + tr("Weight").toHtmlEscaped() + QString("(%1)").arg(Helpers::getAdjustmentString(input.weight, &model, true).toHtmlEscaped()); if (input.curve.value) - str += " " + input.curve.toString().toHtmlEscaped(); + str += " " + input.curve.toString(&model).toHtmlEscaped(); QString flightModesStr = printFlightModes(input.flightModes); if (!flightModesStr.isEmpty()) @@ -388,7 +382,7 @@ QString ModelPrinter::printInputLine(const ExpoData & input) } if (input.offset) - str += " " + tr("Offset(%1)").arg(getGVarString(input.offset)).toHtmlEscaped(); + str += " " + tr("Offset(%1)").arg(Helpers::getAdjustmentString(input.offset, &model)).toHtmlEscaped(); if (firmware->getCapability(HasExpoNames) && input.name[0]) str += QString(" [%1]").arg(input.name).toHtmlEscaped(); @@ -396,25 +390,6 @@ QString ModelPrinter::printInputLine(const ExpoData & input) return str; } -QString ModelPrinter::printMixerName(int curDest) -{ - QString str = printChannelName(curDest-1) + " "; - if (firmware->getCapability(ChannelsName) > 0) { - QString name = model.limitData[curDest-1].name; - if (!name.isEmpty()) { - name = QString("(") + name + QString(")"); - } - name.append(" "); - str += name.left(8); - } - return str.toHtmlEscaped(); -} - -QString ModelPrinter::printMixerLine(int idx, bool showMultiplex, int highlightedSource) -{ - return printMixerLine(model.mixData[idx], highlightedSource, showMultiplex); -} - QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, int highlightedSource) { QString str = " "; @@ -439,7 +414,7 @@ QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, in if (mix.mltpx == MLTPX_MUL && !showMultiplex) str += " " + QString("MULT!").toHtmlEscaped(); else - str += " " + tr("Weight(%1)").arg(getGVarString(mix.weight, true)).toHtmlEscaped(); + str += " " + tr("Weight(%1)").arg(Helpers::getAdjustmentString(mix.weight, &model, true)).toHtmlEscaped(); QString flightModesStr = printFlightModes(mix.flightModes); if (!flightModesStr.isEmpty()) @@ -456,9 +431,9 @@ QString ModelPrinter::printMixerLine(const MixData & mix, bool showMultiplex, in if (firmware->getCapability(HasNoExpo) && mix.noExpo) str += " " + tr("No DR/Expo").toHtmlEscaped(); if (mix.sOffset) - str += " " + tr("Offset(%1)").arg(getGVarString(mix.sOffset)).toHtmlEscaped(); + str += " " + tr("Offset(%1)").arg(Helpers::getAdjustmentString(mix.sOffset, &model)).toHtmlEscaped(); if (mix.curve.value) - str += " " + mix.curve.toString().toHtmlEscaped(); + str += " " + mix.curve.toString(&model).toHtmlEscaped(); int scale = firmware->getCapability(SlowScale); if (scale == 0) scale = 1; @@ -519,7 +494,7 @@ QString ModelPrinter::printLogicalSwitchLine(int idx) const QString sw1Name = RawSwitch(ls.val1).toString(getCurrentBoard(), &generalSettings); const QString sw2Name = RawSwitch(ls.val2).toString(getCurrentBoard(), &generalSettings); - if (!ls.func) + if (ls.isEmpty()) return result; if (ls.andsw!=0) { @@ -642,7 +617,7 @@ QString ModelPrinter::printCustomFunctionLine(int idx) return result; result += cf.swtch.toString(getCurrentBoard(), &generalSettings) + " - "; - result += cf.funcToString() + "("; + result += cf.funcToString(&model) + " ("; result += cf.paramToString(&model) + ")"; if (!cf.repeatToString().isEmpty()) result += " " + cf.repeatToString(); @@ -651,6 +626,11 @@ QString ModelPrinter::printCustomFunctionLine(int idx) return result; } +QString ModelPrinter::printCurveName(int idx) +{ + return model.curves[idx].nameToString(idx).toHtmlEscaped(); +} + QString ModelPrinter::printCurve(int idx) { QString result; diff --git a/companion/src/modelprinter.h b/companion/src/modelprinter.h index 68c38105a..2da443de7 100644 --- a/companion/src/modelprinter.h +++ b/companion/src/modelprinter.h @@ -75,13 +75,11 @@ class ModelPrinter: public QObject QString printInputName(int idx); QString printInputLine(int idx); QString printInputLine(const ExpoData & ed); - QString printMixerName(int curDest); - QString printMixerLine(int idx, bool showMultiplex, int highlightedSource = 0); QString printMixerLine(const MixData & md, bool showMultiplex, int highlightedSource = 0); QString printLogicalSwitchLine(int idx); QString printCustomFunctionLine(int idx); - static QString printChannelName(int idx); - QString printOutputName(int idx); + QString printChannelName(int idx); + QString printCurveName(int idx); QString printCurve(int idx); QString createCurveImage(int idx, QTextDocument * document); diff --git a/companion/src/multimodelprinter.cpp b/companion/src/multimodelprinter.cpp index 73df83002..615bd5897 100644 --- a/companion/src/multimodelprinter.cpp +++ b/companion/src/multimodelprinter.cpp @@ -351,7 +351,6 @@ QString MultiModelPrinter::printLimits() columns.append("" \ "" \ " " \ - " " \ " " \ " " \ " " \ @@ -365,8 +364,6 @@ QString MultiModelPrinter::printLimits() continue; columns.append("
" + tr("Channel") + "" + (firmware->getCapability(ChannelsName) > 0 ? tr("Name") : "") + "" + tr("Offset") + "" + tr("Min") + "" + tr("Max") + "
"); COMPARE(modelPrinter->printChannelName(i)); - columns.append(""); - COMPARE(modelPrinter->printOutputName(i)); columns.append(""); COMPARE(model->limitData[i].offsetToString()); columns.append(""); @@ -441,7 +438,7 @@ QString MultiModelPrinter::printMixers() } if (count > 0) { columns.append("
"); - COMPARE(modelPrinter->printMixerName(i+1)); + COMPARE(modelPrinter->printChannelName(i)); columns.append(""); for (int j=0; j 0) @@ -471,7 +468,9 @@ QString MultiModelPrinter::printCurves(QTextDocument * document) } if (!curveEmpty) { count++; - columns.append("
" + tr("CV%1").arg(i+1) + ""); + columns.append("
"); + COMPARE(modelPrinter->printCurveName(i)); + columns.append(""); COMPARE(modelPrinter->printCurve(i)); for (int k=0; k < modelPrinterMap.size(); k++) columns.append(k, QString("
").arg(modelPrinterMap.value(k).second->createCurveImage(i, document))); @@ -495,7 +494,7 @@ QString MultiModelPrinter::printLogicalSwitches() for (int i=0; igetCapability(LogicalSwitches); i++) { bool lsEmpty = true; for (int k=0; k < modelPrinterMap.size(); k++) { - if (!modelPrinterMap.value(k).second->printLogicalSwitchLine(i).isEmpty()) { + if (!modelPrinterMap.value(k).first->logicalSw[i].isEmpty()) { lsEmpty = false; break; } @@ -524,7 +523,7 @@ QString MultiModelPrinter::printCustomFunctions() for (int i=0; i < firmware->getCapability(CustomFunctions); i++) { bool sfEmpty = true; for (int k=0; k < modelPrinterMap.size(); k++) { - if (modelPrinterMap.value(k).first->customFn[i].swtch.type != SWITCH_TYPE_NONE) { + if (!modelPrinterMap.value(k).first->customFn[i].isEmpty()) { sfEmpty = false; break; } diff --git a/companion/src/radiodata.cpp b/companion/src/radiodata.cpp index 6a284b5c5..dfddfa71a 100644 --- a/companion/src/radiodata.cpp +++ b/companion/src/radiodata.cpp @@ -171,6 +171,16 @@ void GeneralSettings::convert(Board::Type before, Board::Type after) } } + +/* + * RadioData +*/ + +RadioData::RadioData() +{ + models.resize(getCurrentFirmware()->getCapability(Models)); +} + void RadioData::setCurrentModel(unsigned int index) { generalSettings.currModelIndex = index; @@ -244,4 +254,4 @@ void RadioData::convert(Board::Type before, Board::Type after) if (IS_HORUS(after)) { fixModelFilenames(); } -} \ No newline at end of file +} diff --git a/companion/src/radiodata.h b/companion/src/radiodata.h index 9fe15f7b9..15d029af8 100644 --- a/companion/src/radiodata.h +++ b/companion/src/radiodata.h @@ -316,7 +316,7 @@ class CurveReference { CurveRefType type; int value; - QString toString() const; + QString toString(const ModelData * model = NULL, bool verbose = true) const; }; enum InputMode { @@ -361,6 +361,8 @@ class CurveData { CurveData(); void clear(int count); bool isEmpty() const; + QString nameToString(const int idx) const; + CurveType type; bool smooth; int count; @@ -468,7 +470,9 @@ class LogicalSwitchData { // Logical Switches data unsigned int delay; unsigned int duration; int andsw; + void clear() { memset(this, 0, sizeof(LogicalSwitchData)); } + bool isEmpty() const; CSFunctionFamily getFunctionFamily() const; unsigned int getRangeFlags() const; QString funcToString() const; @@ -531,8 +535,10 @@ class CustomFunctionData { // Function Switches data unsigned int enabled; // TODO perhaps not any more the right name unsigned int adjustMode; int repeatParam; + void clear(); - QString funcToString() const; + bool isEmpty() const; + QString funcToString(const ModelData * model = NULL) const; QString paramToString(const ModelData * model) const; QString repeatToString() const; QString enabledToString() const;