Skip to content
Merged
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
12 changes: 2 additions & 10 deletions companion/src/firmwares/customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,8 @@ QString CustomFunctionData::repeatToString(const int value, const bool abbrev)

QString CustomFunctionData::enabledToString() const
{
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) ||
(func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) ||
(func == FuncReset) ||
(func >= FuncSetTimer1 && func <= FuncSetTimerLast) ||
(func == FuncVolume) ||
(func == FuncBacklight) ||
(func <= FuncInstantTrim)) {
if (!enabled) {
return tr("DISABLED");
}
if (!enabled) {
return tr("DISABLED");
}
return "";
}
Expand Down
55 changes: 30 additions & 25 deletions companion/src/firmwares/edgetx/yaml_customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
#include "yaml_rawsource.h"
#include "eeprominterface.h"

static bool fnHasEnable(AssignFunc fn)
{
return (fn <= FuncInstantTrim)
|| (fn >= FuncReset && fn <= FuncSetTimerLast)
|| (fn >= FuncAdjustGV1 && fn <= FuncBindExternalModule)
|| (fn == FuncVolume)
|| (fn == FuncBacklight);
}

static bool fnHasRepeat(AssignFunc fn)
{
return (fn == FuncPlayPrompt)
Expand Down Expand Up @@ -226,15 +217,15 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
break;
}

if (fnHasEnable(rhs.func)) {
if (add_comma) {
def += ",";
}
def += std::to_string((int)rhs.enabled);
} else if(fnHasRepeat(rhs.func)) {
if (add_comma) {
def += ",";
}
if (add_comma) {
def += ",";
}

def += std::to_string((int)rhs.enabled);

if(fnHasRepeat(rhs.func)) {
def += ",";

if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
def += ((rhs.repeatParam == 0) ? "On" : "1x");
} else if (rhs.repeatParam == 0) {
Expand Down Expand Up @@ -385,13 +376,27 @@ bool convert<CustomFunctionData>::decode(const Node& node,
def.ignore();
}

if (fnHasEnable(rhs.func)) {
int en = 0;
def >> en;
rhs.enabled = en;
} else if(fnHasRepeat(rhs.func)) {
std::string repeat;
getline(def, repeat);
// Need to handle older YAML files where only one of enabled/repeat was present
std::string en, repeat;
getline(def, en, ',');
getline(def, repeat);

if (repeat.empty()) {
// Only one value left to parse
if (fnHasRepeat(rhs.func)) {
// Assume it is repeat and set enabled to true
repeat = en;
rhs.enabled = 1;
} else {
// Func does not have repeat
rhs.enabled = en[0] == '1' ? 1 : 0;
}
} else {
// Two values - first is 'enabled' flag
rhs.enabled = en[0] == '1' ? 1 : 0;
}

if(fnHasRepeat(rhs.func)) {
if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
rhs.repeatParam = (repeat == "1x") ? 1 : 0;
} else if (repeat == "1x") {
Expand Down
35 changes: 16 additions & 19 deletions companion/src/modeledit/customfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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") << tr("Repeat") << tr("Enable");
TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels);

for (int i = 0; i < fswCapability; i++) {
Expand Down Expand Up @@ -215,11 +215,12 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
repeatLayout->addWidget(fswtchRepeat[i], i + 1);
connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));

QHBoxLayout *enableLayout = new QHBoxLayout();
tableLayout->addLayout(i, 5, enableLayout);
fswtchEnable[i] = new QCheckBox(this);
fswtchEnable[i]->setProperty("index", i);
fswtchEnable[i]->setText(tr("ON"));
fswtchEnable[i]->setFixedWidth(200);
repeatLayout->addWidget(fswtchEnable[i], i + 1);
enableLayout->addWidget(fswtchEnable[i], i + 1);
connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
}

Expand Down Expand Up @@ -351,6 +352,7 @@ void CustomFunctionsPanel::functionEdited()
functions[index].clear();
functions[index].swtch = swtch;
functions[index].func = (AssignFunc)fswtchFunc[index]->currentData().toInt();
functions[index].enabled = true;
if (functions[index].func == FuncPlayScript || functions[index].func == FuncRGBLed)
fswtchRepeat[index]->setModel(tabModelFactory->getItemModel(repeatLuaId));
else
Expand All @@ -375,10 +377,11 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
else {
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(cfn.swtch.toValue()));
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(cfn.func));
fswtchEnable[i]->setChecked(cfn.enabled);
}

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

if (func >= FuncOverrideCH1 && func <= FuncOverrideCH32) {
if (model) {
Expand All @@ -391,7 +394,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
cfn.param = fswtchParam[i]->value();
}
fswtchParam[i]->setValue(cfn.param);
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_ENABLE;
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
}
}
else if (func == FuncLogs) {
Expand All @@ -409,7 +412,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
if (modified)
cfn.adjustMode = fswtchGVmode[i]->currentData().toInt();
fswtchGVmode[i]->setCurrentIndex(fswtchGVmode[i]->findData(cfn.adjustMode));
widgetsMask |= CUSTOM_FUNCTION_GV_MODE | CUSTOM_FUNCTION_ENABLE;
widgetsMask |= CUSTOM_FUNCTION_GV_MODE;
if (cfn.adjustMode == FUNC_ADJUST_GVAR_CONSTANT || cfn.adjustMode == FUNC_ADJUST_GVAR_INCDEC) {
if (modified)
cfn.param = fswtchParam[i]->value() * model->gvarData[gvidx].multiplierSet();
Expand Down Expand Up @@ -440,24 +443,21 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
if (modified)
cfn.param = fswtchParamT[i]->currentData().toInt();
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE;
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
}
else if (func >= FuncSetTimer1 && func <= FuncSetTimer3) {
if (modified)
cfn.param = fswtchParamTime[i]->timeInSeconds();
RawSourceRange range = RawSource(SOURCE_TYPE_SPECIAL, func - FuncSetTimer1 + 2).getRange(model, generalSettings);
fswtchParamTime[i]->setTimeRange((int)range.min, (int)range.max);
fswtchParamTime[i]->setTime(cfn.param);
widgetsMask |= CUSTOM_FUNCTION_TIME_PARAM | CUSTOM_FUNCTION_ENABLE;
}
else if (func >= FuncSetFailsafe && func <= FuncBindExternalModule) {
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
widgetsMask |= CUSTOM_FUNCTION_TIME_PARAM;
}
else if (func == FuncVolume || func == FuncBacklight) {
if (modified)
cfn.param = fswtchParamT[i]->currentData().toInt();
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE;
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
}
else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic || func == FuncSetScreen) {
if (func != FuncBackgroundMusic) {
Expand Down Expand Up @@ -568,11 +568,12 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
fswtchParam[i]->setDecimals(0);
fswtchParam[i]->setSingleStep(1);
fswtchParam[i]->setValue(cfn.param);
if (func <= FuncInstantTrim) {
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
}
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
}
}
else {
cfn.enabled = true;
}

fswtchFunc[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SHOW_FUNC);
fswtchParam[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_NUMERIC_PARAM);
Expand All @@ -581,10 +582,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
fswtchParamT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SOURCE_PARAM);
fswtchParamArmT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_FILE_PARAM);
fswtchEnable[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_ENABLE);
if (widgetsMask & CUSTOM_FUNCTION_ENABLE)
fswtchEnable[i]->setChecked(cfn.enabled);
else
fswtchEnable[i]->setChecked(false);
fswtchRepeat[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_REPEAT);
fswtchGVmode[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_GV_MODE);
playBT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_PLAY);
Expand Down
3 changes: 2 additions & 1 deletion radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ PACK(struct CustomFunctionData {
NOBACKUP(CFN_SPARE_TYPE val2);
}) clear);
}) NAME(fp) SKIP;
uint8_t active SKIP;
uint8_t active : 1 SKIP;
int8_t repeat:7 SKIP;

bool isEmpty() const
{
Expand Down
11 changes: 4 additions & 7 deletions radio/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool isRepeatDelayElapsed(const CustomFunctionData * functions, CustomFunctionsC
{
const CustomFunctionData * cfn = &functions[index];
tmr10ms_t tmr10ms = get_tmr10ms();
uint8_t repeatParam = CFN_PLAY_REPEAT(cfn);
int8_t repeatParam = CFN_PLAY_REPEAT(cfn);
if (!IS_SILENCE_PERIOD_ELAPSED() && repeatParam == CFN_PLAY_REPEAT_NOSTART) {
functionsContext.lastFunctionTime[index] = tmr10ms;
}
Expand Down Expand Up @@ -156,12 +156,9 @@ void evalFunctions(const CustomFunctionData * functions, CustomFunctionsContext
if (swtch) {
MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i);

bool active = getSwitch(
swtch, IS_PLAY_FUNC(CFN_FUNC(cfn)) ? GETSWITCH_MIDPOS_DELAY : 0);

if (HAS_ENABLE_PARAM(CFN_FUNC(cfn))) {
active &= (bool)CFN_ACTIVE(cfn);
}
bool active = getSwitch(swtch, IS_PLAY_FUNC(CFN_FUNC(cfn)) ? GETSWITCH_MIDPOS_DELAY : 0);
if (CFN_ACTIVE(cfn) == 0)
active = false;

if (active) {
switch (CFN_FUNC(cfn)) {
Expand Down
42 changes: 26 additions & 16 deletions radio/src/gui/128x64/model_special_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

#include "opentx.h"

#define MODEL_SPECIAL_FUNC_1ST_COLUMN (0)
#define MODEL_SPECIAL_FUNC_2ND_COLUMN (4*FW-1)
#define MODEL_SPECIAL_FUNC_3RD_COLUMN (15*FW-3)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN (20*FW)
#define MODEL_SPECIAL_FUNC_1ST_COLUMN (0)
#define MODEL_SPECIAL_FUNC_2ND_COLUMN (4*FW-1)
#define MODEL_SPECIAL_FUNC_3RD_COLUMN (15*FW-3)
#if defined(GRAPHICS)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (20*FW)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN (19 * FW - 3)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (19 * FW - 3)
#define MODEL_SPECIAL_FUNC_5TH_COLUMN_ONOFF (20 * FW + 1)
#else
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (18*FW+2)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (17 * FW)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (17 * FW)
#define MODEL_SPECIAL_FUNC_5TH_COLUMN_ONOFF (18 * FW + 3)
#endif

#if defined(SDCARD)
Expand Down Expand Up @@ -186,12 +189,13 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF

CustomFunctionData * cfn = &functions[k];
uint8_t func = CFN_FUNC(cfn);
for (uint8_t j=0; j<5; j++) {
for (uint8_t j=0; j<6; j++) {
uint8_t attr = ((sub==k && menuHorizontalPosition==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
uint8_t active = (attr && s_editMode > 0);
switch (j) {
case 0:
if (sub==k && menuHorizontalPosition < 1 && CFN_SWITCH(cfn) == SWSRC_NONE) {
CFN_ACTIVE(cfn) = 0; // Default is disabled
drawSwitch(MODEL_SPECIAL_FUNC_1ST_COLUMN, y, CFN_SWITCH(cfn), attr | INVERS | ((functionsContext->activeSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
if (active) CHECK_INCDEC_SWITCH(event, CFN_SWITCH(cfn), SWSRC_FIRST, SWSRC_LAST, eeFlags, isSwitchAvailableInCustomFunctions);
}
Expand All @@ -213,7 +217,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
}
}
else {
j = 4; // skip other fields
j = 5; // skip other fields
if (sub==k && menuHorizontalPosition > 0) {
repeatLastCursorMove(event);
}
Expand Down Expand Up @@ -308,9 +312,14 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
}
#endif
#if defined(SDCARD)
else if (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT || func==FUNC_RGB_LED) {
else if (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT || func == FUNC_RGB_LED) {
coord_t x = MODEL_SPECIAL_FUNC_3RD_COLUMN - 6;
if (func == FUNC_PLAY_SCRIPT)
x = x - 5 * FW;
else if (func == FUNC_PLAY_TRACK)
x = x - 2 * FW;
if (ZEXIST(cfn->play.name))
lcdDrawSizedText(MODEL_SPECIAL_FUNC_3RD_COLUMN-6, y, cfn->play.name, sizeof(cfn->play.name), attr);
lcdDrawSizedText(x, y, cfn->play.name, sizeof(cfn->play.name), attr);
else
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_VCSWFUNC, 0, attr);
if (active && event==EVT_KEY_BREAK(KEY_ENTER)) {
Expand Down Expand Up @@ -439,11 +448,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
}

case 4:
if (HAS_ENABLE_PARAM(func)) {
drawCheckBox(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF, y, CFN_ACTIVE(cfn), attr);
if (active) CFN_ACTIVE(cfn) = checkIncDec(event, CFN_ACTIVE(cfn), 0, 1, eeFlags);
}
else if (HAS_REPEAT_PARAM(func)) {
if (HAS_REPEAT_PARAM(func)) {
if (func == FUNC_PLAY_SCRIPT) {
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF-3, y, (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x", attr);
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn), 0, 1, eeFlags);
Expand All @@ -465,6 +470,11 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
repeatLastCursorMove(event);
}
break;

case 5:
drawCheckBox(MODEL_SPECIAL_FUNC_5TH_COLUMN_ONOFF, y, CFN_ACTIVE(cfn), attr);
if (active) CFN_ACTIVE(cfn) = checkIncDec(event, CFN_ACTIVE(cfn), 0, 1, eeFlags);
break;
}
}
#if defined(NAVIGATION_X7)
Expand All @@ -483,7 +493,7 @@ void menuModelSpecialFunctions(event_t event)
menuHorizontalPosition = 0;
}
#endif
MENU(STR_MENUCUSTOMFUNC, menuTabModel, MENU_MODEL_SPECIAL_FUNCTIONS, HEADER_LINE+MAX_SPECIAL_FUNCTIONS, { HEADER_LINE_COLUMNS NAVIGATION_LINE_BY_LINE|4/*repeated*/ });
MENU(STR_MENUCUSTOMFUNC, menuTabModel, MENU_MODEL_SPECIAL_FUNCTIONS, HEADER_LINE+MAX_SPECIAL_FUNCTIONS, { HEADER_LINE_COLUMNS NAVIGATION_LINE_BY_LINE|5/*repeated*/ });

menuSpecialFunctions(event, g_model.customFn, &modelFunctionsContext);

Expand Down
Loading