feat: Add "Enable" button to all SF/GF (#3024) (#3601)

Co-authored-by: eshifri <eshifri@hotmail.com>
Co-authored-by: philmoz <philmoz@users.noreply.github.com>
This commit is contained in:
Peter Feerick
2023-12-03 12:23:34 +10:00
committed by GitHub
co-authored by eshifri philmoz
parent 878a365e72
commit ee73fa47f0
33 changed files with 262 additions and 194 deletions
@@ -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)
@@ -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);
}
@@ -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);
}
@@ -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)) {
@@ -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);
@@ -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)
@@ -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);
@@ -24,7 +24,7 @@
#define MODEL_SPECIAL_FUNC_1ST_COLUMN (4*FW+2)
#define MODEL_SPECIAL_FUNC_2ND_COLUMN (8*FW+2)
#define MODEL_SPECIAL_FUNC_3RD_COLUMN (21*FW)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN (33*FW-3)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN (31*FW-3)
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF (34*FW-3)
#define SD_LOGS_PERIOD_MIN 1 // 0.1s fastest period
@@ -145,8 +145,9 @@ enum CustomFunctionsItems {
ITEM_CUSTOM_FUNCTIONS_PARAM1,
ITEM_CUSTOM_FUNCTIONS_PARAM2,
ITEM_CUSTOM_FUNCTIONS_REPEAT,
ITEM_CUSTOM_FUNCTIONS_ENABLE,
ITEM_CUSTOM_FUNCTIONS_COUNT,
ITEM_CUSTOM_FUNCTIONS_LAST = ITEM_CUSTOM_FUNCTIONS_COUNT-1
ITEM_CUSTOM_FUNCTIONS_LAST = ITEM_CUSTOM_FUNCTIONS_COUNT - 1
};
void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext * functionsContext)
@@ -181,11 +182,12 @@ 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 ITEM_CUSTOM_FUNCTIONS_SWITCH:
if(CFN_SWITCH(cfn) == SWSRC_NONE) CFN_ACTIVE(cfn) = 0; // Disable new function by default
drawSwitch(MODEL_SPECIAL_FUNC_1ST_COLUMN, y, CFN_SWITCH(cfn), attr | ((functionsContext->activeSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
if (active || AUTOSWITCH_ENTER_LONG()) CHECK_INCDEC_SWITCH(event, CFN_SWITCH(cfn), SWSRC_FIRST, SWSRC_LAST, eeFlags, isSwitchAvailableInCustomFunctions);
if (func == FUNC_OVERRIDE_CHANNEL && functions != g_model.customFn) {
@@ -411,11 +413,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
}
case ITEM_CUSTOM_FUNCTIONS_REPEAT:
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+2, y, (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x", attr);
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn), 0, 1, eeFlags);
@@ -439,6 +437,13 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
repeatLastCursorMove(event);
}
break;
case ITEM_CUSTOM_FUNCTIONS_ENABLE:
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);
break;
}
}
}
@@ -446,6 +451,6 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
void menuModelSpecialFunctions(event_t event)
{
MENU(STR_MENUCUSTOMFUNC, menuTabModel, MENU_MODEL_SPECIAL_FUNCTIONS, MAX_SPECIAL_FUNCTIONS, { NAVIGATION_LINE_BY_LINE|4/*repeated*/ });
MENU(STR_MENUCUSTOMFUNC, menuTabModel, MENU_MODEL_SPECIAL_FUNCTIONS, MAX_SPECIAL_FUNCTIONS, { NAVIGATION_LINE_BY_LINE|5/*repeated*/ });
return menuSpecialFunctions(event, g_model.customFn, &modelFunctionsContext);
}
+28 -29
View File
@@ -328,12 +328,7 @@ class SpecialFunctionEditPage : public Page
}
}
if (HAS_ENABLE_PARAM(func)) {
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_ENABLE, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{},
GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
} else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_REPEAT,
0, COLOR_THEME_PRIMARY1);
@@ -360,6 +355,11 @@ class SpecialFunctionEditPage : public Page
});
}
}
line = specialFunctionOneWindow->newLine(&grid);
new StaticText(line, rect_t{}, STR_ENABLE, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
}
void buildBody(FormWindow *window)
@@ -375,6 +375,10 @@ class SpecialFunctionEditPage : public Page
CustomFunctionData *cfn = &functions[index];
// Set new function to "disabled" by default
if (!CFN_SWITCH(cfn))
CFN_ACTIVE(cfn) = false;
// Switch
auto line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_SF_SWITCH, 0, COLOR_THEME_PRIMARY1);
@@ -516,7 +520,6 @@ class SpecialFunctionButton : public Button
sfEnable = lv_obj_create(lvobj);
lv_obj_set_size(sfEnable, 22, 22);
lv_obj_add_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_style_border_width(sfEnable, 3, 0);
lv_obj_set_style_border_color(sfEnable, makeLvColor(COLOR_THEME_PRIMARY2), 0);
lv_obj_set_style_border_opa(sfEnable, LV_OPA_100, 0);
@@ -665,16 +668,14 @@ class SpecialFunctionButton : public Button
lv_label_set_text(sfFunc, s);
lv_obj_add_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
s[0] = 0;
if (HAS_ENABLE_PARAM(func)) {
if (CFN_ACTIVE(cfn))
lv_obj_add_state(sfEnable, LV_STATE_CHECKED);
else
lv_obj_clear_state(sfEnable, LV_STATE_CHECKED);
lv_obj_clear_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
} else if (HAS_REPEAT_PARAM(func)) {
if (CFN_ACTIVE(cfn))
lv_obj_add_state(sfEnable, LV_STATE_CHECKED);
else
lv_obj_clear_state(sfEnable, LV_STATE_CHECKED);
if (HAS_REPEAT_PARAM(func)) {
if (func == FUNC_PLAY_SCRIPT) {
sprintf(s, "(%s)", (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x");
} else {
@@ -867,20 +868,18 @@ void SpecialFunctionsPage::build(FormWindow *window)
}
CustomFunctionData *cfn = &functions[i];
uint8_t func = CFN_FUNC(cfn);
if (HAS_ENABLE_PARAM(func)) {
if (CFN_ACTIVE(cfn)) {
menu->addLine(STR_DISABLE, [=]() {
CFN_ACTIVE(cfn) = 0;
SET_DIRTY();
rebuild(window);
});
} else {
menu->addLine(STR_ENABLE, [=]() {
CFN_ACTIVE(cfn) = 1;
SET_DIRTY();
rebuild(window);
});
}
if (CFN_ACTIVE(cfn)) {
menu->addLine(STR_DISABLE, [=]() {
CFN_ACTIVE(cfn) = 0;
SET_DIRTY();
rebuild(window);
});
} else {
menu->addLine(STR_ENABLE, [=]() {
CFN_ACTIVE(cfn) = 1;
SET_DIRTY();
rebuild(window);
});
}
if (functions[MAX_SPECIAL_FUNCTIONS - 1].isEmpty()) {
for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) {