1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

onExit is now called with pointer to OSD_Entry at the time of exit

This will remove the final remaining reference to RC preview menu
(which required not to exit with KEY_ESC).
This commit is contained in:
jflyper 2016-11-05 13:14:54 +09:00
parent f66a08d457
commit 9008116823
4 changed files with 30 additions and 16 deletions

View file

@ -78,10 +78,6 @@
// Forwards // Forwards
static long cmsx_InfoInit(void); static long cmsx_InfoInit(void);
#if 0
long cmsx_FeatureRead(void);
long cmsx_FeatureWriteback(void);
#endif
// Device management // Device management
@ -509,8 +505,8 @@ long cmsMenuChange(displayPort_t *pDisplay, void *ptr)
static long cmsMenuBack(displayPort_t *pDisplay) static long cmsMenuBack(displayPort_t *pDisplay)
{ {
if (currentMenu->onExit) if (currentMenu->onExit && currentMenu->onExit(pageTop + cursorRow) < 0)
currentMenu->onExit(); return -1;
if (menuStackIdx) { if (menuStackIdx) {
displayClear(pDisplay); displayClear(pDisplay);
@ -581,7 +577,7 @@ static long cmsMenuExit(displayPort_t *pDisplay, void *ptr)
cmsTraverseGlobalExit(&menuMain); cmsTraverseGlobalExit(&menuMain);
if (currentMenu->onExit) if (currentMenu->onExit)
currentMenu->onExit(); currentMenu->onExit((OSD_Entry *)NULL); // Forced exit
} }
cmsInMenu = false; cmsInMenu = false;
@ -812,7 +808,7 @@ static void cmsUpdate(displayPort_t *pDisplay, uint32_t currentTime)
key = KEY_RIGHT; key = KEY_RIGHT;
rcDelay = BUTTON_TIME; rcDelay = BUTTON_TIME;
} }
else if ((IS_HI(YAW) || IS_LO(YAW)) && currentMenu != &cmsx_menuRc) // this menu is used to check transmitter signals so can't exit using YAW else if (IS_HI(YAW) || IS_LO(YAW))
{ {
key = KEY_ESC; key = KEY_ESC;
rcDelay = BUTTON_TIME; rcDelay = BUTTON_TIME;
@ -856,7 +852,7 @@ void cmsInit(void)
} }
// //
// Menu contents // Built-in menu contents and support functions
// //
// Info // Info

View file

@ -63,8 +63,10 @@ long cmsx_PidRead(void)
return 0; return 0;
} }
long cmsx_PidWriteback(void) long cmsx_PidWriteback(OSD_Entry *self)
{ {
UNUSED(self);
uint8_t i; uint8_t i;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
@ -132,13 +134,23 @@ long cmsx_RateExpoRead(void)
return 0; return 0;
} }
long cmsx_RateExpoWriteback(void) long cmsx_RateExpoWriteback(OSD_Entry *self)
{ {
UNUSED(self);
memcpy(&masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], &rateProfile, sizeof(controlRateConfig_t)); memcpy(&masterConfig.profile[masterConfig.current_profile_index].controlRateProfile[masterConfig.profile[masterConfig.current_profile_index].activeRateProfile], &rateProfile, sizeof(controlRateConfig_t));
return 0; return 0;
} }
long cmsx_menuRcConfirmBack(OSD_Entry *self)
{
if (self && self->type == OME_Back)
return 0;
else
return -1;
}
OSD_Entry cmsx_menuRateExpoEntries[] = OSD_Entry cmsx_menuRateExpoEntries[] =
{ {
{"--- RATE&EXPO ---", OME_Label, NULL, NULL, 0}, {"--- RATE&EXPO ---", OME_Label, NULL, NULL, 0},
@ -198,7 +210,7 @@ CMS_Menu cmsx_menuRc = {
"MENURC", "MENURC",
OME_MENU, OME_MENU,
NULL, NULL,
NULL, cmsx_menuRcConfirmBack,
NULL, NULL,
cmsx_menuRcEntries, cmsx_menuRcEntries,
}; };

View file

@ -1,4 +1 @@
extern CMS_Menu cmsx_menuImu; extern CMS_Menu cmsx_menuImu;
// This should be gone
extern CMS_Menu cmsx_menuRc;

View file

@ -57,6 +57,15 @@ typedef struct
typedef long (*CMSMenuFuncPtr)(void); typedef long (*CMSMenuFuncPtr)(void);
/*
onExit function is called with self:
(1) Pointer to an OSD_Entry when cmsMenuBack() was called.
Point to an OSD_Entry with type == OME_Back if BACK was selected.
(2) 0 if called from menu exit (forced exit).
*/
typedef long (*CMSMenuOnExitPtr)(OSD_Entry *self);
typedef struct typedef struct
{ {
// These two are debug aids for menu content creators. // These two are debug aids for menu content creators.
@ -64,7 +73,7 @@ typedef struct
OSD_MenuElement GUARD_type; OSD_MenuElement GUARD_type;
CMSMenuFuncPtr onEnter; CMSMenuFuncPtr onEnter;
CMSMenuFuncPtr onExit; CMSMenuOnExitPtr onExit;
CMSMenuFuncPtr onGlobalExit; CMSMenuFuncPtr onGlobalExit;
OSD_Entry *entries; OSD_Entry *entries;
} CMS_Menu; } CMS_Menu;