MCPcopy Create free account
hub / github.com/BruceDevices/firmware / loopOptions

Function loopOptions

src/core/display.cpp:468–656  ·  view source on GitHub ↗

** Function: loopOptions ** Where you choose among the options in menu **********************************************************************/

Source from the content-addressed store, hash-verified

466** Where you choose among the options in menu
467**********************************************************************/
468int loopOptions(
469 std::vector<Option> &options, uint8_t menuType, const char *subText, int index, bool interpreter
470) {
471 if (options.empty()) return -1;
472
473 auto findFirstEnabled = [&]() -> int {
474 for (size_t i = 0; i < options.size(); i++) {
475 if (options[i].enabled) return static_cast<int>(i);
476 }
477 return -1;
478 };
479
480 auto findNextEnabled = [&](int start, int step) -> int {
481 if (options.empty()) return -1;
482 int size = static_cast<int>(options.size());
483 int idx = start;
484 for (int i = 0; i < size; i++) {
485 idx = (idx + step + size) % size;
486 if (options[idx].enabled) return idx;
487 }
488 return -1;
489 };
490
491 if (index < 0 || index >= static_cast<int>(options.size())) index = 0;
492 if (!options[index].enabled) {
493 int firstEnabled = findFirstEnabled();
494 if (firstEnabled < 0) return -1;
495 index = firstEnabled;
496 }
497
498 Opt_Coord coord;
499 bool redraw = true;
500 bool exit = false;
501 int menuSize = options.size();
502 int devModeCounter = 0;
503 static unsigned long _clock_bat_timer = millis();
504 if (options.size() > MAX_MENU_SIZE) { menuSize = MAX_MENU_SIZE; }
505 if (index > 0)
506 tft.fillRoundRect(
507 tftWidth * 0.10,
508 tftHeight / 2 - menuSize * (FM * 8 + 4) / 2 - 5,
509 tftWidth * 0.8,
510 (FM * 8 + 4) * menuSize + 10,
511 5,
512 bruceConfig.bgColor
513 );
514 if (index >= options.size()) index = 0;
515 bool firstRender = true;
516 static unsigned long menuOpenTs = 0; // timestamp when menu was first rendered
517 drawMainBorder();
518 while (1) {
519 // Check for shutdown before drawing menu to avoid drawing a black bar on the screen
520 if (exit) break;
521 if (menuType == MENU_TYPE_MAIN) {
522 checkReboot();
523 if (devModeCounter >= 5 && !bruceConfig.devMode) {
524 bruceConfig.setDevMode(true);
525 displayInfo("Dev Mode Enabled", true);

Callers

nothing calls this directly

Calls 15

millisFunction · 0.85
drawMainBorderFunction · 0.85
displayInfoFunction · 0.85
drawStatusBarFunction · 0.85
drawSubmenuFunction · 0.85
drawOptionsFunction · 0.85
checkShortcutPressFunction · 0.85
displayScrollingTextFunction · 0.85
checkFunction · 0.85
getColorVariationFunction · 0.85
sizeMethod · 0.80
setDevModeMethod · 0.80

Tested by

no test coverage detected