From 6a9f8ba146dd8225612f363e65c28d10dbcfa555 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sat, 8 Aug 2026 10:09:54 +0100 Subject: [PATCH] Encapsulate colors.cpp's own runtime state as static, not global lastRandomIndex was referenced only in colors.cpp. Converted it to file-local `static`. No behavior change - purely a storage-class change. Verified: esp32dev builds and links cleanly via `pio run -e esp32dev`, no warnings from either changed file. Co-Authored-By: Claude Sonnet 5 --- wled00/colors.cpp | 4 ++++ wled00/wled.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 6ddc4ec892..767b8cf0b2 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -144,6 +144,10 @@ uint32_t ColorFromPalette(const CRGBPalette16& pal, unsigned index, uint8_t brig return RGBW32(red1,green1,blue1,0); } +// Runtime state private to this file - previously WLED_GLOBAL, a leftover from +// when all state lived in one big extern block regardless of who used it. +static byte lastRandomIndex = 0; // used to save last random color so the new one is not the same + void setRandomColor(byte* rgb) { lastRandomIndex = get_random_wheel_index(lastRandomIndex); diff --git a/wled00/wled.h b/wled00/wled.h index 9bafb49196..192d087629 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -585,7 +585,7 @@ WLED_GLOBAL bool interfacesInited _INIT(false); WLED_GLOBAL bool wasConnected _INIT(false); // color -WLED_GLOBAL byte lastRandomIndex _INIT(0); // used to save last random color so the new one is not the same +// lastRandomIndex is private to colors.cpp - see there. WLED_GLOBAL std::vector customPalettes; // custom palettes (file-based, IDs grow downwards starting at 200) WLED_GLOBAL std::vector usermodPalettes; // usermod-registered palettes (IDs 255, 254, 253...) WLED_GLOBAL uint8_t paletteBlend _INIT(0); // determines blending and wrapping of palette: 0: blend, wrap if moving (SEGMENT.speed>0); 1: blend, always wrap; 2: blend, never wrap; 3: don't blend or wrap