Skip to content

Commit

Permalink
feat(radio): Show model level setting for 'Enabled Features' when alt…
Browse files Browse the repository at this point in the history
…ering radio level setting (#4036)
  • Loading branch information
philmoz authored Oct 13, 2023
1 parent cb16786 commit 614ff28
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 72 deletions.
39 changes: 27 additions & 12 deletions radio/src/gui/128x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ enum {
ITEM_RADIO_SETUP_MAX
};

uint8_t viewOptCheckBox(coord_t y, const char* title, uint8_t value, uint8_t attr, event_t event)
uint8_t viewOptCheckBox(coord_t y, const char* title, uint8_t value, uint8_t attr, event_t event, uint8_t modelOption)
{
lcdDrawText(INDENT_WIDTH, y, title);
return !editCheckBox(!value, LCD_W-9, y, nullptr, attr, event ) ;
if (modelOption != OVERRIDE_GLOBAL) {
std::string s(STR_ADCFILTERVALUES[modelOption]);
lcdDrawText(LCD_W-3*FW, y, s.c_str());
}
return !editCheckBox(!value, LCD_W-4*FW-3, y, nullptr, attr, event ) ;
}

void menuRadioSetup(event_t event)
Expand Down Expand Up @@ -211,7 +215,18 @@ void menuRadioSetup(event_t event)
0,
CASE_TX_MODE(LABEL(TX_MODE))
CASE_TX_MODE(0)
LABEL(ViewOptions), LABEL(RadioMenuTabs), 0, 0, LABEL(ModelMenuTabs), CASE_HELI(0) CASE_FLIGHT_MODES(0) 0, 0, 0, CASE_LUA_MODEL_SCRIPTS(0) 0,
LABEL(ViewOptions),
LABEL(RadioMenuTabs),
0,
0,
LABEL(ModelMenuTabs),
CASE_HELI(0)
CASE_FLIGHT_MODES(0)
0,
0,
0,
CASE_LUA_MODEL_SCRIPTS(0)
0,
1/*to force edit mode*/});

if (event == EVT_ENTRY) {
Expand Down Expand Up @@ -775,40 +790,40 @@ void menuRadioSetup(event_t event)
lcdDrawText(INDENT_WIDTH-2, y, TR_RADIO_MENU_TABS);
break;
case ITEM_VIEW_OPTIONS_GF:
g_eeGeneral.radioGFDisabled = viewOptCheckBox(y, STR_MENUSPECIALFUNCS, g_eeGeneral.radioGFDisabled, attr, event);
g_eeGeneral.radioGFDisabled = viewOptCheckBox(y, STR_MENUSPECIALFUNCS, g_eeGeneral.radioGFDisabled, attr, event, g_model.radioGFDisabled);
break;
case ITEM_VIEW_OPTIONS_TRAINER:
g_eeGeneral.radioTrainerDisabled = viewOptCheckBox(y, STR_MENUTRAINER, g_eeGeneral.radioTrainerDisabled, attr, event);
g_eeGeneral.radioTrainerDisabled = viewOptCheckBox(y, STR_MENUTRAINER, g_eeGeneral.radioTrainerDisabled, attr, event, g_model.radioTrainerDisabled);
break;
case ITEM_VIEW_OPTIONS_MODEL_TAB:
lcdDrawText(INDENT_WIDTH-2, y, TR_MODEL_MENU_TABS);
break;
#if defined(HELI)
case ITEM_VIEW_OPTIONS_HELI:
g_eeGeneral.modelHeliDisabled = viewOptCheckBox(y, STR_MENUHELISETUP, g_eeGeneral.modelHeliDisabled, attr, event);
g_eeGeneral.modelHeliDisabled = viewOptCheckBox(y, STR_MENUHELISETUP, g_eeGeneral.modelHeliDisabled, attr, event, g_model.modelHeliDisabled);
break;
#endif
#if defined(FLIGHT_MODES)
case ITEM_VIEW_OPTIONS_FM:
g_eeGeneral.modelFMDisabled = viewOptCheckBox(y, STR_MENUFLIGHTMODES, g_eeGeneral.modelFMDisabled, attr, event);
g_eeGeneral.modelFMDisabled = viewOptCheckBox(y, STR_MENUFLIGHTMODES, g_eeGeneral.modelFMDisabled, attr, event, g_model.modelFMDisabled);
break;
#endif
case ITEM_VIEW_OPTIONS_CURVES:
g_eeGeneral.modelCurvesDisabled = viewOptCheckBox(y, STR_MENUCURVES, g_eeGeneral.modelCurvesDisabled, attr, event);
g_eeGeneral.modelCurvesDisabled = viewOptCheckBox(y, STR_MENUCURVES, g_eeGeneral.modelCurvesDisabled, attr, event, g_model.modelCurvesDisabled);
break;
case ITEM_VIEW_OPTIONS_LS:
g_eeGeneral.modelLSDisabled = viewOptCheckBox(y, STR_MENULOGICALSWITCHES, g_eeGeneral.modelLSDisabled, attr, event);
g_eeGeneral.modelLSDisabled = viewOptCheckBox(y, STR_MENULOGICALSWITCHES, g_eeGeneral.modelLSDisabled, attr, event, g_model.modelLSDisabled);
break;
case ITEM_VIEW_OPTIONS_SF:
g_eeGeneral.modelSFDisabled = viewOptCheckBox(y, STR_MENUCUSTOMFUNC, g_eeGeneral.modelSFDisabled, attr, event);
g_eeGeneral.modelSFDisabled = viewOptCheckBox(y, STR_MENUCUSTOMFUNC, g_eeGeneral.modelSFDisabled, attr, event, g_model.modelSFDisabled);
break;
#if defined(LUA_MODEL_SCRIPTS)
case ITEM_VIEW_OPTIONS_CUSTOM_SCRIPTS:
g_eeGeneral.modelCustomScriptsDisabled = viewOptCheckBox(y, STR_MENUCUSTOMSCRIPTS, g_eeGeneral.modelCustomScriptsDisabled, attr, event);
g_eeGeneral.modelCustomScriptsDisabled = viewOptCheckBox(y, STR_MENUCUSTOMSCRIPTS, g_eeGeneral.modelCustomScriptsDisabled, attr, event, g_model.modelCustomScriptsDisabled);
break;
#endif
case ITEM_VIEW_OPTIONS_TELEMETRY:
g_eeGeneral.modelTelemetryDisabled = viewOptCheckBox(y, STR_MENUTELEMETRY, g_eeGeneral.modelTelemetryDisabled, attr, event);
g_eeGeneral.modelTelemetryDisabled = viewOptCheckBox(y, STR_MENUTELEMETRY, g_eeGeneral.modelTelemetryDisabled, attr, event, g_model.modelTelemetryDisabled);
break;
}
}
Expand Down
44 changes: 31 additions & 13 deletions radio/src/gui/212x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ enum MenuRadioSetupItems {
ITEM_RADIO_SETUP_MAX
};

uint8_t viewOptCheckBox(coord_t y, const char* title, uint8_t value, uint8_t attr, event_t event)
uint8_t viewOptCheckBox(coord_t y, const char* title, uint8_t value, uint8_t attr, event_t event, uint8_t modelOption)
{
lcdDrawText(INDENT_WIDTH*2, y, title);
return !editCheckBox(!value, RADIO_SETUP_2ND_COLUMN, y, nullptr, attr, event );
if (modelOption != OVERRIDE_GLOBAL) {
std::string s(STR_MODEL);
s += " - ";
s += STR_ADCFILTERVALUES[modelOption];
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, s.c_str());
}
return !editCheckBox(!value, RADIO_SETUP_2ND_COLUMN-10, y, nullptr, attr, event );
}

void menuRadioSetup(event_t event)
Expand Down Expand Up @@ -207,7 +213,19 @@ void menuRadioSetup(event_t event)
CASE_ROTARY_ENCODER(0) // Invert rotary encoder
LABEL(TX_MODE),
0, // sticks mode
LABEL(ViewOptions), LABEL(RadioMenuTabs), 0, 0, LABEL(ModelMenuTabs), CASE_HELI(0) CASE_FLIGHT_MODES(0) CASE_GVARS(0) 0, 0, 0, CASE_LUA_MODEL_SCRIPTS(0) 0,
LABEL(ViewOptions),
LABEL(RadioMenuTabs),
0,
0,
LABEL(ModelMenuTabs),
CASE_HELI(0)
CASE_FLIGHT_MODES(0)
0,
CASE_GVARS(0)
0,
0,
CASE_LUA_MODEL_SCRIPTS(0)
0,
1 /*to force edit mode*/
});

Expand Down Expand Up @@ -700,45 +718,45 @@ void menuRadioSetup(event_t event)
lcdDrawText(INDENT_WIDTH, y, TR_RADIO_MENU_TABS);
break;
case ITEM_VIEW_OPTIONS_GF:
g_eeGeneral.radioGFDisabled = viewOptCheckBox(y, STR_MENUSPECIALFUNCS, g_eeGeneral.radioGFDisabled, attr, event);
g_eeGeneral.radioGFDisabled = viewOptCheckBox(y, STR_MENUSPECIALFUNCS, g_eeGeneral.radioGFDisabled, attr, event, g_model.radioGFDisabled);
break;
case ITEM_VIEW_OPTIONS_TRAINER:
g_eeGeneral.radioTrainerDisabled = viewOptCheckBox(y, STR_MENUTRAINER, g_eeGeneral.radioTrainerDisabled, attr, event);
g_eeGeneral.radioTrainerDisabled = viewOptCheckBox(y, STR_MENUTRAINER, g_eeGeneral.radioTrainerDisabled, attr, event, g_model.radioTrainerDisabled);
break;
case ITEM_VIEW_OPTIONS_MODEL_TAB:
lcdDrawText(INDENT_WIDTH, y, TR_MODEL_MENU_TABS);
break;
#if defined(HELI)
case ITEM_VIEW_OPTIONS_HELI:
g_eeGeneral.modelHeliDisabled = viewOptCheckBox(y, STR_MENUHELISETUP, g_eeGeneral.modelHeliDisabled, attr, event);
g_eeGeneral.modelHeliDisabled = viewOptCheckBox(y, STR_MENUHELISETUP, g_eeGeneral.modelHeliDisabled, attr, event, g_model.modelHeliDisabled);
break;
#endif
#if defined(FLIGHT_MODES)
case ITEM_VIEW_OPTIONS_FM:
g_eeGeneral.modelFMDisabled = viewOptCheckBox(y, STR_MENUFLIGHTMODES, g_eeGeneral.modelFMDisabled, attr, event);
g_eeGeneral.modelFMDisabled = viewOptCheckBox(y, STR_MENUFLIGHTMODES, g_eeGeneral.modelFMDisabled, attr, event, g_model.modelFMDisabled);
break;
#endif
case ITEM_VIEW_OPTIONS_CURVES:
g_eeGeneral.modelCurvesDisabled = viewOptCheckBox(y, STR_MENUCURVES, g_eeGeneral.modelCurvesDisabled, attr, event);
g_eeGeneral.modelCurvesDisabled = viewOptCheckBox(y, STR_MENUCURVES, g_eeGeneral.modelCurvesDisabled, attr, event, g_model.modelCurvesDisabled);
break;
#if defined(GVARS)
case ITEM_VIEW_OPTIONS_GV:
g_model.modelGVDisabled = viewOptCheckBox(y, STR_MENU_GLOBAL_VARS, g_model.modelGVDisabled, attr, event);
g_model.modelGVDisabled = viewOptCheckBox(y, STR_MENU_GLOBAL_VARS, g_model.modelGVDisabled, attr, event, g_model.modelGVDisabled);
break;
#endif
case ITEM_VIEW_OPTIONS_LS:
g_eeGeneral.modelLSDisabled = viewOptCheckBox(y, STR_MENULOGICALSWITCHES, g_eeGeneral.modelLSDisabled, attr, event);
g_eeGeneral.modelLSDisabled = viewOptCheckBox(y, STR_MENULOGICALSWITCHES, g_eeGeneral.modelLSDisabled, attr, event, g_model.modelLSDisabled);
break;
case ITEM_VIEW_OPTIONS_SF:
g_eeGeneral.modelSFDisabled = viewOptCheckBox(y, STR_MENUCUSTOMFUNC, g_eeGeneral.modelSFDisabled, attr, event);
g_eeGeneral.modelSFDisabled = viewOptCheckBox(y, STR_MENUCUSTOMFUNC, g_eeGeneral.modelSFDisabled, attr, event, g_model.modelSFDisabled);
break;
#if defined(LUA_MODEL_SCRIPTS)
case ITEM_VIEW_OPTIONS_CUSTOM_SCRIPTS:
g_eeGeneral.modelCustomScriptsDisabled = viewOptCheckBox(y, STR_MENUCUSTOMSCRIPTS, g_eeGeneral.modelCustomScriptsDisabled, attr, event);
g_eeGeneral.modelCustomScriptsDisabled = viewOptCheckBox(y, STR_MENUCUSTOMSCRIPTS, g_eeGeneral.modelCustomScriptsDisabled, attr, event, g_model.modelCustomScriptsDisabled);
break;
#endif
case ITEM_VIEW_OPTIONS_TELEMETRY:
g_eeGeneral.modelTelemetryDisabled = viewOptCheckBox(y, STR_MENUTELEMETRY, g_eeGeneral.modelTelemetryDisabled, attr, event);
g_eeGeneral.modelTelemetryDisabled = viewOptCheckBox(y, STR_MENUTELEMETRY, g_eeGeneral.modelTelemetryDisabled, attr, event, g_model.modelTelemetryDisabled);
break;
}
}
Expand Down
64 changes: 28 additions & 36 deletions radio/src/gui/colorlcd/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,26 @@ class GpsPage : public SubPage {

class ViewOptionsPage : public SubPage
{
public:
const lv_coord_t opt_col_two_dsc[3] = {LV_GRID_FR(7), LV_GRID_FR(3), LV_GRID_TEMPLATE_LAST};
private:
const lv_coord_t opt_col_dsc[4] = {LV_GRID_FR(5), LV_GRID_FR(2), LV_GRID_FR(4), LV_GRID_TEMPLATE_LAST};

void viewOption(FormWindow::Line *line, const char* name, std::function<uint8_t()> getValue, std::function<void(uint8_t)> setValue, uint8_t modelOption)
{
line->padLeft(10);
new StaticText(line, rect_t{}, name, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, getValue, setValue);
if (modelOption != OVERRIDE_GLOBAL) {
std::string s(STR_MODEL);
s += " - ";
s += STR_ADCFILTERVALUES[modelOption];
new StaticText(line, rect_t{}, s.c_str(), 0, COLOR_THEME_SECONDARY1);
}
}

public:
ViewOptionsPage() : SubPage(ICON_RADIO_SETUP, STR_ENABLED_FEATURES, false)
{
FlexGridLayout grid(opt_col_two_dsc, row_dsc, 2);
FlexGridLayout grid(opt_col_dsc, row_dsc, 2);

auto form = new FormWindow(&body, rect_t{});
form->setFlexLayout();
Expand All @@ -611,70 +625,48 @@ class ViewOptionsPage : public SubPage
new StaticText(line, rect_t{}, STR_RADIO_MENU_TABS, 0, COLOR_THEME_PRIMARY1);

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_THEME_EDITOR, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioThemesDisabled));
viewOption(line, STR_THEME_EDITOR, GET_SET_INVERTED(g_eeGeneral.radioThemesDisabled), g_model.radioThemesDisabled);

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUSPECIALFUNCS, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioGFDisabled));
viewOption(line, STR_MENUSPECIALFUNCS, GET_SET_INVERTED(g_eeGeneral.radioGFDisabled), g_model.radioGFDisabled);

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUTRAINER, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.radioTrainerDisabled));
viewOption(line, STR_MENUTRAINER, GET_SET_INVERTED(g_eeGeneral.radioTrainerDisabled), g_model.radioTrainerDisabled);

line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_MODEL_MENU_TABS, 0, COLOR_THEME_PRIMARY1);

#if defined(HELI)
line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUHELISETUP, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelHeliDisabled));
viewOption(line, STR_MENUHELISETUP, GET_SET_INVERTED(g_eeGeneral.modelHeliDisabled), g_model.modelHeliDisabled);
#endif

#if defined(FLIGHT_MODES)
line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUFLIGHTMODES, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelFMDisabled));
viewOption(line, STR_MENUFLIGHTMODES, GET_SET_INVERTED(g_eeGeneral.modelFMDisabled), g_model.modelFMDisabled);
#endif

#if defined(GVARS)
line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENU_GLOBAL_VARS, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelGVDisabled));
viewOption(line, STR_MENU_GLOBAL_VARS, GET_SET_INVERTED(g_eeGeneral.modelGVDisabled), g_model.modelGVDisabled);
#endif

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUCURVES, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCurvesDisabled));
viewOption(line, STR_MENUCURVES, GET_SET_INVERTED(g_eeGeneral.modelCurvesDisabled), g_model.modelCurvesDisabled);

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENULOGICALSWITCHES, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelLSDisabled));
viewOption(line, STR_MENULOGICALSWITCHES, GET_SET_INVERTED(g_eeGeneral.modelLSDisabled), g_model.modelLSDisabled);

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUCUSTOMFUNC, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelSFDisabled));
viewOption(line, STR_MENUCUSTOMFUNC, GET_SET_INVERTED(g_eeGeneral.modelSFDisabled), g_model.modelSFDisabled);

#if defined(LUA_MODEL_SCRIPTS)
line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUCUSTOMSCRIPTS, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelCustomScriptsDisabled));
viewOption(line, STR_MENUCUSTOMSCRIPTS, GET_SET_INVERTED(g_eeGeneral.modelCustomScriptsDisabled), g_model.modelCustomScriptsDisabled);
#endif

line = form->newLine(&grid);
line->padLeft(10);
new StaticText(line, rect_t{}, STR_MENUTELEMETRY, 0, COLOR_THEME_PRIMARY1);
new ToggleSwitch(line, rect_t{}, GET_SET_INVERTED(g_eeGeneral.modelTelemetryDisabled));
viewOption(line, STR_MENUTELEMETRY, GET_SET_INVERTED(g_eeGeneral.modelTelemetryDisabled), g_model.modelTelemetryDisabled);
}
};

Expand Down
24 changes: 13 additions & 11 deletions radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,41 +1927,43 @@ uint32_t availableMemory()
#endif
}

#define FEATURE_ENABLED(f) (g_model.f == OVERRIDE_GLOBAL && g_eeGeneral.f == 0) || (g_model.f == OVERRIDE_ON)

// Radio menu tab state
#if defined(COLORLCD)
bool radioThemesEnabled() {
return (g_model.radioThemesDisabled == OVERRIDE_GLOBAL && g_eeGeneral.radioThemesDisabled == 0) || (g_model.radioThemesDisabled == 2);
return FEATURE_ENABLED(radioThemesDisabled);
}
#endif
bool radioGFEnabled() {
return (g_model.radioGFDisabled == OVERRIDE_GLOBAL && g_eeGeneral.radioGFDisabled == 0) || (g_model.radioGFDisabled == 2);
return FEATURE_ENABLED(radioGFDisabled);
}
bool radioTrainerEnabled() {
return (g_model.radioTrainerDisabled == OVERRIDE_GLOBAL && g_eeGeneral.radioTrainerDisabled == 0) || (g_model.radioTrainerDisabled == 2);
return FEATURE_ENABLED(radioTrainerDisabled);
}

// Model menu tab state
bool modelHeliEnabled() {
return (g_model.modelHeliDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelHeliDisabled == 0) || (g_model.modelHeliDisabled == 2);
return FEATURE_ENABLED(modelHeliDisabled);
}
bool modelFMEnabled() {
return (g_model.modelFMDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelFMDisabled == 0) || (g_model.modelFMDisabled == 2);
return FEATURE_ENABLED(modelFMDisabled);
}
bool modelCurvesEnabled() {
return (g_model.modelCurvesDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelCurvesDisabled == 0) || (g_model.modelCurvesDisabled == 2);
return FEATURE_ENABLED(modelCurvesDisabled);
}
bool modelGVEnabled() {
return (g_model.modelGVDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelGVDisabled == 0) || (g_model.modelGVDisabled == 2);
return FEATURE_ENABLED(modelGVDisabled);
}
bool modelLSEnabled() {
return (g_model.modelLSDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelLSDisabled == 0) || (g_model.modelLSDisabled == 2);
return FEATURE_ENABLED(modelLSDisabled);
}
bool modelSFEnabled() {
return (g_model.modelSFDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelSFDisabled == 0) || (g_model.modelSFDisabled == 2);
return FEATURE_ENABLED(modelSFDisabled);
}
bool modelCustomScriptsEnabled() {
return (g_model.modelCustomScriptsDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelCustomScriptsDisabled == 0) || (g_model.modelCustomScriptsDisabled == 2);
return FEATURE_ENABLED(modelCustomScriptsDisabled);
}
bool modelTelemetryEnabled() {
return (g_model.modelTelemetryDisabled == OVERRIDE_GLOBAL && g_eeGeneral.modelTelemetryDisabled == 0) || (g_model.modelTelemetryDisabled == 2);
return FEATURE_ENABLED(modelTelemetryDisabled);
}

0 comments on commit 614ff28

Please sign in to comment.