From 8ef1456fe90e558f1f1ca1b9234773b8dd5470c0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 31 Jan 2014 17:19:21 +0100 Subject: [PATCH] EEPROM support in Companion for the 6pos pots on Taranis --- companion/src/eeprominterface.cpp | 48 +++++++++++-------- companion/src/eeprominterface.h | 8 +++- .../src/firmwares/opentx/opentxeeprom.cpp | 40 ++++++++++++---- .../src/firmwares/opentx/opentxinterface.cpp | 4 ++ companion/src/helpers.cpp | 11 +++++ radio/src/myeeprom.h | 4 +- 6 files changed, 82 insertions(+), 33 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index cf7686bea..9b5126780 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -67,7 +67,7 @@ RawSourceRange RawSource::getRange(bool singleprec) case TELEMETRY_SOURCE_A1: case TELEMETRY_SOURCE_A2: if (model) { - FrSkyChannelData channel = model->frsky.channels[index-TELEMETRY_SOURCE_A1]; // TODO const & + const FrSkyChannelData & channel = model->frsky.channels[index-TELEMETRY_SOURCE_A1]; float ratio = channel.getRatio(); if (channel.type==0 || channel.type==1 || channel.type==2) result.decimals = 2; @@ -239,26 +239,34 @@ QString SwitchDn(const char sw) QString RawSwitch::toString() { - static const QString switches9X[] = { QObject::tr("THR"), QObject::tr("RUD"), QObject::tr("ELE"), - QObject::tr("ID0"), QObject::tr("ID1"), QObject::tr("ID2"), - QObject::tr("AIL"), QObject::tr("GEA"), QObject::tr("TRN") - }; + static const QString switches9X[] = { + QString("THR"), QString("RUD"), QString("ELE"), + QString("ID0"), QString("ID1"), QString("ID2"), + QString("AIL"), QString("GEA"), QString("TRN") + }; - static const QString switchesX9D[] = { SwitchUp('A'), QString::fromUtf8("SA-"), SwitchDn('A'), - SwitchUp('B'), QString::fromUtf8("SB-"), SwitchDn('B'), - SwitchUp('C'), QString::fromUtf8("SC-"), SwitchDn('C'), - SwitchUp('D'), QString::fromUtf8("SD-"), SwitchDn('D'), - SwitchUp('E'), QString::fromUtf8("SE-"), SwitchDn('E'), - SwitchUp('F'), SwitchDn('F'), - SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'), - SwitchUp('H'), SwitchDn('H'), - }; + static const QString switchesX9D[] = { + SwitchUp('A'), QString::fromUtf8("SA-"), SwitchDn('A'), + SwitchUp('B'), QString::fromUtf8("SB-"), SwitchDn('B'), + SwitchUp('C'), QString::fromUtf8("SC-"), SwitchDn('C'), + SwitchUp('D'), QString::fromUtf8("SD-"), SwitchDn('D'), + SwitchUp('E'), QString::fromUtf8("SE-"), SwitchDn('E'), + SwitchUp('F'), SwitchDn('F'), + SwitchUp('G'), QString::fromUtf8("SG-"), SwitchDn('G'), + SwitchUp('H'), SwitchDn('H'), + }; - static const QString virtualSwitches[] = { QObject::tr("LS1"), QObject::tr("LS2"), QObject::tr("LS3"), QObject::tr("LS4"), QObject::tr("LS5"), QObject::tr("LS6"), QObject::tr("LS7"), QObject::tr("LS8"), QObject::tr("LS9"), QObject::tr("LSA"), - QObject::tr("LSB"), QObject::tr("LSC"), QObject::tr("LSD"), QObject::tr("LSE"), QObject::tr("LSF"), QObject::tr("LSG"), QObject::tr("LSH"), QObject::tr("LSI"), QObject::tr("LSJ"), QObject::tr("LSK"), - QObject::tr("LSL"), QObject::tr("LSM"), QObject::tr("LSN"), QObject::tr("LSO"), QObject::tr("LSP"), QObject::tr("LSQ"), QObject::tr("LSR"), QObject::tr("LSS"), QObject::tr("LST"), QObject::tr("LSU"), - QObject::tr("LSV"), QObject::tr("LSW") - }; + static const QString virtualSwitches[] = { + QObject::tr("LS1"), QObject::tr("LS2"), QObject::tr("LS3"), QObject::tr("LS4"), QObject::tr("LS5"), QObject::tr("LS6"), QObject::tr("LS7"), QObject::tr("LS8"), QObject::tr("LS9"), QObject::tr("LSA"), + QObject::tr("LSB"), QObject::tr("LSC"), QObject::tr("LSD"), QObject::tr("LSE"), QObject::tr("LSF"), QObject::tr("LSG"), QObject::tr("LSH"), QObject::tr("LSI"), QObject::tr("LSJ"), QObject::tr("LSK"), + QObject::tr("LSL"), QObject::tr("LSM"), QObject::tr("LSN"), QObject::tr("LSO"), QObject::tr("LSP"), QObject::tr("LSQ"), QObject::tr("LSR"), QObject::tr("LSS"), QObject::tr("LST"), QObject::tr("LSU"), + QObject::tr("LSV"), QObject::tr("LSW") + }; + + static const QString multiposPots[] = { + QObject::tr("S11"), QObject::tr("S12"), QObject::tr("S13"), QObject::tr("S14"), QObject::tr("S15"), QObject::tr("S16"), + QObject::tr("S21"), QObject::tr("S22"), QObject::tr("S23"), QObject::tr("S24"), QObject::tr("S25"), QObject::tr("S26") + }; switch(type) { case SWITCH_TYPE_SWITCH: @@ -268,6 +276,8 @@ QString RawSwitch::toString() return index > 0 ? CHECK_IN_ARRAY(switches9X, index-1) : QString("!") + CHECK_IN_ARRAY(switches9X, -index-1); case SWITCH_TYPE_VIRTUAL: return index > 0 ? CHECK_IN_ARRAY(virtualSwitches, index-1) : QString("!") + CHECK_IN_ARRAY(virtualSwitches, -index-1); + case SWITCH_TYPE_MULTIPOS_POT: + return CHECK_IN_ARRAY(multiposPots, index); case SWITCH_TYPE_ON: return QObject::tr("ON"); case SWITCH_TYPE_ONM: diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 915387e01..38b713c24 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -356,6 +356,7 @@ enum RawSwitchType { SWITCH_TYPE_NONE, SWITCH_TYPE_SWITCH, SWITCH_TYPE_VIRTUAL, + SWITCH_TYPE_MULTIPOS_POT, SWITCH_TYPE_MOMENT_SWITCH, SWITCH_TYPE_MOMENT_VIRTUAL, SWITCH_TYPE_ON, @@ -503,6 +504,7 @@ class GeneralSettings { unsigned int mavbaud; unsigned int switchUnlockStates; unsigned int hw_uartMode; + unsigned int potsType[8]; }; class CurveReference { @@ -737,7 +739,7 @@ class FrSkyChannelData { unsigned int multiplier; FrSkyAlarmData alarms[2]; - float getRatio() + float getRatio() const { if (type==0 || type==1 || type==2) return float(ratio << multiplier) / 10.0; @@ -1052,7 +1054,9 @@ enum Capability { EnhancedCurves, TelemetryInternalAlarms, HasFasOffset, - HasMahPersistent + HasMahPersistent, + MultiposPots, + MultiposPotsPositions }; enum UseContext { diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index a238d344d..0febeaf4e 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -56,21 +56,29 @@ class SwitchesConversionTable: public ConversionTable { addConversion(RawSwitch(SWITCH_TYPE_VIRTUAL, i), val++); } + if (IS_TARANIS(board) && version >= 216) { + for (int i=0; i<2; i++) { + for (int j=0; j<6; j++) { + addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i*6+j), val++); + } + } + } + addConversion(RawSwitch(SWITCH_TYPE_OFF), -val); addConversion(RawSwitch(SWITCH_TYPE_ON), val++); for (int i=1; i<=MAX_SWITCHES_POSITION(board); i++) { int s = switchIndex(i, board, version); - addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, -s), -val); + // addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, -s), -val); addConversion(RawSwitch(SWITCH_TYPE_MOMENT_SWITCH, s), val++); } for (int i=1; i<=MAX_CUSTOM_SWITCHES(board, version); i++) { - addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, -i), -val); + // addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, -i), -val); addConversion(RawSwitch(SWITCH_TYPE_MOMENT_VIRTUAL, i), val++); } - addConversion(RawSwitch(SWITCH_TYPE_ONM, 1 ), -val); + // addConversion(RawSwitch(SWITCH_TYPE_ONM, 1 ), -val); addConversion(RawSwitch(SWITCH_TYPE_ONM, 0 ), val++); addConversion(RawSwitch(SWITCH_TYPE_TRN, 0), val++); addConversion(RawSwitch(SWITCH_TYPE_TRN, 1), val++); @@ -2011,12 +2019,21 @@ Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardE if (version >= 213 || (!IS_ARM(board) && version >= 212)) internalField.Append(new UnsignedField<16>(generalData.variant)); - for (int i=0; i(generalData.calibMid[i])); - for (int i=0; i(generalData.calibSpanNeg[i])); - for (int i=0; i(generalData.calibSpanPos[i])); + if (version >= 216) { + for (int i=0; i(generalData.calibMid[i])); + internalField.Append(new SignedField<16>(generalData.calibSpanNeg[i])); + internalField.Append(new SignedField<16>(generalData.calibSpanPos[i])); + } + } + else { + for (int i=0; i(generalData.calibMid[i])); + for (int i=0; i(generalData.calibSpanNeg[i])); + for (int i=0; i(generalData.calibSpanPos[i])); + } internalField.Append(new UnsignedField<16>(chkSum)); internalField.Append(new UnsignedField<8>(generalData.currModel)); @@ -2110,8 +2127,11 @@ Open9xGeneralDataNew::Open9xGeneralDataNew(GeneralSettings & generalData, BoardE internalField.Append(new SignedField<8>(generalData.varioVolume)); internalField.Append(new SignedField<8>(generalData.backgroundVolume)); } - if (version >= 216) { + if (IS_TARANIS(board) && version >= 216) { internalField.Append(new UnsignedField<8>(generalData.hw_uartMode)); + for (int i=0; i<8; i++) { + internalField.Append(new UnsignedField<1>(generalData.potsType[i])); + } } } } diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 178dcf5a1..b70ef9d8a 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -682,6 +682,10 @@ int Open9xInterface::getCapability(const Capability capability) return (IS_STOCK(board) ? false : true); case HasMahPersistent: return (IS_ARM(board) ? true : false); + case MultiposPots: + return IS_TARANIS(board) ? 2 : 0; + case MultiposPotsPositions: + return IS_TARANIS(board) ? 6 : 0; default: return 0; } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 1c69e2207..97ef84275 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -842,6 +842,8 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, return; } +#if 0 + // TODO check ... I removed negative toggle switches in the FW, no? if (attr & POPULATE_MSWITCHES) { if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_ONM, 1); @@ -860,6 +862,7 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, if (item == value) b->setCurrentIndex(b->count()-1); } } +#endif if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_OFF); @@ -905,6 +908,14 @@ void populateSwitchCB(QComboBox *b, const RawSwitch & value, unsigned long attr, if (item == value) b->setCurrentIndex(b->count()-1); } + if (IS_TARANIS(GetEepromInterface()->getBoard())) { + for (int i=0; igetCapability(MultiposPots) * GetEepromInterface()->getCapability(MultiposPotsPositions); i++) { + item = RawSwitch(SWITCH_TYPE_MULTIPOS_POT, i); + b->addItem(item.toString(), item.toValue()); + if (item == value) b->setCurrentIndex(b->count()-1); + } + } + if (attr & POPULATE_ONOFF) { item = RawSwitch(SWITCH_TYPE_ON); b->addItem(item.toString(), item.toValue()); diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index d0b1147d1..0a0eaffcf 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -245,8 +245,8 @@ enum BeeperMode { #if defined(PCBTARANIS) #define EXTRA_GENERAL_FIELDS \ EXTRA_GENERAL_FIELDS_ARM \ - uint8_t potsType; \ - uint8_t hw_uartMode; + uint8_t hw_uartMode; \ + uint8_t potsType; #elif defined(CPUARM) #define EXTRA_GENERAL_FIELDS EXTRA_GENERAL_FIELDS_ARM #elif defined(PXX)