1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Add CMS menu entry level control of forced reboot on changes

CMS menu items can now be defined with a `REBOOT_REQUIRED` flag. If the user changes flagged elements the the exit/save options will change to `EXIT&REBOOT` and `SAVE&REBOOT` - ensuring that the changed items will be handled properly. This should be used for options where runtime changes either won't take effect (because they are read at boot), or for items that could have unexpected behavior if changed.

Several appropriate menus have been updated to include the flag.

To accomodate the dynamic nature of the save/exit options, the individual options have been removed from the main menu and replaced with a `SAVE/EXIT` submenu. This is the same menu that is presented as the quick-access popup save menu (yaw-right). This menu will adapt to requiring a reboot if any flagged setting is changed. Additionally the `REBOOT_REQD` arming disabled reason will be set (cleared by the reboot).
This commit is contained in:
Bruce Luckcuck 2019-05-20 12:20:34 -04:00
parent 7cd030559d
commit 9081bd3338
9 changed files with 119 additions and 42 deletions

View file

@ -776,8 +776,9 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr)
cmsTraverseGlobalExit(&menuMain);
if (currentCtx.menu->onExit)
if (currentCtx.menu->onExit) {
currentCtx.menu->onExit((OSD_Entry *)NULL); // Forced exit
}
if ((exitType == CMS_POPUP_SAVE) || (exitType == CMS_POPUP_SAVEREBOOT)) {
// traverse through the menu stack and call their onExit functions
@ -800,7 +801,7 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr)
displayRelease(pDisplay);
currentCtx.menu = NULL;
if ((exitType == CMS_EXIT_SAVEREBOOT) || (exitType == CMS_POPUP_SAVEREBOOT)) {
if ((exitType == CMS_EXIT_SAVEREBOOT) || (exitType == CMS_POPUP_SAVEREBOOT) || (exitType == CMS_POPUP_EXITREBOOT)) {
displayClearScreen(pDisplay);
displayWrite(pDisplay, 5, 3, "REBOOTING...");
@ -832,8 +833,9 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
uint16_t res = BUTTON_TIME;
const OSD_Entry *p;
if (!currentCtx.menu)
if (!currentCtx.menu) {
return res;
}
if (key == CMS_KEY_MENU) {
cmsMenuOpen();
@ -851,7 +853,11 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
if (key == CMS_KEY_SAVEMENU) {
osdElementEditing = false;
cmsMenuChange(pDisplay, &cmsx_menuSaveExit);
if (getRebootRequired()) {
cmsMenuChange(pDisplay, &cmsx_menuSaveExitReboot);
} else {
cmsMenuChange(pDisplay, &cmsx_menuSaveExit);
}
return BUTTON_PAUSE;
}
@ -868,8 +874,9 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
currentCtx.cursorRow--;
// Skip non-title labels
if ((pageTop + currentCtx.cursorRow)->type == OME_Label && currentCtx.cursorRow > 0)
if ((pageTop + currentCtx.cursorRow)->type == OME_Label && currentCtx.cursorRow > 0) {
currentCtx.cursorRow--;
}
if (currentCtx.cursorRow == -1 || (pageTop + currentCtx.cursorRow)->type == OME_Label) {
// Goto previous page
@ -878,8 +885,9 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
}
}
if ((key == CMS_KEY_DOWN || key == CMS_KEY_UP) && (!osdElementEditing))
if ((key == CMS_KEY_DOWN || key == CMS_KEY_UP) && (!osdElementEditing)) {
return res;
}
p = pageTop + currentCtx.cursorRow;
@ -895,8 +903,9 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
long retval;
if (p->func && key == CMS_KEY_RIGHT) {
retval = p->func(pDisplay, p->data);
if (retval == MENU_CHAIN_BACK)
if (retval == MENU_CHAIN_BACK) {
cmsMenuBack(pDisplay);
}
res = BUTTON_PAUSE;
}
break;
@ -917,11 +926,12 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_Bool:
if (p->data) {
uint8_t *val = p->data;
if (key == CMS_KEY_RIGHT)
*val = 1;
else
*val = 0;
const uint8_t previousValue = *val;
*val = (key == CMS_KEY_RIGHT) ? 1 : 0;
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*val != previousValue)) {
setRebootRequired();
}
}
break;
@ -929,6 +939,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_VISIBLE:
if (p->data) {
uint16_t *val = (uint16_t *)p->data;
const uint16_t previousValue = *val;
if ((key == CMS_KEY_RIGHT) && (!osdElementEditing)) {
osdElementEditing = true;
osdProfileCursor = 1;
@ -953,6 +964,9 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
}
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*val != previousValue)) {
setRebootRequired();
}
}
break;
#endif
@ -961,15 +975,21 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_FLOAT:
if (p->data) {
OSD_UINT8_t *ptr = p->data;
const uint16_t previousValue = *ptr->val;
if (key == CMS_KEY_RIGHT) {
if (*ptr->val < ptr->max)
if (*ptr->val < ptr->max) {
*ptr->val += ptr->step;
}
}
else {
if (*ptr->val > ptr->min)
if (*ptr->val > ptr->min) {
*ptr->val -= ptr->step;
}
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*ptr->val != previousValue)) {
setRebootRequired();
}
if (p->func) {
p->func(pDisplay, p);
}
@ -979,33 +999,44 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_TAB:
if (p->type == OME_TAB) {
OSD_TAB_t *ptr = p->data;
const uint8_t previousValue = *ptr->val;
if (key == CMS_KEY_RIGHT) {
if (*ptr->val < ptr->max)
if (*ptr->val < ptr->max) {
*ptr->val += 1;
}
else {
if (*ptr->val > 0)
}
} else {
if (*ptr->val > 0) {
*ptr->val -= 1;
}
}
if (p->func)
if (p->func) {
p->func(pDisplay, p->data);
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*ptr->val != previousValue)) {
setRebootRequired();
}
}
break;
case OME_INT8:
if (p->data) {
OSD_INT8_t *ptr = p->data;
const int8_t previousValue = *ptr->val;
if (key == CMS_KEY_RIGHT) {
if (*ptr->val < ptr->max)
if (*ptr->val < ptr->max) {
*ptr->val += ptr->step;
}
else {
if (*ptr->val > ptr->min)
}
} else {
if (*ptr->val > ptr->min) {
*ptr->val -= ptr->step;
}
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*ptr->val != previousValue)) {
setRebootRequired();
}
if (p->func) {
p->func(pDisplay, p);
}
@ -1015,15 +1046,20 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_UINT16:
if (p->data) {
OSD_UINT16_t *ptr = p->data;
const uint16_t previousValue = *ptr->val;
if (key == CMS_KEY_RIGHT) {
if (*ptr->val < ptr->max)
if (*ptr->val < ptr->max) {
*ptr->val += ptr->step;
}
else {
if (*ptr->val > ptr->min)
}
} else {
if (*ptr->val > ptr->min) {
*ptr->val -= ptr->step;
}
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*ptr->val != previousValue)) {
setRebootRequired();
}
if (p->func) {
p->func(pDisplay, p);
}
@ -1033,15 +1069,20 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, cms_key_e key)
case OME_INT16:
if (p->data) {
OSD_INT16_t *ptr = p->data;
const int16_t previousValue = *ptr->val;
if (key == CMS_KEY_RIGHT) {
if (*ptr->val < ptr->max)
if (*ptr->val < ptr->max) {
*ptr->val += ptr->step;
}
else {
if (*ptr->val > ptr->min)
}
} else {
if (*ptr->val > ptr->min) {
*ptr->val -= ptr->step;
}
}
SET_PRINTVALUE(runtimeEntryFlags[currentCtx.cursorRow]);
if ((p->flags & REBOOT_REQUIRED) && (*ptr->val != previousValue)) {
setRebootRequired();
}
if (p->func) {
p->func(pDisplay, p);
}