From 90081168238d2938ec5d19aba741a1eb4e378304 Mon Sep 17 00:00:00 2001 From: jflyper Date: Sat, 5 Nov 2016 13:14:54 +0900 Subject: [PATCH] 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). --- src/main/io/cms.c | 14 +++++--------- src/main/io/cms_imu.c | 18 +++++++++++++++--- src/main/io/cms_imu.h | 3 --- src/main/io/cms_types.h | 11 ++++++++++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/main/io/cms.c b/src/main/io/cms.c index 610e2a3d9a..1bc51778eb 100644 --- a/src/main/io/cms.c +++ b/src/main/io/cms.c @@ -78,10 +78,6 @@ // Forwards static long cmsx_InfoInit(void); -#if 0 -long cmsx_FeatureRead(void); -long cmsx_FeatureWriteback(void); -#endif // Device management @@ -509,8 +505,8 @@ long cmsMenuChange(displayPort_t *pDisplay, void *ptr) static long cmsMenuBack(displayPort_t *pDisplay) { - if (currentMenu->onExit) - currentMenu->onExit(); + if (currentMenu->onExit && currentMenu->onExit(pageTop + cursorRow) < 0) + return -1; if (menuStackIdx) { displayClear(pDisplay); @@ -581,7 +577,7 @@ static long cmsMenuExit(displayPort_t *pDisplay, void *ptr) cmsTraverseGlobalExit(&menuMain); if (currentMenu->onExit) - currentMenu->onExit(); + currentMenu->onExit((OSD_Entry *)NULL); // Forced exit } cmsInMenu = false; @@ -812,7 +808,7 @@ static void cmsUpdate(displayPort_t *pDisplay, uint32_t currentTime) key = KEY_RIGHT; 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; rcDelay = BUTTON_TIME; @@ -856,7 +852,7 @@ void cmsInit(void) } // -// Menu contents +// Built-in menu contents and support functions // // Info diff --git a/src/main/io/cms_imu.c b/src/main/io/cms_imu.c index 5b6d742f4e..385c462398 100644 --- a/src/main/io/cms_imu.c +++ b/src/main/io/cms_imu.c @@ -63,8 +63,10 @@ long cmsx_PidRead(void) return 0; } -long cmsx_PidWriteback(void) +long cmsx_PidWriteback(OSD_Entry *self) { + UNUSED(self); + uint8_t i; for (i = 0; i < 3; i++) { @@ -132,13 +134,23 @@ long cmsx_RateExpoRead(void) 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)); return 0; } +long cmsx_menuRcConfirmBack(OSD_Entry *self) +{ + if (self && self->type == OME_Back) + return 0; + else + return -1; +} + OSD_Entry cmsx_menuRateExpoEntries[] = { {"--- RATE&EXPO ---", OME_Label, NULL, NULL, 0}, @@ -198,7 +210,7 @@ CMS_Menu cmsx_menuRc = { "MENURC", OME_MENU, NULL, - NULL, + cmsx_menuRcConfirmBack, NULL, cmsx_menuRcEntries, }; diff --git a/src/main/io/cms_imu.h b/src/main/io/cms_imu.h index 0a05ed8daa..9fb44f05b9 100644 --- a/src/main/io/cms_imu.h +++ b/src/main/io/cms_imu.h @@ -1,4 +1 @@ extern CMS_Menu cmsx_menuImu; - -// This should be gone -extern CMS_Menu cmsx_menuRc; diff --git a/src/main/io/cms_types.h b/src/main/io/cms_types.h index 6a051de382..3243e05bd5 100644 --- a/src/main/io/cms_types.h +++ b/src/main/io/cms_types.h @@ -57,6 +57,15 @@ typedef struct 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 { // These two are debug aids for menu content creators. @@ -64,7 +73,7 @@ typedef struct OSD_MenuElement GUARD_type; CMSMenuFuncPtr onEnter; - CMSMenuFuncPtr onExit; + CMSMenuOnExitPtr onExit; CMSMenuFuncPtr onGlobalExit; OSD_Entry *entries; } CMS_Menu;