Skip to content

Commit

Permalink
Inhibit 'Save & Exit' menu when in RC preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeller committed Dec 7, 2019
1 parent 18c4857 commit 9a5e647
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
28 changes: 20 additions & 8 deletions src/main/cms/cms.c
Expand Up @@ -190,6 +190,8 @@ static uint8_t pageMaxRow; // Max row in the current page

static cmsCtx_t currentCtx;

static bool saveMenuInhibited = false;

#ifdef CMS_MENU_DEBUG // For external menu content creators

static char menuErrLabel[21 + 1] = "RANDOM DATA";
Expand Down Expand Up @@ -217,8 +219,6 @@ static CMS_Menu menuErr = {
debug[1] = currentCtx.page; \
debug[2] = pageMaxRow; \
debug[3] = currentCtx.cursorRow; } struct _dummy
#else
#define cmsPageDebug()
#endif

static void cmsUpdateMaxRow(displayPort_t *instance)
Expand Down Expand Up @@ -555,6 +555,8 @@ STATIC_UNIT_TESTED const void *cmsMenuBack(displayPort_t *pDisplay)
return currentCtx.menu->onExit(pageTop + currentCtx.cursorRow);
}

saveMenuInhibited = false;

if (!menuStackIdx) {
return NULL;
}
Expand All @@ -564,7 +566,9 @@ STATIC_UNIT_TESTED const void *cmsMenuBack(displayPort_t *pDisplay)
cmsMenuCountPage(pDisplay);
cmsPageSelect(pDisplay, currentCtx.page);

#if defined(CMS_PAGE_DEBUG)
cmsPageDebug();
#endif

return NULL;
}
Expand Down Expand Up @@ -610,7 +614,9 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
currentCtx.cursorRow++;
}

#if defined(CMS_PAGE_DEBUG)
cmsPageDebug();
#endif

if (pDisplay->cursorRow >= 0 && currentCtx.cursorRow != pDisplay->cursorRow) {
room -= displayWrite(pDisplay, leftMenuColumn, top + pDisplay->cursorRow * linesPerMenuItem, DISPLAYPORT_ATTR_NONE, " ");
Expand Down Expand Up @@ -685,6 +691,8 @@ const void *cmsMenuChange(displayPort_t *pDisplay, const void *ptr)
#endif

if (pMenu != currentCtx.menu) {
saveMenuInhibited = false;

// Stack the current menu and move to a new menu.
if (menuStackIdx >= CMS_MENU_STACK_LIMIT - 1) {
// menu stack limit reached - prevent array overflow
Expand Down Expand Up @@ -715,7 +723,9 @@ const void *cmsMenuChange(displayPort_t *pDisplay, const void *ptr)
cmsPageSelect(pDisplay, cursorAbs / maxMenuItems);
}

#if defined(CMS_PAGE_DEBUG)
cmsPageDebug();
#endif

return NULL;
}
Expand Down Expand Up @@ -871,13 +881,10 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
return BUTTON_PAUSE;
}

if (key == CMS_KEY_SAVEMENU) {
if (key == CMS_KEY_SAVEMENU && !saveMenuInhibited) {
osdElementEditing = false;
if (getRebootRequired()) {
cmsMenuChange(pDisplay, &cmsx_menuSaveExitReboot);
} else {
cmsMenuChange(pDisplay, &cmsx_menuSaveExit);
}
cmsMenuChange(pDisplay, getSaveExitMenu());

return BUTTON_PAUSE;
}

Expand Down Expand Up @@ -1290,4 +1297,9 @@ void cmsInit(void)
cmsCurrentDevice = -1;
}

void inhibitSaveMenu(void)
{
saveMenuInhibited = true;
}

#endif // CMS
1 change: 1 addition & 0 deletions src/main/cms/cms.h
Expand Up @@ -51,6 +51,7 @@ void cmsMenuOpen(void);
const void *cmsMenuChange(displayPort_t *pPort, const void *ptr);
const void *cmsMenuExit(displayPort_t *pPort, const void *ptr);
void cmsSetExternKey(cms_key_e extKey);
void inhibitSaveMenu(void);

#define CMS_STARTUP_HELP_TEXT1 "MENU:THR MID"
#define CMS_STARTUP_HELP_TEXT2 "+ YAW LEFT"
Expand Down
7 changes: 2 additions & 5 deletions src/main/cms/cms_menu_main.c
Expand Up @@ -92,11 +92,8 @@ static const void *cmsx_SaveExitMenu(displayPort_t *pDisplay, const void *ptr)
{
UNUSED(ptr);

if (getRebootRequired()) {
cmsMenuChange(pDisplay, &cmsx_menuSaveExitReboot);
} else {
cmsMenuChange(pDisplay, &cmsx_menuSaveExit);
}
cmsMenuChange(pDisplay, getSaveExitMenu());

return NULL;
}

Expand Down
14 changes: 11 additions & 3 deletions src/main/cms/cms_menu_misc.c
Expand Up @@ -60,12 +60,20 @@
// Misc
//

static const void *cmsx_menuRcOnEnter(void)
{
inhibitSaveMenu();

return NULL;
}

static const void *cmsx_menuRcConfirmBack(const OSD_Entry *self)
{
if (self && self->type == OME_Back)
if (self && self->type == OME_Back) {
return NULL;
else
} else {
return MENU_CHAIN_BACK;
}
}

//
Expand Down Expand Up @@ -94,7 +102,7 @@ CMS_Menu cmsx_menuRcPreview = {
.GUARD_text = "XRCPREV",
.GUARD_type = OME_MENU,
#endif
.onEnter = NULL,
.onEnter = cmsx_menuRcOnEnter,
.onExit = cmsx_menuRcConfirmBack,
.onDisplayUpdate = NULL,
.entries = cmsx_menuRcEntries
Expand Down
13 changes: 10 additions & 3 deletions src/main/cms/cms_menu_saveexit.c
Expand Up @@ -44,7 +44,7 @@ static const OSD_Entry cmsx_menuSaveExitEntries[] =
{ NULL, OME_END, NULL, NULL, 0 }
};

CMS_Menu cmsx_menuSaveExit = {
static CMS_Menu cmsx_menuSaveExit = {
#ifdef CMS_MENU_DEBUG
.GUARD_text = "MENUSAVE",
.GUARD_type = OME_MENU,
Expand All @@ -64,7 +64,7 @@ static const OSD_Entry cmsx_menuSaveExitRebootEntries[] =
{ NULL, OME_END, NULL, NULL, 0 }
};

CMS_Menu cmsx_menuSaveExitReboot = {
static CMS_Menu cmsx_menuSaveExitReboot = {
#ifdef CMS_MENU_DEBUG
.GUARD_text = "MENUSAVE",
.GUARD_type = OME_MENU,
Expand All @@ -75,5 +75,12 @@ CMS_Menu cmsx_menuSaveExitReboot = {
.entries = cmsx_menuSaveExitRebootEntries
};


CMS_Menu *getSaveExitMenu(void)
{
if (getRebootRequired()) {
return &cmsx_menuSaveExitReboot;
} else {
return &cmsx_menuSaveExit;
}
}
#endif
3 changes: 1 addition & 2 deletions src/main/cms/cms_menu_saveexit.h
Expand Up @@ -20,5 +20,4 @@

#pragma once

extern CMS_Menu cmsx_menuSaveExit;
extern CMS_Menu cmsx_menuSaveExitReboot;
CMS_Menu *getSaveExitMenu(void);

0 comments on commit 9a5e647

Please sign in to comment.