Skip to content

Commit

Permalink
Companion: custom function Friendly Name Label
Browse files Browse the repository at this point in the history
  • Loading branch information
shane-droid authored and pfeerick committed Dec 7, 2022
1 parent 45b0b7b commit 207650e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions companion/src/firmwares/customfunctiondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class CustomFunctionData {
unsigned int enabled; // TODO perhaps not any more the right name
unsigned int adjustMode;
int repeatParam;
char custName[10+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 @@ -238,6 +238,8 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
node["def"] = def;
}

node["custName"] = rhs.custName;

return node;
}

Expand All @@ -246,6 +248,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
40 changes: 37 additions & 3 deletions companion/src/modeledit/customfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
playIcon.addImage("stop.png", QIcon::Normal, QIcon::On);

QStringList headerLabels;
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << "";
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << "" << "Name";
TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels);

for (int i = 0; i < fswCapability; i++) {
Expand All @@ -116,6 +116,16 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
connect(label, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint)));
tableLayout->addWidget(i, 0, label);


// The Custom Name
name[i] = new QLineEdit(this);
name[i]->setProperty("index", i);
name[i]->setMaxLength(10);
QRegExp rx(CHAR_FOR_NAMES_REGEX);
name[i]->setValidator(new QRegExpValidator(rx, this));
connect(name[i], SIGNAL(editingFinished()), this, SLOT(nameEdited()));
tableLayout->addWidget(i, 5, name[i]);

// The switch
fswtchSwtch[i] = new QComboBox(this);
Expand Down Expand Up @@ -205,6 +215,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchEnable[i]->setFixedWidth(200);
repeatLayout->addWidget(fswtchEnable[i], i + 1);
connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));


}

disableMouseScrolling();
Expand Down Expand Up @@ -330,34 +342,56 @@ void CustomFunctionsPanel::functionEdited()
}
}

void CustomFunctionsPanel::nameEdited()
{
QLineEdit *le = qobject_cast<QLineEdit*>(sender());
int index = le->property("index").toInt();
CustomFunctionData & cfn = functions[index];
if (cfn.custName != le->text()) {
strcpy(cfn.custName, le->text().toLatin1());

emit modified();
}
}

void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
{
CustomFunctionData & cfn = functions[i];
AssignFunc func = (AssignFunc)fswtchFunc[i]->currentData().toInt();



unsigned int widgetsMask = 0;
if (modified) {

cfn.swtch = RawSwitch(fswtchSwtch[i]->currentData().toInt());
cfn.func = func;
cfn.enabled = fswtchEnable[i]->isChecked();

}
else {
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(cfn.swtch.toValue()));
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(cfn.func));
name[i]->setText(cfn.custName);
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(cfn.swtch.toValue()));
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(cfn.func));
}

if (!cfn.isEmpty()) {
widgetsMask |= CUSTOM_FUNCTION_SHOW_FUNC;

name[i]->setText(cfn.custName);

if (func >= FuncOverrideCH1 && func <= FuncOverrideCH32) {
if (model) {
int channelsMax = model->getChannelsMax(true);
fswtchParam[i]->setDecimals(0);
fswtchParam[i]->setSingleStep(1);
fswtchParam[i]->setMinimum(-channelsMax);
fswtchParam[i]->setMaximum(channelsMax);
name[i]->setText(cfn.custName);

if (modified) {
cfn.param = fswtchParam[i]->value();
strcpy(cfn.custName, name[i]->text().toLatin1());
}
fswtchParam[i]->setValue(cfn.param);
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_ENABLE;
Expand Down
2 changes: 2 additions & 0 deletions companion/src/modeledit/customfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CustomFunctionsPanel : public GenericPanel

private slots:
void customFunctionEdited();
void nameEdited();
void functionEdited();
void onCustomContextMenuRequested(QPoint pos);
void refreshCustomFunction(int index, bool modified=false);
Expand Down Expand Up @@ -92,6 +93,7 @@ class CustomFunctionsPanel : public GenericPanel
QSet<QString> tracksSet;
QSet<QString> scriptsSet;
int mediaPlayerCurrent;
QLineEdit *name[CPN_MAX_SPECIAL_FUNCTIONS];
QComboBox * fswtchSwtch[CPN_MAX_SPECIAL_FUNCTIONS];
QComboBox * fswtchFunc[CPN_MAX_SPECIAL_FUNCTIONS];
QCheckBox * fswtchParamGV[CPN_MAX_SPECIAL_FUNCTIONS];
Expand Down
6 changes: 6 additions & 0 deletions radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,12 @@ bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
if (!w_swtchSrc_unquoted(&_ls_node_v2, ls->v2, wf, opaque)) return false;
break;

case LS_FAMILY_SAFE:
if (!w_swtchSrc_unquoted(&_ls_node_v1, ls->v1, wf, opaque)) return false;
if (!wf(opaque,",",1)) return false;
if (!w_swtchSrc_unquoted(&_ls_node_v2, ls->v2, wf, opaque)) return false;
break;

case LS_FAMILY_EDGE:
if (!w_swtchSrc_unquoted(&_ls_node_v1, ls->v1, wf, opaque)) return false;
if (!wf(opaque,",",1)) return false;
Expand Down
14 changes: 14 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,14 @@ static void r_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
ls->v2 = r_swtchSrc(nullptr, val, val_len);
break;

case LS_FAMILY_SAFE:
ls->v1 = r_swtchSrc(nullptr, val, l_sep);
val += l_sep; val_len -= l_sep;
if (!val_len || val[0] != ',') return;
val++; val_len--;
ls->v2 = r_swtchSrc(nullptr, val, val_len);
break;

case LS_FAMILY_EDGE:
ls->v1 = r_swtchSrc(nullptr, val, l_sep);
val += l_sep; val_len -= l_sep;
Expand Down Expand Up @@ -1670,6 +1678,12 @@ static bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs,
if (!w_swtchSrc_unquoted(&_ls_node_v2, ls->v2, wf, opaque)) return false;
break;

case LS_FAMILY_SAFE:
if (!w_swtchSrc_unquoted(&_ls_node_v1, ls->v1, wf, opaque)) return false;
if (!wf(opaque,",",1)) return false;
if (!w_swtchSrc_unquoted(&_ls_node_v2, ls->v2, wf, opaque)) return false;
break;

case LS_FAMILY_EDGE:
if (!w_swtchSrc_unquoted(&_ls_node_v1, ls->v1, wf, opaque)) return false;
if (!wf(opaque,",",1)) return false;
Expand Down

0 comments on commit 207650e

Please sign in to comment.