Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

static_assert(MAX_NUM_SEGMENTS >= WLED_MAX_BUSSES, "Max segments must be at least max number of busses!");

// 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.
// json.cpp only ever reads it for status reporting, so it gets a by-value
// getter rather than a mutable reference.
static uint8_t currentLedmap = 0;
uint8_t getCurrentLedmap() { return currentLedmap; }


///////////////////////////////////////////////////////////////////////////////
// Segment class implementation
Expand Down
22 changes: 22 additions & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ bool writeObjectToFile(const char* file, const char* key, const JsonDocument* co
bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest, const JsonDocument* filter = nullptr);
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest, const JsonDocument* filter = nullptr);
void updateFSInfo();
bool isDoCloseFile();
void closeFile();
inline bool writeObjectToFileUsingId(const String &file, uint16_t id, const JsonDocument* content) { return writeObjectToFileUsingId(file.c_str(), id, content); };
inline bool writeObjectToFile(const String &file, const char* key, const JsonDocument* content) { return writeObjectToFile(file.c_str(), key, content); };
Expand All @@ -134,13 +135,19 @@ bool checkBackupExists(const char* filename);
bool validateJsonFile(const char* filename);
void dumpFilesToSerial();

//FX_fcn.cpp
uint8_t getCurrentLedmap();

//hue.cpp
void handleHue();
void reconnectHue();
void onHueError(void* arg, AsyncClient* client, int8_t error);
void onHueConnect(void* arg, AsyncClient* client);
void sendHuePoll();
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
#ifndef WLED_DISABLE_HUESYNC
byte getHueError();
#endif

//image_loader.cpp
class Segment;
Expand Down Expand Up @@ -169,6 +176,7 @@ void sendImprovInfoResponse();
void startImprovWifiScan();
void handleImprovWifiScan();
void sendImprovIPRPCResult(ImprovRPCType type);
byte getImprovError();

//ir.cpp
void initIR();
Expand Down Expand Up @@ -205,6 +213,7 @@ void updateInterfaces(uint8_t callMode);
void handleTransitions();
void handleNightlight();
byte scaledBri(byte in);
uint32_t getNightlightDelayMs();

#ifdef WLED_ENABLE_LOXONE
//lx_parser.cpp
Expand Down Expand Up @@ -294,6 +303,14 @@ bool isAsterisksOnly(const char* str, byte maxLen);
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply=true);

//wled.cpp
int8_t getSelectedWiFi();
bool isSerialCanRX();
uint16_t getNtpLocalPort();
#ifndef WLED_DISABLE_ESPNOW
byte getStatusESPNow();
#endif

//udp.cpp
void notify(byte callMode, bool followUp=false);
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, const uint8_t* buffer, uint8_t bri=255, bool isRGBW=false);
Expand Down Expand Up @@ -438,6 +455,11 @@ void userLoop();
#define inoise8 perlin8 // fastled legacy alias
#define inoise16 perlin16 // fastled legacy alias
#define hex2int(a) (((a)>='0' && (a)<='9') ? (a)-'0' : ((a)>='A' && (a)<='F') ? (a)-'A'+10 : ((a)>='a' && (a)<='f') ? (a)-'a'+10 : 0)
#if WLED_MAX_LEDMAPS>16
uint32_t getLedMaps();
#else
uint16_t getLedMaps();
#endif
[[gnu::pure]] int getNumVal(const String &req, uint16_t pos);
void parseNumber(const char* str, byte &val, byte minv=0, byte maxv=255);
bool getVal(JsonVariant elem, byte &val, byte vmin=0, byte vmax=255); // getVal supports inc/decrementing and random ("X~Y(r|[w]~[-][Z])" form)
Expand Down
7 changes: 7 additions & 0 deletions wled00/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

#define FS_BUFSIZE 256

// 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.
// wled.cpp only ever reads it (to decide whether to call closeFile() from the
// main loop), so it gets a by-value getter rather than a mutable reference.
static bool doCloseFile = false;
bool isDoCloseFile() { return doCloseFile; }

/*
* Structural requirements for files managed by writeObjectToFile() and readObjectFromFile() utilities:
* 1. File must be a string representation of a valid JSON object
Expand Down
7 changes: 7 additions & 0 deletions wled00/hue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

#ifndef WLED_DISABLE_HUESYNC

// 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.
// xml.cpp only ever reads it for settings-page status reporting, so it gets
// a by-value getter rather than a mutable reference.
static byte hueError = HUE_ERROR_INACTIVE;
byte getHueError() { return hueError; }

void handleHue()
{
if (hueReceived)
Expand Down
7 changes: 7 additions & 0 deletions wled00/improv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#define DIMPROV_PRINTF(x...)
#endif

// 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.
// wled.cpp only ever reads it (to decide whether to send an Improv RPC
// result), so it gets a by-value getter rather than a mutable reference.
static byte improvError = 0;
byte getImprovError() { return improvError; }

#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32S3) // ToDO check if C6, C61, P4 support this
#undef WLED_DISABLE_IMPROV_WIFISCAN
#define WLED_DISABLE_IMPROV_WIFISCAN
Expand Down
6 changes: 3 additions & 3 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme

root["ps"] = (currentPreset > 0) ? currentPreset : -1;
root[F("pl")] = currentPlaylist;
root[F("ledmap")] = currentLedmap;
root[F("ledmap")] = getCurrentLedmap();

UsermodManager::addToJsonState(root);

Expand All @@ -667,7 +667,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
nl["dur"] = nightlightDelayMins;
nl["mode"] = nightlightMode;
nl[F("tbri")] = nightlightTargetBri;
nl[F("rem")] = nightlightActive ? (int)(nightlightDelayMs - (millis() - nightlightStartTime)) / 1000 : -1; // seconds remaining
nl[F("rem")] = nightlightActive ? (int)(getNightlightDelayMs() - (millis() - nightlightStartTime)) / 1000 : -1; // seconds remaining

JsonObject udpn = root.createNestedObject("udpn");
udpn[F("send")] = sendNotificationsRT;
Expand Down Expand Up @@ -809,7 +809,7 @@ void serializeInfo(JsonObject root)

JsonArray ledmaps = root.createNestedArray(F("maps"));
for (size_t i=0; i<WLED_MAX_LEDMAPS; i++) {
if ((ledMaps>>i) & 0x00000001U) {
if ((getLedMaps()>>i) & 0x00000001U) {
JsonObject ledmaps0 = ledmaps.createNestedObject();
ledmaps0["id"] = i;
#ifndef ESP8266
Expand Down
7 changes: 7 additions & 0 deletions wled00/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
* LED methods
*/

// 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.
// json.cpp only ever reads it for status reporting, so it gets a by-value
// getter rather than a mutable reference.
static uint32_t nightlightDelayMs = 10;
uint32_t getNightlightDelayMs() { return nightlightDelayMs; }

// applies chosen setment properties to legacy values
void setValuesFromSegment(uint8_t s) {
const Segment& seg = strip.getSegment(s);
Expand Down
2 changes: 1 addition & 1 deletion wled00/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ int findWiFi(bool doScan) {
} else if (status >= 0) { // status contains number of found networks (including duplicate SSIDs with different BSSID)
DEBUG_PRINTF_P(PSTR("WiFi: Found %d SSIDs. @ %lus\n"), status, millis()/1000);
int rssi = -9999;
size_t selected = (static_cast<size_t>(selectedWiFi) < multiWiFi.size()) ? static_cast<size_t>(selectedWiFi) : 0; // ensure valid starting index
size_t selected = (static_cast<size_t>(getSelectedWiFi()) < multiWiFi.size()) ? static_cast<size_t>(getSelectedWiFi()) : 0; // ensure valid starting index
for (int o = 0; o < status; o++) {
DEBUG_PRINTF_P(PSTR(" SSID: %s (BSSID: %s) RSSI: %ddB\n"), WiFi.SSID(o).c_str(), WiFi.BSSIDstr(o).c_str(), WiFi.RSSI(o));
for (unsigned n = 0; n < multiWiFi.size(); n++)
Expand Down
2 changes: 1 addition & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
utcOffsetSecs = request->arg(F("UO")).toInt();

//start ntp if not already connected
if (ntpEnabled && WLED_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(ntpLocalPort);
if (ntpEnabled && WLED_CONNECTED && !ntpConnected) ntpConnected = ntpUdp.begin(getNtpLocalPort());
ntpLastSyncTime = NTP_NEVER; // force new NTP query

longitude = request->arg(F("LN")).toFloat();
Expand Down
2 changes: 1 addition & 1 deletion wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void notify(byte callMode, bool followUp)
//next value to be added has index: udpOut[offs + 0]

#ifndef WLED_DISABLE_ESPNOW
if (enableESPNow && useESPNowSync && statusESPNow == ESP_NOW_STATE_ON) {
if (enableESPNow && useESPNowSync && getStatusESPNow() == ESP_NOW_STATE_ON) {
partial_packet_t buffer = {'W', 0, 1, {0}};
// send global data
DEBUG_PRINTLN(F("ESP-NOW sending first packet."));
Expand Down
13 changes: 13 additions & 0 deletions wled00/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,19 @@ um_data_t* simulateSound(uint8_t simulationId)
return um_data;
}

// 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.
// json.cpp only ever reads it for status reporting, so it gets a by-value
// getter rather than a mutable reference. Type matches the original
// WLED_MAX_LEDMAPS-dependent conditional.
#if WLED_MAX_LEDMAPS>16
static uint32_t ledMaps = 0; // bitfield representation of available ledmaps
uint32_t getLedMaps() { return ledMaps; }
#else
static uint16_t ledMaps = 0; // bitfield representation of available ledmaps
uint16_t getLedMaps() { return ledMaps; }
#endif

static const char s_ledmap_tmpl[] PROGMEM = "ledmap%d.json";
// enumerate all ledmapX.json files on FS and extract ledmap names if existing
void enumerateLedmaps() {
Expand Down
23 changes: 21 additions & 2 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@
#endif
extern "C" void usePWMFixedNMI();

// 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.
// Each is read-only from outside this file, so each gets a by-value getter
// rather than a mutable reference: an accidental write from elsewhere is now
// a build error instead of a silent bug.
static int8_t selectedWiFi = 0;
static bool serialCanRX = false;
// nobody in the codebase writes ntpLocalPort at runtime beyond this default,
// so it's a constexpr rather than a mutable static.
static constexpr uint16_t ntpLocalPort = 2390;
int8_t getSelectedWiFi() { return selectedWiFi; }
bool isSerialCanRX() { return serialCanRX; }
uint16_t getNtpLocalPort() { return ntpLocalPort; }

#ifndef WLED_DISABLE_ESPNOW
static byte statusESPNow = ESP_NOW_STATE_UNINIT; // state of ESP-NOW stack (0 uninitialised, 1 initialised, 2 error)
byte getStatusESPNow() { return statusESPNow; }
#endif

/*
* Main WLED class implementation. Mostly initialization and connection logic
*/
Expand Down Expand Up @@ -113,7 +132,7 @@ void WLED::loop()
handleAlexa();
#endif

if (doCloseFile) {
if (isDoCloseFile()) {
closeFile();
yield();
}
Expand Down Expand Up @@ -1069,7 +1088,7 @@ void WLED::handleConnection()
#endif

if (improvActive) {
if (improvError == 3) sendImprovStateResponse(0x00, true);
if (getImprovError() == 3) sendImprovStateResponse(0x00, true);
sendImprovStateResponse(0x04);
if (improvActive > 1) sendImprovIPRPCResult(ImprovRPCType::Command_Wifi);
}
Expand Down
24 changes: 10 additions & 14 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ WLED_GLOBAL std::vector<WiFiConfig> multiWiFi;
WLED_GLOBAL IPAddress dnsAddress _INIT_N((( 8, 8, 8, 8))); // Google's DNS
WLED_GLOBAL char cmDNS[33] _INIT(MDNS_NAME); // mDNS address (*.local, replaced by wledXXXXXX if default is used)
WLED_GLOBAL char apSSID[33] _INIT(""); // AP off by default (unless setup)
WLED_GLOBAL int8_t selectedWiFi _INIT(0);
// selectedWiFi is private to wled.cpp - use getSelectedWiFi() instead.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
WLED_GLOBAL byte apChannel _INIT(6); // 2.4GHz WiFi AP channel (1-13)
WLED_GLOBAL byte apHide _INIT(0); // hidden AP SSID
WLED_GLOBAL byte apBehavior _INIT(AP_BEHAVIOR_BOOT_NO_CONN); // access point opens when no connection after boot by default
Expand Down Expand Up @@ -512,12 +512,12 @@ WLED_GLOBAL bool hueApplyColor _INIT(true);
#endif

WLED_GLOBAL uint16_t serialBaud _INIT(1152); // serial baud rate, multiply by 100
WLED_GLOBAL bool serialCanRX _INIT(false);
// serialCanRX is private to wled.cpp - use isSerialCanRX() instead.
WLED_GLOBAL bool serialCanTX _INIT(false);

#ifndef WLED_DISABLE_ESPNOW
WLED_GLOBAL bool enableESPNow _INIT(false); // global on/off for ESP-NOW
WLED_GLOBAL byte statusESPNow _INIT(ESP_NOW_STATE_UNINIT); // state of ESP-NOW stack (0 uninitialised, 1 initialised, 2 error)
// statusESPNow is private to wled.cpp - use getStatusESPNow() instead.
WLED_GLOBAL bool useESPNowSync _INIT(false); // use ESP-NOW wireless technology for sync
//WLED_GLOBAL char linked_remote[13] _INIT(""); // MAC of ESP-NOW remote (Wiz Mote)
WLED_GLOBAL std::vector<std::array<char, 13>> linked_remotes; // MAC of ESP-NOW remotes (Wiz Mote)
Expand Down Expand Up @@ -603,7 +603,7 @@ WLED_GLOBAL bool useHarmonicRandomPalette _INIT(true); // use *harmon
// nightlight
WLED_GLOBAL bool nightlightActive _INIT(false);
WLED_GLOBAL bool nightlightActiveOld _INIT(false);
WLED_GLOBAL uint32_t nightlightDelayMs _INIT(10);
// nightlightDelayMs is private to led.cpp - use getNightlightDelayMs() instead.
WLED_GLOBAL byte nightlightDelayMinsDefault _INIT(nightlightDelayMins);
WLED_GLOBAL unsigned long nightlightStartTime;
WLED_GLOBAL unsigned long lastNlUpdate;
Expand Down Expand Up @@ -691,7 +691,7 @@ WLED_GLOBAL bool showWelcomePage _INIT(false);

// hue
#ifndef WLED_DISABLE_HUESYNC
WLED_GLOBAL byte hueError _INIT(HUE_ERROR_INACTIVE);
// hueError is private to hue.cpp - use getHueError() instead.
// WLED_GLOBAL uint16_t hueFailCount _INIT(0);
WLED_GLOBAL float hueXLast _INIT(0), hueYLast _INIT(0);
WLED_GLOBAL uint16_t hueHueLast _INIT(0), hueCtLast _INIT(0);
Expand All @@ -712,7 +712,7 @@ WLED_GLOBAL bool doAdvancePlaylist _INIT(false);

//improv
WLED_GLOBAL byte improvActive _INIT(0); //0: no improv packet received, 1: improv active, 2: provisioning
WLED_GLOBAL byte improvError _INIT(0);
// improvError is private to improv.cpp - use getImprovError() instead.

//playlists
WLED_GLOBAL int16_t currentPlaylist _INIT(-1);
Expand Down Expand Up @@ -757,7 +757,7 @@ 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;
WLED_GLOBAL uint16_t ntpLocalPort _INIT(2390);
// ntpLocalPort is private to wled.cpp - use getNtpLocalPort() instead.
WLED_GLOBAL uint16_t rolloverMillis _INIT(0);
WLED_GLOBAL float longitude _INIT(WLED_LON);
WLED_GLOBAL float latitude _INIT(WLED_LAT);
Expand All @@ -769,7 +769,7 @@ WLED_GLOBAL Toki toki _INIT(Toki());
WLED_GLOBAL size_t fsBytesUsed _INIT(0);
WLED_GLOBAL size_t fsBytesTotal _INIT(0);
WLED_GLOBAL unsigned long presetsModifiedTime _INIT(0L);
WLED_GLOBAL bool doCloseFile _INIT(false);
// doCloseFile is private to file.cpp - use isDoCloseFile() instead.

// presets
WLED_GLOBAL byte currentPreset _INIT(0);
Expand Down Expand Up @@ -811,15 +811,11 @@ WLED_GLOBAL WS2812FX strip _INIT(WS2812FX());
WLED_GLOBAL std::vector<BusConfig> busConfigs; //temporary, to remember values from network callback until after
WLED_GLOBAL bool doInitBusses _INIT(false);
WLED_GLOBAL int8_t loadLedmap _INIT(-1);
WLED_GLOBAL uint8_t currentLedmap _INIT(0);
// currentLedmap is private to FX_fcn.cpp - use getCurrentLedmap() instead.
#ifndef ESP8266
WLED_GLOBAL char *ledmapNames[WLED_MAX_LEDMAPS-1] _INIT_N(({nullptr}));
#endif
#if WLED_MAX_LEDMAPS>16
WLED_GLOBAL uint32_t ledMaps _INIT(0); // bitfield representation of available ledmaps
#else
WLED_GLOBAL uint16_t ledMaps _INIT(0); // bitfield representation of available ledmaps
#endif
// ledMaps is private to util.cpp - use getLedMaps() instead.

// global I2C SDA pin (used for usermods)
#ifndef I2CSDAPIN
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void sendBytes(){

void handleSerial()
{
if (!(serialCanRX && Serial)) return; // arduino docs: `if (Serial)` indicates whether or not the USB CDC serial connection is open. For all non-USB CDC ports, this will always return true
if (!(isSerialCanRX() && Serial)) return; // arduino docs: `if (Serial)` indicates whether or not the USB CDC serial connection is open. For all non-USB CDC ports, this will always return true

static auto state = AdaState::Header_A;
static uint16_t count = 0;
Expand Down
4 changes: 2 additions & 2 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
printSetFormCheckbox(settingsScript,PSTR("HB"),hueApplyBri);
printSetFormCheckbox(settingsScript,PSTR("HC"),hueApplyColor);
char hueErrorString[25];
switch (hueError)
switch (getHueError())
{
case HUE_ERROR_INACTIVE : strcpy_P(hueErrorString,PSTR("Inactive")); break;
case HUE_ERROR_ACTIVE : strcpy_P(hueErrorString,PSTR("Active")); break;
Expand All @@ -580,7 +580,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
case HUE_ERROR_PUSHLINK : strcpy_P(hueErrorString,PSTR("Link button not pressed")); break;
case HUE_ERROR_JSON_PARSING : strcpy_P(hueErrorString,PSTR("JSON parsing error")); break;
case HUE_ERROR_TIMEOUT : strcpy_P(hueErrorString,PSTR("Timeout")); break;
default: sprintf_P(hueErrorString,PSTR("Bridge Error %i"),hueError);
default: sprintf_P(hueErrorString,PSTR("Bridge Error %i"),getHueError());
}

printSetClassElementHTML(settingsScript,PSTR("sip"),0,hueErrorString);
Expand Down
Loading