1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 09:45:33 +03:00

Combine BACK and END entries in CMS menus in a single item

As suggested by @hydra. OME_Back and OME_END continue to be valid
items, but we now also have OME_BACK_AND_END which creates a back
entry and indicates the end of the menu, saving an entry. On F3,
this saves 464 bytes of flash.
This commit is contained in:
Alberto García Hierro 2019-02-16 22:10:25 +00:00
parent 826e339988
commit 3ba770c1e2
14 changed files with 69 additions and 89 deletions

View file

@ -207,6 +207,9 @@ static void cmsUpdateMaxRow(displayPort_t *instance)
for (const OSD_Entry *ptr = pageTop; ptr->type != OME_END; ptr++) {
pageMaxRow++;
if (ptr->type == OME_BACK_AND_END) {
break;
}
}
if (pageMaxRow > MAX_MENU_ITEMS(instance)) {
@ -516,6 +519,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, const OSD_Entry *p, uint8_t
case OME_OSD_Exit:
case OME_END:
case OME_Back:
case OME_BACK_AND_END:
break;
case OME_MENU:
@ -592,8 +596,12 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
coloff += cmsElementIsLabel(p->type) ? 1 : 2;
room -= displayWrite(pDisplay, coloff, i + top, p->text);
CLR_PRINTLABEL(p, i);
if (room < 30)
if (room < 30) {
return;
}
}
if (p->type == OME_BACK_AND_END) {
break;
}
}
@ -605,8 +613,12 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
for (i = 0, p = pageTop; i < MAX_MENU_ITEMS(pDisplay) && p->type != OME_END; i++, p++) {
if (IS_PRINTVALUE(p, i)) {
room -= cmsDrawMenuEntry(pDisplay, p, top + i, i);
if (room < 30)
if (room < 30) {
return;
}
}
if (p->type == OME_BACK_AND_END) {
break;
}
}
}
@ -614,7 +626,12 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
static void cmsMenuCountPage(displayPort_t *pDisplay)
{
const OSD_Entry *p;
for (p = currentCtx.menu->entries; p->type != OME_END; p++);
for (p = currentCtx.menu->entries; p->type != OME_END; p++) {
if (p->type == OME_BACK_AND_END) {
p++;
break;
}
}
pageCount = (p - currentCtx.menu->entries - 1) / MAX_MENU_ITEMS(pDisplay) + 1;
}
@ -722,6 +739,9 @@ static void cmsTraverseGlobalExit(const CMS_Menu *pMenu)
if (p->type == OME_Submenu) {
cmsTraverseGlobalExit(p->data);
}
if (p->type == OME_BACK_AND_END) {
break;
}
}
if (pMenu->onGlobalExit) {
@ -866,6 +886,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
break;
case OME_Back:
case OME_BACK_AND_END:
cmsMenuBack(pDisplay);
res = BUTTON_PAUSE;
break;

View file

@ -109,8 +109,7 @@ static const OSD_Entry menuBattSettingsEntries[]=
OSD_SETTING_ENTRY("CAP WARN", SETTING_BATTERY_CAPACITY_WARNING),
OSD_SETTING_ENTRY("CAP CRIT", SETTING_BATTERY_CAPACITY_CRITICAL),
OSD_BACK_ENTRY,
OSD_END_ENTRY
OSD_BACK_AND_END_ENTRY,
};
static CMS_Menu cmsx_menuBattSettings = {
@ -134,8 +133,7 @@ static OSD_Entry menuBatteryEntries[]=
OSD_UINT8_CALLBACK_ENTRY("PROF", cmsx_onBatteryProfileIndexChange, (&(const OSD_UINT8_t){ &battDispProfileIndex, 1, MAX_BATTERY_PROFILE_COUNT, 1})),
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuBattSettings),
OSD_BACK_ENTRY,
OSD_END_ENTRY
OSD_BACK_AND_END_ENTRY,
};
CMS_Menu cmsx_menuBattery = {

View file

@ -86,8 +86,7 @@ static const OSD_Entry cmsx_menuBlackboxEntries[] =
OSD_FUNC_CALL_ENTRY("ERASE FLASH", cmsx_EraseFlash),
#endif // USE_FLASHFS
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuBlackbox = {

View file

@ -86,8 +86,7 @@ static const OSD_Entry menuInfoEntries[] = {
OSD_STRING_ENTRY("GITREV", infoGitRev),
OSD_STRING_ENTRY("TARGET", infoTargetName),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu menuInfo = {
@ -128,8 +127,7 @@ static const OSD_Entry menuFeaturesEntries[] =
OSD_SUBMENU_ENTRY("LED STRIP", &cmsx_menuLedstrip),
#endif // LED_STRIP
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu menuFeatures = {

View file

@ -142,8 +142,7 @@ static const OSD_Entry cmsx_menuPidEntries[] =
OSD_UINT8_ENTRY("YAW I", (&(const OSD_UINT8_t){ &cmsx_pidYaw[1], 0, 200, 1 })),
OSD_UINT8_ENTRY("YAW D", (&(const OSD_UINT8_t){ &cmsx_pidYaw[2], 0, 200, 1 })),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuPid = {
@ -198,8 +197,7 @@ static const OSD_Entry cmsx_menuPidAltMagEntries[] =
OSD_UINT8_ENTRY("MAG P", (&(const OSD_UINT8_t){ &cmsx_pidHead[0], 0, 255, 1 })),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuPidAltMag = {
@ -248,8 +246,7 @@ static const OSD_Entry cmsx_menuPidGpsnavEntries[] =
OSD_UINT8_ENTRY("POSR I", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[1], 0, 255, 1 })),
OSD_UINT8_ENTRY("POSR D", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[2], 0, 255, 1 })),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuPidGpsnav = {
@ -277,8 +274,7 @@ static const OSD_Entry cmsx_menuManualRateProfileEntries[] =
OSD_SETTING_ENTRY("MANU RC EXPO", SETTING_MANUAL_RC_EXPO),
OSD_SETTING_ENTRY("MANU RC YAW EXP", SETTING_MANUAL_RC_YAW_EXPO),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuManualRateProfile = {
@ -317,8 +313,7 @@ static const OSD_Entry cmsx_menuRateProfileEntries[] =
OSD_SETTING_ENTRY("THRPID ATT", SETTING_TPA_RATE),
OSD_SETTING_ENTRY_STEP("TPA BRKPT", SETTING_TPA_BREAKPOINT, 10),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuRateProfile = {
@ -376,8 +371,7 @@ static const OSD_Entry cmsx_menuProfileOtherEntries[] = {
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonStrength, 0, 200, 1 } , 0 },
{ "HORZN TRS", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonTransition, 0, 200, 1 } , 0 },
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuProfileOther = {
@ -404,8 +398,7 @@ static const OSD_Entry cmsx_menuFilterPerProfileEntries[] =
OSD_SETTING_ENTRY("YAW P LIM", SETTING_YAW_P_LIMIT),
OSD_SETTING_ENTRY("YAW LPF", SETTING_YAW_LPF_HZ),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuFilterPerProfile = {
@ -426,8 +419,7 @@ static const OSD_Entry cmsx_menuGyroEntries[] =
OSD_SETTING_ENTRY("GYRO SYNC", SETTING_GYRO_SYNC),
OSD_SETTING_ENTRY("GYRO LPF", SETTING_GYRO_HARDWARE_LPF),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuGyro = {
@ -466,8 +458,7 @@ static const OSD_Entry cmsx_menuImuEntries[] =
{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
#endif
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuImu = {

View file

@ -60,8 +60,7 @@ static const OSD_Entry cmsx_menuLedstripEntries[] =
OSD_LABEL_ENTRY("-- LED STRIP --"),
OSD_BOOL_FUNC_ENTRY("ENABLED", cmsx_FeatureLedStrip_Enabled),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuLedstrip = {

View file

@ -67,8 +67,7 @@ static const OSD_Entry cmsx_menuRcEntries[] =
OSD_INT16_RO_ENTRY("AUX3", &rcData[AUX3]),
OSD_INT16_RO_ENTRY("AUX4", &rcData[AUX4]),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuRcPreview = {
@ -94,8 +93,7 @@ static const OSD_Entry menuMiscEntries[]=
OSD_SUBMENU_ENTRY("RC PREV", &cmsx_menuRcPreview),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuMisc = {

View file

@ -52,8 +52,7 @@ static const OSD_Entry cmsx_menuNavSettingsEntries[] =
OSD_SETTING_ENTRY("MID THR FOR AH", SETTING_NAV_USE_MIDTHR_FOR_ALTHOLD),
OSD_SETTING_ENTRY("MC HOVER THR", SETTING_NAV_MC_HOVER_THR),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuNavSettings = {
@ -83,8 +82,7 @@ static const CMS_Menu cmsx_menuNavSettings = {
OSD_SETTING_ENTRY("RTH ABORT THRES", SETTING_NAV_RTH_ABORT_THRESHOLD),
OSD_SETTING_ENTRY("EMERG LANDING SPEED", SETTING_NAV_EMERG_LANDING_SPEED),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuRTH = {
@ -111,8 +109,7 @@ static const OSD_Entry cmsx_menuFixedWingEntries[] =
OSD_SETTING_ENTRY("PITCH TO THR RATIO", SETTING_NAV_FW_PITCH2THR),
OSD_SETTING_ENTRY("LOITER RADIUS", SETTING_NAV_FW_LOITER_RADIUS),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuFixedWing = {
@ -134,8 +131,7 @@ static const OSD_Entry cmsx_menuNavigationEntries[] =
OSD_SUBMENU_ENTRY("RTH", &cmsx_menuRTH),
OSD_SUBMENU_ENTRY("FIXED WING", &cmsx_menuFixedWing),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuNavigation = {

View file

@ -57,8 +57,7 @@ static const OSD_Entry cmsx_menuAlarmsEntries[] = {
OSD_SETTING_ENTRY("MAX DIST", SETTING_OSD_DIST_ALARM),
OSD_SETTING_ENTRY("MAX NEG ALT", SETTING_OSD_NEG_ALT_ALARM),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuAlarms = {
@ -101,8 +100,7 @@ static const OSD_Entry menuOsdElemActionsEntries[] = {
OSD_UINT8_CALLBACK_ENTRY("COLUMN", cmsx_osdElementOnChange, (&(const OSD_UINT8_t){ &osdCurrentElementColumn, 0, OSD_Y(OSD_POS_MAX), 1 })),
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const OSD_Entry menuOsdFixedElemActionsEntries[] = {
@ -110,8 +108,7 @@ static const OSD_Entry menuOsdFixedElemActionsEntries[] = {
OSD_BOOL_CALLBACK_ENTRY("ENABLED", cmsx_osdElementOnChange, &osdCurrentElementVisible),
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static CMS_Menu cmsx_menuOsdElementActions = {
@ -261,15 +258,14 @@ static const OSD_Entry menuOsdElemsEntries[] =
OSD_ELEMENT_ENTRY("SENSOR 7 TEMP", OSD_TEMP_SENSOR_7_TEMPERATURE),
#endif
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
#if defined(USE_GPS) && defined(USE_BARO) && defined(USE_PITOT) && defined(USE_TEMPERATURE_SENSOR)
// All CMS OSD elements should be enabled in this case. The menu has 3 extra
// elements (label, back and end), but there's an OSD element that we intentionally
// All CMS OSD elements should be enabled in this case. The menu has 2 extra
// elements (label, back+end), but there's an OSD element that we intentionally
// don't show here (OSD_DEBUG).
_Static_assert(ARRAYLEN(menuOsdElemsEntries) - 3 + 1 == OSD_ITEM_COUNT, "missing OSD elements in CMS");
_Static_assert(ARRAYLEN(menuOsdElemsEntries) - 2 + 1 == OSD_ITEM_COUNT, "missing OSD elements in CMS");
#endif
const CMS_Menu menuOsdElements = {
@ -301,8 +297,7 @@ static const OSD_Entry cmsx_menuOsdLayoutEntries[] =
#endif
#endif
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuOsdLayout = {
@ -344,9 +339,7 @@ static const OSD_Entry menuOsdSettingsEntries[] = {
OSD_SETTING_ENTRY("RIGHT SCROLL", SETTING_OSD_RIGHT_SIDEBAR_SCROLL),
OSD_SETTING_ENTRY("SCROLL ARROWS", SETTING_OSD_SIDEBAR_SCROLL_ARROWS),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu cmsx_menuOsdSettings = {
@ -367,8 +360,7 @@ static const OSD_Entry menuOsdEntries[] = {
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuOsdSettings),
OSD_SUBMENU_ENTRY("ALARMS", &cmsx_menuAlarms),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

View file

@ -128,8 +128,7 @@ static const OSD_Entry cmsx_menuVtxEntries[] =
OSD_BOOL_ENTRY("LOW POWER", &masterConfig.vtx_power),
#endif // USE_RTC6705
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuVtx = {

View file

@ -173,8 +173,7 @@ static const OSD_Entry ffpvCmsMenuCommenceEntries[] =
OSD_LABEL_ENTRY("CONFIRM"),
OSD_FUNC_CALL_ENTRY("YES", ffpvCmsCommence),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu ffpvCmsMenuCommence = {
@ -199,8 +198,7 @@ static const OSD_Entry ffpvMenuEntries[] =
OSD_TAB_CALLBACK_ENTRY("POWER", ffpvCmsConfigPower, &ffpvCmsEntPower),
OSD_SUBMENU_ENTRY("SET", &ffpvCmsMenuCommence),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuVtxFFPV = {

View file

@ -364,8 +364,7 @@ static const OSD_Entry saCmsMenuStatsEntries[] = {
OSD_UINT16_RO_ENTRY("CRCERR", &saStat.crc),
OSD_UINT16_RO_ENTRY("OOOERR", &saStat.ooopresp),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu saCmsMenuStats = {
@ -547,8 +546,7 @@ static const OSD_Entry saCmsMenuPORFreqEntries[] =
OSD_UINT16_ENTRY("NEW FREQ", (&(const OSD_UINT16_t){ &saCmsORFreqNew, 5000, 5900, 1 })),
OSD_FUNC_CALL_ENTRY("SET", saCmsSetPORFreq),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu saCmsMenuPORFreq =
@ -571,8 +569,7 @@ static const OSD_Entry saCmsMenuUserFreqEntries[] =
OSD_UINT16_ENTRY("NEW FREQ", (&(const OSD_UINT16_t){ &saCmsUserFreqNew, 5000, 5900, 1 })),
OSD_FUNC_CALL_ENTRY("SET", saCmsConfigUserFreq),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu saCmsMenuUserFreq =
@ -601,8 +598,7 @@ static const OSD_Entry saCmsMenuConfigEntries[] =
OSD_SUBMENU_ENTRY("STATX", &saCmsMenuStats),
#endif /* USE_EXTENDED_CMS_MENUS */
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu saCmsMenuConfig = {
@ -621,8 +617,7 @@ static const OSD_Entry saCmsMenuCommenceEntries[] =
OSD_LABEL_ENTRY("CONFIRM"),
OSD_FUNC_CALL_ENTRY("YES", saCmsCommence),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu saCmsMenuCommence = {
@ -651,8 +646,7 @@ static const OSD_Entry saCmsMenuFreqModeEntries[] =
OSD_SUBMENU_ENTRY("SET", &saCmsMenuCommence),
OSD_SUBMENU_ENTRY("CONFIG", &saCmsMenuConfig),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
#pragma GCC diagnostic pop
@ -668,8 +662,7 @@ static const OSD_Entry saCmsMenuChanModeEntries[] =
OSD_SUBMENU_ENTRY("SET", &saCmsMenuCommence),
OSD_SUBMENU_ENTRY("CONFIG", &saCmsMenuConfig),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const OSD_Entry saCmsMenuOfflineEntries[] =
@ -681,8 +674,7 @@ static const OSD_Entry saCmsMenuOfflineEntries[] =
OSD_SUBMENU_ENTRY("STATX", &saCmsMenuStats),
#endif /* USE_EXTENDED_CMS_MENUS */
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
CMS_Menu cmsx_menuVtxSmartAudio; // Forward

View file

@ -211,8 +211,7 @@ static const OSD_Entry trampCmsMenuCommenceEntries[] =
OSD_LABEL_ENTRY("CONFIRM"),
OSD_FUNC_CALL_ENTRY("YES", trampCmsCommence),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
static const CMS_Menu trampCmsMenuCommence = {
@ -239,8 +238,7 @@ static const OSD_Entry trampMenuEntries[] =
OSD_INT16_RO_ENTRY("T(C)", &trampData.temperature),
OSD_SUBMENU_ENTRY("SET", &trampCmsMenuCommence),
OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};
const CMS_Menu cmsx_menuVtxTramp = {

View file

@ -46,6 +46,7 @@ typedef enum
//wlasciwosci elementow
OME_TAB,
OME_END,
OME_BACK_AND_END,
// Debug aid
OME_MENU,