feat: add inverted sources (#4722)

Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
Neil Horne
2024-05-25 09:25:15 +10:00
committed by GitHub
co-authored by elecpower
parent ca50d4ee04
commit 80659c3e3f
87 changed files with 798 additions and 496 deletions
+96 -97
View File
@@ -85,7 +85,7 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
}
case SOURCE_TYPE_SPECIAL:
if (index == 0) { //Batt
if (index == 0) { //Batt
result.step = 0.1;
result.decimals = 1;
result.max = 25.5;
@@ -100,12 +100,13 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
result.max = 30000;
result.min = -result.max;
}
else { // Timers 1 - 3
result.step = 1;
result.max = 9 * 60 * 60 - 1; // 8:59:59 (to match firmware)
result.min = -result.max;
result.unit = tr("s");
}
break;
case SOURCE_TYPE_TIMER:
result.step = 1;
result.max = 9 * 60 * 60 - 1; // 8:59:59 (to match firmware)
result.min = -result.max;
result.unit = tr("s");
break;
case SOURCE_TYPE_CH:
@@ -128,27 +129,25 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
QString RawSource::toString(const ModelData * model, const GeneralSettings * const generalSettings, Board::Type board, bool prefixCustomName) const
{
if (board == Board::BOARD_UNKNOWN) {
if (index < 0)
return CPN_STR_SRC_INDICATOR_INVERT % RawSource(type, -index).toString(model, generalSettings, board, prefixCustomName);
if (board == Board::BOARD_UNKNOWN)
board = getCurrentBoard();
}
static const QString trims[] = {
tr("TrmR"), tr("TrmE"), tr("TrmT"), tr("TrmA"), tr("Trm5"), tr("Trm6"), tr("Trm7"), tr("Trm8")
"", tr("TrmR"), tr("TrmE"), tr("TrmT"), tr("TrmA"), tr("Trm5"), tr("Trm6"), tr("Trm7"), tr("Trm8")
};
static const QString trims2[] = {
tr("TrmH"), tr("TrmV")
"", tr("TrmH"), tr("TrmV")
};
static const QString special[] = {
tr("Batt"), tr("Time"), tr("GPS"), tr("Reserved1"), tr("Reserved2"), tr("Reserved3"), tr("Reserved4")
"", tr("Batt"), tr("Time"), tr("GPS"), tr("Reserved1"), tr("Reserved2"), tr("Reserved3"), tr("Reserved4")
};
static const QString rotary[] = { tr("REa"), tr("REb") };
if (index < 0) {
return QString(CPN_STR_UNKNOWN_ITEM);
}
static const QString rotary[] = { "", tr("REa"), tr("REb") };
QString result;
QString dfltName;
@@ -161,18 +160,21 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
case SOURCE_TYPE_VIRTUAL_INPUT:
{
const char * name = nullptr;
if (model)
name = model->inputNames[index];
return RadioData::getElementName(tr("I", "as in Input"), index + 1, name);
if (model && index <= CPN_MAX_INPUTS)
name = model->inputNames[index - 1];
return RadioData::getElementName(tr("I", "as in Input"), index, name);
}
case SOURCE_TYPE_LUA_OUTPUT:
return tr("LUA%1%2").arg(index / 16 + 1).arg(QChar('a' + index % 16));
{
div_t qr = div(index - 1, 16);
return tr("LUA%1%2").arg(qr.quot + 1).arg(QChar('a' + qr.rem));
}
case SOURCE_TYPE_STICK:
dfltName = Boards::getInputName(index, board);
if (generalSettings)
custName = QString(generalSettings->inputConfig[index].name).trimmed();
case SOURCE_TYPE_INPUT:
dfltName = Boards::getInputName(index - 1, board);
if (generalSettings && index <= CPN_MAX_INPUTS)
custName = QString(generalSettings->inputConfig[index - 1].name).trimmed();
return DataHelpers::getCompositeName(dfltName, custName, prefixCustomName);
case SOURCE_TYPE_TRIM:
@@ -188,53 +190,53 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return tr("MAX");
case SOURCE_TYPE_SWITCH:
dfltName = Boards::getSwitchInfo(index, board).name.c_str();
if (Boards::isSwitchFunc(index, board)) {
if (model) {
int fsindex = Boards::getSwitchTagNum(index, board) - 1;
dfltName = Boards::getSwitchInfo(index - 1, board).name.c_str();
if (Boards::isSwitchFunc(index - 1, board)) {
if (model && index <= CPN_MAX_SWITCHES_FUNCTION) {
int fsindex = Boards::getSwitchTagNum(index - 1, board) - 1;
custName = QString(model->functionSwitchNames[fsindex]).trimmed();
}
}
else {
if (generalSettings) {
custName = QString(generalSettings->switchConfig[index].name).trimmed();
if (generalSettings && index <= CPN_MAX_SWITCHES) {
custName = QString(generalSettings->switchConfig[index - 1].name).trimmed();
}
}
return DataHelpers::getCompositeName(dfltName, custName, prefixCustomName);
case SOURCE_TYPE_CUSTOM_SWITCH:
return RawSwitch(SWITCH_TYPE_VIRTUAL, index + 1).toString();
return RawSwitch(SWITCH_TYPE_VIRTUAL, index).toString(); // RawSwitch uses 1 based index
case SOURCE_TYPE_CYC:
return tr("CYC%1").arg(index + 1);
return tr("CYC%1").arg(index);
case SOURCE_TYPE_PPM:
return RadioData::getElementName(tr("TR", "as in Trainer"), index + 1);
return RadioData::getElementName(tr("TR", "as in Trainer"), index);
case SOURCE_TYPE_CH:
if (model)
result = QString(model->limitData[index].nameToString(index)).trimmed();
if (model && index <= CPN_MAX_CHNOUT)
result = QString(model->limitData[index - 1].nameToString(index - 1)).trimmed();
if (result.isEmpty())
return LimitData().nameToString(index);
return LimitData().nameToString(index - 1);
return result;
case SOURCE_TYPE_SPECIAL:
if (index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER) {
if (model)
result = QString(model->timers[index - SOURCE_TYPE_SPECIAL_FIRST_TIMER].nameToString(index - SOURCE_TYPE_SPECIAL_FIRST_TIMER)).trimmed();
if (result.isEmpty())
result = TimerData().nameToString(index - SOURCE_TYPE_SPECIAL_FIRST_TIMER);
}
else
result = CHECK_IN_ARRAY(special, index);
return CHECK_IN_ARRAY(special, index);
case SOURCE_TYPE_TIMER:
if (model && index <= CPN_MAX_TIMERS)
result = QString(model->timers[index - 1].nameToString(index - 1)).trimmed();
if (result.isEmpty())
result = TimerData().nameToString(index - 1);
return result;
case SOURCE_TYPE_TELEMETRY:
{
div_t qr = div(index, 3);
if (model)
div_t qr = div(index - 1, 3);
if (model && qr.quot < CPN_MAX_SENSORS)
result = QString(model->sensorData[qr.quot].nameToString(qr.quot)).trimmed();
if (result.isEmpty())
result = SensorData().nameToString(qr.quot);
@@ -244,14 +246,14 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
}
case SOURCE_TYPE_GVAR:
if (model)
result = QString(model->gvarData[index].nameToString(index)).trimmed();
if (model && index <= CPN_MAX_GVARS)
result = QString(model->gvarData[index - 1].nameToString(index - 1)).trimmed();
if (result.isEmpty())
result = GVarData().nameToString(index);
result = GVarData().nameToString(index - 1);
return result;
case SOURCE_TYPE_SPACEMOUSE:
return tr("sm%1").arg(QChar('A' + index));
return tr("sm%1").arg(QChar('A' + (index - 1)));
default:
return QString(CPN_STR_UNKNOWN_ITEM);
@@ -263,87 +265,100 @@ bool RawSource::isStick(Board::Type board) const
if (board == Board::BOARD_UNKNOWN)
board = getCurrentBoard();
if (type == SOURCE_TYPE_STICK && index < Boards::getCapability(board, Board::Sticks)) {
if (type == SOURCE_TYPE_INPUT && index - 1 < Boards::getCapability(board, Board::Sticks)) {
return true;
}
return false;
}
bool RawSource::isTimeBased(Board::Type board) const
{
return (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER);
}
bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const
{
if (type == SOURCE_TYPE_NONE && index == 0)
return true;
if (board == Board::BOARD_UNKNOWN)
board = getCurrentBoard();
Boards b(board);
if (type == SOURCE_TYPE_STICK && index >= b.getCapability(Board::Inputs))
if (type == SOURCE_TYPE_CH && abs(index) > CPN_MAX_CHNOUT)
return false;
if (type == SOURCE_TYPE_SWITCH && index >= b.getCapability(Board::Switches))
if (type == SOURCE_TYPE_CUSTOM_SWITCH && abs(index) > CPN_MAX_LOGICAL_SWITCHES)
return false;
if (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED && index <= SOURCE_TYPE_SPECIAL_LAST_RESERVED)
return false;
if (type == SOURCE_TYPE_LUA_OUTPUT && div(abs(index - 1), 16).quot >= CPN_MAX_SCRIPTS)
return false;
if (type == SOURCE_TYPE_INPUT && abs(index) > b.getCapability(Board::Inputs))
return false;
if (type == SOURCE_TYPE_SWITCH && abs(index) > b.getCapability(Board::Switches))
return false;
if (type == SOURCE_TYPE_SPECIAL && abs(index) >= SOURCE_TYPE_SPECIAL_FIRST_RESERVED)
return false;
if (type == SOURCE_TYPE_TIMER && abs(index) > CPN_MAX_TIMERS)
return false;
if (type == SOURCE_TYPE_TELEMETRY && div(abs(index), 3).quot > CPN_MAX_SENSORS)
return false;
if (model) {
if (type == SOURCE_TYPE_SPECIAL && index >= SOURCE_TYPE_SPECIAL_FIRST_TIMER && index <= SOURCE_TYPE_SPECIAL_LAST_TIMER &&
model->timers[index - SOURCE_TYPE_SPECIAL_FIRST_TIMER].isModeOff())
if (type == SOURCE_TYPE_TIMER && model->timers[abs(index) - 1].isModeOff())
return false;
if (type == SOURCE_TYPE_SWITCH && b.isSwitchFunc(index, board) &&
!model->isFunctionSwitchSourceAllowed(b.getSwitchTagNum(index, board) - 1))
if (type == SOURCE_TYPE_SWITCH && b.isSwitchFunc(abs(index) - 1, board) &&
!model->isFunctionSwitchSourceAllowed(b.getSwitchTagNum(abs(index) - 1, board) - 1))
return false;
if (type == SOURCE_TYPE_VIRTUAL_INPUT && !model->isInputValid(index))
if (type == SOURCE_TYPE_VIRTUAL_INPUT && !model->isInputValid(abs(index) - 1))
return false;
if (type == SOURCE_TYPE_PPM && model->trainerMode == TRAINER_MODE_OFF)
return false;
if (type == SOURCE_TYPE_CUSTOM_SWITCH && model->logicalSw[index].isEmpty())
if (type == SOURCE_TYPE_CUSTOM_SWITCH && model->logicalSw[abs(index) - 1].isEmpty())
return false;
if (type == SOURCE_TYPE_TELEMETRY) {
if (!model->sensorData[div(index, 3).quot].isAvailable()) {
if (!model->sensorData[div(abs(index) - 1, 3).quot].isAvailable()) {
return false;
}
}
if (type == SOURCE_TYPE_CH && !model->hasMixes(index))
if (type == SOURCE_TYPE_CH && !model->hasMixes(abs(index) - 1))
return false;
}
if (gs) {
if (type == SOURCE_TYPE_STICK) {
if (!gs->isInputAvailable(index))
if (type == SOURCE_TYPE_INPUT) {
if (!gs->isInputAvailable(abs(index) - 1))
return false;
if (gs->inputConfig[index].flexType == Board::FLEX_SWITCH)
if (gs->inputConfig[abs(index) - 1].flexType == Board::FLEX_SWITCH)
return false;
}
if (type == SOURCE_TYPE_SWITCH && !b.isSwitchFunc(index, board) && IS_HORUS_OR_TARANIS(board) &&
!gs->switchSourceAllowed(index))
if (type == SOURCE_TYPE_SWITCH && !b.isSwitchFunc(abs(index) - 1, board) && IS_HORUS_OR_TARANIS(board) &&
!gs->switchSourceAllowed(abs(index) - 1))
return false;
}
else {
if (type == SOURCE_TYPE_STICK) {
if (!Boards::isInputAvailable(index, board))
if (type == SOURCE_TYPE_INPUT) {
if (!Boards::isInputAvailable(abs(index) - 1, board))
return false;
if (Boards::getInputInfo(index, board).flexType == Board::FLEX_SWITCH)
if (Boards::getInputInfo(abs(index) - 1, board).flexType == Board::FLEX_SWITCH)
return false;
}
}
if (type == SOURCE_TYPE_TRIM && index >= b.getCapability(Board::NumTrims))
if (type == SOURCE_TYPE_TRIM && abs(index) > b.getCapability(Board::NumTrims))
return false;
if (type == SOURCE_TYPE_SPACEMOUSE &&
(index >= CPN_MAX_SPACEMOUSE ||
(abs(index) > CPN_MAX_SPACEMOUSE ||
(!(gs->serialPort[GeneralSettings::SP_AUX1] == GeneralSettings::AUX_SERIAL_SPACEMOUSE ||
gs->serialPort[GeneralSettings::SP_AUX2] == GeneralSettings::AUX_SERIAL_SPACEMOUSE))))
return false;
@@ -356,7 +371,7 @@ RawSource RawSource::convert(RadioDataConversionState & cstate)
cstate.setItemType(tr("SRC"), 1);
RadioDataConversionState::LogField oldData(index, toString(cstate.fromModel(), cstate.fromGS(), cstate.fromType));
if (type == SOURCE_TYPE_STICK)
if (type == SOURCE_TYPE_INPUT)
index = Boards::getInputIndex(Boards::getInputTag(oldData.id, cstate.fromType), Board::LVT_TAG, cstate.toType);
else if (type == SOURCE_TYPE_SWITCH)
index = Boards::getSwitchIndex(Boards::getSwitchTag(oldData.id, cstate.fromType), Board::LVT_TAG, cstate.toType);
@@ -376,6 +391,7 @@ StringTagMappingTable RawSource::getSpecialTypesLookupTable()
StringTagMappingTable tbl;
tbl.insert(tbl.end(), {
{std::to_string(SOURCE_TYPE_SPECIAL_NONE), "NONE"},
{std::to_string(SOURCE_TYPE_SPECIAL_TX_BATT), "TX_VOLTAGE"},
{std::to_string(SOURCE_TYPE_SPECIAL_TX_TIME), "TX_TIME"},
{std::to_string(SOURCE_TYPE_SPECIAL_TX_GPS), "TX_GPS"},
@@ -383,23 +399,6 @@ tbl.insert(tbl.end(), {
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED2), "RESERVED2"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED3), "RESERVED3"},
{std::to_string(SOURCE_TYPE_SPECIAL_RESERVED4), "RESERVED4"},
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER1), "Tmr1"},
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER2), "Tmr2"},
{std::to_string(SOURCE_TYPE_SPECIAL_TIMER3), "Tmr3"},
});
return tbl;
}
// static
StringTagMappingTable RawSource::getCyclicLookupTable()
{
StringTagMappingTable tbl;
tbl.insert(tbl.end(), {
{"0", "CYC1"},
{"1", "CYC2"},
{"2", "CYC3"},
});
return tbl;