Remove sync preset loading (ugly core check)
WS buffer check for ESP32-S2 Delay for Serial init on CDC USB
This commit is contained in:
parent
fb00bef05f
commit
7824f9ee63
@ -191,8 +191,8 @@ int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
|
|||||||
void handlePlaylist();
|
void handlePlaylist();
|
||||||
|
|
||||||
//presets.cpp
|
//presets.cpp
|
||||||
void handlePresets(bool force = false);
|
void handlePresets();
|
||||||
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE, bool fromJson = false);
|
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
|
||||||
inline bool applyTemporaryPreset() {return applyPreset(255);};
|
inline bool applyTemporaryPreset() {return applyPreset(255);};
|
||||||
void savePreset(byte index, const char* pname = nullptr, JsonObject saveobj = JsonObject());
|
void savePreset(byte index, const char* pname = nullptr, JsonObject saveobj = JsonObject());
|
||||||
inline void saveTemporaryPreset() {savePreset(255);};
|
inline void saveTemporaryPreset() {savePreset(255);};
|
||||||
|
@ -11,29 +11,36 @@ static char *tmpRAMbuffer = nullptr;
|
|||||||
static volatile byte presetToApply = 0;
|
static volatile byte presetToApply = 0;
|
||||||
static volatile byte callModeToApply = 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_PRINT(F("Request to apply preset: "));
|
||||||
DEBUG_PRINTLN(index);
|
DEBUG_PRINTLN(index);
|
||||||
presetToApply = index;
|
presetToApply = index;
|
||||||
callModeToApply = callMode;
|
callModeToApply = callMode;
|
||||||
|
/*
|
||||||
// the following is needed in case of HTTP JSON API call to return correct state to the caller
|
// 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
|
// fromJson is true in case when deserializeState() was called with presetId==0
|
||||||
if (fromJson) handlePresets(true); // force immediate processing
|
if (fromJson) handlePresets(true); // force immediate processing
|
||||||
|
*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlePresets(bool force)
|
void handlePresets()
|
||||||
{
|
{
|
||||||
bool changePreset = false;
|
bool changePreset = false;
|
||||||
uint8_t tmpPreset = presetToApply; // store temporary since deserializeState() may call applyPreset()
|
uint8_t tmpPreset = presetToApply; // store temporary since deserializeState() may call applyPreset()
|
||||||
uint8_t tmpMode = callModeToApply;
|
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;
|
JsonObject fdo;
|
||||||
const char *filename = tmpPreset < 255 ? "/presets.json" : "/tmp.json";
|
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
|
//crude way to determine if this was called by a network request
|
||||||
uint8_t core = 1;
|
uint8_t core = 1;
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#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
|
if (force) return; // something went wrong with force option (most likely WS request), quit and wait for async load
|
||||||
|
*/
|
||||||
// allocate buffer
|
// allocate buffer
|
||||||
if (!requestJSONBufferLock(9)) return; // will also assign fileDoc
|
if (!requestJSONBufferLock(9)) return; // will also assign fileDoc
|
||||||
|
|
||||||
|
@ -267,6 +267,9 @@ void WLED::setup()
|
|||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.setTimeout(50);
|
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_PRINTLN();
|
||||||
DEBUG_PRINT(F("---WLED "));
|
DEBUG_PRINT(F("---WLED "));
|
||||||
DEBUG_PRINT(versionString);
|
DEBUG_PRINT(versionString);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// 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
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
@ -111,13 +111,18 @@ void sendDataWs(AsyncWebSocketClient * client)
|
|||||||
DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len);
|
DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len);
|
||||||
|
|
||||||
size_t heap1 = ESP.getFreeHeap();
|
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();
|
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<len) {
|
if (!buffer || heap1-heap2<len) {
|
||||||
releaseJSONBufferLock();
|
releaseJSONBufferLock();
|
||||||
DEBUG_PRINTLN(F("WS buffer allocation failed."));
|
DEBUG_PRINTLN(F("WS buffer allocation failed."));
|
||||||
ws.closeAll(1013); //code 1013 = temporary overload, try again later
|
ws.closeAll(1013); //code 1013 = temporary overload, try again later
|
||||||
ws.cleanupClients(0); //disconnect all clients to release memory
|
ws.cleanupClients(0); //disconnect all clients to release memory
|
||||||
|
ws._cleanBuffers();
|
||||||
return; //out of memory
|
return; //out of memory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user