| 470 | } |
| 471 | |
| 472 | void setCustomColorSettingMenu(int rgb, std::function<uint32_t(uint32_t, int)> colorGenerator) { |
| 473 | uint32_t originalColor = bruceConfig.ledColor; |
| 474 | |
| 475 | options.clear(); |
| 476 | |
| 477 | static auto hoverFunction = [](void *pointer, bool shouldRender) -> bool { |
| 478 | uint32_t colorToSet = *static_cast<uint32_t *>(pointer); |
| 479 | setLedColor(colorToSet); |
| 480 | previewLedColor = CRGB(colorToSet); |
| 481 | return false; |
| 482 | }; |
| 483 | |
| 484 | static uint32_t colorStorage[(int)(255 / LED_COLOR_STEP) + 1]; |
| 485 | short selectedIndex = 0; |
| 486 | short colorPart = 0; |
| 487 | short i = 0; |
| 488 | short index = 0; |
| 489 | |
| 490 | if (rgb == 1) { |
| 491 | colorPart = (originalColor >> 16) & 0xFF; |
| 492 | } else if (rgb == 2) { |
| 493 | colorPart = (originalColor >> 8) & 0xFF; |
| 494 | } else { |
| 495 | colorPart = originalColor & 0xFF; |
| 496 | } |
| 497 | |
| 498 | while (i <= 255) { |
| 499 | if (i % LED_COLOR_STEP == 0 || i == 255) { |
| 500 | uint32_t updatedColor = colorGenerator(originalColor, i); |
| 501 | colorStorage[index] = updatedColor; |
| 502 | |
| 503 | // Select nearest color step rounding down |
| 504 | if (colorPart >= i && colorPart < i + LED_COLOR_STEP) selectedIndex = index; |
| 505 | |
| 506 | options.emplace_back( |
| 507 | String(i), |
| 508 | [updatedColor]() { bruceConfig.setLedColor(updatedColor); }, |
| 509 | selectedIndex == index, |
| 510 | hoverFunction, |
| 511 | &colorStorage[index] |
| 512 | ); |
| 513 | ++index; |
| 514 | } |
| 515 | ++i; |
| 516 | } |
| 517 | |
| 518 | addOptionToMainMenu(); |
| 519 | |
| 520 | int selectedOption = loopOptions(options, MENU_TYPE_SUBMENU, "", selectedIndex); |
| 521 | if (selectedOption == -1 || selectedOption == options.size() - 1) { |
| 522 | setLedColor(originalColor); |
| 523 | return; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | void setCustomColorSettingMenuR() { |
| 528 | setCustomColorSettingMenu(1, [](uint32_t baseColor, int i) { |
no test coverage detected