Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Squashed rebase of #2085 #5392

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions companion/src/firmwares/customfunctiondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QtCore>
#include <QComboBox>

#define CF_CUSTNAME_LEN 10

class Firmware;
class ModelData;
class GeneralSettings;
Expand Down Expand Up @@ -109,6 +111,7 @@ class CustomFunctionData {
unsigned int enabled; // TODO perhaps not any more the right name
unsigned int adjustMode;
int repeatParam;
char custName[CF_CUSTNAME_LEN + 1];

void convert(RadioDataConversionState & cstate);

Expand Down
4 changes: 4 additions & 0 deletions companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
node["def"] = def;
}

node["custName"] = rhs.custName;

return node;
}

Expand All @@ -265,6 +267,8 @@ bool convert<CustomFunctionData>::decode(const Node& node,
{
node["swtch"] >> rhs.swtch;

node["custName"] >> rhs.custName;

int func = 0;
node["func"] >> customFnLut >> func;
rhs.func = (AssignFunc)func;
Expand Down
18 changes: 17 additions & 1 deletion companion/src/firmwares/edgetx/yaml_logicalswitchdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static const YamlLookupTable funcLut = {
{LS_FN_DAPOS, "FUNC_ADIFFEGREATER"},
{LS_FN_TIMER, "FUNC_TIMER"},
{LS_FN_STICKY, "FUNC_STICKY"},
{LS_FN_SAFE, "FUNC_SAFE"},
};

static int timerValue2lsw(uint32_t t)
Expand Down Expand Up @@ -80,6 +81,12 @@ Node convert<LogicalSwitchData>::encode(const LogicalSwitchData& rhs)
def += YamlRawSwitchEncode(RawSwitch(rhs.val2));
} break;

case LS_FAMILY_SAFE: {
def += YamlRawSwitchEncode(RawSwitch(rhs.val1));
def += ",";
def += YamlRawSwitchEncode(RawSwitch(rhs.val2));
} break;

case LS_FAMILY_EDGE: {
def += YamlRawSwitchEncode(RawSwitch(rhs.val1));
def += ",";
Expand Down Expand Up @@ -119,14 +126,15 @@ Node convert<LogicalSwitchData>::encode(const LogicalSwitchData& rhs)
node["andsw"] = YamlRawSwitchEncode(RawSwitch(rhs.andsw));
node["lsPersist"] = (int)rhs.lsPersist;
node["lsState"] = (int)rhs.lsState;

node["custName"] = rhs.custName;
return node;
}

bool convert<LogicalSwitchData>::decode(const Node& node,
LogicalSwitchData& rhs)
{
node["func"] >> funcLut >> rhs.func;
node["custName"] >> rhs.custName;

std::string def_str;
node["def"] >> def_str;
Expand All @@ -142,6 +150,14 @@ bool convert<LogicalSwitchData>::decode(const Node& node,
rhs.val2 = YamlRawSwitchDecode(sw_str).toValue();
} break;

case LS_FAMILY_SAFE: {
std::string sw_str;
getline(def, sw_str, ',');
rhs.val1 = YamlRawSwitchDecode(sw_str).toValue();
getline(def, sw_str);
rhs.val2 = YamlRawSwitchDecode(sw_str).toValue();
} break;

case LS_FAMILY_EDGE: {
std::string sw_str;
getline(def, sw_str, ',');
Expand Down
12 changes: 10 additions & 2 deletions companion/src/firmwares/logicalswitchdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

bool LogicalSwitchData::isEmpty() const
{
return (func == 0);
return (func == LS_FN_OFF);
}

CSFunctionFamily LogicalSwitchData::getFunctionFamily() const
Expand All @@ -39,6 +39,8 @@ CSFunctionFamily LogicalSwitchData::getFunctionFamily() const
return LS_FAMILY_TIMER;
else if (func == LS_FN_STICKY)
return LS_FAMILY_STICKY;
else if (func == LS_FN_SAFE)
return LS_FAMILY_SAFE;
else if (func < LS_FN_AND || func > LS_FN_ELESS)
return LS_FAMILY_VOFS;
else if (func < LS_FN_EQUAL)
Expand Down Expand Up @@ -103,6 +105,8 @@ QString LogicalSwitchData::funcToString() const
return tr("Timer");
case LS_FN_STICKY:
return tr("Sticky");
case LS_FN_SAFE:
return tr("Safe");
case LS_FN_EDGE:
return tr("Edge");
default:
Expand All @@ -112,7 +116,7 @@ QString LogicalSwitchData::funcToString() const

QString LogicalSwitchData::nameToString(int index) const
{
return RadioData::getElementName(tr("L"), index + 1, NULL, true);
return RadioData::getElementName(tr("L"), index + 1, custName, true);
}

void LogicalSwitchData::convert(RadioDataConversionState & cstate)
Expand All @@ -125,6 +129,10 @@ void LogicalSwitchData::convert(RadioDataConversionState & cstate)
val1 = RawSource(val1).convert(cstate.withComponentField("V1")).toValue();
break;
case LS_FAMILY_STICKY:
case LS_FAMILY_SAFE:
val1 = RawSwitch(val1).convert(cstate.withComponentField("V1")).toValue();
val2 = RawSwitch(val2).convert(cstate.withComponentField("V2")).toValue();
break;
case LS_FAMILY_VBOOL:
val1 = RawSwitch(val1).convert(cstate.withComponentField("V1")).toValue();
val2 = RawSwitch(val2).convert(cstate.withComponentField("V2")).toValue();
Expand Down
7 changes: 6 additions & 1 deletion companion/src/firmwares/logicalswitchdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <QtCore>

#define LS_CUSTNAME_LEN 10

class RadioDataConversionState;

enum CSFunction {
Expand All @@ -48,8 +50,9 @@ enum CSFunction {
LS_FN_TIMER,
LS_FN_STICKY,
LS_FN_EDGE,
LS_FN_SAFE,
// later ... LS_FN_RANGE,
LS_FN_MAX
LS_FN_MAX
};

enum CSFunctionFamily {
Expand All @@ -59,6 +62,7 @@ enum CSFunctionFamily {
LS_FAMILY_TIMER,
LS_FAMILY_STICKY,
LS_FAMILY_EDGE,
LS_FAMILY_SAFE
};

class LogicalSwitchData {
Expand All @@ -79,6 +83,7 @@ class LogicalSwitchData {
int andsw;
bool lsState;
bool lsPersist;
char custName[LS_CUSTNAME_LEN + 1];

void clear() { memset(this, 0, sizeof(LogicalSwitchData)); }
bool isEmpty() const;
Expand Down
6 changes: 6 additions & 0 deletions companion/src/firmwares/modeldata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,12 @@ int ModelData::updateReference()
}
break;
case LS_FAMILY_STICKY:
case LS_FAMILY_SAFE:
if (lsd->val1 != 0)
updateSwitchIntRef(lsd->val1);
if (lsd->val2 != 0)
updateSwitchIntRef(lsd->val2);
break;
case LS_FAMILY_VBOOL:
oldval1 = lsd->val1;
oldval2 = lsd->val2;
Expand Down
5 changes: 3 additions & 2 deletions companion/src/firmwares/opentx/opentxeeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,7 @@ class LogicalSwitchesFunctionsTable: public ConversionTable {
addConversion(LS_FN_DAPOS, val++);
addConversion(LS_FN_TIMER, val++);
addConversion(LS_FN_STICKY, val++);
addConversion(LS_FN_SAFE, val++);
}
};

Expand Down Expand Up @@ -1570,7 +1571,7 @@ class LogicalSwitchField: public TransformedField {
v2 = csw.val2;
v3 = csw.val3;
}
else if ((csw.func >= LS_FN_AND && csw.func <= LS_FN_XOR) || csw.func == LS_FN_STICKY) {
else if ((csw.func >= LS_FN_AND && csw.func <= LS_FN_XOR) || csw.func == LS_FN_STICKY || csw.func == LS_FN_SAFE) {
switchesConversionTable->exportValue(csw.val1, v1);
switchesConversionTable->exportValue(csw.val2, v2);
}
Expand All @@ -1595,7 +1596,7 @@ class LogicalSwitchField: public TransformedField {
csw.val2 = v2;
csw.val3 = v3;
}
else if ((csw.func >= LS_FN_AND && csw.func <= LS_FN_XOR) || csw.func == LS_FN_STICKY) {
else if ((csw.func >= LS_FN_AND && csw.func <= LS_FN_XOR) || csw.func == LS_FN_STICKY || csw.func == LS_FN_SAFE) {
switchesConversionTable->importValue(v1, csw.val1);
switchesConversionTable->importValue(v2, csw.val2);
}
Expand Down
2 changes: 1 addition & 1 deletion companion/src/firmwares/rawsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
return DataHelpers::getCompositeName(dfltName, custName, prefixCustomName);

case SOURCE_TYPE_CUSTOM_SWITCH:
return RawSwitch(SWITCH_TYPE_VIRTUAL, index).toString(); // RawSwitch uses 1 based index
return RawSwitch(SWITCH_TYPE_VIRTUAL, index + 1) .toString(board, generalSettings, model); // RawSwitch uses 1 based index

case SOURCE_TYPE_CYC:
return tr("CYC%1").arg(index);
Expand Down
12 changes: 11 additions & 1 deletion companion/src/firmwares/rawswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,20 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen

case SWITCH_TYPE_VIRTUAL:
if (modelData)
return modelData->logicalSw[index].nameToString(index - 1);
return modelData->logicalSw[index - 1].nameToString(index - 1);
else
return LogicalSwitchData().nameToString(index - 1);

case SWITCH_TYPE_FUNCTIONSWITCH:
if (!Boards::getCapability(board, Board::FunctionSwitches))
return CPN_STR_UNKNOWN_ITEM;
qr = div(index - 1, 3);
if (modelData)
swName = QString(modelData->functionSwitchNames[qr.quot]).trimmed();
if (swName.isEmpty())
swName = tr("SW%1").arg(qr.quot + 1);
return swName + directionIndicators.at(qr.rem > -1 && qr.rem < directionIndicators.size() ? qr.rem : 1);

case SWITCH_TYPE_MULTIPOS_POT:
if (!Boards::getCapability(board, Board::MultiposPotsPositions))
return CPN_STR_UNKNOWN_ITEM;
Expand Down
Loading
Loading