Skip to content

Commit

Permalink
feat: add inverted sources (#4722)
Browse files Browse the repository at this point in the history
Co-authored-by: elecpower <neilh713@tpg.com.au>
  • Loading branch information
elecpower and elecpower authored May 24, 2024
1 parent ca50d4e commit 80659c3
Show file tree
Hide file tree
Showing 87 changed files with 796 additions and 494 deletions.
2 changes: 2 additions & 0 deletions companion/src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
#define CPN_STR_SW_INDICATOR_NEUT QCoreApplication::translate("RawSwitch", "-") // Switch neutral (middle) position indicator.
#define CPN_STR_SW_INDICATOR_REV QCoreApplication::translate("RawSwitch", "!") // Switch reversed logic (NOT) indicator.

#define CPN_STR_SRC_INDICATOR_INVERT QCoreApplication::translate("RawSource", "!") // Source inverted logic indicator.

#define EDGETX_HOME_PAGE_URL "https://edgetx.org"

#define CPN_ADC_REFACTOR_VERSION "2.10.0"
38 changes: 32 additions & 6 deletions companion/src/datamodels/compounditemmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,31 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
setId(IMID_RawSource);
setUpdateMask(IMUE_All &~ (IMUE_Curves | IMUE_Scripts));

// Descending source direction: inverted (!) sources
addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, -firmware->getCapability(Sensors) * 3);
addItems(SOURCE_TYPE_TIMER, RawSource::TelemGroup, -firmware->getCapability(Timers));
addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, -(SOURCE_TYPE_SPECIAL_COUNT - 1));
addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, -firmware->getCapability(Gvars));
addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, -firmware->getCapability(Outputs));
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, -firmware->getCapability(TrainerInputs));
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, -CPN_MAX_CYC);
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, -firmware->getCapability(LogicalSwitches));
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, -board->getCapability(Board::Switches));
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, -1);
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, -1);
addItems(SOURCE_TYPE_SPACEMOUSE, RawSource::SourcesGroup, -CPN_MAX_SPACEMOUSE);
addItems(SOURCE_TYPE_TRIM, RawSource::TrimsGroup, -board->getCapability(Board::NumTrims));
addItems(SOURCE_TYPE_INPUT, RawSource::SourcesGroup, -board->getCapability(Board::Inputs));
addItems(SOURCE_TYPE_VIRTUAL_INPUT, RawSource::InputsGroup, -firmware->getCapability(VirtualInputs));
for (int i = firmware->getCapability(LuaScripts) - 1; i >= 0; i--)
addItems(SOURCE_TYPE_LUA_OUTPUT, RawSource::ScriptsGroup, -firmware->getCapability(LuaOutputsPerScript), -i * 16);

// Ascending source direction (including zero)
addItems(SOURCE_TYPE_NONE, RawSource::NoneGroup, 1);
for (int i = 0; i < firmware->getCapability(LuaScripts); i++)
addItems(SOURCE_TYPE_LUA_OUTPUT, RawSource::ScriptsGroup, firmware->getCapability(LuaOutputsPerScript), i * 16);
addItems(SOURCE_TYPE_VIRTUAL_INPUT, RawSource::InputsGroup, firmware->getCapability(VirtualInputs));
addItems(SOURCE_TYPE_STICK, RawSource::SourcesGroup, board->getCapability(Board::Inputs));
addItems(SOURCE_TYPE_INPUT, RawSource::SourcesGroup, board->getCapability(Board::Inputs));
addItems(SOURCE_TYPE_TRIM, RawSource::TrimsGroup, board->getCapability(Board::NumTrims));
addItems(SOURCE_TYPE_SPACEMOUSE, RawSource::SourcesGroup, CPN_MAX_SPACEMOUSE);
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, 1);
Expand All @@ -121,7 +141,8 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, firmware->getCapability(TrainerInputs));
addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, firmware->getCapability(Outputs));
addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, firmware->getCapability(Gvars));
addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, SOURCE_TYPE_SPECIAL_COUNT);
addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, SOURCE_TYPE_SPECIAL_COUNT - 1);
addItems(SOURCE_TYPE_TIMER, RawSource::TelemGroup, firmware->getCapability(Timers));
addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, firmware->getCapability(Sensors) * 3);
}

Expand All @@ -131,14 +152,19 @@ void RawSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSourc
item->setData(src.isAvailable(modelData, generalSettings, boardType), IMDR_Available);
}

void RawSourceItemModel::addItems(const RawSourceType & type, const int group, const int count, const int start)
void RawSourceItemModel::addItems(const RawSourceType & type, const int group, int count, const int start)
{
for (int i = start; i < start + count; i++) {
const RawSource src = RawSource(type, i);
const int idxAdj = (type == SOURCE_TYPE_NONE ? -1 : 0);

int first = start + count < 0 ? start + count : start + 1;
int last = start + count < 0 ? start : start + count + 1;

for (int i = first; i < last; ++i) {
const RawSource src = RawSource(type, i + idxAdj);
QStandardItem * modelItem = new QStandardItem();
modelItem->setData(src.toValue(), IMDR_Id);
modelItem->setData(type, IMDR_Type);
modelItem->setData(group, IMDR_Flags);
modelItem->setData((group | (i + idxAdj < 0 ? RawSource::NegativeGroup : i > 0 ? RawSource::PositiveGroup : 0)), IMDR_Flags);
setDynamicItemData(modelItem, src);
appendRow(modelItem);
}
Expand Down
2 changes: 1 addition & 1 deletion companion/src/datamodels/compounditemmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class RawSourceItemModel: public AbstractDynamicItemModel

protected:
virtual void setDynamicItemData(QStandardItem * item, const RawSource & src) const;
void addItems(const RawSourceType & type, const int group, const int count, const int start = 0);
void addItems(const RawSourceType & type, const int group, int count, const int start = 0);
};

class RawSwitchItemModel: public AbstractDynamicItemModel
Expand Down
2 changes: 1 addition & 1 deletion companion/src/firmwares/adjustmentreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ QString AdjustmentReference::toString(const ModelData * model, const bool sign)

switch(type) {
case ADJUST_REF_GVAR:
ret = RawSource(SOURCE_TYPE_GVAR, abs(value) - 1).toString(model);
ret = RawSource(SOURCE_TYPE_GVAR, abs(value)).toString(model);
if (value < 0)
ret.prepend("-");
else if (sign)
Expand Down
3 changes: 1 addition & 2 deletions companion/src/firmwares/boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ Boards::Boards(Board::Type board) :
legacyTrimSourcesLookupTable(legacyTrimSourcesLut),
trimSwitchesLookupTable(trimSwitchesLut),
rawSwitchTypesLookupTable(RawSwitch::getRawSwitchTypesLookupTable()),
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable()),
rawSourceCyclicLookupTable(RawSource::getCyclicLookupTable())
rawSourceSpecialTypesLookupTable(RawSource::getSpecialTypesLookupTable())
{
setBoardType(board);
}
Expand Down
2 changes: 0 additions & 2 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ class Boards
STRINGTAGMAPPINGFUNCS(trimSwitchesLookupTable, TrimSwitch);
STRINGTAGMAPPINGFUNCS(rawSwitchTypesLookupTable, RawSwitchType);
STRINGTAGMAPPINGFUNCS(rawSourceSpecialTypesLookupTable, RawSourceSpecialType);
STRINGTAGMAPPINGFUNCS(rawSourceCyclicLookupTable, RawSourceCyclic);

static bool isInputAvailable(int index, Board::Type board = Board::BOARD_UNKNOWN);
static bool isInputCalibrated(int index, Board::Type board = Board::BOARD_UNKNOWN);
Expand All @@ -382,7 +381,6 @@ class Boards
const StringTagMappingTable trimSwitchesLookupTable;
const StringTagMappingTable rawSwitchTypesLookupTable;
const StringTagMappingTable rawSourceSpecialTypesLookupTable;
const StringTagMappingTable rawSourceCyclicLookupTable;

static StringTagMappingTable getLegacyAnalogsLookupTable(Board::Type board = Board::BOARD_UNKNOWN);
};
Expand Down
10 changes: 5 additions & 5 deletions companion/src/firmwares/customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QString CustomFunctionData::funcToString(const ModelData * model) const
QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData * model)
{
if (func >= FuncOverrideCH1 && func <= FuncOverrideCHLast)
return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func).toString(model));
return tr("Override %1").arg(RawSource(SOURCE_TYPE_CH, func + 1).toString(model));
else if (func == FuncTrainer)
return tr("Trainer Axis");
else if (func == FuncTrainerRUD)
Expand All @@ -84,7 +84,7 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
else if (func == FuncReset)
return tr("Reset");
else if (func >= FuncSetTimer1 && func <= FuncSetTimerLast)
return tr("Set %1").arg(RawSource(SOURCE_TYPE_SPECIAL, SOURCE_TYPE_SPECIAL_FIRST_TIMER + func - FuncSetTimer1).toString(model));
return tr("Set %1").arg(RawSource(SOURCE_TYPE_TIMER, func - FuncSetTimer1 + 1).toString(model));
else if (func == FuncVario)
return tr("Vario");
else if (func == FuncPlayPrompt)
Expand All @@ -108,7 +108,7 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
else if (func == FuncBackgroundMusicPause)
return tr("Background Music Pause");
else if (func >= FuncAdjustGV1 && func <= FuncAdjustGVLast)
return tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR, func - FuncAdjustGV1).toString(model));
return tr("Adjust %1").arg(RawSource(SOURCE_TYPE_GVAR, func - FuncAdjustGV1 + 1).toString(model));
else if (func == FuncSetFailsafe)
return tr("Set Failsafe");
else if (func == FuncRangeCheckInternalModule)
Expand Down Expand Up @@ -281,7 +281,7 @@ QString CustomFunctionData::resetToString(const int value, const ModelData * mod

if (value < step) {
if (value < firmware->getCapability(Timers))
return RawSource(SOURCE_TYPE_SPECIAL, value + SOURCE_TYPE_SPECIAL_FIRST_TIMER).toString(model);
return RawSource(SOURCE_TYPE_TIMER, value).toString(model);
else
return QString(CPN_STR_UNKNOWN_ITEM);
}
Expand All @@ -293,7 +293,7 @@ QString CustomFunctionData::resetToString(const int value, const ModelData * mod
return tr("Telemetry");

if (value < step + firmware->getCapability(Sensors))
return RawSource(SOURCE_TYPE_TELEMETRY, 3 * (value - step)).toString(model);
return RawSource(SOURCE_TYPE_TELEMETRY, 3 * (value - step + 1)).toString(model);

return QString(CPN_STR_UNKNOWN_ITEM);
}
Expand Down
3 changes: 0 additions & 3 deletions companion/src/firmwares/customfunctiondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class AbstractStaticItemModel;
enum AssignFunc {
FuncOverrideCH1 = 0,
FuncOverrideCHLast = FuncOverrideCH1 + CPN_MAX_CHNOUT - 1,
FuncOverrideCH32 = FuncOverrideCHLast, // TODO remove
FuncTrainer,
FuncTrainerRUD,
FuncTrainerELE,
Expand All @@ -48,8 +47,6 @@ enum AssignFunc {
FuncPlayHaptic,
FuncReset,
FuncSetTimer1,
FuncSetTimer2, // TODO remove
FuncSetTimer3, // TODO remove
FuncSetTimerLast = FuncSetTimer1 + CPN_MAX_TIMERS - 1,
FuncVario,
FuncPlayPrompt,
Expand Down
6 changes: 3 additions & 3 deletions companion/src/firmwares/edgetx/yaml_modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ struct YamlThrTrace {
YamlThrTrace(unsigned int cpn_value)
{
if (cpn_value == 0) {
src = RawSource(SOURCE_TYPE_STICK, 2/* throttle */);
src = RawSource(SOURCE_TYPE_INPUT, 2/* throttle */);
return;
}
cpn_value--;
Boards board(getCurrentBoard());
int pots = board.getCapability(Board::Pots);
int sliders = board.getCapability(Board::Sliders);
if (cpn_value < (unsigned int)(pots + sliders)) {
src = RawSource(SOURCE_TYPE_STICK, 4/* sticks */ + cpn_value);
src = RawSource(SOURCE_TYPE_INPUT, 4/* sticks */ + cpn_value);
}
else {
cpn_value -= pots + sliders;
Expand All @@ -186,7 +186,7 @@ struct YamlThrTrace {
unsigned int toCpn()
{
switch (src.type) {
case SOURCE_TYPE_STICK:
case SOURCE_TYPE_INPUT:
if (src.index == 2 /* throttle */) {
return 0;
} else {
Expand Down
Loading

0 comments on commit 80659c3

Please sign in to comment.