diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index d0073f85..fe702fa3 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -191,8 +191,8 @@ int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0); void handlePlaylist(); //presets.cpp -void handlePresets(bool force = false); -bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE, bool fromJson = false); +void handlePresets(); +bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE); inline bool applyTemporaryPreset() {return applyPreset(255);}; void savePreset(byte index, const char* pname = nullptr, JsonObject saveobj = JsonObject()); inline void saveTemporaryPreset() {savePreset(255);}; diff --git a/wled00/presets.cpp b/wled00/presets.cpp index 30aaeb3e..748cbd2c 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -11,29 +11,36 @@ static char *tmpRAMbuffer = nullptr; static volatile byte presetToApply = 0; static volatile byte callModeToApply = 0; -bool applyPreset(byte index, byte callMode, bool fromJson) +bool applyPreset(byte index, byte callMode) { DEBUG_PRINT(F("Request to apply preset: ")); DEBUG_PRINTLN(index); presetToApply = index; callModeToApply = callMode; +/* // the following is needed in case of HTTP JSON API call to return correct state to the caller // fromJson is true in case when deserializeState() was called with presetId==0 if (fromJson) handlePresets(true); // force immediate processing +*/ return true; } -void handlePresets(bool force) +void handlePresets() { bool changePreset = false; uint8_t tmpPreset = presetToApply; // store temporary since deserializeState() may call applyPreset() uint8_t tmpMode = callModeToApply; - if (tmpPreset == 0 || (fileDoc && !force)) return; // JSON buffer already allocated and not force apply or no preset waiting + if (tmpPreset == 0 || (fileDoc /*&& !force*/)) return; // JSON buffer already allocated and not force apply or no preset waiting JsonObject fdo; const char *filename = tmpPreset < 255 ? "/presets.json" : "/tmp.json"; +/* + * The following code is no longer needed as handlePreset() is never run from + * network callback. + * ************************************************************************** + * //crude way to determine if this was called by a network request uint8_t core = 1; #ifdef ARDUINO_ARCH_ESP32 @@ -80,7 +87,7 @@ void handlePresets(bool force) } if (force) return; // something went wrong with force option (most likely WS request), quit and wait for async load - +*/ // allocate buffer if (!requestJSONBufferLock(9)) return; // will also assign fileDoc diff --git a/wled00/wled.cpp b/wled00/wled.cpp index f0788c55..47c0ed02 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -267,6 +267,9 @@ void WLED::setup() Serial.begin(115200); Serial.setTimeout(50); + #if defined(WLED_DEBUG) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)) + delay(2500); // allow CDC USB serial to initialise + #endif DEBUG_PRINTLN(); DEBUG_PRINT(F("---WLED ")); DEBUG_PRINT(versionString); diff --git a/wled00/wled.h b/wled00/wled.h index 8da85147..1212134b 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2209161 +#define VERSION 2209191 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/ws.cpp b/wled00/ws.cpp index 0f3cbabe..8c1a9d3d 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -111,13 +111,18 @@ void sendDataWs(AsyncWebSocketClient * client) DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len); size_t heap1 = ESP.getFreeHeap(); - buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes + buffer = ws.makeBuffer(len); // will not allocate correct memory sometimes on ESP8266 + #ifdef ESP8266 size_t heap2 = ESP.getFreeHeap(); + #else + size_t heap2 = 0; // ESP32 variants do not have the same issue and will work without checking heap allocation + #endif if (!buffer || heap1-heap2