From aa41c930ea82e9b94a9f1ae80f4e08131749f75b Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sat, 8 Aug 2026 10:00:36 +0100 Subject: [PATCH] Encapsulate ntp.cpp's own runtime state as static, not global 3 WLED_GLOBAL variables were referenced only in ntp.cpp: lastTimerMinute, ntpPacketSentTime, ntpServerIP. Converted all 3 to file-local `static`. No behavior change - purely a storage-class change. Verified: esp32dev builds and links cleanly via `pio run -e esp32dev` (1,320,323 bytes flash, no warnings from either changed file). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01UtCyBD91vAYWvBzaMyQSHd --- wled00/ntp.cpp | 6 ++++++ wled00/wled.h | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 6e57f8cad3..e791d05741 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -8,6 +8,12 @@ static void sendNTPPacket(); static bool checkNTPResponse(); +// 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 lastTimerMinute = 0; +static unsigned long ntpPacketSentTime = NTP_NEVER; +static IPAddress ntpServerIP; + // WARNING: may cause errors in sunset calculations on ESP8266, see #3400 // building with `-D WLED_USE_REAL_MATH` will prevent those errors at the expense of flash and RAM diff --git a/wled00/wled.h b/wled00/wled.h index 9bafb49196..182847df3f 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -706,7 +706,7 @@ WLED_GLOBAL bool hueStoreAllowed _INIT(false), hueNewKey _INIT(false); WLED_GLOBAL unsigned long countdownTime _INIT(1514764800L); WLED_GLOBAL bool countdownOverTriggered _INIT(true); -WLED_GLOBAL byte lastTimerMinute _INIT(0); +// lastTimerMinute is private to ntp.cpp - see there. WLED_GLOBAL std::vector timers; WLED_GLOBAL bool doAdvancePlaylist _INIT(false); @@ -755,8 +755,7 @@ WLED_GLOBAL DNSServer dnsServer; WLED_GLOBAL bool ntpConnected _INIT(false); WLED_GLOBAL time_t localTime _INIT(0); WLED_GLOBAL unsigned long ntpLastSyncTime _INIT(NTP_NEVER); -WLED_GLOBAL unsigned long ntpPacketSentTime _INIT(NTP_NEVER); -WLED_GLOBAL IPAddress ntpServerIP; +// ntpPacketSentTime/ntpServerIP are private to ntp.cpp - see there. WLED_GLOBAL uint16_t ntpLocalPort _INIT(2390); WLED_GLOBAL uint16_t rolloverMillis _INIT(0); WLED_GLOBAL float longitude _INIT(WLED_LON);