Skip to content

Commit 65f84a8

Browse files
committed
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.
1 parent 826e339 commit 65f84a8

14 files changed

+66
-86
lines changed

src/main/cms/cms.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ static void cmsUpdateMaxRow(displayPort_t *instance)
207207

208208
for (const OSD_Entry *ptr = pageTop; ptr->type != OME_END; ptr++) {
209209
pageMaxRow++;
210+
if (ptr->type == OME_BACK_AND_END) {
211+
break;
212+
}
210213
}
211214

212215
if (pageMaxRow > MAX_MENU_ITEMS(instance)) {
@@ -516,6 +519,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, const OSD_Entry *p, uint8_t
516519
case OME_OSD_Exit:
517520
case OME_END:
518521
case OME_Back:
522+
case OME_BACK_AND_END:
519523
break;
520524

521525
case OME_MENU:
@@ -592,8 +596,12 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
592596
coloff += cmsElementIsLabel(p->type) ? 1 : 2;
593597
room -= displayWrite(pDisplay, coloff, i + top, p->text);
594598
CLR_PRINTLABEL(p, i);
595-
if (room < 30)
599+
if (room < 30) {
596600
return;
601+
}
602+
}
603+
if (p->type == OME_BACK_AND_END) {
604+
break;
597605
}
598606
}
599607

@@ -605,16 +613,25 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
605613
for (i = 0, p = pageTop; i < MAX_MENU_ITEMS(pDisplay) && p->type != OME_END; i++, p++) {
606614
if (IS_PRINTVALUE(p, i)) {
607615
room -= cmsDrawMenuEntry(pDisplay, p, top + i, i);
608-
if (room < 30)
616+
if (room < 30) {
609617
return;
618+
}
619+
}
620+
if (p->type == OME_BACK_AND_END) {
621+
break;
610622
}
611623
}
612624
}
613625

614626
static void cmsMenuCountPage(displayPort_t *pDisplay)
615627
{
616628
const OSD_Entry *p;
617-
for (p = currentCtx.menu->entries; p->type != OME_END; p++);
629+
for (p = currentCtx.menu->entries; p->type != OME_END; p++) {
630+
if (p->type == OME_BACK_AND_END) {
631+
p++;
632+
break;
633+
}
634+
}
618635
pageCount = (p - currentCtx.menu->entries - 1) / MAX_MENU_ITEMS(pDisplay) + 1;
619636
}
620637

@@ -722,6 +739,9 @@ static void cmsTraverseGlobalExit(const CMS_Menu *pMenu)
722739
if (p->type == OME_Submenu) {
723740
cmsTraverseGlobalExit(p->data);
724741
}
742+
if (p->type == OME_BACK_AND_END) {
743+
break;
744+
}
725745
}
726746

727747
if (pMenu->onGlobalExit) {
@@ -866,6 +886,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
866886
break;
867887

868888
case OME_Back:
889+
case OME_BACK_AND_END:
869890
cmsMenuBack(pDisplay);
870891
res = BUTTON_PAUSE;
871892
break;

src/main/cms/cms_menu_battery.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ static const OSD_Entry menuBattSettingsEntries[]=
109109
OSD_SETTING_ENTRY("CAP WARN", SETTING_BATTERY_CAPACITY_WARNING),
110110
OSD_SETTING_ENTRY("CAP CRIT", SETTING_BATTERY_CAPACITY_CRITICAL),
111111

112-
OSD_BACK_ENTRY,
113-
OSD_END_ENTRY
112+
OSD_BACK_AND_END_ENTRY,
114113
};
115114

116115
static CMS_Menu cmsx_menuBattSettings = {
@@ -134,8 +133,7 @@ static OSD_Entry menuBatteryEntries[]=
134133
OSD_UINT8_CALLBACK_ENTRY("PROF", cmsx_onBatteryProfileIndexChange, (&(const OSD_UINT8_t){ &battDispProfileIndex, 1, MAX_BATTERY_PROFILE_COUNT, 1})),
135134
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuBattSettings),
136135

137-
OSD_BACK_ENTRY,
138-
OSD_END_ENTRY
136+
OSD_BACK_AND_END_ENTRY,
139137
};
140138

141139
CMS_Menu cmsx_menuBattery = {

src/main/cms/cms_menu_blackbox.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ static const OSD_Entry cmsx_menuBlackboxEntries[] =
8686
OSD_FUNC_CALL_ENTRY("ERASE FLASH", cmsx_EraseFlash),
8787
#endif // USE_FLASHFS
8888

89-
OSD_BACK_ENTRY,
90-
OSD_END_ENTRY,
89+
OSD_BACK_AND_END_ENTRY,
9190
};
9291

9392
const CMS_Menu cmsx_menuBlackbox = {

src/main/cms/cms_menu_builtin.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ static const OSD_Entry menuInfoEntries[] = {
8686
OSD_STRING_ENTRY("GITREV", infoGitRev),
8787
OSD_STRING_ENTRY("TARGET", infoTargetName),
8888

89-
OSD_BACK_ENTRY,
90-
OSD_END_ENTRY,
89+
OSD_BACK_AND_END_ENTRY,
9190
};
9291

9392
static const CMS_Menu menuInfo = {
@@ -128,8 +127,7 @@ static const OSD_Entry menuFeaturesEntries[] =
128127
OSD_SUBMENU_ENTRY("LED STRIP", &cmsx_menuLedstrip),
129128
#endif // LED_STRIP
130129

131-
OSD_BACK_ENTRY,
132-
OSD_END_ENTRY,
130+
OSD_BACK_AND_END_ENTRY,
133131
};
134132

135133
static const CMS_Menu menuFeatures = {

src/main/cms/cms_menu_imu.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ static const OSD_Entry cmsx_menuPidEntries[] =
142142
OSD_UINT8_ENTRY("YAW I", (&(const OSD_UINT8_t){ &cmsx_pidYaw[1], 0, 200, 1 })),
143143
OSD_UINT8_ENTRY("YAW D", (&(const OSD_UINT8_t){ &cmsx_pidYaw[2], 0, 200, 1 })),
144144

145-
OSD_BACK_ENTRY,
146-
OSD_END_ENTRY,
145+
OSD_BACK_AND_END_ENTRY,
147146
};
148147

149148
static const CMS_Menu cmsx_menuPid = {
@@ -198,8 +197,7 @@ static const OSD_Entry cmsx_menuPidAltMagEntries[] =
198197

199198
OSD_UINT8_ENTRY("MAG P", (&(const OSD_UINT8_t){ &cmsx_pidHead[0], 0, 255, 1 })),
200199

201-
OSD_BACK_ENTRY,
202-
OSD_END_ENTRY,
200+
OSD_BACK_AND_END_ENTRY,
203201
};
204202

205203
static const CMS_Menu cmsx_menuPidAltMag = {
@@ -248,8 +246,7 @@ static const OSD_Entry cmsx_menuPidGpsnavEntries[] =
248246
OSD_UINT8_ENTRY("POSR I", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[1], 0, 255, 1 })),
249247
OSD_UINT8_ENTRY("POSR D", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[2], 0, 255, 1 })),
250248

251-
OSD_BACK_ENTRY,
252-
OSD_END_ENTRY,
249+
OSD_BACK_AND_END_ENTRY,
253250
};
254251

255252
static const CMS_Menu cmsx_menuPidGpsnav = {
@@ -277,8 +274,7 @@ static const OSD_Entry cmsx_menuManualRateProfileEntries[] =
277274
OSD_SETTING_ENTRY("MANU RC EXPO", SETTING_MANUAL_RC_EXPO),
278275
OSD_SETTING_ENTRY("MANU RC YAW EXP", SETTING_MANUAL_RC_YAW_EXPO),
279276

280-
OSD_BACK_ENTRY,
281-
OSD_END_ENTRY,
277+
OSD_BACK_AND_END_ENTRY,
282278
};
283279

284280
static const CMS_Menu cmsx_menuManualRateProfile = {
@@ -317,8 +313,7 @@ static const OSD_Entry cmsx_menuRateProfileEntries[] =
317313
OSD_SETTING_ENTRY("THRPID ATT", SETTING_TPA_RATE),
318314
OSD_SETTING_ENTRY_STEP("TPA BRKPT", SETTING_TPA_BREAKPOINT, 10),
319315

320-
OSD_BACK_ENTRY,
321-
OSD_END_ENTRY,
316+
OSD_BACK_AND_END_ENTRY,
322317
};
323318

324319
static const CMS_Menu cmsx_menuRateProfile = {
@@ -376,8 +371,7 @@ static const OSD_Entry cmsx_menuProfileOtherEntries[] = {
376371
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonStrength, 0, 200, 1 } , 0 },
377372
{ "HORZN TRS", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonTransition, 0, 200, 1 } , 0 },
378373

379-
OSD_BACK_ENTRY,
380-
OSD_END_ENTRY,
374+
OSD_BACK_AND_END_ENTRY,
381375
};
382376

383377
static const CMS_Menu cmsx_menuProfileOther = {
@@ -404,8 +398,7 @@ static const OSD_Entry cmsx_menuFilterPerProfileEntries[] =
404398
OSD_SETTING_ENTRY("YAW P LIM", SETTING_YAW_P_LIMIT),
405399
OSD_SETTING_ENTRY("YAW LPF", SETTING_YAW_LPF_HZ),
406400

407-
OSD_BACK_ENTRY,
408-
OSD_END_ENTRY,
401+
OSD_BACK_AND_END_ENTRY,
409402
};
410403

411404
static const CMS_Menu cmsx_menuFilterPerProfile = {
@@ -426,8 +419,7 @@ static const OSD_Entry cmsx_menuGyroEntries[] =
426419
OSD_SETTING_ENTRY("GYRO SYNC", SETTING_GYRO_SYNC),
427420
OSD_SETTING_ENTRY("GYRO LPF", SETTING_GYRO_HARDWARE_LPF),
428421

429-
OSD_BACK_ENTRY,
430-
OSD_END_ENTRY,
422+
OSD_BACK_AND_END_ENTRY,
431423
};
432424

433425
static const CMS_Menu cmsx_menuGyro = {
@@ -466,8 +458,7 @@ static const OSD_Entry cmsx_menuImuEntries[] =
466458
{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
467459
#endif
468460

469-
OSD_BACK_ENTRY,
470-
OSD_END_ENTRY,
461+
OSD_BACK_AND_END_ENTRY,
471462
};
472463

473464
const CMS_Menu cmsx_menuImu = {

src/main/cms/cms_menu_ledstrip.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ static const OSD_Entry cmsx_menuLedstripEntries[] =
6060
OSD_LABEL_ENTRY("-- LED STRIP --"),
6161
OSD_BOOL_FUNC_ENTRY("ENABLED", cmsx_FeatureLedStrip_Enabled),
6262

63-
OSD_BACK_ENTRY,
64-
OSD_END_ENTRY,
63+
OSD_BACK_AND_END_ENTRY,
6564
};
6665

6766
const CMS_Menu cmsx_menuLedstrip = {

src/main/cms/cms_menu_misc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ static const OSD_Entry cmsx_menuRcEntries[] =
6767
OSD_INT16_RO_ENTRY("AUX3", &rcData[AUX3]),
6868
OSD_INT16_RO_ENTRY("AUX4", &rcData[AUX4]),
6969

70-
OSD_BACK_ENTRY,
71-
OSD_END_ENTRY,
70+
OSD_BACK_AND_END_ENTRY,
7271
};
7372

7473
static const CMS_Menu cmsx_menuRcPreview = {
@@ -94,8 +93,7 @@ static const OSD_Entry menuMiscEntries[]=
9493

9594
OSD_SUBMENU_ENTRY("RC PREV", &cmsx_menuRcPreview),
9695

97-
OSD_BACK_ENTRY,
98-
OSD_END_ENTRY,
96+
OSD_BACK_AND_END_ENTRY,
9997
};
10098

10199
const CMS_Menu cmsx_menuMisc = {

src/main/cms/cms_menu_navigation.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ static const OSD_Entry cmsx_menuNavSettingsEntries[] =
5252
OSD_SETTING_ENTRY("MID THR FOR AH", SETTING_NAV_USE_MIDTHR_FOR_ALTHOLD),
5353
OSD_SETTING_ENTRY("MC HOVER THR", SETTING_NAV_MC_HOVER_THR),
5454

55-
OSD_BACK_ENTRY,
56-
OSD_END_ENTRY,
55+
OSD_BACK_AND_END_ENTRY,
5756
};
5857

5958
static const CMS_Menu cmsx_menuNavSettings = {
@@ -83,8 +82,7 @@ static const CMS_Menu cmsx_menuNavSettings = {
8382
OSD_SETTING_ENTRY("RTH ABORT THRES", SETTING_NAV_RTH_ABORT_THRESHOLD),
8483
OSD_SETTING_ENTRY("EMERG LANDING SPEED", SETTING_NAV_EMERG_LANDING_SPEED),
8584

86-
OSD_BACK_ENTRY,
87-
OSD_END_ENTRY,
85+
OSD_BACK_AND_END_ENTRY,
8886
};
8987

9088
static const CMS_Menu cmsx_menuRTH = {
@@ -111,8 +109,7 @@ static const OSD_Entry cmsx_menuFixedWingEntries[] =
111109
OSD_SETTING_ENTRY("PITCH TO THR RATIO", SETTING_NAV_FW_PITCH2THR),
112110
OSD_SETTING_ENTRY("LOITER RADIUS", SETTING_NAV_FW_LOITER_RADIUS),
113111

114-
OSD_BACK_ENTRY,
115-
OSD_END_ENTRY,
112+
OSD_BACK_AND_END_ENTRY,
116113
};
117114

118115
static const CMS_Menu cmsx_menuFixedWing = {
@@ -134,8 +131,7 @@ static const OSD_Entry cmsx_menuNavigationEntries[] =
134131
OSD_SUBMENU_ENTRY("RTH", &cmsx_menuRTH),
135132
OSD_SUBMENU_ENTRY("FIXED WING", &cmsx_menuFixedWing),
136133

137-
OSD_BACK_ENTRY,
138-
OSD_END_ENTRY,
134+
OSD_BACK_AND_END_ENTRY,
139135
};
140136

141137
const CMS_Menu cmsx_menuNavigation = {

src/main/cms/cms_menu_osd.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ static const OSD_Entry cmsx_menuAlarmsEntries[] = {
5757
OSD_SETTING_ENTRY("MAX DIST", SETTING_OSD_DIST_ALARM),
5858
OSD_SETTING_ENTRY("MAX NEG ALT", SETTING_OSD_NEG_ALT_ALARM),
5959

60-
OSD_BACK_ENTRY,
61-
OSD_END_ENTRY,
60+
OSD_BACK_AND_END_ENTRY,
6261
};
6362

6463
static const CMS_Menu cmsx_menuAlarms = {
@@ -101,17 +100,15 @@ static const OSD_Entry menuOsdElemActionsEntries[] = {
101100
OSD_UINT8_CALLBACK_ENTRY("COLUMN", cmsx_osdElementOnChange, (&(const OSD_UINT8_t){ &osdCurrentElementColumn, 0, OSD_Y(OSD_POS_MAX), 1 })),
102101
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),
103102

104-
OSD_BACK_ENTRY,
105-
OSD_END_ENTRY,
103+
OSD_BACK_AND_END_ENTRY,
106104
};
107105

108106
static const OSD_Entry menuOsdFixedElemActionsEntries[] = {
109107

110108
OSD_BOOL_CALLBACK_ENTRY("ENABLED", cmsx_osdElementOnChange, &osdCurrentElementVisible),
111109
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),
112110

113-
OSD_BACK_ENTRY,
114-
OSD_END_ENTRY,
111+
OSD_BACK_AND_END_ENTRY,
115112
};
116113

117114
static CMS_Menu cmsx_menuOsdElementActions = {
@@ -261,8 +258,7 @@ static const OSD_Entry menuOsdElemsEntries[] =
261258
OSD_ELEMENT_ENTRY("SENSOR 7 TEMP", OSD_TEMP_SENSOR_7_TEMPERATURE),
262259
#endif
263260

264-
OSD_BACK_ENTRY,
265-
OSD_END_ENTRY,
261+
OSD_BACK_AND_END_ENTRY,
266262
};
267263

268264
#if defined(USE_GPS) && defined(USE_BARO) && defined(USE_PITOT) && defined(USE_TEMPERATURE_SENSOR)
@@ -301,8 +297,7 @@ static const OSD_Entry cmsx_menuOsdLayoutEntries[] =
301297
#endif
302298
#endif
303299

304-
OSD_BACK_ENTRY,
305-
OSD_END_ENTRY,
300+
OSD_BACK_AND_END_ENTRY,
306301
};
307302

308303
const CMS_Menu cmsx_menuOsdLayout = {
@@ -344,9 +339,7 @@ static const OSD_Entry menuOsdSettingsEntries[] = {
344339
OSD_SETTING_ENTRY("RIGHT SCROLL", SETTING_OSD_RIGHT_SIDEBAR_SCROLL),
345340
OSD_SETTING_ENTRY("SCROLL ARROWS", SETTING_OSD_SIDEBAR_SCROLL_ARROWS),
346341

347-
348-
OSD_BACK_ENTRY,
349-
OSD_END_ENTRY,
342+
OSD_BACK_AND_END_ENTRY,
350343
};
351344

352345
static const CMS_Menu cmsx_menuOsdSettings = {
@@ -367,8 +360,7 @@ static const OSD_Entry menuOsdEntries[] = {
367360
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuOsdSettings),
368361
OSD_SUBMENU_ENTRY("ALARMS", &cmsx_menuAlarms),
369362

370-
OSD_BACK_ENTRY,
371-
OSD_END_ENTRY,
363+
OSD_BACK_AND_END_ENTRY,
372364
};
373365

374366

src/main/cms/cms_menu_vtx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static const OSD_Entry cmsx_menuVtxEntries[] =
128128
OSD_BOOL_ENTRY("LOW POWER", &masterConfig.vtx_power),
129129
#endif // USE_RTC6705
130130

131-
OSD_BACK_ENTRY,
132-
OSD_END_ENTRY,
131+
OSD_BACK_AND_END_ENTRY,
133132
};
134133

135134
const CMS_Menu cmsx_menuVtx = {

0 commit comments

Comments
 (0)