chore: Companion - port of OpenTX function switches management (#1694)

* TPro - Port of OpenTX function switches management (https://github.com/opentx/opentx/pull/8847)

* cleanup

* Corrections

* Fix YAML generation and adjusted switches to match TPRO firmware

Co-authored-by: Batam <batam@macbook-pro.home>
This commit is contained in:
Batambatam
2022-03-21 10:43:27 +10:00
committed by GitHub
co-authored by Batam
parent 1d7c153979
commit ab15a5a514
22 changed files with 434 additions and 186 deletions
+37 -10
View File
@@ -45,26 +45,44 @@ inline int MAX_SWITCHES(Board::Type board, int version)
if (IS_TARANIS_X9D(board))
return 9;
if (IS_JUMPER_TPRO(board))
return 10;
if (IS_FAMILY_T12(board))
return 8;
if (IS_TARANIS_X7(board))
return 8;
if (IS_JUMPER_TPRO(board))
return 10;
return Boards::getCapability(board, Board::Switches);
}
inline int MAX_SWITCHES_SOURCE(Board::Type board, int version)
{
if (IS_JUMPER_TPRO(board)) // 10 switches are allocated in EEprom but 6 are reserved for FS
return Boards::getCapability(board, Board::Switches);
else
return MAX_SWITCHES(board, version);
}
inline int MAX_SWITCHES_POSITION(Board::Type board, int version)
{
if (IS_HORUS_OR_TARANIS(board)) {
if (IS_JUMPER_TPRO(board))
return Boards::getCapability(board, Board::SwitchPositions);
else if (IS_HORUS_OR_TARANIS(board))
return MAX_SWITCHES(board, version) * 3;
}
else {
else
return Boards::getCapability(board, Board::SwitchPositions);
}
inline int MAX_FUNCTIONSWITCHES(Board::Type board, int version)
{
return Boards::getCapability(board, Board::FunctionSwitches);
}
inline int MAX_FUNCTIONSWITCHES_POSITION(Board::Type board, int version)
{
return Boards::getCapability(board, Board::NumFunctionSwitchesPositions);
}
inline int POTS_CONFIG_SIZE(Board::Type board, int version)
@@ -156,7 +174,7 @@ inline int SWITCHES_CONFIG_SIZE(Board::Type board, int version)
if (IS_FAMILY_HORUS_OR_T16(board))
return 32;
if (version >= 219 && IS_TARANIS_X9D(board))
if (version >= 219 && (IS_TARANIS_X9D(board) || IS_JUMPER_TPRO(board)))
return 32;
return 16;
@@ -220,6 +238,13 @@ class SwitchesConversionTable: public ConversionTable {
val++;
}
for (int i=1; i<=MAX_FUNCTIONSWITCHES_POSITION(board, version); i++) {
int s = switchIndex(i, board, version);
addConversion(RawSwitch(SWITCH_TYPE_FUNCTIONSWITCH, s), val);
addConversion(RawSwitch(SWITCH_TYPE_FUNCTIONSWITCH, -s), -val+offset);
val++;
}
if (IS_HORUS_OR_TARANIS(board)) {
for (int i=1; i<=MAX_XPOTS(board, version)*6; i++) {
addConversion(RawSwitch(SWITCH_TYPE_MULTIPOS_POT, -i), -val+offset);
@@ -368,8 +393,10 @@ class SourcesConversionTable: public ConversionTable {
addConversion(RawSource(SOURCE_TYPE_SWITCH, 0), val++);
if (!(flags & FLAG_NOSWITCHES)) {
for (int i=1; i<MAX_SWITCHES(board, version); i++)
for (int i=1; i<MAX_SWITCHES_SOURCE(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_SWITCH, i), val++);
for (int i=0; i<MAX_FUNCTIONSWITCHES(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_FUNCTIONSWITCH, i), val++);
for (int i=0; i<MAX_LOGICAL_SWITCHES(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_CUSTOM_SWITCH, i), val++);
}
@@ -2877,7 +2904,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, Board::Type board, unsig
internalField.Append(new UnsignedField<16>(this, modelData.functionSwitchGroup));
internalField.Append(new UnsignedField<16>(this, modelData.functionSwitchStartConfig));
internalField.Append(new UnsignedField<8>(this, modelData.functionSwitchLogicalState));
for (int i=0; i < MAX_FUNCTION_SWITCHES(board, version); ++i) {
for (int i=0; i < Boards::getCapability(board, Board::FunctionSwitches); ++i) {
internalField.Append(new ZCharField<3>(this, modelData.functionSwitchNames[i], "Function switch name"));
}
}
@@ -3209,7 +3236,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
if (IS_TARANIS_X9E(board))
internalField.Append(new SpareBitsField<64>(this)); // switchUnlockStates
else if (version >= 219 && IS_TARANIS_X9D(board))
else if (version >= 219 && (IS_TARANIS_X9D(board) || IS_JUMPER_TPRO(board)))
internalField.Append(new SpareBitsField<32>(this)); // switchUnlockStates
else if (IS_TARANIS(board))
internalField.Append(new SpareBitsField<16>(this)); // switchUnlockStates